Skip to content

Commit

Permalink
change index to graphIndex in update selected variables payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Jun 27, 2024
1 parent 90c9c08 commit 01adf76
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/static/src/app/components/code/SelectedVariables.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default defineComponent({
const updateSelectedVariables = (newVariables: string[]) => {
store.dispatch(`graphs/${GraphsAction.UpdateSelectedVariables}`, {
index: 0,
graphIndex: 0,
selectedVariables: newVariables
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/graphs/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum GraphsAction {
}

export const actions: ActionTree<GraphsState, AppState> = {
UpdateSelectedVariables(context, payload: { index: number; selectedVariables: string[] }) {
UpdateSelectedVariables(context, payload: { graphIndex: number; selectedVariables: string[] }) {
const { commit, dispatch, rootState } = context;
// Maintain unselected variables too, so we know which variables had been explicitly unselected when model
// updates
Expand Down
6 changes: 3 additions & 3 deletions app/static/src/app/store/graphs/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum GraphsMutation {
}

export interface SetSelectedVariablesPayload {
index: number;
graphIndex: number;
selectedVariables: string[];
unselectedVariables: string[];
}
Expand All @@ -29,7 +29,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.index].selectedVariables = payload.selectedVariables;
state.config[payload.index].unselectedVariables = payload.unselectedVariables;
state.config[payload.graphIndex].selectedVariables = payload.selectedVariables;
state.config[payload.graphIndex].unselectedVariables = payload.unselectedVariables;
}
};
2 changes: 1 addition & 1 deletion app/static/src/app/store/model/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const compileModelAndUpdateStore = (context: ActionContext<ModelState, AppState>

// Retain variable selections. Newly added variables will be selected by default in the first graph
const selectedVariables = variables.filter((s) => !rootState.graphs.config[0].unselectedVariables.includes(s));
dispatch(`graphs/${GraphsAction.UpdateSelectedVariables}`, { index: 0, selectedVariables }, { root: true });
dispatch(`graphs/${GraphsAction.UpdateSelectedVariables}`, { graphIndex: 0, selectedVariables }, { root: true });

Check failure on line 73 in app/static/src/app/store/model/actions.ts

View workflow job for this annotation

GitHub Actions / test

This line has a length of 121. Maximum allowed is 120

if (state.compileRequired) {
commit(ModelMutation.SetCompileRequired, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("SelectedVariables", () => {
const s = wrapper.findAll(".selected-variables-panel span.variable").at(0)!;
await s.trigger("click");
expect(mockUpdateSelectedVariables).toBeCalledTimes(1);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: ["R"] });
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["R"] });
});

it("clicking an unselected variables selects it", async () => {
Expand All @@ -82,7 +82,7 @@ describe("SelectedVariables", () => {
await i.trigger("click");
expect(mockUpdateSelectedVariables).toBeCalledTimes(1);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({
index: 0,
graphIndex: 0,
selectedVariables: ["S", "R", "I"]
});
});
Expand All @@ -92,7 +92,7 @@ describe("SelectedVariables", () => {
wrapper.find("span#select-variables-all").trigger("click");
expect(mockUpdateSelectedVariables).toBeCalledTimes(1);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({
index: 0,
graphIndex: 0,
selectedVariables: ["S", "I", "R"]
});
});
Expand All @@ -101,6 +101,6 @@ describe("SelectedVariables", () => {
const wrapper = getWrapper();
wrapper.find("span#select-variables-none").trigger("click");
expect(mockUpdateSelectedVariables).toBeCalledTimes(1);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: [] });
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: [] });
});
});
8 changes: 4 additions & 4 deletions app/static/tests/unit/store/graphs/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ describe("Graphs actions", () => {
state,
rootState
},
{ index: 1, selectedVariables: ["a", "b"] }
{ graphIndex: 1, selectedVariables: ["a", "b"] }
);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(GraphsMutation.SetSelectedVariables);
expect(commit.mock.calls[0][1]).toStrictEqual({
index: 1,
graphIndex: 1,
selectedVariables: ["a", "b"],
unselectedVariables: ["c"]
});
Expand All @@ -61,12 +61,12 @@ describe("Graphs actions", () => {
state,
rootState: fitRootState
},
{ index: 1, selectedVariables: ["a", "b"] }
{ graphIndex: 1, selectedVariables: ["a", "b"] }
);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(GraphsMutation.SetSelectedVariables);
expect(commit.mock.calls[0][1]).toStrictEqual({
index: 1,
graphIndex: 1,
selectedVariables: ["a", "b"],
unselectedVariables: ["c"]
});
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/store/graphs/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Graphs mutations", () => {
]
});
mutations.SetSelectedVariables(testState, {
index: 1,
graphIndex: 1,
selectedVariables: ["x", "z"],
unselectedVariables: ["y"]
});
Expand Down
10 changes: 5 additions & 5 deletions app/static/tests/unit/store/model/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("Model actions", () => {
// does not dispatch updated linked variables or update params to vary if app type is not Fit
expect(dispatch.mock.calls.length).toBe(1);
expect(dispatch.mock.calls[0][0]).toBe(`graphs/${GraphsAction.UpdateSelectedVariables}`);
expect(dispatch.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: ["x", "y", "z"] });
expect(dispatch.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["x", "y", "z"] });
});

