mirror of
https://github.com/appwrite/console.git
synced 2026-04-07 19:17:46 +00:00
fix: types.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
>([
|
||||
|
||||
@@ -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>>(
|
||||
|
||||
+17
-14
@@ -3,14 +3,15 @@
|
||||
import { Filters, hasPageQueries, queries } from '$lib/components/filters';
|
||||
import ViewSelector from '$lib/components/viewSelector.svelte';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import type { SheetColumn, SheetColumnType } from '$lib/helpers/types';
|
||||
import type { Column, ColumnType } from '$lib/helpers/types';
|
||||
import { Container } from '$lib/layout';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
// TODO: use these for actions
|
||||
// import { canWriteCollections, canWriteDocuments } from '$lib/stores/roles';
|
||||
import { Icon, Layout, Divider } from '@appwrite.io/pink-svelte';
|
||||
import type { PageData } from './$types';
|
||||
import type { Option } from './attributes/store';
|
||||
import CreateAttribute from './createAttribute.svelte';
|
||||
// import type { Option } from './attributes/store';
|
||||
// import CreateAttribute from './createAttribute.svelte';
|
||||
import { collection, columns, isCsvImportInProgress } from './store';
|
||||
import SpreadSheet from './spreadsheet.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
@@ -30,11 +31,12 @@
|
||||
export let data: PageData;
|
||||
|
||||
let showImportCSV = false;
|
||||
let showCreateAttribute = false;
|
||||
let showRecordsCreateSheet = false;
|
||||
let selectedAttribute: Option['name'] = null;
|
||||
|
||||
const filterColumns = writable<SheetColumn[]>([]);
|
||||
// let showCreateAttribute = false;
|
||||
// let selectedAttribute: Option['name'] = null;
|
||||
|
||||
const filterColumns = writable<Column[]>([]);
|
||||
|
||||
$: selected = preferences.getCustomCollectionColumns(page.params.collection);
|
||||
|
||||
@@ -42,7 +44,7 @@
|
||||
$collection.attributes.map((attribute) => ({
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type as SheetColumnType,
|
||||
type: attribute.type as ColumnType,
|
||||
hide: !!selected?.includes(attribute.key),
|
||||
array: attribute?.array,
|
||||
format: 'format' in attribute && attribute?.format === 'enum' ? attribute.format : null,
|
||||
@@ -162,7 +164,7 @@
|
||||
{:else}
|
||||
<EmptySheet
|
||||
mode="records"
|
||||
cta={{
|
||||
actions={{
|
||||
primary: {
|
||||
onClick: () => {
|
||||
showRecordsCreateSheet = true;
|
||||
@@ -174,7 +176,7 @@
|
||||
<EmptySheet
|
||||
mode="records"
|
||||
title="You have no columns yet"
|
||||
cta={{
|
||||
actions={{
|
||||
primary: {
|
||||
text: 'Create column',
|
||||
onClick: async () => {
|
||||
@@ -188,11 +190,12 @@
|
||||
</div>
|
||||
{/key}
|
||||
|
||||
{#if showCreateAttribute}
|
||||
<CreateAttribute
|
||||
bind:showCreate={showCreateAttribute}
|
||||
bind:selectedOption={selectedAttribute} />
|
||||
{/if}
|
||||
<!-- TODO: goto attributes page -->
|
||||
<!--{#if showCreateAttribute}-->
|
||||
<!-- <CreateAttribute-->
|
||||
<!-- bind:showCreate={showCreateAttribute}-->
|
||||
<!-- bind:selectedOption={selectedAttribute} />-->
|
||||
<!--{/if}-->
|
||||
|
||||
{#if showImportCSV}
|
||||
<!-- CSVs can be text/plain or text/csv sometimes! -->
|
||||
|
||||
+11
-11
@@ -4,11 +4,11 @@
|
||||
import Delete from './deleteIndex.svelte';
|
||||
import Create from './createIndex.svelte';
|
||||
import Overview from './overviewIndex.svelte';
|
||||
import CreateAttribute from '../createAttribute.svelte';
|
||||
// import CreateAttribute from '../createAttribute.svelte';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
// import CreateAttributeDropdown from '../attributes/createAttributeDropdown.svelte';
|
||||
import type { Option } from '../attributes/store';
|
||||
// import type { Option } from '../attributes/store';
|
||||
import FailedModal from '../failedModal.svelte';
|
||||
import { canWriteCollections } from '$lib/stores/roles';
|
||||
import {
|
||||
@@ -40,8 +40,8 @@
|
||||
let showCreateIndex = false;
|
||||
let showOverview = false;
|
||||
let showDelete = false;
|
||||
let showCreateAttribute = false;
|
||||
let selectedAttribute: Option['name'] = null;
|
||||
// let showCreateAttribute = false;
|
||||
// let selectedAttribute: Option['name'] = null;
|
||||
let showFailed = false;
|
||||
let error = '';
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
{:else}
|
||||
<EmptySheet
|
||||
mode="indexes"
|
||||
cta={{
|
||||
actions={{
|
||||
primary: {
|
||||
onClick: () => (showCreateIndex = true),
|
||||
disabled: !$collection?.attributes?.length
|
||||
@@ -173,7 +173,7 @@
|
||||
<EmptySheet
|
||||
mode="indexes"
|
||||
title="You have no columns yet"
|
||||
cta={{
|
||||
actions={{
|
||||
primary: {
|
||||
text: 'Create columns',
|
||||
onClick: async () => {
|
||||
@@ -193,10 +193,10 @@
|
||||
<Overview bind:showOverview {selectedIndex} />
|
||||
{/if}
|
||||
|
||||
{#if showCreateAttribute}
|
||||
<CreateAttribute
|
||||
bind:showCreate={showCreateAttribute}
|
||||
bind:selectedOption={selectedAttribute} />
|
||||
{/if}
|
||||
<!--{#if showCreateAttribute}-->
|
||||
<!-- <CreateAttribute-->
|
||||
<!-- bind:showCreate={showCreateAttribute}-->
|
||||
<!-- bind:selectedOption={selectedAttribute} />-->
|
||||
<!--{/if}-->
|
||||
|
||||
<FailedModal bind:show={showFailed} title="Create index" header="Creation failed" {error} />
|
||||
|
||||
+3
-3
@@ -7,13 +7,13 @@
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import type { SheetColumn } from '$lib/helpers/types';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import { IconCalendar, IconFingerPrint, IconPlus } from '@appwrite.io/pink-icons-svelte';
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
|
||||
type Mode = 'records' | 'columns' | 'indexes';
|
||||
|
||||
type ColumnsMap = Record<Mode, SheetColumn[]>;
|
||||
type ColumnsMap = Record<Mode, Column[]>;
|
||||
|
||||
type Action = {
|
||||
text?: string;
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
| undefined = undefined;
|
||||
|
||||
function makeColumns(...middle: SheetColumn[]): SheetColumn[] {
|
||||
function makeColumns(...middle: Column[]): Column[] {
|
||||
return [
|
||||
{
|
||||
id: '$id',
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@
|
||||
} from './document-[document]/attributes/store';
|
||||
import { attributes, collection, columns, databaseSheetOptions } from './store';
|
||||
import RelationshipsModal from './relationshipsModal.svelte';
|
||||
import type { SheetColumn, SheetColumnType } from '$lib/helpers/types';
|
||||
import type { Column, ColumnType } from '$lib/helpers/types';
|
||||
import {
|
||||
Tooltip,
|
||||
Spreadsheet,
|
||||
@@ -144,7 +144,7 @@
|
||||
const baseColumns = $collection.attributes.map((attribute) => ({
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type as SheetColumnType,
|
||||
type: attribute.type as ColumnType,
|
||||
hide: !!selected?.includes(attribute.key),
|
||||
array: attribute?.array,
|
||||
width: { min: 168 },
|
||||
@@ -154,7 +154,7 @@
|
||||
elements: 'elements' in attribute ? attribute.elements : null
|
||||
}));
|
||||
|
||||
const staticColumns: SheetColumn[] = [
|
||||
const staticColumns: Column[] = [
|
||||
{
|
||||
id: '$id',
|
||||
title: 'ID',
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { page } from '$app/stores';
|
||||
import type { SheetColumn } from '$lib/helpers/types';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
@@ -25,7 +25,7 @@ export const attributes = derived(
|
||||
);
|
||||
export const indexes = derived(page, ($page) => $page.data.collection.indexes as Models.Index[]);
|
||||
|
||||
export const columns = writable<SheetColumn[]>([]);
|
||||
export const columns = writable<Column[]>([]);
|
||||
|
||||
export const isCsvImportInProgress = writable(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user