Skip to content

Commit aef2a2d

Browse files
committed
update: logic as per changes on backend.
1 parent dc3beb6 commit aef2a2d

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/lib/components/csvImportBox.svelte

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,35 @@
2727
const importItems: Writable<ImportItemsMap> = writable(new Map());
2828
2929
async function showCompletionNotification(
30-
databaseId: string,
31-
collectionId: string,
32-
importData: Payload
30+
database: string,
31+
collection: string,
32+
payload: Payload
3333
) {
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';
3635
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;
4038
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}`;
4645
4746
addNotification({
4847
type,
4948
message,
5049
isHtml: true,
5150
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
6054
});
55+
56+
if (isSuccess) {
57+
await invalidate(Dependencies.DOCUMENTS);
58+
}
6159
}
6260
6361
async function updateOrAddItem(importData: Payload | Models.Migration) {

0 commit comments

Comments
 (0)