it("does not set multi-sensitivity update required or parameter to vary when multiSensitivity not enabled", () => {
Expand Down Expand Up @@ -333,7 +333,7 @@ describe("Model actions", () => {

expect(dispatch).toHaveBeenCalledTimes(3);
expect(dispatch.mock.calls[0][0]).toBe(`graphs/${GraphsAction.UpdateSelectedVariables}`);
expect(dispatch.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: ["x", "y"] });
expect(dispatch.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["x", "y"] });
expect(dispatch.mock.calls[1][0]).toBe(`fitData/${FitDataAction.UpdateLinkedVariables}`);
expect(dispatch.mock.calls[2][0]).toBe(`modelFit/${ModelFitAction.UpdateParamsToVary}`);
});
Expand Down Expand Up @@ -393,7 +393,7 @@ describe("Model actions", () => {

expect(dispatch.mock.calls.length).toBe(1);
expect(dispatch.mock.calls[0][0]).toBe(`graphs/${GraphsAction.UpdateSelectedVariables}`);
expect(dispatch.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: ["x", "y"] });
expect(dispatch.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["x", "y"] });
});

it("compile model does not update runRequired or compileRequired if compileRequired was false", () => {
Expand Down Expand Up @@ -423,7 +423,7 @@ describe("Model actions", () => {

expect(dispatch.mock.calls.length).toBe(1);
expect(dispatch.mock.calls[0][0]).toBe(`graphs/${GraphsAction.UpdateSelectedVariables}`);
expect(dispatch.mock.calls[0][1]).toStrictEqual({ index: 0, selectedVariables: ["x", "y"] });
expect(dispatch.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["x", "y"] });
});

it("compile model does nothing if no odin response", () => {
Expand Down Expand Up @@ -554,7 +554,7 @@ describe("Model actions", () => {

expect(dispatch.mock.calls.length).toBe(3);
expect(dispatch.mock.calls[1][0]).toBe(`graphs/${GraphsAction.UpdateSelectedVariables}`);
expect(dispatch.mock.calls[1][1]).toStrictEqual({ index: 0, selectedVariables: ["x", "y"] });
expect(dispatch.mock.calls[1][1]).toStrictEqual({ graphIndex: 0, selectedVariables: ["x", "y"] });

expect(dispatch.mock.calls[2][0]).toBe(`run/${RunAction.RunModel}`);
});
Expand Down

0 comments on commit 01adf76

Please sign in to comment.