|
27 | 27 | const importItems: Writable<ImportItemsMap> = writable(new Map());
|
28 | 28 |
|
29 | 29 | async function showCompletionNotification(
|
30 |
| - databaseId: string, |
31 |
| - collectionId: string, |
32 |
| - importData: Payload |
| 30 | + database: string, |
| 31 | + collection: string, |
| 32 | + payload: Payload |
33 | 33 | ) {
|
34 |
| - await invalidate(Dependencies.DOCUMENTS); |
35 |
| - const url = `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/collection-${collectionId}`; |
| 34 | + const isSuccess = payload.status === 'completed'; |
36 | 35 |
|
37 |
| - // extract clean message from nested backend error. |
38 |
| - const match = importData.errors.join('').match(/message: '(.*)' Message:/i); |
39 |
| - const errorMessage = match?.[1]; |
| 36 | + // TODO: the migrations worker sends 2 events! |
| 37 | + const isError = !isSuccess && !!payload.error; |
40 | 38 |
|
41 |
| - const type = importData.status === 'completed' ? 'success' : 'error'; |
42 |
| - const message = |
43 |
| - importData.status === 'completed' |
44 |
| - ? 'CSV import finished successfully.' |
45 |
| - : `${errorMessage}`; |
| 39 | + if (!isSuccess && !isError) return; |
| 40 | +
|
| 41 | + const type = isSuccess ? 'success' : 'error'; |
| 42 | + const message = isError ? payload.error : 'CSV import finished successfully.'; |
| 43 | +
|
| 44 | + const url = `${base}/project-${page.params.region}-${page.params.project}/databases/database-${database}/collection-${collection}`; |
46 | 45 |
|
47 | 46 | addNotification({
|
48 | 47 | type,
|
49 | 48 | message,
|
50 | 49 | isHtml: true,
|
51 | 50 | buttons:
|
52 |
| - collectionId === page.params.collection || type === 'error' |
53 |
| - ? undefined |
54 |
| - : [ |
55 |
| - { |
56 |
| - name: 'View documents', |
57 |
| - method: () => goto(url) |
58 |
| - } |
59 |
| - ] |
| 51 | + isSuccess && collection !== page.params.collection |
| 52 | + ? [{ name: 'View documents', method: () => goto(url) }] |
| 53 | + : undefined |
60 | 54 | });
|
| 55 | +
|
| 56 | + if (isSuccess) { |
| 57 | + await invalidate(Dependencies.DOCUMENTS); |
| 58 | + } |
61 | 59 | }
|
62 | 60 |
|
63 | 61 | async function updateOrAddItem(importData: Payload | Models.Migration) {
|
|
0 commit comments