|
1 | 1 | <script lang="ts"> |
2 | 2 | import { onMount } from 'svelte'; |
3 | | - import { base } from '$app/paths'; |
4 | 3 | import { page } from '$app/state'; |
5 | 4 | import { realtime, sdk } from '$lib/stores/sdk'; |
6 | | - import { goto } from '$app/navigation'; |
7 | 5 | import { getProjectId } from '$lib/helpers/project'; |
8 | 6 | import { addNotification } from '$lib/stores/notifications'; |
9 | 7 | import { Layout, Typography, Code } from '@appwrite.io/pink-svelte'; |
|
33 | 31 | window.open(downloadUrl, '_blank'); |
34 | 32 | } |
35 | 33 |
|
36 | | - async function showCompletionNotification( |
37 | | - table: string, |
38 | | - bucketId: string, |
39 | | - downloadUrl: string, |
40 | | - payload: Payload |
41 | | - ) { |
42 | | - const isSuccess = payload.status === 'completed'; |
43 | | - const isError = !isSuccess && !!payload.errors; |
44 | | -
|
45 | | - if (!isSuccess && !isError) return; |
46 | | -
|
| 34 | + async function showErrorNotification(payload: Payload) { |
47 | 35 | let errorMessage = 'Export failed. Please try again.'; |
48 | | - if (isError && Array.isArray(payload.errors) && payload.errors.length > 0) { |
49 | | - try { |
50 | | - const parsed = JSON.parse(payload.errors[0]); |
51 | | - errorMessage = parsed?.message || errorMessage; |
52 | | - } catch { |
53 | | - errorMessage = payload.errors[0] || errorMessage; |
54 | | - } |
| 36 | + try { |
| 37 | + const parsed = JSON.parse(payload.errors[0]); |
| 38 | + errorMessage = parsed?.message || errorMessage; |
| 39 | + } catch { |
| 40 | + errorMessage = payload.errors[0] || errorMessage; |
55 | 41 | } |
56 | 42 |
|
57 | | - const type = isSuccess ? 'success' : 'error'; |
58 | | - const message = isError ? errorMessage : `"${table}" has been exported`; |
59 | | - const region = page.params.region; |
60 | | - const project = page.params.project; |
61 | | -
|
62 | 43 | addNotification({ |
63 | | - type, |
64 | | - message, |
| 44 | + type: 'error', |
| 45 | + message: errorMessage, |
65 | 46 | isHtml: true, |
66 | 47 | timeout: 10000, |
67 | | - buttons: isSuccess |
68 | | - ? [ |
69 | | - { |
70 | | - name: 'View bucket', |
71 | | - method: () => |
72 | | - goto( |
73 | | - `${base}/project-${region}-${project}/storage/bucket-${bucketId}` |
74 | | - ) |
75 | | - }, |
76 | | - { |
77 | | - name: 'Download', |
78 | | - method: () => downloadExportedFile(downloadUrl) |
79 | | - } |
80 | | - ] |
81 | | - : undefined |
82 | 48 | }); |
83 | 49 | } |
84 | 50 |
|
85 | 51 | async function updateOrAddItem(exportData: Payload | Models.Migration) { |
86 | 52 | if (exportData.destination?.toLowerCase() !== 'csv') return; |
87 | 53 |
|
88 | 54 | const status = exportData.status; |
89 | | - const resourceId = exportData.resourceId ?? ''; |
90 | | - const [_, tableId] = resourceId.split(':') ?? []; |
91 | | -
|
92 | 55 | const current = exportItems.get(exportData.$id); |
93 | 56 | let tableName = current?.table; |
94 | 57 |
|
|
132 | 95 | } |
133 | 96 | break; |
134 | 97 | case 'failed': |
135 | | - await showCompletionNotification( |
136 | | - tableName ?? tableId, |
137 | | - bucketId, |
138 | | - downloadUrl, |
139 | | - exportData |
140 | | - ); |
| 98 | + await showErrorNotification(exportData); |
141 | 99 | break; |
142 | 100 | } |
143 | 101 | } |
|
0 commit comments