Skip to content

Commit

Permalink
fix(Workspaces): Service reordering within workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed May 8, 2019
1 parent 6cdcafe commit 17f3a22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/features/workspaces/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export default class WorkspacesStore extends FeatureStore {
return !this.isPremiumUpgradeRequired;
}

@computed get isAnyWorkspaceActive() {
return !!this.activeWorkspace;
}

// ========== PRIVATE PROPERTIES ========= //

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

@action reorderServicesOfActiveWorkspace = async ({ oldIndex, newIndex }) => {
const { activeWorkspace } = this;
const { services } = activeWorkspace;
// Move services from the old to the new position
services.splice(newIndex, 0, services.splice(oldIndex, 1)[0]);
await updateWorkspaceRequest.execute(activeWorkspace);
};

// Reactions

_setFeatureEnabledReaction = () => {
Expand Down
11 changes: 10 additions & 1 deletion src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,16 @@ export default class ServicesStore extends Store {
this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false });
}

@action _reorder({ oldIndex, newIndex }) {
@action _reorder(params) {
const { workspaces } = this.stores;
if (workspaces.isAnyWorkspaceActive) {
workspaces.reorderServicesOfActiveWorkspace(params);
} else {
this._reorderService(params);
}
}

@action _reorderService({ oldIndex, newIndex }) {
const showDisabledServices = this.stores.settings.all.app.showDisabledServices;
const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
Expand Down

0 comments on commit 17f3a22

Please sign in to comment.