mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge pull request #2428 from appwrite/fix-suggestions-ui
This commit is contained in:
6 files changed
+19
-114
No files matched your search
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { navigationCancelled } from '$lib/stores/navigation';
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation';
|
||||
|
||||
const minimum = 0.08;
|
||||
@@ -98,13 +97,6 @@
|
||||
complete();
|
||||
});
|
||||
|
||||
navigationCancelled.subscribe((cancelled) => {
|
||||
if (cancelled) {
|
||||
complete();
|
||||
navigationCancelled.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
$: barStyle = (width && width * 100 && `width: ${width * 100}%;`) || '';
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const navigationCancelled = writable(false);
|
||||
+7
-91
@@ -25,23 +25,18 @@
|
||||
tableColumnSuggestions,
|
||||
basicColumnOptions,
|
||||
mockSuggestions,
|
||||
createTableRequest,
|
||||
showIndexesSuggestions
|
||||
} from './store';
|
||||
import { addNotification, dismissNotification } from '$lib/stores/notifications';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { sleep } from '$lib/helpers/promises';
|
||||
import { invalidate, beforeNavigate, goto } from '$app/navigation';
|
||||
import { showCreateTable } from '../store';
|
||||
import { showSubNavigation } from '$lib/stores/layout';
|
||||
import { navigationCancelled } from '$lib/stores/navigation';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
import type { Columns } from '../table-[table]/store';
|
||||
import { columnOptions } from '../table-[table]/columns/store';
|
||||
import Options from './options.svelte';
|
||||
import { InputSelect, InputText } from '$lib/elements/forms';
|
||||
import { Confirm } from '$lib/components';
|
||||
import { isCloud, VARS } from '$lib/system';
|
||||
|
||||
import IconAINotification from './icon/aiNotification.svelte';
|
||||
@@ -62,10 +57,6 @@
|
||||
let hasTransitioned = $state(false);
|
||||
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 };
|
||||
|
||||
@@ -289,26 +280,6 @@
|
||||
});
|
||||
};
|
||||
|
||||
// Handle create table requests from subNavigation
|
||||
const unsubscribeCreateTable = createTableRequest.subscribe((requested) => {
|
||||
if (requested) {
|
||||
const hasRealColumns = customColumns.some((col) => !col.isPlaceholder);
|
||||
if (hasRealColumns && !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);
|
||||
@@ -381,17 +352,6 @@
|
||||
];
|
||||
};
|
||||
|
||||
// Handle browser back/forward navigation
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
const hasRealColumns = customColumns.some((col) => !col.isPlaceholder);
|
||||
if (hasRealColumns && !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));
|
||||
|
||||
@@ -405,16 +365,6 @@
|
||||
await suggestColumns();
|
||||
});
|
||||
|
||||
beforeNavigate(({ cancel, to }) => {
|
||||
const hasRealColumns = customColumns.some((col) => !col.isPlaceholder);
|
||||
if (hasRealColumns && !creatingColumns) {
|
||||
cancel();
|
||||
confirmNavigation = true;
|
||||
$navigationCancelled = true;
|
||||
pendingNavigationUrl = to?.url?.pathname || null;
|
||||
}
|
||||
});
|
||||
|
||||
function resetSuggestionsStore(fullReset: boolean = true) {
|
||||
if ($tableColumnSuggestions.table?.id !== page.params.table) {
|
||||
return;
|
||||
@@ -459,7 +409,7 @@
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
context: $tableColumnSuggestions.context ?? undefined,
|
||||
min: 6 // TODO: to not break the sheet layout's width!
|
||||
min: 6
|
||||
})) as unknown as {
|
||||
total: number;
|
||||
columns: ColumnInput[];
|
||||
@@ -740,11 +690,10 @@
|
||||
|
||||
customColumns = [];
|
||||
resetSuggestionsStore();
|
||||
unsubscribeCreateTable();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={recalcAll} on:scroll={recalcAll} on:beforeunload={handleBeforeUnload} />
|
||||
<svelte:window on:resize={recalcAll} on:scroll={recalcAll} />
|
||||
|
||||
<div
|
||||
bind:this={spreadsheetContainer}
|
||||
@@ -1023,7 +972,10 @@
|
||||
size="xs"
|
||||
variant="text"
|
||||
disabled={creatingColumns}
|
||||
on:click={() => (confirmDismiss = true)}
|
||||
on:click={() => {
|
||||
customColumns = [];
|
||||
resetSuggestionsStore();
|
||||
}}
|
||||
style="opacity: {creatingColumns ? '0' : '1'}"
|
||||
>Dismiss
|
||||
</Button.Button>
|
||||
@@ -1042,42 +994,6 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Confirm
|
||||
confirmDeletion
|
||||
action="Dismiss"
|
||||
title="Dismiss columns"
|
||||
bind:open={confirmDismiss}
|
||||
onSubmit={() => {
|
||||
customColumns = [];
|
||||
resetSuggestionsStore();
|
||||
}}>
|
||||
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%;
|
||||
|
||||
-2
@@ -46,8 +46,6 @@ export const tableColumnSuggestions = writable<TableColumnSuggestions>({
|
||||
table: null
|
||||
});
|
||||
|
||||
export const createTableRequest = writable<boolean>(false);
|
||||
|
||||
export const showIndexesSuggestions = writable<boolean>(false);
|
||||
|
||||
export const mockSuggestions: { total: number; columns: ColumnInput[] } = {
|
||||
|
||||
+10
@@ -27,6 +27,13 @@
|
||||
|
||||
let creatingTable = $state(false);
|
||||
|
||||
function enableThinkingModeForSuggestions() {
|
||||
if ($tableColumnSuggestions.enabled) {
|
||||
// if enabled, trigger thinking mode!
|
||||
$tableColumnSuggestions.thinking = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function createTable() {
|
||||
error = null;
|
||||
try {
|
||||
@@ -53,6 +60,9 @@
|
||||
name = id = null;
|
||||
showCreate = false;
|
||||
creatingTable = false;
|
||||
|
||||
// don't wait for UI to mount!
|
||||
enableThinkingModeForSuggestions();
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
trackError(e, Submit.TableCreate);
|
||||
|
||||
+2
-10
@@ -28,7 +28,6 @@
|
||||
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;
|
||||
|
||||
@@ -147,15 +146,8 @@
|
||||
<Button
|
||||
compact
|
||||
on:click={() => {
|
||||
if (
|
||||
$tableColumnSuggestions.enabled &&
|
||||
$tableColumnSuggestions.table?.id
|
||||
) {
|
||||
$createTableRequest = true;
|
||||
} else {
|
||||
$showCreateTable = true;
|
||||
$showSubNavigation = false;
|
||||
}
|
||||
$showCreateTable = true;
|
||||
$showSubNavigation = false;
|
||||
}}>
|
||||
Create table
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user