Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions src/lib/components/csvImportBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import { getProjectId } from '$lib/helpers/project';
import { writable, type Writable } from 'svelte/store';
import { addNotification } from '$lib/stores/notifications';
import { Layout, Typography } from '@appwrite.io/pink-svelte';
import { Layout, Typography, Icon } from '@appwrite.io/pink-svelte';
import { IconExclamationCircle } from '@appwrite.io/pink-icons-svelte';
import { Modal, Code } from '$lib/components';
import { type Models, type Payload, Query } from '@appwrite.io/console';
// re-render the key for sheet UI.
Expand All @@ -18,6 +20,7 @@
type ImportItem = {
status: string;
table?: string;
errors?: string[];
};
type ImportItemsMap = Map<string, ImportItem>;
Expand Down Expand Up @@ -112,7 +115,10 @@
if (shouldSkip) return items;
const next = new Map(items);
next.set(importData.$id, { status, table: tableName ?? undefined });
const errors = Array.isArray((importData as Payload).errors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we need to cast here. we have a similar check above for showCompletionNotification, we can make a helper function to return the error instead of hard type casts and duplicating the logic.

? ((importData as Payload).errors as string[])
: undefined;
next.set(importData.$id, { status, table: tableName ?? undefined, errors });
return next;
});
Expand All @@ -138,7 +144,7 @@
return 60;
case 'completed':
case 'failed':
return 100;
return 60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 100% because the process is completed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this marked resolved?

default:
return 30;
}
Expand All @@ -149,7 +155,7 @@
switch (status) {
case 'completed':
case 'failed':
return `Import to ${name} ${status}`;
return `Importing CSV file${name ? ` to ${name}` : ''}`;
case 'processing':
return `Importing CSV file${name ? ` to ${name}` : ''}`;
default:
Comment on lines 157 to 162
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Copy fix: Completed/failed messages shouldn't say "Importing".

Use explicit completed/failed text for clarity.

Apply this diff:

-            case 'completed':
-            case 'failed':
-                return `Importing CSV file${name ? ` to ${name}` : ''}`;
+            case 'completed':
+                return `CSV import finished${name ? ` for ${name}` : ''}.`;
+            case 'failed':
+                return `CSV import failed${name ? ` for ${name}` : ''}.`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case 'completed':
case 'failed':
return `Import to ${name} ${status}`;
return `Importing CSV file${name ? ` to ${name}` : ''}`;
case 'processing':
return `Importing CSV file${name ? ` to ${name}` : ''}`;
default:
case 'completed':
return `CSV import finished${name ? ` for ${name}` : ''}.`;
case 'failed':
return `CSV import failed${name ? ` for ${name}` : ''}.`;
case 'processing':
return `Importing CSV file${name ? ` to ${name}` : ''}`;
default:
🤖 Prompt for AI Agents
In src/lib/components/csvImportBox.svelte around lines 156 to 161, the
'completed' and 'failed' cases currently return "Importing CSV file...", which
is incorrect; update those two cases to return explicit end-state messages
(e.g., "CSV import completed" when 'completed' and "CSV import failed" when
'failed'), preserving the existing optional "to {name}" interpolation when name
is present; leave the 'processing' case as-is returning the ongoing "Importing
CSV file" message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @HarshMN2345

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Expand Down Expand Up @@ -179,6 +185,22 @@
$: isOpen = true;
$: showCsvImportBox = $importItems.size > 0;
let showDetails = false;
let selectedErrors: string[] = [];
function openDetails(errors: string[] | undefined) {
selectedErrors = errors ?? [];
showDetails = true;
}
$: parsedErrors = selectedErrors.map((err) => {
try {
return JSON.stringify(JSON.parse(err), null, 2);
} catch {
return err;
}
});
</script>

{#if showCsvImportBox}
Expand Down Expand Up @@ -222,6 +244,25 @@
class:is-danger={value.status === 'failed'}
style="--graph-size:{graphSize(value.status)}%">
</div>
{#if value.status === 'failed'}
<Layout.Stack
direction="row"
gap="xs"
alignItems="center"
inline>
<Icon
icon={IconExclamationCircle}
color="--fgcolor-error"
size="s" />
<Typography.Text color="--fgcolor-error">
There was an import issue.
<button
class="link-button"
on:click={() => openDetails(value.errors)}
>View details</button>
</Typography.Text>
</Layout.Stack>
{/if}
</section>
</li>
</ul>
Expand All @@ -232,6 +273,14 @@
</Layout.Stack>
{/if}

<Modal title="Import error" bind:show={showDetails} hideFooter>
<Layout.Stack gap="m">
<Layout.Stack>
<Code language="json" code={parsedErrors.join('\n\n')} withCopy allowScroll />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</Layout.Stack>
</Layout.Stack>
</Modal>

<style lang="scss">
.upload-box {
display: flex;
Expand All @@ -252,7 +301,7 @@
}
.upload-box-content {
width: 304px;
width: 324px;
}
.upload-box-button {
Expand All @@ -274,4 +323,13 @@
background-color: var(--bgcolor-error);
}
}
.link-button {
background: none;
border: none;
padding: 0;
color: var(--fgcolor-error);
text-decoration: underline;
cursor: pointer;
}
</style>