|
| 1 | +<script lang="ts"> |
| 2 | + import { page } from '$app/state'; |
| 3 | + import { resolve } from '$app/paths'; |
| 4 | + import { goto } from '$app/navigation'; |
| 5 | +
|
| 6 | + import Input from './input.svelte'; |
| 7 | + import { Modal } from '$lib/components'; |
| 8 | + import { Button } from '$lib/elements/forms'; |
| 9 | + import { tableColumnSuggestions } from './store'; |
| 10 | +
|
| 11 | + let { |
| 12 | + show = $bindable(false) |
| 13 | + }: { |
| 14 | + show?: boolean; |
| 15 | + } = $props(); |
| 16 | +
|
| 17 | + const isOnRowsPage = $derived(page.route?.id?.endsWith('table-[table]')); |
| 18 | +
|
| 19 | + function resetSuggestionsStore() { |
| 20 | + show = false; |
| 21 | +
|
| 22 | + $tableColumnSuggestions.table = null; |
| 23 | + $tableColumnSuggestions.context = null; |
| 24 | +
|
| 25 | + $tableColumnSuggestions.force = false; |
| 26 | + $tableColumnSuggestions.enabled = false; |
| 27 | + $tableColumnSuggestions.thinking = false; |
| 28 | + } |
| 29 | +
|
| 30 | + async function triggerColumnSuggestions() { |
| 31 | + // set table info. first! |
| 32 | + $tableColumnSuggestions.table = { |
| 33 | + id: page.params.table, |
| 34 | + name: page.data.table?.name ?? 'Table' |
| 35 | + }; |
| 36 | +
|
| 37 | + if (!isOnRowsPage) { |
| 38 | + await goto( |
| 39 | + resolve( |
| 40 | + '/(console)/project-[region]-[project]/databases/database-[database]/table-[table]', |
| 41 | + { |
| 42 | + region: page.params.region, |
| 43 | + project: page.params.project, |
| 44 | + database: page.params.database, |
| 45 | + table: page.params.table |
| 46 | + } |
| 47 | + ) |
| 48 | + ); |
| 49 | + } |
| 50 | +
|
| 51 | + $tableColumnSuggestions.force = true; |
| 52 | + $tableColumnSuggestions.enabled = true; |
| 53 | +
|
| 54 | + show = false; |
| 55 | + } |
| 56 | +</script> |
| 57 | + |
| 58 | +<Modal bind:show title="Suggest columns" onSubmit={triggerColumnSuggestions}> |
| 59 | + <Input isModal /> |
| 60 | + |
| 61 | + <svelte:fragment slot="footer"> |
| 62 | + <Button text on:click={resetSuggestionsStore}>Cancel</Button> |
| 63 | + <Button submit>Generate columns</Button> |
| 64 | + </svelte:fragment> |
| 65 | +</Modal> |
0 commit comments