mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix types?
This commit is contained in:
1 parent
899a7df49d
commit
cac04c22ef
2 files changed
+45
-23
No files matched your search
@@ -9,7 +9,7 @@
|
||||
} from '$lib/elements/forms';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { tags, type Operator, queries } from './store';
|
||||
import { tags, type Operator, queries, isTypeTagValue } from './store';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import type { Writable } from 'svelte/store';
|
||||
import { tooltip } from '$lib/actions/tooltip';
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
let columnId: string | null = null;
|
||||
$: column = $columns.find((c) => c.id === columnId) as Column;
|
||||
let arrayValues = [];
|
||||
let arrayValues: string[] = [];
|
||||
|
||||
dispatch('apply', { applied: $tags.length });
|
||||
|
||||
@@ -213,20 +213,32 @@
|
||||
|
||||
<ul class="u-flex u-flex-wrap u-cross-center u-gap-8 u-margin-block-start-16 tags">
|
||||
{#each $tags as tag (tag)}
|
||||
<button
|
||||
use:tooltip={{
|
||||
content: tag?.value,
|
||||
disabled: !tag?.value?.length
|
||||
}}
|
||||
class="tag"
|
||||
on:click={() => {
|
||||
queries.removeFilter(tag);
|
||||
}}>
|
||||
<span class="text" use:tagFormat>
|
||||
{tag?.tag ?? tag}
|
||||
</span>
|
||||
<i class="icon-x" />
|
||||
</button>
|
||||
{#if isTypeTagValue(tag)}
|
||||
<button
|
||||
use:tooltip={{
|
||||
content: tag?.value?.toString()
|
||||
}}
|
||||
class="tag"
|
||||
on:click={() => {
|
||||
queries.removeFilter(tag);
|
||||
}}>
|
||||
<span class="text" use:tagFormat>
|
||||
{tag.tag}
|
||||
</span>
|
||||
<i class="icon-x" />
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
class="tag"
|
||||
on:click={() => {
|
||||
queries.removeFilter(tag);
|
||||
}}>
|
||||
<span class="text" use:tagFormat>
|
||||
{tag}
|
||||
</span>
|
||||
<i class="icon-x" />
|
||||
</button>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -5,17 +5,27 @@ import { page } from '$app/stores';
|
||||
import deepEqual from 'deep-equal';
|
||||
import type { Column, ColumnType } from '$lib/helpers/types';
|
||||
|
||||
type TagValue = {
|
||||
tag: string;
|
||||
value: string | number | string[];
|
||||
};
|
||||
|
||||
export function isTypeTagValue(obj: any): obj is TagValue {
|
||||
return (
|
||||
obj &&
|
||||
typeof obj.tag === 'string' &&
|
||||
(typeof obj.value === 'string' || typeof obj.value === 'number')
|
||||
);
|
||||
}
|
||||
|
||||
export type Operator = {
|
||||
toTag: (
|
||||
attribute: string,
|
||||
input?: string | number | string[]
|
||||
) => string | { tag: string; value: string };
|
||||
toTag: (attribute: string, input?: string | number | string[]) => string | TagValue;
|
||||
toQuery: (attribute: string, input?: string | number | string[]) => string;
|
||||
types: ColumnType[];
|
||||
hideInput?: boolean;
|
||||
};
|
||||
|
||||
export function mapToQueryParams(map: Map<string, string>) {
|
||||
export function mapToQueryParams(map: Map<string | TagValue, string>) {
|
||||
return encodeURIComponent(JSON.stringify(Array.from(map.entries())));
|
||||
}
|
||||
|
||||
@@ -25,7 +35,7 @@ export function queryParamToMap(queryParam: string) {
|
||||
return new Map(queries);
|
||||
}
|
||||
|
||||
function initQueries(initialValue = new Map<string, string | { tag: string; value: string }>()) {
|
||||
function initQueries(initialValue = new Map<string | TagValue, string>()) {
|
||||
const queries = writable(initialValue);
|
||||
|
||||
type AddFilterArgs = {
|
||||
@@ -41,7 +51,7 @@ function initQueries(initialValue = new Map<string, string | { tag: string; valu
|
||||
});
|
||||
}
|
||||
|
||||
function removeFilter(tag: string) {
|
||||
function removeFilter(tag: string | TagValue) {
|
||||
queries.update((map) => {
|
||||
map.delete(tag);
|
||||
return map;
|
||||
|
||||
Reference in new issue
Block a user