address comments

This commit is contained in:
Atharva Deosthale
2026-02-04 19:09:54 +05:30
parent ee4f95869b
commit dc1a6bf7ae
7 changed files with 74 additions and 74 deletions
@@ -265,7 +265,9 @@
icon
variant="extra-compact"
onclick={() => {
onOpenCreateColumn?.();
if (mode !== 'indexes') {
onOpenCreateColumn?.();
}
}}>
<Icon icon={IconPlus} color="--fgcolor-neutral-primary" />
</Button.Button>
@@ -15,7 +15,6 @@
isCsvImportInProgress,
showRowCreateSheet,
showCreateColumnSheet,
openCreateColumnSheet,
randomDataModalState,
expandTabs
} from './store';
@@ -109,8 +108,6 @@
$: disableButton = canShowSuggestionsSheet;
const onOpenCreateColumnSheet = () => openCreateColumnSheet({ columns: $tableColumns });
async function onSelect(file: Models.File, localFile = false) {
$isCsvImportInProgress = true;
@@ -309,7 +306,9 @@
<EmptySheet
mode="rows-filtered"
title="There are no rows that match your filters"
onOpenCreateColumn={onOpenCreateColumnSheet}
onOpenCreateColumn={() => {
$showCreateColumnSheet.show = true;
}}
customColumns={createTableColumns(table.fields, selected)}>
{#snippet actions()}
<Button
@@ -330,7 +329,9 @@
<EmptySheet
mode="rows"
showActions={$canWriteRows}
onOpenCreateColumn={onOpenCreateColumnSheet}
onOpenCreateColumn={() => {
$showCreateColumnSheet.show = true;
}}
customColumns={createTableColumns(table.fields, selected)}>
{#snippet actions()}
<EmptySheetCards
@@ -386,7 +387,7 @@
title="Create column"
subtitle="Create columns manually"
onClick={() => {
openCreateColumnSheet();
$showCreateColumnSheet.show = true;
}} />
<EmptySheetCards
@@ -47,7 +47,7 @@
import { Click, trackEvent } from '$lib/actions/analytics';
import { isSmallViewport } from '$lib/stores/viewport';
import { SideSheet, SpreadsheetContainer, FailedModal, CsvDisabled } from '$database/(entity)';
import { openCreateColumnSheet, showCreateColumnSheet } from '../store';
import { showCreateColumnSheet } from '../store';
import { type Models } from '@appwrite.io/console';
import { preferences } from '$lib/stores/preferences';
import { page } from '$app/state';
@@ -358,7 +358,7 @@
size="s"
secondary
disabled={$isCsvImportInProgress}
on:click={() => openCreateColumnSheet()}
on:click={() => ($showCreateColumnSheet.show = true)}
event="create_attribute">
<Icon icon={IconPlus} slot="start" size="s" />
Create column
@@ -376,7 +376,7 @@
emptyCells={emptyCellsCount}
bind:selectedRows={selectedColumns}
columns={spreadsheetColumns}
bottomActionClick={() => openCreateColumnSheet()}
bottomActionClick={() => ($showCreateColumnSheet.show = true)}
on:columnsResize={(resize) => saveColumnsWidth(resize.detail)}>
<svelte:fragment slot="header" let:root>
<Spreadsheet.Header.Cell column="key" {root}>Column name</Spreadsheet.Header.Cell>
@@ -145,44 +145,54 @@
return newOrder;
}
function invalidateTableOnColumnAvailable(createdKey: string) {
const { cleanup, waitPromise, startWaiting, columnCreationHandler } = setupColumnObserver();
const unsubscribe = realtime.forProject(
page.params.region,
['project', 'console'],
(response) => {
const payload = response.payload as Columns;
// We only care about the column we just created
if (payload?.key !== createdKey) return;
columnCreationHandler(response);
}
);
startWaiting(1);
waitPromise
.then(async () => {
await invalidate(Dependencies.TABLE);
})
.finally(() => {
unsubscribe();
cleanup();
});
}
export async function submit() {
const createdKey = key;
let stopObserver: (() => void) | null = null;
let waitPromise: Promise<void> | null = null;
let startWaiting: ((count: number) => void) | null = null;
if (createdKey) {
const observer = setupColumnObserver();
waitPromise = observer.waitPromise;
startWaiting = observer.startWaiting;
const unsubscribe = realtime.forProject(
page.params.region,
['project', 'console'],
(response) => {
const payload = response.payload as Columns;
// We only care about the column we just created
if (payload?.key !== createdKey) return;
observer.columnCreationHandler(response);
}
);
stopObserver = () => {
unsubscribe();
observer.cleanup();
};
}
try {
const createdKey = key;
await $option.create(databaseId, tableId, key, data);
columnId = key;
insertColumnInOrder();
if (createdKey) {
invalidateTableOnColumnAvailable(createdKey);
if (createdKey && waitPromise && startWaiting && stopObserver) {
startWaiting(1);
waitPromise
.then(async () => {
await invalidate(Dependencies.TABLE);
})
.finally(() => {
stopObserver?.();
});
} else {
stopObserver?.();
}
await invalidate(Dependencies.TABLE);
@@ -200,6 +210,7 @@
}
return false; // close sheet
} catch (e) {
stopObserver?.();
addNotification({
type: 'error',
message: e.message
@@ -7,7 +7,7 @@
import { canWriteTables } from '$lib/stores/roles';
import { Typography, Link } from '@appwrite.io/pink-svelte';
import IconAI from '../../(suggestions)/icon/aiForButton.svelte';
import { openCreateColumnSheet, showCreateColumnSheet } from '$database/table-[table]/store';
import { showCreateColumnSheet } from '$database/table-[table]/store';
import { IconBookOpen, IconPlus } from '@appwrite.io/pink-icons-svelte';
import { showIndexesSuggestions, showColumnsSuggestionsModal } from '$database/(suggestions)';
import {
@@ -127,7 +127,7 @@
title="Create column"
subtitle="Create columns manually"
onClick={() => {
openCreateColumnSheet();
$showCreateColumnSheet.show = true;
}} />
{:else}
<EmptySheetCards
@@ -135,7 +135,7 @@
title="Create column"
subtitle="Create columns manually"
onClick={() => {
openCreateColumnSheet();
$showCreateColumnSheet.show = true;
}} />
<EmptySheetCards
@@ -41,8 +41,7 @@
expandTabs,
databaseRelatedRowSheetOptions,
rowPermissionSheet,
type Columns,
openCreateColumnSheet
type Columns
} from './store';
import type { Column, ColumnType } from '$lib/helpers/types';
import {
@@ -533,12 +532,11 @@
if (action === 'column-left' || action === 'column-right') {
const { to, neighbour } = $databaseColumnSheetOptions.direction;
openCreateColumnSheet({
title: `Create column to the ${to} of ${neighbour}`,
direction: $databaseColumnSheetOptions.direction,
columns: $tableColumns,
columnsOrder: $columnsOrder
});
$showCreateColumnSheet.title = `Create column to the ${to} of ${neighbour}`;
$showCreateColumnSheet.direction = $databaseColumnSheetOptions.direction;
$showCreateColumnSheet.columns = $tableColumns;
$showCreateColumnSheet.columnsOrder = $columnsOrder;
$showCreateColumnSheet.show = true;
}
if (action === 'delete') {
@@ -559,12 +557,11 @@
}
if (action === 'duplicate-header') {
openCreateColumnSheet({
title: `Duplicate column`,
column: $columns.find((attr) => attr.key === columnId),
columns: $tableColumns,
columnsOrder: $columnsOrder
});
$showCreateColumnSheet.title = `Duplicate column`;
$showCreateColumnSheet.column = $columns.find((attr) => attr.key === columnId);
$showCreateColumnSheet.columns = $tableColumns;
$showCreateColumnSheet.columnsOrder = $columnsOrder;
$showCreateColumnSheet.show = true;
}
} else if (type === 'row') {
if (action === 'update') {
@@ -840,10 +837,11 @@
icon
variant="extra-compact"
on:click={() => {
openCreateColumnSheet({
columns: $tableColumns,
columnsOrder: $columnsOrder
});
$showCreateColumnSheet.show = true;
$showCreateColumnSheet.column = null;
$showCreateColumnSheet.title = 'Create column';
$showCreateColumnSheet.columns = $tableColumns;
$showCreateColumnSheet.columnsOrder = $columnsOrder;
}}>
<Icon icon={IconPlus} color="--fgcolor-neutral-primary" />
</Button.Button>
@@ -154,18 +154,6 @@ export const showCreateColumnSheet = writable<CreateColumn>({
columnsOrder: null
});
export function openCreateColumnSheet(params: Partial<Omit<CreateColumn, 'show'>> = {}): void {
showCreateColumnSheet.set({
show: true,
title: params.title ?? 'Create column',
column: params.column ?? null,
direction: params.direction ?? null,
onDone: params.onDone ?? null,
columns: params.columns ?? null,
columnsOrder: params.columnsOrder ?? null
});
}
export const showCreateIndexSheet = writable<{
show: boolean;
column?: string;