aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index ba48022c2..ea601700e 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -74,6 +74,7 @@ export default class WorkspacesStore extends FeatureStore {
74 this._setIsPremiumFeatureReaction, 74 this._setIsPremiumFeatureReaction,
75 this._activateLastUsedWorkspaceReaction, 75 this._activateLastUsedWorkspaceReaction,
76 this._openDrawerWithSettingsReaction, 76 this._openDrawerWithSettingsReaction,
77 this._cleanupInvalidServiceReferences,
77 ]); 78 ]);
78 79
79 getUserWorkspacesRequest.execute(); 80 getUserWorkspacesRequest.execute();
@@ -92,16 +93,17 @@ export default class WorkspacesStore extends FeatureStore {
92 93
93 filterServicesByActiveWorkspace = (services) => { 94 filterServicesByActiveWorkspace = (services) => {
94 const { activeWorkspace, isFeatureActive } = this; 95 const { activeWorkspace, isFeatureActive } = this;
95 96 if (isFeatureActive && activeWorkspace) {
96 if (!isFeatureActive) return services; 97 return this.getWorkspaceServices(activeWorkspace);
97 if (activeWorkspace) {
98 return services.filter(s => (
99 activeWorkspace.services.includes(s.id)
100 ));
101 } 98 }
102 return services; 99 return services;
103 }; 100 };
104 101
102 getWorkspaceServices(workspace) {
103 const { services } = this.stores;
104 return workspace.services.map(id => services.one(id)).filter(s => !!s);
105 }
106
105 // ========== PRIVATE ========= // 107 // ========== PRIVATE ========= //
106 108
107 _wasDrawerOpenBeforeSettingsRoute = null; 109 _wasDrawerOpenBeforeSettingsRoute = null;
@@ -218,7 +220,8 @@ export default class WorkspacesStore extends FeatureStore {
218 if (this.activeWorkspace) { 220 if (this.activeWorkspace) {
219 const services = this.stores.services.allDisplayed; 221 const services = this.stores.services.allDisplayed;
220 const activeService = services.find(s => s.isActive); 222 const activeService = services.find(s => s.isActive);
221 const workspaceServices = this.filterServicesByActiveWorkspace(services); 223 const workspaceServices = this.getWorkspaceServices(this.activeWorkspace);
224 if (workspaceServices.length <= 0) return;
222 const isActiveServiceInWorkspace = workspaceServices.includes(activeService); 225 const isActiveServiceInWorkspace = workspaceServices.includes(activeService);
223 if (!isActiveServiceInWorkspace) { 226 if (!isActiveServiceInWorkspace) {
224 this.actions.service.setActive({ serviceId: workspaceServices[0].id }); 227 this.actions.service.setActive({ serviceId: workspaceServices[0].id });
@@ -255,4 +258,19 @@ export default class WorkspacesStore extends FeatureStore {
255 } 258 }
256 } 259 }
257 }; 260 };
261
262 _cleanupInvalidServiceReferences = () => {
263 const { services } = this.stores;
264 let invalidServiceReferencesExist = false;
265 this.workspaces.forEach((workspace) => {
266 workspace.services.forEach((serviceId) => {
267 if (!services.one(serviceId)) {
268 invalidServiceReferencesExist = true;
269 }
270 });
271 });
272 if (invalidServiceReferencesExist) {
273 getUserWorkspacesRequest.execute();
274 }
275 };
258} 276}