From 899a7df49d07ce553650e6629e3747bf8aeaa328 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 7 Feb 2024 16:19:01 +0100 Subject: [PATCH] feat: add tootip --- src/lib/components/filters/content.svelte | 36 +++++++++++++++++++---- src/lib/components/filters/store.ts | 11 ++++--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/lib/components/filters/content.svelte b/src/lib/components/filters/content.svelte index 11eb886bc..86a6020b9 100644 --- a/src/lib/components/filters/content.svelte +++ b/src/lib/components/filters/content.svelte @@ -12,6 +12,7 @@ import { tags, type Operator, queries } from './store'; import type { Column } from '$lib/helpers/types'; import type { Writable } from 'svelte/store'; + import { tooltip } from '$lib/actions/tooltip'; export let columns: Writable; @@ -81,8 +82,12 @@ }, contains: { toQuery: Query.contains, - toTag: (attribute, input) => - `**${attribute}** contains **${Array.isArray(input) ? input.join(' or') : input}**`, + toTag: (attribute, input) => { + return { + value: input, + tag: `**${attribute}** contains **${Array.isArray(input) ? formatArray(input) : input}**` + }; + }, types: ['string', 'integer', 'double', 'boolean', 'datetime', 'enum'] } }; @@ -113,16 +118,31 @@ // This Map is keyed by tags, and has a query as the value function addFilter() { if (!column || !operator) return; - - queries.addFilter({ column, operator, value: value ?? '' }); - value = null; + if (column.array) { + queries.addFilter({ column, operator, value: arrayValues }); + arrayValues = []; + } else { + queries.addFilter({ column, operator, value: value ?? '' }); + value = null; + } } function tagFormat(node: HTMLElement) { node.innerHTML = node.innerHTML.replace(/\*\*(.*?)\*\*/g, '$1'); } + function formatArray(array: string[]) { + if (!array?.length) return; + if (array.length > 2) { + return `${array[0]} or ${array.length - 1} others`; + } else { + return array.join(' or '); + } + } + $: isDisabled = !operator; + + $: console.log($tags);
@@ -194,12 +214,16 @@
    {#each $tags as tag (tag)} diff --git a/src/lib/components/filters/store.ts b/src/lib/components/filters/store.ts index aa027c74f..13dc1f9b7 100644 --- a/src/lib/components/filters/store.ts +++ b/src/lib/components/filters/store.ts @@ -6,8 +6,11 @@ import deepEqual from 'deep-equal'; import type { Column, ColumnType } from '$lib/helpers/types'; export type Operator = { - toTag: (attribute: string, input?: string | number) => string; - toQuery: (attribute: string, input?: string | number) => string; + toTag: ( + attribute: string, + input?: string | number | string[] + ) => string | { tag: string; value: string }; + toQuery: (attribute: string, input?: string | number | string[]) => string; types: ColumnType[]; hideInput?: boolean; }; @@ -22,13 +25,13 @@ export function queryParamToMap(queryParam: string) { return new Map(queries); } -function initQueries(initialValue = new Map()) { +function initQueries(initialValue = new Map()) { const queries = writable(initialValue); type AddFilterArgs = { operator: Operator; column: Column; - value: string | number; + value: string | number | string[]; }; function addFilter({ column, operator, value }: AddFilterArgs) {