aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/models/Workspace.ts
blob: bc636011dc1e151f532d8585d80d09fa87921313 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { observable } from 'mobx';

import { KEEP_WS_LOADED_USID } from '../../../config';

export default class Workspace {
  id = null;

  @observable name = null;

  @observable order = null;

  @observable services: string[] = [];

  @observable userId = null;

  constructor(data) {
    if (!data.id) {
      throw new Error('Workspace requires Id');
    }

    this.id = data.id;
    this.name = data.name;
    this.order = data.order;

    let { services } = data;
    if (data.saving && Boolean(data.keepLoaded)) {
      // Keep workspaces loaded
      services.push(KEEP_WS_LOADED_USID);
    } else if (data.saving && data.services.includes(KEEP_WS_LOADED_USID)) {
      // Don't keep loaded
      services = services.filter(e => e !== KEEP_WS_LOADED_USID);
    }

    // @ts-expect-error Property 'replace' does not exist on type 'never[]'.
    this.services.replace(services);

    this.userId = data.userId;
  }
}