diff options
Diffstat (limited to 'src/features/workspaces/models/Workspace.ts')
-rw-r--r-- | src/features/workspaces/models/Workspace.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/features/workspaces/models/Workspace.ts b/src/features/workspaces/models/Workspace.ts new file mode 100644 index 000000000..cd3918fba --- /dev/null +++ b/src/features/workspaces/models/Workspace.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | |||
3 | import { KEEP_WS_LOADED_USID } from '../../../config'; | ||
4 | |||
5 | export default class Workspace { | ||
6 | id = null; | ||
7 | |||
8 | @observable name = null; | ||
9 | |||
10 | @observable order = null; | ||
11 | |||
12 | @observable services = []; | ||
13 | |||
14 | @observable userId = null; | ||
15 | |||
16 | constructor(data) { | ||
17 | if (!data.id) { | ||
18 | throw new Error('Workspace requires Id'); | ||
19 | } | ||
20 | |||
21 | this.id = data.id; | ||
22 | this.name = data.name; | ||
23 | this.order = data.order; | ||
24 | |||
25 | let { services } = data; | ||
26 | if (data.saving && Boolean(data.keepLoaded)) { | ||
27 | // Keep workspaces loaded | ||
28 | services.push(KEEP_WS_LOADED_USID); | ||
29 | } else if (data.saving && data.services.includes(KEEP_WS_LOADED_USID)) { | ||
30 | // Don't keep loaded | ||
31 | services = services.filter(e => e !== KEEP_WS_LOADED_USID); | ||
32 | } | ||
33 | |||
34 | // @ts-expect-error Property 'replace' does not exist on type 'never[]'. | ||
35 | this.services.replace(services); | ||
36 | |||
37 | this.userId = data.userId; | ||
38 | } | ||
39 | } | ||