diff options
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r-- | src/features/workspaces/store.js | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index bddcb6eb4..632f3c299 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -1,8 +1,4 @@ | |||
1 | import { | 1 | import { computed, observable, action } from 'mobx'; |
2 | computed, | ||
3 | observable, | ||
4 | action, | ||
5 | } from 'mobx'; | ||
6 | import localStorage from 'mobx-localstorage'; | 2 | import localStorage from 'mobx-localstorage'; |
7 | import { matchRoute } from '../../helpers/routing-helpers'; | 3 | import { matchRoute } from '../../helpers/routing-helpers'; |
8 | import { workspaceActions } from './actions'; | 4 | import { workspaceActions } from './actions'; |
@@ -105,7 +101,10 @@ export default class WorkspacesStore extends FeatureStore { | |||
105 | [workspaceActions.update, this._update], | 101 | [workspaceActions.update, this._update], |
106 | [workspaceActions.activate, this._setActiveWorkspace], | 102 | [workspaceActions.activate, this._setActiveWorkspace], |
107 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], | 103 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], |
108 | [workspaceActions.toggleKeepAllWorkspacesLoadedSetting, this._toggleKeepAllWorkspacesLoadedSetting], | 104 | [ |
105 | workspaceActions.toggleKeepAllWorkspacesLoadedSetting, | ||
106 | this._toggleKeepAllWorkspacesLoadedSetting, | ||
107 | ], | ||
109 | ]); | 108 | ]); |
110 | this._allActions = this._freeUserActions.concat(this._premiumUserActions); | 109 | this._allActions = this._freeUserActions.concat(this._premiumUserActions); |
111 | this._registerActions(this._allActions); | 110 | this._registerActions(this._allActions); |
@@ -124,7 +123,9 @@ export default class WorkspacesStore extends FeatureStore { | |||
124 | this._activateLastUsedWorkspaceReaction, | 123 | this._activateLastUsedWorkspaceReaction, |
125 | this._setWorkspaceBeingEditedReaction, | 124 | this._setWorkspaceBeingEditedReaction, |
126 | ]); | 125 | ]); |
127 | this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions); | 126 | this._allReactions = this._freeUserReactions.concat( |
127 | this._premiumUserReactions, | ||
128 | ); | ||
128 | 129 | ||
129 | this._registerReactions(this._allReactions); | 130 | this._registerReactions(this._allReactions); |
130 | 131 | ||
@@ -157,12 +158,12 @@ export default class WorkspacesStore extends FeatureStore { | |||
157 | 158 | ||
158 | getWorkspaceServices(workspace) { | 159 | getWorkspaceServices(workspace) { |
159 | const { services } = this.stores; | 160 | const { services } = this.stores; |
160 | return workspace.services.map(id => services.one(id)).filter(s => !!s); | 161 | return workspace.services.map((id) => services.one(id)).filter((s) => !!s); |
161 | } | 162 | } |
162 | 163 | ||
163 | // ========== PRIVATE METHODS ========= // | 164 | // ========== PRIVATE METHODS ========= // |
164 | 165 | ||
165 | _getWorkspaceById = id => this.workspaces.find(w => w.id === id); | 166 | _getWorkspaceById = (id) => this.workspaces.find((w) => w.id === id); |
166 | 167 | ||
167 | _updateSettings = (changes) => { | 168 | _updateSettings = (changes) => { |
168 | localStorage.setItem('workspaces', { | 169 | localStorage.setItem('workspaces', { |
@@ -178,6 +179,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
178 | }; | 179 | }; |
179 | 180 | ||
180 | @action _create = async ({ name }) => { | 181 | @action _create = async ({ name }) => { |
182 | // eslint-disable-next-line no-useless-catch | ||
181 | try { | 183 | try { |
182 | const workspace = await createWorkspaceRequest.execute(name); | 184 | const workspace = await createWorkspaceRequest.execute(name); |
183 | await getUserWorkspacesRequest.result.push(workspace); | 185 | await getUserWorkspacesRequest.result.push(workspace); |
@@ -188,6 +190,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
188 | }; | 190 | }; |
189 | 191 | ||
190 | @action _delete = async ({ workspace }) => { | 192 | @action _delete = async ({ workspace }) => { |
193 | // eslint-disable-next-line no-useless-catch | ||
191 | try { | 194 | try { |
192 | await deleteWorkspaceRequest.execute(workspace); | 195 | await deleteWorkspaceRequest.execute(workspace); |
193 | await getUserWorkspacesRequest.result.remove(workspace); | 196 | await getUserWorkspacesRequest.result.remove(workspace); |
@@ -198,6 +201,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
198 | }; | 201 | }; |
199 | 202 | ||
200 | @action _update = async ({ workspace }) => { | 203 | @action _update = async ({ workspace }) => { |
204 | // eslint-disable-next-line no-useless-catch | ||
201 | try { | 205 | try { |
202 | await updateWorkspaceRequest.execute(workspace); | 206 | await updateWorkspaceRequest.execute(workspace); |
203 | // Path local result optimistically | 207 | // Path local result optimistically |
@@ -235,7 +239,9 @@ export default class WorkspacesStore extends FeatureStore { | |||
235 | this.activeWorkspace = null; | 239 | this.activeWorkspace = null; |
236 | }, 100); | 240 | }, 100); |
237 | // Indicate that we are done switching to the default workspace | 241 | // Indicate that we are done switching to the default workspace |
238 | setTimeout(() => { this.isSwitchingWorkspace = false; }, 1000); | 242 | setTimeout(() => { |
243 | this.isSwitchingWorkspace = false; | ||
244 | }, 1000); | ||
239 | }; | 245 | }; |
240 | 246 | ||
241 | @action _toggleWorkspaceDrawer = () => { | 247 | @action _toggleWorkspaceDrawer = () => { |
@@ -255,7 +261,9 @@ export default class WorkspacesStore extends FeatureStore { | |||
255 | }; | 261 | }; |
256 | 262 | ||
257 | _toggleKeepAllWorkspacesLoadedSetting = async () => { | 263 | _toggleKeepAllWorkspacesLoadedSetting = async () => { |
258 | this._updateSettings({ keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded }); | 264 | this._updateSettings({ |
265 | keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded, | ||
266 | }); | ||
259 | }; | 267 | }; |
260 | 268 | ||
261 | // Reactions | 269 | // Reactions |
@@ -309,7 +317,9 @@ export default class WorkspacesStore extends FeatureStore { | |||
309 | 317 | ||
310 | _openDrawerWithSettingsReaction = () => { | 318 | _openDrawerWithSettingsReaction = () => { |
311 | const { router } = this.stores; | 319 | const { router } = this.stores; |
312 | const isWorkspaceSettingsRoute = router.location.pathname.includes(WORKSPACES_ROUTES.ROOT); | 320 | const isWorkspaceSettingsRoute = router.location.pathname.includes( |
321 | WORKSPACES_ROUTES.ROOT, | ||
322 | ); | ||
313 | const isSwitchingToSettingsRoute = !this.isSettingsRouteActive && isWorkspaceSettingsRoute; | 323 | const isSwitchingToSettingsRoute = !this.isSettingsRouteActive && isWorkspaceSettingsRoute; |
314 | const isLeavingSettingsRoute = !isWorkspaceSettingsRoute && this.isSettingsRouteActive; | 324 | const isLeavingSettingsRoute = !isWorkspaceSettingsRoute && this.isSettingsRouteActive; |
315 | 325 | ||
@@ -321,7 +331,10 @@ export default class WorkspacesStore extends FeatureStore { | |||
321 | } | 331 | } |
322 | } else if (isLeavingSettingsRoute) { | 332 | } else if (isLeavingSettingsRoute) { |
323 | this.isSettingsRouteActive = false; | 333 | this.isSettingsRouteActive = false; |
324 | if (!this._wasDrawerOpenBeforeSettingsRoute && this.isWorkspaceDrawerOpen) { | 334 | if ( |
335 | !this._wasDrawerOpenBeforeSettingsRoute | ||
336 | && this.isWorkspaceDrawerOpen | ||
337 | ) { | ||
325 | workspaceActions.toggleWorkspaceDrawer(); | 338 | workspaceActions.toggleWorkspaceDrawer(); |
326 | } | 339 | } |
327 | } | 340 | } |
@@ -334,7 +347,11 @@ export default class WorkspacesStore extends FeatureStore { | |||
334 | // Loop through all workspaces and remove invalid service ids (locally) | 347 | // Loop through all workspaces and remove invalid service ids (locally) |
335 | this.workspaces.forEach((workspace) => { | 348 | this.workspaces.forEach((workspace) => { |
336 | workspace.services.forEach((serviceId) => { | 349 | workspace.services.forEach((serviceId) => { |
337 | if (servicesHaveBeenLoaded && !services.one(serviceId) && serviceId !== KEEP_WS_LOADED_USID) { | 350 | if ( |
351 | servicesHaveBeenLoaded | ||
352 | && !services.one(serviceId) | ||
353 | && serviceId !== KEEP_WS_LOADED_USID | ||
354 | ) { | ||
338 | workspace.services.remove(serviceId); | 355 | workspace.services.remove(serviceId); |
339 | } | 356 | } |
340 | }); | 357 | }); |
@@ -351,5 +368,5 @@ export default class WorkspacesStore extends FeatureStore { | |||
351 | this._startActions(this._premiumUserActions); | 368 | this._startActions(this._premiumUserActions); |
352 | this._startReactions(this._premiumUserReactions); | 369 | this._startReactions(this._premiumUserReactions); |
353 | } | 370 | } |
354 | } | 371 | }; |
355 | } | 372 | } |