Skip to content

Commit

Permalink
variable order should match that in mode
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Jun 27, 2024
1 parent 1d7ea2d commit 644b537
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/static/src/app/store/graphs/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export const actions: ActionTree<GraphsState, AppState> = {
const { commit, dispatch, rootState } = context;
// Maintain unselected variables too, so we know which variables had been explicitly unselected when model
// updates
const allVariables = rootState.model.odinModelResponse?.metadata?.variables || [];
const unselectedVariables =
rootState.model.odinModelResponse?.metadata?.variables.filter(
(s) => !payload.selectedVariables.includes(s)
) || [];
commit(GraphsMutation.SetSelectedVariables, { ...payload, unselectedVariables });
// sort the selected variables to match the order in the model
const selectedVariables = payload.selectedVariables
.sort((a, b) => allVariables.indexOf(a) > allVariables.indexOf(b) ? 1 : -1);

commit(GraphsMutation.SetSelectedVariables, { ...payload, selectedVariables, unselectedVariables });
if (rootState.appType === AppType.Fit) {
dispatch(`fitData/${FitDataAction.UpdateLinkedVariables}`, null, { root: true });
}
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/graphs/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const mutations: MutationTree<GraphsState> = {

[GraphsMutation.SetSelectedVariables](state: GraphsState, payload: SetSelectedVariablesPayload) {
// We don't simply replace the GraphConfig in the index here, as that will eventually include GraphSettings too
state.config[payload.graphIndex].selectedVariables = payload.selectedVariables.sort();
state.config[payload.graphIndex].selectedVariables = payload.selectedVariables;
state.config[payload.graphIndex].unselectedVariables = payload.unselectedVariables;
},

Expand Down

0 comments on commit 644b537

Please sign in to comment.