diff --git a/src/lib/stores/preferences.ts b/src/lib/stores/preferences.ts index 723721410..fc6a864e2 100644 --- a/src/lib/stores/preferences.ts +++ b/src/lib/stores/preferences.ts @@ -224,6 +224,8 @@ function createPreferences() { delete teamPreferences?.displayNames?.[tableId]; delete teamPreferences?.columnOrder?.[tableId]; delete teamPreferences?.columnWidths?.[tableId]; + delete teamPreferences?.columnWidths?.[tableId + '#columns']; + delete teamPreferences?.columnWidths?.[tableId + '#indexes']; const removeTablePreferences = sdk.forConsole.teams.updatePrefs({ teamId: orgId, diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/+page.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/+page.svelte index bb115a7f3..adc70ad97 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/+page.svelte @@ -20,6 +20,7 @@ import { columns, type Columns, + type ColumnsWidth, indexes, isCsvImportInProgress, reorderItems, @@ -51,6 +52,14 @@ import { type Models } from '@appwrite.io/console'; import { preferences } from '$lib/stores/preferences'; import { page } from '$app/state'; + import { debounce } from '$lib/helpers/debounce'; + import type { PageData } from './$types'; + + const { + data + }: { + data: PageData; + } = $props(); const updatedColumnsForSheet = $derived.by(() => { const baseAttrs = [ @@ -104,8 +113,11 @@ let selectedColumn: Columns = $state(null); let columnIndexMap: Record = $state({}); - let columnsOrder = $state([]); + let columnsOrder = $state([]); + let columnsWidth = $state(null); + const tableId = page.params.table; + const organizationId = data.organization.$id ?? data.project.teamId; let showEdit = $state(false); let editColumn: EditColumn; @@ -126,6 +138,7 @@ onMount(() => { columnsOrder = preferences.getColumnOrder(tableId); + columnsWidth = preferences.getColumnWidths(tableId + '#columns'); }); function getColumnStatusBadge(status: string): ComponentProps['type'] { @@ -186,8 +199,70 @@ return column.key.startsWith('$'); } + function getColumnWidth(columnId: string, defaultWidth: number): number { + const savedWidth = columnsWidth?.[columnId]; + if (!savedWidth) return defaultWidth; + + return savedWidth.resized; + } + + function saveColumnsWidth({ columnId, newWidth }: { columnId: string; newWidth: number }) { + const existing = columnsWidth?.[columnId]; + const fixed = existing + ? typeof existing?.fixed === 'number' + ? existing.fixed + : existing?.fixed?.min + : newWidth; + + columnsWidth = { + ...(columnsWidth ?? {}), + [columnId]: { + fixed, + resized: Math.ceil(newWidth) + } + }; + + saveColumnWidthsToPreferences({ columnId, newWidth, fixedWidth: fixed }); + } + + const saveColumnWidthsToPreferences = debounce( + (column: { columnId: string; newWidth: number; fixedWidth: number }) => { + if (!organizationId) return; + + preferences.saveColumnWidths(organizationId, tableId + '#columns', { + [column.columnId]: { + fixed: column.fixedWidth, + resized: Math.ceil(column.newWidth) + } + }); + }, + 1000 + ); + onDestroy(() => ($showCreateColumnSheet.show = false)); + const spreadsheetColumns = $derived([ + { + id: 'key', + width: getColumnWidth('key', 300), + minimumWidth: 300, + resizable: true + }, + { + id: 'indexed', + width: getColumnWidth('indexed', 150), + minimumWidth: 150, + resizable: true + }, + { + id: 'default', + width: getColumnWidth('default', 200), + minimumWidth: 200, + resizable: true + }, + { id: 'actions', width: 40, isAction: true, resizable: false } + ]); + $effect(() => { if (!$showCreateIndexSheet.show && $showCreateIndexSheet.column) { const columnKey = $showCreateIndexSheet.column; @@ -228,14 +303,9 @@ height="100%" emptyCells={emptyCellsCount} bind:selectedRows={selectedColumns} - columns={[ - // more size until we decide if we want a new column! - { id: 'key', width: { min: 300 }, resizable: false }, - { id: 'indexed', width: { min: 150 }, resizable: false }, - { id: 'default', width: { min: 200 }, resizable: false }, - { id: 'actions', width: 40, isAction: true } - ]} - bottomActionClick={() => ($showCreateColumnSheet.show = true)}> + columns={spreadsheetColumns} + bottomActionClick={() => ($showCreateColumnSheet.show = true)} + on:columnsResize={(resize) => saveColumnsWidth(resize.detail)}> Column name Indexed diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/+page.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/+page.svelte index 9a77979dc..bce6d08c1 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/+page.svelte @@ -1,6 +1,6 @@