diff --git a/src/lib/components/filters/store.ts b/src/lib/components/filters/store.ts index 354621b58..10cd6f183 100644 --- a/src/lib/components/filters/store.ts +++ b/src/lib/components/filters/store.ts @@ -13,27 +13,23 @@ export type TagValue = { }; export type Operator = { - toTag: ( - attribute: string, - input?: string | number | string[], - type?: string - ) => string | TagValue; + toTag: (attribute: string, input?: string | number | string[], type?: string) => TagValue; toQuery: (attribute: string, input?: string | number | string[]) => string; types: ColumnType[]; hideInput?: boolean; }; -export function mapToQueryParams(map: Map) { +export function mapToQueryParams(map: Map) { return encodeURIComponent(JSON.stringify(Array.from(map.entries()))); } export function queryParamToMap(queryParam: string) { const decodedQueryParam = decodeURIComponent(queryParam); - const queries = JSON.parse(decodedQueryParam) as [string, string][]; + const queries = JSON.parse(decodedQueryParam) as [TagValue, string][]; return new Map(queries); } -function initQueries(initialValue = new Map()) { +function initQueries(initialValue = new Map()) { const queries = writable(initialValue); type AddFilterArgs = { @@ -52,7 +48,7 @@ function initQueries(initialValue = new Map()) { }); } - function removeFilter(tag: string | TagValue) { + function removeFilter(tag: TagValue) { queries.update((map) => { map.delete(tag); return map; @@ -256,16 +252,22 @@ function generateDefaultOperators() { toQuery: operator.query, toTag: (attribute, input = null, type = null) => { if (input === null) { - return `**${attribute}** ${operatorName}`; + return { + value: '', + tag: `**${attribute}** ${operatorName}` + }; } else if (Array.isArray(input) && input.length > 2) { return { value: input, tag: `**${attribute}** ${operatorName} **${formatArray(input)}** ` }; } else if (type === ValidTypes.Datetime) { - return `**${attribute}** ${operatorName} **${toLocaleDateTime(input.toString())}**`; + return { + value: input, + tag: `**${attribute}** ${operatorName} **${toLocaleDateTime(input.toString())}**` + }; } else { - return `**${attribute}** ${operatorName} **${input}**`; + return { value: input, tag: `**${attribute}** ${operatorName} **${input}**` }; } }, types: operator.types, diff --git a/src/lib/components/filters/tagList.svelte b/src/lib/components/filters/tagList.svelte index b9d5a4e7b..443366955 100644 --- a/src/lib/components/filters/tagList.svelte +++ b/src/lib/components/filters/tagList.svelte @@ -1,49 +1,23 @@ {#each $tags as tag (tag)} - {#if isTypeTagValue(tag)} - - {:else} - - {/if} + {/each} diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/simpleFilters.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/simpleFilters.svelte index e90d7a1fa..f5ef75a2c 100644 --- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/simpleFilters.svelte +++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/simpleFilters.svelte @@ -13,10 +13,21 @@ export let columns: Writable; - const colStatus = $columns.find((col) => col.id === 'status'); + const statusCol = $columns.find((col) => col.id === 'status'); let showStatusFilter = false; let statusTag: string = null; - let statusOptions = colStatus?.elements?.map((element) => { + let statusOptions = statusCol?.elements?.map((element) => { + return { + value: (element?.value ?? element) as string, + label: (element?.label ?? element) as string, + checked: false + }; + }); + + const triggerCol = $columns.find((col) => col.id === 'trigger'); + let showTriggerFilter = false; + let triggerTag: string = null; + let triggerOptions = triggerCol?.elements?.map((element) => { return { value: (element?.value ?? element) as string, label: (element?.label ?? element) as string, @@ -30,25 +41,15 @@ } else { const list = [...tagList].reverse(); list.forEach((tag) => { - if (typeof tag === 'string') { - // Status - if (tag.includes(`**${colStatus.title}**`)) { - statusTag = tag; + // Status + if (tag.tag.includes(`**${statusCol.title}**`)) { + statusTag = tag.tag; + if (Array.isArray(tag.value) && tag.value?.length) { + const values = tag.value as string[]; statusOptions.forEach((option) => { - option.checked = tag.toLowerCase().includes(option.value); + option.checked = values.includes(option.value); }); } - } else if (typeof tag !== 'string') { - // Status - if (tag.tag.includes(`**${colStatus.title}**`)) { - statusTag = tag.tag; - if (Array.isArray(tag.value) && tag.value?.length) { - const values = tag.value as string[]; - statusOptions.forEach((option) => { - option.checked = values.includes(option.value); - }); - } - } } else { statusTag = null; } @@ -62,11 +63,7 @@ value: unknown, arrayValues: string[] = [] ) { - const tagsList = $tags.filter((tag) => - typeof tag === 'string' - ? tag.toLowerCase().includes(colId) - : tag.tag.toLowerCase().includes(colId) - ); + const tagsList = $tags.filter((tag) => tag.tag.toLowerCase().includes(colId)); tagsList.forEach((tag) => queries.removeFilter(tag)); if (value || arrayValues?.length) { addFilter($columns, colId, operator, value, arrayValues); @@ -74,8 +71,14 @@ queries.apply(); } - $: multipleStatusQueries = [...$queries.values()].reduce((acc, query) => { - if (query.includes(`"attribute":"${colStatus.id}"`)) { + $: statusQueriesTotal = [...$queries.values()].reduce((acc, query) => { + if (query.includes(`"attribute":"${statusCol.id}"`)) { + acc++; + } + return acc; + }, 0); + $: triggerQueriesTotal = [...$queries.values()].reduce((acc, query) => { + if (query.includes(`"attribute":"${triggerCol.id}"`)) { acc++; } return acc; @@ -92,7 +95,7 @@ {/key} {:else} - {colStatus.title} + {statusCol.title} {/if} - {#if multipleStatusQueries > 1} + {#if statusQueriesTotal > 1}
  • This will override your previous query.
  • {/if} {#each statusOptions as option (option.value + option.checked)} @@ -111,7 +114,7 @@ option.checked = !option.checked; statusOptions = statusOptions; addFilterAndApply( - colStatus.id, + statusCol.id, ValidOperators.Equal, null, statusOptions.filter((opt) => opt.checked).map((opt) => opt.value) ?? [] @@ -122,3 +125,43 @@ {/each}
    + + (showTriggerFilter = !showTriggerFilter)}> + {#if triggerTag} + {#key triggerTag} + + {triggerTag} + + {/key} + {:else} + + {triggerCol.title} + + {/if} + + + + + {#if triggerQueriesTotal > 1} +
  • This will override your previous query.
  • + {/if} + {#each triggerOptions as option (option.value + option.checked)} + { + option.checked = !option.checked; + triggerOptions = triggerOptions; + addFilterAndApply( + triggerCol.id, + ValidOperators.Equal, + null, + triggerOptions.filter((opt) => opt.checked).map((opt) => opt.value) ?? [] + ); + }}> + {option.label} + + {/each} +
    +