update: cancel navigating when suggestions are up for review.

update: change border colors for custom columns.
This commit is contained in:
Darshan committed 2025-09-26 11:04:37 +05:30
1 parent e496836f5e
commit c05e2f5ab9
6 files changed
+129 -13

No files matched your search

+8
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { navigationCancelled } from '$lib/stores/navigation';
import { afterNavigate, beforeNavigate } from '$app/navigation';
const minimum = 0.08;
@@ -97,6 +98,13 @@
complete();
});
navigationCancelled.subscribe((cancelled) => {
if (cancelled) {
complete();
navigationCancelled.set(false);
}
});
$: barStyle = (width && width * 100 && `width: ${width * 100}%;`) || '';
</script>
+3
View File
@@ -0,0 +1,3 @@
import { writable } from 'svelte/store';
export const navigationCancelled = writable(false);
@@ -24,12 +24,16 @@
type SuggestedColumnSchema,
tableColumnSuggestions,
basicColumnOptions,
mockSuggestions
mockSuggestions,
createTableRequest
} from './store';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { sleep } from '$lib/helpers/promises';
import { invalidate } from '$app/navigation';
import { invalidate, beforeNavigate, goto } from '$app/navigation';
import { showCreateTable } from '../store';
import { showSubNavigation } from '$lib/stores/layout';
import { navigationCancelled } from '$lib/stores/navigation';
import { Dependencies } from '$lib/constants';
import { isWithinSafeRange } from '$lib/helpers/numbers';
import type { Columns } from '../table-[table]/store';
@@ -52,6 +56,9 @@
let scrollAnimationFrame: number | null = null;
let confirmDismiss = $state(false);
let confirmNavigation = $state(false);
let pendingNavigationUrl: string | null = null;
let creatingColumns = $state(false);
const baseColProps = { draggable: false, resizable: false };
@@ -252,6 +259,25 @@
});
};
// Handle create table requests from subNavigation
const unsubscribeCreateTable = createTableRequest.subscribe((requested) => {
if (requested) {
if (customColumns.length > 0 && !creatingColumns) {
confirmNavigation = true;
pendingNavigationUrl = 'create-table';
} else {
executeCreateTable();
}
createTableRequest.set(false);
}
});
function executeCreateTable() {
$showCreateTable = true;
$showSubNavigation = false;
}
const customSuggestedColumns = $derived.by(() => {
return customColumns.map((col: SuggestedColumnSchema) => {
const columnOption = getColumnOption(col.type, col.format);
@@ -314,6 +340,16 @@
}
];
// Handle browser back/forward navigation
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
if (customColumns.length > 0 && !creatingColumns) {
event.preventDefault();
event.returnValue =
'You have unsaved column suggestions. Are you sure you want to leave?';
return event.returnValue;
}
};
const spreadsheetColumns = $derived(getRowColumns());
const emptyCells = $derived(($isSmallViewport ? 14 : 17) + (!$expandTabs ? 2 : 0));
@@ -327,7 +363,20 @@
await suggestColumns();
});
beforeNavigate(({ cancel, to }) => {
if (customColumns.length > 0 && !creatingColumns) {
cancel();
confirmNavigation = true;
$navigationCancelled = true;
pendingNavigationUrl = to?.url?.pathname || null;
}
});
function resetSuggestionsStore(fullReset: boolean = true) {
if ($tableColumnSuggestions.table?.id !== page.params.table) {
return;
}
if (fullReset) {
// these are referenced in
// `table-[table]/+page.svelte`
@@ -434,6 +483,10 @@
);
}
function isCustomColumn(id: string) {
return !['$id', '$createdAt', '$updatedAt', 'actions'].includes(id);
}
async function createColumns() {
creatingColumns = true;
const client = sdk.forProject(page.params.region, page.params.project);
@@ -563,14 +616,11 @@
customColumns = [];
resetSuggestionsStore();
unsubscribeCreateTable();
});
function isCustomColumn(id: string) {
return !['$id', '$createdAt', '$updatedAt', 'actions'].includes(id);
}
</script>
<svelte:window on:resize={recalcAll} on:scroll={recalcAll} />
<svelte:window on:resize={recalcAll} on:scroll={recalcAll} on:beforeunload={handleBeforeUnload} />
<div
bind:this={spreadsheetContainer}
@@ -851,6 +901,30 @@
Are you sure you want to dismiss these columns suggested by AI? This action is irreversible.
</Confirm>
<Confirm
confirmDeletion
action="Leave"
title="Leave page"
bind:open={confirmNavigation}
onSubmit={() => {
customColumns = [];
resetSuggestionsStore();
confirmNavigation = false;
if (pendingNavigationUrl) {
if (pendingNavigationUrl === 'create-table') {
executeCreateTable();
} else {
goto(pendingNavigationUrl);
}
pendingNavigationUrl = null;
}
}}>
You have unsaved column suggestions. If you leave this page, you'll lose these suggestions. Are
you sure you want to continue?
</Confirm>
<style lang="scss">
.spreadsheet-container-outer {
width: 100%;
@@ -866,6 +940,23 @@
display: none;
}
&:not(:has(.columns-range-overlay.thinking)) {
&
:global(
[role='cell']:has(.column-resizer-disabled):not([data-column-id^='$']):not(
[data-column-id='actions']
)
) {
box-shadow: 0 -1px 0 0 rgba(253, 54, 110, 0.24) inset !important;
transition: box-shadow 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
& :global(.column-resizer-disabled) {
border-left: var(--border-width-s, 1px) solid rgba(253, 54, 110, 0.24) !important;
transition: border-color 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
}
.columns-range-overlay {
position: absolute;
left: var(--group-left, 0px);
@@ -4,6 +4,12 @@
import { tableColumnSuggestions } from './store';
import { InputTextarea } from '$lib/elements/forms';
import { Card, Layout, Selector, Typography } from '@appwrite.io/pink-svelte';
import { onMount } from 'svelte';
onMount(() => {
// enable by default!
$tableColumnSuggestions.enabled = true;
});
</script>
<Card.Base variant="secondary" radius="s" padding="xs">
@@ -36,7 +42,6 @@
id="context"
rows={3}
maxlength={255}
autofocus
bind:value={$tableColumnSuggestions.context}
placeholder="Optional: Add context to improve suggestions" />
</div>
@@ -1,5 +1,5 @@
import { writable } from 'svelte/store';
import { columnOptions } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/store';
import { columnOptions } from '../table-[table]/columns/store';
export type TableColumnSuggestions = {
enabled: boolean;
@@ -31,7 +31,8 @@ export const tableColumnSuggestions = writable<TableColumnSuggestions>({
table: null
});
// TODO: @itznotabug, remove later, this is MOCK DATA ONLY.
export const createTableRequest = writable<boolean>(false);
export const mockSuggestions: { total: number; columns: ColumnInput[] } = {
total: 7,
columns: [
@@ -1,10 +1,10 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/state';
import { showCreateTable, databaseSubNavigationItems } from './store';
import type { PageData } from './$types';
import { showSubNavigation } from '$lib/stores/layout';
import { bannerSpacing } from '$lib/layout/headerAlert.svelte';
import { showCreateTable, databaseSubNavigationItems } from './store';
import {
Icon,
@@ -28,6 +28,7 @@
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { subNavigation } from '$lib/stores/database';
import { createTableRequest, tableColumnSuggestions } from './(suggestions)/store';
let data = $derived(page.data) as PageData;
@@ -144,8 +145,15 @@
<Button
compact
on:click={() => {
$showCreateTable = true;
$showSubNavigation = false;
if (
$tableColumnSuggestions.enabled &&
$tableColumnSuggestions.table?.id
) {
$createTableRequest = true;
} else {
$showCreateTable = true;
$showSubNavigation = false;
}
}}>
Create table
</Button>