fix: types.

This commit is contained in:
Darshan
2025-07-16 16:42:03 +05:30
parent 33326e0e3a
commit 797f3f7cc3
8 changed files with 52 additions and 63 deletions
+2 -2
View File
@@ -2,7 +2,7 @@
import { beforeNavigate } from '$app/navigation';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import type { PinkSheetColumn } from '$lib/helpers/types';
import type { Column } from '$lib/helpers/types';
import type { Writable } from 'svelte/store';
import Content from './content.svelte';
import {
@@ -19,7 +19,7 @@
import { Click, Submit, trackEvent } from '$lib/actions/analytics';
export let query = '[]';
export let columns: Writable<PinkSheetColumn[]>;
export let columns: Writable<Column[]>;
export let disabled = false;
export let fullWidthMobile = false;
export let singleCondition = false;
+6 -6
View File
@@ -4,7 +4,7 @@ import deepEqual from 'deep-equal';
import { Query } from '@appwrite.io/console';
import { toLocaleDateTime } from '$lib/helpers/date';
import { derived, get, writable } from 'svelte/store';
import type { SheetColumn, SheetColumnType } from '$lib/helpers/types';
import type { Column, ColumnType } from '$lib/helpers/types';
export type TagValue = {
tag: string;
@@ -14,7 +14,7 @@ export type TagValue = {
export type Operator = {
toTag: (attribute: string, input?: string | number | string[], type?: string) => TagValue;
toQuery: (attribute: string, input?: string | number | string[]) => string;
types: SheetColumnType[];
types: ColumnType[];
hideInput?: boolean;
};
@@ -33,7 +33,7 @@ function initQueries(initialValue = new Map<TagValue, string>()) {
type AddFilterArgs = {
operator: Operator;
column: SheetColumn;
column: Column;
value: string | number | string[];
};
@@ -91,14 +91,14 @@ export const tags = derived(queries, ($queries) => Array.from($queries.keys()));
/* eslint @typescript-eslint/no-explicit-any: 'off' */
export function addFilter(
columns: SheetColumn[],
columns: Column[],
columnId: string,
operatorKey: string,
value: any, // We cast to any to not cause type errors in the input components
arrayValues: string[] = []
) {
const operator = operatorKey ? operators[operatorKey] : null;
const column = columns.find((c) => c.id === columnId) as SheetColumn;
const column = columns.find((c) => c.id === columnId) as Column;
if (!column || !operator) return;
if (column.array) {
queries.addFilter({ column, operator, value: arrayValues });
@@ -135,7 +135,7 @@ const operatorsDefault = new Map<
ValidOperators,
{
query: (attr: string, input: string | number | string[]) => string;
types: SheetColumnType[];
types: ColumnType[];
hideInput?: boolean;
}
>([
+8 -22
View File
@@ -15,25 +15,6 @@ export type PinkColumn = {
hide?: boolean;
};
export type PinkSheetColumn = {
id: string;
width?:
| {
min: number;
max: number;
}
| {
min: number;
}
| number;
hide?: boolean;
fixed?: boolean;
resizable?: boolean;
draggable?: boolean;
resizedWidth?: number;
isAction?: boolean;
};
export type WritableValue<T> = T extends Writable<infer U> ? U : never;
export function isHTMLElement(el: unknown): el is HTMLElement {
@@ -55,10 +36,10 @@ const columnTypes = [
'relationship',
'enum'
] as const;
export type SheetColumnType = (typeof columnTypes)[number];
export type SheetColumn = PinkSheetColumn & {
export type ColumnType = (typeof columnTypes)[number];
export type Column = PinkColumn & {
title: string;
type: SheetColumnType;
type: ColumnType;
filter?: boolean;
array?: boolean;
format?: string;
@@ -68,6 +49,11 @@ export type SheetColumn = PinkSheetColumn & {
icon?: ComponentType;
isPrimary?: boolean;
isEditable?: boolean;
fixed?: boolean;
resizable?: boolean;
draggable?: boolean;
resizedWidth?: number;
isAction?: boolean;
};
export function isValueOfStringEnum<T extends Record<string, string>>(