diff options
Diffstat (limited to 'src/features/workspaces')
-rw-r--r-- | src/features/workspaces/store.js | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index e11513d1f..07b16ff23 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -57,6 +57,10 @@ export default class WorkspacesStore extends FeatureStore { | |||
57 | return !this.isPremiumUpgradeRequired; | 57 | return !this.isPremiumUpgradeRequired; |
58 | } | 58 | } |
59 | 59 | ||
60 | @computed get isAnyWorkspaceActive() { | ||
61 | return !!this.activeWorkspace; | ||
62 | } | ||
63 | |||
60 | // ========== PRIVATE PROPERTIES ========= // | 64 | // ========== PRIVATE PROPERTIES ========= // |
61 | 65 | ||
62 | _wasDrawerOpenBeforeSettingsRoute = null; | 66 | _wasDrawerOpenBeforeSettingsRoute = null; |
@@ -229,6 +233,14 @@ export default class WorkspacesStore extends FeatureStore { | |||
229 | this.actions.ui.openSettings({ path: 'workspaces' }); | 233 | this.actions.ui.openSettings({ path: 'workspaces' }); |
230 | }; | 234 | }; |
231 | 235 | ||
236 | @action reorderServicesOfActiveWorkspace = async ({ oldIndex, newIndex }) => { | ||
237 | const { activeWorkspace } = this; | ||
238 | const { services } = activeWorkspace; | ||
239 | // Move services from the old to the new position | ||
240 | services.splice(newIndex, 0, services.splice(oldIndex, 1)[0]); | ||
241 | await updateWorkspaceRequest.execute(activeWorkspace); | ||
242 | }; | ||
243 | |||
232 | // Reactions | 244 | // Reactions |
233 | 245 | ||
234 | _setFeatureEnabledReaction = () => { | 246 | _setFeatureEnabledReaction = () => { |
@@ -255,13 +267,15 @@ export default class WorkspacesStore extends FeatureStore { | |||
255 | _setActiveServiceOnWorkspaceSwitchReaction = () => { | 267 | _setActiveServiceOnWorkspaceSwitchReaction = () => { |
256 | if (!this.isFeatureActive) return; | 268 | if (!this.isFeatureActive) return; |
257 | if (this.activeWorkspace) { | 269 | if (this.activeWorkspace) { |
258 | const services = this.stores.services.allDisplayed; | 270 | const activeService = this.stores.services.active; |
259 | const activeService = services.find(s => s.isActive); | ||
260 | const workspaceServices = this.getWorkspaceServices(this.activeWorkspace); | 271 | const workspaceServices = this.getWorkspaceServices(this.activeWorkspace); |
261 | if (workspaceServices.length <= 0) return; | 272 | if (workspaceServices.length <= 0) return; |
262 | const isActiveServiceInWorkspace = workspaceServices.includes(activeService); | 273 | const isActiveServiceInWorkspace = workspaceServices.includes(activeService); |
263 | if (!isActiveServiceInWorkspace) { | 274 | if (!isActiveServiceInWorkspace) { |
264 | this.actions.service.setActive({ serviceId: workspaceServices[0].id }); | 275 | this.actions.service.setActive({ |
276 | serviceId: workspaceServices[0].id, | ||
277 | keepActiveRoute: true, | ||
278 | }); | ||
265 | } | 279 | } |
266 | } | 280 | } |
267 | }; | 281 | }; |
@@ -298,17 +312,16 @@ export default class WorkspacesStore extends FeatureStore { | |||
298 | 312 | ||
299 | _cleanupInvalidServiceReferences = () => { | 313 | _cleanupInvalidServiceReferences = () => { |
300 | const { services } = this.stores; | 314 | const { services } = this.stores; |
301 | let invalidServiceReferencesExist = false; | 315 | const { allServicesRequest } = services; |
316 | const servicesHaveBeenLoaded = allServicesRequest.wasExecuted && !allServicesRequest.isError; | ||
317 | // Loop through all workspaces and remove invalid service ids (locally) | ||
302 | this.workspaces.forEach((workspace) => { | 318 | this.workspaces.forEach((workspace) => { |
303 | workspace.services.forEach((serviceId) => { | 319 | workspace.services.forEach((serviceId) => { |
304 | if (!services.one(serviceId)) { | 320 | if (servicesHaveBeenLoaded && !services.one(serviceId)) { |
305 | invalidServiceReferencesExist = true; | 321 | workspace.services.remove(serviceId); |
306 | } | 322 | } |
307 | }); | 323 | }); |
308 | }); | 324 | }); |
309 | if (invalidServiceReferencesExist) { | ||
310 | getUserWorkspacesRequest.execute(); | ||
311 | } | ||
312 | }; | 325 | }; |
313 | 326 | ||
314 | _stopPremiumActionsAndReactions = () => { | 327 | _stopPremiumActionsAndReactions = () => { |