|
24 | 24 | IconTable |
25 | 25 | } from '@appwrite.io/pink-icons-svelte'; |
26 | 26 | import { isTabletViewport } from '$lib/stores/viewport'; |
27 | | - import { BottomSheet } from '$lib/components'; |
| 27 | + import { BottomSheet, Confirm } from '$lib/components'; |
28 | 28 | import Button from '$lib/elements/forms/button.svelte'; |
29 | 29 | import { type Models, Query } from '@appwrite.io/console'; |
30 | 30 | import { sdk } from '$lib/stores/sdk'; |
|
38 | 38 | import FilePicker from '$lib/components/filePicker.svelte'; |
39 | 39 |
|
40 | 40 | import { preferences } from '$lib/stores/preferences'; |
| 41 | + import { organization } from '$lib/stores/organization'; |
41 | 42 |
|
42 | 43 | const data = $derived(page.data) as PageData; |
43 | 44 |
|
|
143 | 144 | } |
144 | 145 | } |
145 | 146 |
|
| 147 | + let showDelete = $state(false); |
| 148 | + let deleteError = $state<string | undefined>(); |
| 149 | +
|
| 150 | + async function deleteTable() { |
| 151 | + if (!selectedTableForAction) return; |
| 152 | + try { |
| 153 | + await sdk.forProject(region, project).tablesDB.deleteTable({ |
| 154 | + databaseId, |
| 155 | + tableId: selectedTableForAction.$id |
| 156 | + }); |
| 157 | +
|
| 158 | + showDelete = false; |
| 159 | + subNavigation.update(); |
| 160 | +
|
| 161 | + addNotification({ |
| 162 | + type: 'success', |
| 163 | + message: `${selectedTableForAction.name} has been deleted` |
| 164 | + }); |
| 165 | +
|
| 166 | + trackEvent(Submit.TableDelete); |
| 167 | +
|
| 168 | + await preferences.deleteTableDetails($organization.$id, selectedTableForAction.$id); |
| 169 | +
|
| 170 | + if (tableId === selectedTableForAction.$id) { |
| 171 | + await goto(`${base}/project-${region}-${project}/databases/database-${databaseId}`); |
| 172 | + } |
| 173 | + } catch (e) { |
| 174 | + deleteError = e.message; |
| 175 | + trackError(e, Submit.TableDelete); |
| 176 | + } |
| 177 | + } |
| 178 | +
|
146 | 179 | async function handleTableAction(action: TableAction, table: Models.Table) { |
147 | 180 | selectedTableForAction = table; |
148 | 181 | switch (action) { |
|
186 | 219 | ); |
187 | 220 | break; |
188 | 221 | case 'delete': |
| 222 | + showDelete = true; |
189 | 223 | break; |
190 | 224 | default: |
191 | 225 | break; |
|
385 | 419 | }} /> |
386 | 420 | {/if} |
387 | 421 |
|
| 422 | +<Confirm |
| 423 | + confirmDeletion |
| 424 | + onSubmit={deleteTable} |
| 425 | + title="Delete table" |
| 426 | + bind:open={showDelete} |
| 427 | + bind:error={deleteError}> |
| 428 | + <Typography.Text> |
| 429 | + Are you sure you want to delete <b>{selectedTableForAction?.name}</b>? |
| 430 | + </Typography.Text> |
| 431 | +</Confirm> |
| 432 | + |
388 | 433 | <style lang="scss"> |
389 | 434 | .list-container { |
390 | 435 | height: 100%; |
|
0 commit comments