Skip to content

Commit 74a21eb

Browse files
fix(VariableManager): Update variable local values
- so that page color is updated realtime without any delay
1 parent 20b51f8 commit 74a21eb

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

frontend/src/components/Modals/VariableManager.vue

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
<template #header><h2 class="py-2 text-lg font-semibold">Manage Variables</h2></template>
1717
<template #content>
1818
<div>
19+
<div class="mb-4">
20+
<BuilderInput
21+
:modelValue="searchQuery"
22+
@input="(val: string) => (searchQuery = val)"
23+
@update:modelValue="(val: string) => (searchQuery = val)"
24+
type="text"
25+
placeholder="Search variables"
26+
class="w-full"
27+
icon-left="search" />
28+
</div>
1929
<ListView
2030
:columns="columns"
2131
:rows="listViewRows"
@@ -198,6 +208,7 @@ const csvFileInput = ref<HTMLInputElement>();
198208
const editingCell = ref<string | null>(null);
199209
const nextNewId = ref(1);
200210
const newVariable = ref<Partial<BuilderVariable> | null>(null);
211+
const searchQuery = ref("");
201212
202213
const columns = [
203214
{ label: "Name", key: "variable_name" },
@@ -209,7 +220,15 @@ const columns = [
209220
type ListViewRow = Partial<BuilderVariable> & { id: string; isNew: Boolean };
210221
211222
const listViewRows = computed(() => {
212-
const rows: ListViewRow[] = variables.value.map((variable) => ({
223+
let filteredVariables = variables.value;
224+
if (searchQuery.value.trim()) {
225+
const query = searchQuery.value.toLowerCase().trim();
226+
filteredVariables = variables.value.filter((variable) =>
227+
variable.variable_name?.toLowerCase().includes(query),
228+
);
229+
}
230+
231+
const rows: ListViewRow[] = filteredVariables.map((variable) => ({
213232
...variable,
214233
id: variable.name || `new-${nextNewId.value}`,
215234
isNew: false,
@@ -230,8 +249,12 @@ const listViewOptions = {
230249
showTooltip: false,
231250
resizeColumn: false,
232251
emptyState: {
233-
title: "No Variables",
234-
description: "No variables found. Click 'Add Variable' to create your first one.",
252+
title: computed(() => (searchQuery.value.trim() ? "No Variables Found" : "No Variables")),
253+
description: computed(() =>
254+
searchQuery.value.trim()
255+
? `No variables match "${searchQuery.value}". Try a different search term.`
256+
: "No variables found. Click 'Add Variable' to create your first one.",
257+
),
235258
},
236259
};
237260
@@ -262,6 +285,16 @@ const addNewVariable = async () => {
262285
};
263286
264287
const updateColor = async (row: ListViewRow, value: string | null, mode: "light" | "dark") => {
288+
variables.value = variables.value.map((v) =>
289+
v.name === row.name
290+
? {
291+
...v,
292+
value: mode === "light" ? value || "" : v.value,
293+
dark_value: mode === "dark" ? value || "" : v.dark_value,
294+
}
295+
: v,
296+
);
297+
265298
if (mode === "light") {
266299
row.value = value || "";
267300
} else {
@@ -312,7 +345,6 @@ const saveVariable = async (row: ListViewRow) => {
312345
dark_value: row.dark_value || undefined,
313346
type: row.type || "Color",
314347
});
315-
toast.success("Variable updated successfully");
316348
} catch (error) {
317349
toast.error((error as Error).message || "Failed to update variable");
318350
}

frontend/src/utils/useBuilderVariable.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ function builderVariableComposable() {
8989
createVariable,
9090
updateVariable,
9191
deleteVariable,
92-
variables: computed(() => (builderVariableStore.data as BuilderVariable[]) || []),
92+
variables: computed({
93+
get: () => (builderVariableStore.data as BuilderVariable[]) || [],
94+
set: (value: BuilderVariable[]) => {
95+
builderVariableStore.data = value;
96+
},
97+
}),
9398
};
9499
}
95100

0 commit comments

Comments
 (0)