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>();
198208const editingCell = ref <string | null >(null );
199209const nextNewId = ref (1 );
200210const newVariable = ref <Partial <BuilderVariable > | null >(null );
211+ const searchQuery = ref (" " );
201212
202213const columns = [
203214 { label: " Name" , key: " variable_name" },
@@ -209,7 +220,15 @@ const columns = [
209220type ListViewRow = Partial <BuilderVariable > & { id: string ; isNew: Boolean };
210221
211222const 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
264287const 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 }
0 commit comments