diff options
author | 2019-04-10 17:17:02 +0200 | |
---|---|---|
committer | 2019-04-10 17:17:02 +0200 | |
commit | adf5ac074626dac5bfec9d8fb54b28149e492e1b (patch) | |
tree | 9cab9697096bef0ce56d8ee8709bc1c2c3a42deb /src | |
parent | merge conflicts with latest develop (diff) | |
download | ferdium-app-adf5ac074626dac5bfec9d8fb54b28149e492e1b.tar.gz ferdium-app-adf5ac074626dac5bfec9d8fb54b28149e492e1b.tar.zst ferdium-app-adf5ac074626dac5bfec9d8fb54b28149e492e1b.zip |
handle deleted services that are attached to workspaces
Diffstat (limited to 'src')
-rw-r--r-- | src/containers/layout/AppLayoutContainer.js | 2 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 32 | ||||
-rw-r--r-- | src/i18n/locales/en-US.json | 2 |
3 files changed, 27 insertions, 9 deletions
diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index 52d4e0c27..2d855c78f 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js | |||
@@ -88,7 +88,7 @@ export default @inject('stores', 'actions') @observer class AppLayoutContainer e | |||
88 | const workspacesDrawer = ( | 88 | const workspacesDrawer = ( |
89 | <WorkspaceDrawer | 89 | <WorkspaceDrawer |
90 | getServicesForWorkspace={workspace => ( | 90 | getServicesForWorkspace={workspace => ( |
91 | workspace ? workspace.services.map(id => services.one(id).name) : services.all.map(s => s.name) | 91 | workspace ? workspaceStore.getWorkspaceServices(workspace).map(s => s.name) : services.all.map(s => s.name) |
92 | )} | 92 | )} |
93 | onUpgradeAccountClick={() => openSettings({ path: 'user' })} | 93 | onUpgradeAccountClick={() => openSettings({ path: 'user' })} |
94 | /> | 94 | /> |
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 | } |
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index da7649b90..84a71117a 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json | |||
@@ -317,4 +317,4 @@ | |||
317 | "workspaceDrawer.workspaceFeatureInfo": "<p>Franz Workspaces let you focus on what’s important right now. Set up different sets of services and easily switch between them at any time.</p><p>You decide which services you need when and where, so we can help you stay on top of your game - or easily switch off from work whenever you want.</p>", | 317 | "workspaceDrawer.workspaceFeatureInfo": "<p>Franz Workspaces let you focus on what’s important right now. Set up different sets of services and easily switch between them at any time.</p><p>You decide which services you need when and where, so we can help you stay on top of your game - or easily switch off from work whenever you want.</p>", |
318 | "workspaceDrawer.workspacesSettingsTooltip": "Edit workspaces settings", | 318 | "workspaceDrawer.workspacesSettingsTooltip": "Edit workspaces settings", |
319 | "workspaces.switchingIndicator.switchingTo": "Switching to" | 319 | "workspaces.switchingIndicator.switchingTo": "Switching to" |
320 | } | 320 | } \ No newline at end of file |