Skip to content

Commit

Permalink
show dialog when add a paramsetting - still need to fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Aug 31, 2023
1 parent 9a0c322 commit 543a1ff
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions app/static/src/app/components/options/SensitivityOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import { useStore } from "vuex";
import { computed, defineComponent, ref } from "vue";
import VueFeather from "vue-feather";
import { AppState } from "../../store/appState/state";
import { defaultSensitivityParamSettings } from "../../store/sensitivity/sensitivity";
import { MultiSensitivityGetter } from "../../store/multiSensitivity/getters";
import userMessages from "../../userMessages";
Expand Down Expand Up @@ -90,7 +91,9 @@ export default defineComponent({
EditParamSettings
},
setup(props) {
const store = useStore();
const store = useStore<AppState>();
const addingParamSettings = ref(false);
const multiSensitivitySettings = computed(() => store.state.multiSensitivity.paramSettings);
const allSettings = computed(() => (props.multiSensitivity ? multiSensitivitySettings.value
Expand All @@ -102,8 +105,23 @@ export default defineComponent({
const editSettingsIdx = ref<number | null>(0);
const title = computed(() => (`${props.multiSensitivity ? "Multi-sensitivity" : "Sensitivity"} Options`));
const settingsToEdit = computed(() => (editSettingsIdx.value === null ? null
: allSettings.value[editSettingsIdx.value]));
const paramsWithoutSettings = computed(() => {
const used = multiSensitivitySettings.value.map((p) => p.parameterToVary);
return Object.keys(store.state.run.parameterValues!).filter((p) => !used.includes(p));
});
const defaultNewSettings = computed(() => {
const unused = paramsWithoutSettings.value;
return { ...defaultSensitivityParamSettings(), parameterToVary: unused[0] };
});
const settingsToEdit = computed(() => {
if (addingParamSettings.value) {
return defaultNewSettings.value;
}
return editSettingsIdx.value === null ? null : allSettings.value[editSettingsIdx.value];
});
const openEdit = (settingsIdx: number) => {
editSettingsIdx.value = settingsIdx;
Expand All @@ -112,6 +130,7 @@ export default defineComponent({
const closeEdit = () => {
editSettingsIdx.value = null;
addingParamSettings.value = false;
editOpen.value = false;
};
Expand All @@ -123,28 +142,20 @@ export default defineComponent({
store.commit(`sensitivity/${SensitivityMutation.SetParamSettings}`, settings);
} else {
const newSettings = [...multiSensitivitySettings.value];
newSettings[editSettingsIdx.value!] = settings;
if (addingParamSettings.value) {
newSettings.push(settings);
} else {
newSettings[editSettingsIdx.value!] = settings;
}
updateMultiSensitivitySettings(newSettings);
}
};
const paramsWithoutSettings = computed(() => {
const used = multiSensitivitySettings.value.map((p: SensitivityParameterSettings) => p.parameterToVary);
return Object.keys(store.state.run.parameterValues).filter((p) => !used.includes(p));
});
const canDeleteSettings = computed(() => props.multiSensitivity && multiSensitivitySettings.value.length > 1);
const addSettings = () => {
// Add settings for the first parameter which is not already in the list
const unused = paramsWithoutSettings.value;
if (unused.length) {
const newSettings = [
...multiSensitivitySettings.value,
{ ...defaultSensitivityParamSettings(), parameterToVary: unused[0] }
];
updateMultiSensitivitySettings(newSettings);
}
addingParamSettings.value = true;
editOpen.value = true;
};
const deleteSettings = (idx: number) => {
Expand Down

0 comments on commit 543a1ff

Please sign in to comment.