Skip to content

Commit 17f3a22

Browse files
committed
fix(Workspaces): Service reordering within workspaces
1 parent 6cdcafe commit 17f3a22

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/features/workspaces/store.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export default class WorkspacesStore extends FeatureStore {
5757
return !this.isPremiumUpgradeRequired;
5858
}
5959

60+
@computed get isAnyWorkspaceActive() {
61+
return !!this.activeWorkspace;
62+
}
63+
6064
// ========== PRIVATE PROPERTIES ========= //
6165

6266
_wasDrawerOpenBeforeSettingsRoute = null;
@@ -229,6 +233,14 @@ export default class WorkspacesStore extends FeatureStore {
229233
this.actions.ui.openSettings({ path: 'workspaces' });
230234
};
231235

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+
232244
// Reactions
233245

234246
_setFeatureEnabledReaction = () => {

src/stores/ServicesStore.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,16 @@ export default class ServicesStore extends Store {
517517
this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false });
518518
}
519519

520-
@action _reorder({ oldIndex, newIndex }) {
520+
@action _reorder(params) {
521+
const { workspaces } = this.stores;
522+
if (workspaces.isAnyWorkspaceActive) {
523+
workspaces.reorderServicesOfActiveWorkspace(params);
524+
} else {
525+
this._reorderService(params);
526+
}
527+
}
528+
529+
@action _reorderService({ oldIndex, newIndex }) {
521530
const showDisabledServices = this.stores.settings.all.app.showDisabledServices;
522531
const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
523532
const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);

0 commit comments

Comments
 (0)