refactor: operators are now writable

This commit is contained in:
Arman
2024-06-21 16:16:34 +02:00
parent fc8db9d7db
commit 94dcccc27c
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -24,14 +24,14 @@
$: column = $columns.find((c) => c.id === columnId) as Column;
$: operatorsForColumn = Object.entries(operators)
$: operatorsForColumn = Object.entries($operators)
.filter(([, v]) => v.types.includes(column?.type))
.map(([k]) => ({
label: k,
value: k
}));
$: operator = operatorKey ? operators[operatorKey] : null;
$: operator = operatorKey ? $operators[operatorKey] : null;
$: {
columnId;
operatorKey = null;
+3 -3
View File
@@ -1,6 +1,6 @@
import { goto } from '$app/navigation';
import { derived, get, writable } from 'svelte/store';
import { derived, get, writable, type Writable } from 'svelte/store';
import { page } from '$app/stores';
import deepEqual from 'deep-equal';
import type { Column, ColumnType } from '$lib/helpers/types';
@@ -105,7 +105,7 @@ export function addFilter(
}
}
export const operators: Record<string, Operator> = {
export const operators: Writable<Record<string, Operator>> = writable({
'starts with': {
toQuery: Query.startsWith,
toTag: (attribute, input) => `**${attribute}** starts with **${input}**`,
@@ -172,7 +172,7 @@ export const operators: Record<string, Operator> = {
},
types: ['string', 'integer', 'double', 'boolean', 'datetime', 'enum']
}
};
});
function formatArray(array: string[]) {
if (!array?.length) return;