Skip to content

Commit

Permalink
for query_values set in UI and based on that gets its value in array …
Browse files Browse the repository at this point in the history
…or string
  • Loading branch information
ktx-vaidehi committed Apr 30, 2024
1 parent 74934ac commit 2d6fdc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
45 changes: 35 additions & 10 deletions web/src/components/dashboards/VariablesValueSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,44 @@ export default defineComponent({
value: value.zo_sql_key.toString(),
}));
// if the old value exist in dropdown set the old value otherwise set first value of drop down otherwise set blank string value
// Define oldVariableSelectedValues array
let oldVariableSelectedValues = [];
if (oldVariablesData[currentVariable.name]) {
oldVariableSelectedValues = Array.isArray(
oldVariablesData[currentVariable.name]
)
? oldVariablesData[currentVariable.name]
: [oldVariablesData[currentVariable.name]];
}
console.log(
"oldVariableSelectedValues query_values",
oldVariableSelectedValues);
// if the old value exists in the dropdown, set the old value; otherwise, set the first value of the dropdown; otherwise, set a blank string value
if (
oldVariablesData[currentVariable.name] !== undefined ||
oldVariablesData[currentVariable.name] !== undefined &&
oldVariablesData[currentVariable.name] !== null
) {
currentVariable.value = currentVariable.options.some(
(option: any) =>
option.value === oldVariablesData[currentVariable.name]
)
? oldVariablesData[currentVariable.name]
: currentVariable.options.length
? currentVariable.options[0].value
: null;
if (currentVariable.showMultipleValues) {
const selectedValues = currentVariable.options
.filter((option: any) =>
oldVariableSelectedValues.includes(option.value)
)
.map((option: any) => option.value);
currentVariable.value =
selectedValues.length > 0
? selectedValues
: [currentVariable.options[0].value]; // If no option is available, set as the first value
} else {
currentVariable.value = currentVariable.options.some(
(option: any) =>
option.value === oldVariablesData[currentVariable.name]
)
? oldVariablesData[currentVariable.name]
: currentVariable.options.length
? currentVariable.options[0].value
: null;
}
} else {
currentVariable.value = currentVariable.options.length
? currentVariable.options[0].value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class="textbox col no-case"
:loading="variableItem.isLoading"
data-test="dashboard-variable-query-value-selector"
:multiple="shouldAllowMultipleSelections"
>
<template v-slot:no-option>
<q-item>
Expand All @@ -57,7 +58,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<q-item-section>
<q-item-label v-html="opt.label" />
</q-item-section>
<q-item-section side>
<q-item-section side v-if="shouldAllowMultipleSelections">
<q-checkbox
:model-value="selected"
@update:model-value="toggleOption(opt)"
Expand Down Expand Up @@ -97,6 +98,10 @@ export default defineComponent({
}
);
const shouldAllowMultipleSelections = ref(
props.variableItem?.showMultipleValues === true
);
// update selected value
watch(selectedValue, () => {
emit("update:modelValue", selectedValue.value);
Expand All @@ -106,6 +111,7 @@ export default defineComponent({
selectedValue,
fieldsFilterFn,
fieldsFilteredOptions,
shouldAllowMultipleSelections,
};
},
});
Expand Down

0 comments on commit 2d6fdc2

Please sign in to comment.