-
Notifications
You must be signed in to change notification settings - Fork 184
feat: added create more functionality #2214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: spreadsheet
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,11 @@ | |
import { Permissions } from '$lib/components/permissions'; | ||
import type { Columns } from './store'; | ||
import { ID, type Models } from '@appwrite.io/console'; | ||
import { Alert, Layout, Typography } from '@appwrite.io/pink-svelte'; | ||
import { Alert, Layout, Typography, Selector } from '@appwrite.io/pink-svelte'; | ||
import SideSheet from './layout/sidesheet.svelte'; | ||
import { invalidate } from '$app/navigation'; | ||
import { Dependencies } from '$lib/constants'; | ||
import { tick } from 'svelte'; | ||
|
||
let { | ||
table, | ||
|
@@ -26,6 +27,8 @@ | |
|
||
let isSubmitting = $state(false); | ||
let columnFormWrapper: HTMLDivElement | null = $state(null); | ||
let createMore = $state(false); | ||
let formResetKey = $state(0); | ||
|
||
type CreateRow = { | ||
id?: string; | ||
|
@@ -65,18 +68,23 @@ | |
permissions: $createRow.permissions | ||
}); | ||
|
||
showSheet = false; | ||
addNotification({ | ||
message: 'Row has been created', | ||
type: 'success' | ||
}); | ||
|
||
// post op clear. | ||
existingData = null; | ||
trackEvent(Submit.RowCreate, { | ||
customId: !!$createRow.id | ||
}); | ||
await invalidate(Dependencies.ROW); | ||
|
||
if (createMore) { | ||
createRow = createRowWritable(); | ||
existingData = null; | ||
formResetKey += 1; | ||
await tick(); | ||
focusFirstInput(); | ||
} | ||
Comment on lines
+81
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we not close the sheet if this option is |
||
} catch (error) { | ||
addNotification({ | ||
message: error.message, | ||
|
@@ -100,13 +108,20 @@ | |
if (showSheet) { | ||
focusFirstInput(); | ||
createRow = createRowWritable(); | ||
} else { | ||
createMore = false; | ||
} | ||
}); | ||
</script> | ||
|
||
{#if $createRow} | ||
<div class="sheet-container"> | ||
<!-- TODO: add a ID badge--> | ||
{#snippet footer()} | ||
<Layout.Stack inline direction="row" alignItems="center"> | ||
<Selector.Switch id="create-more" bind:checked={createMore} label="Create more" /> | ||
</Layout.Stack> | ||
{/snippet} | ||
<SideSheet | ||
spaced | ||
title={`${existingData ? 'Duplicate' : 'Create'} row`} | ||
|
@@ -115,36 +130,47 @@ | |
submit={{ | ||
text: 'Create', | ||
disabled: isSubmitting, | ||
onClick: () => create() | ||
}}> | ||
onClick: async () => { | ||
await create(); | ||
if (createMore) { | ||
throw new Error('Keep open'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why throw an error? |
||
} | ||
} | ||
}} | ||
{footer}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already add a snippet footer above, right? |
||
<Layout.Stack gap="xxl"> | ||
<div bind:this={columnFormWrapper}> | ||
<ColumnForm | ||
columns={$createRow.columns} | ||
bind:customId={$createRow.id} | ||
bind:formValues={$createRow.row} /> | ||
</div> | ||
|
||
<Layout.Stack gap="xl"> | ||
<Typography.Text> | ||
Choose which permission scopes to grant your application. It is best | ||
practice to allow only the permissions you need to meet your project goals. | ||
</Typography.Text> | ||
{#if table.rowSecurity} | ||
<Alert.Inline status="info"> | ||
<svelte:fragment slot="title">Row security is enabled</svelte:fragment> | ||
Users will be able to access this row if they have been granted | ||
<b>either row or table permissions</b>. | ||
</Alert.Inline> | ||
<Permissions bind:permissions={$createRow.permissions} /> | ||
{:else} | ||
<Alert.Inline status="info"> | ||
<svelte:fragment slot="title">Row security is disabled</svelte:fragment> | ||
If you want to assign row permissions, navigate to Table settings and enable | ||
row security. Otherwise, only table permissions will be used. | ||
</Alert.Inline> | ||
{/if} | ||
</Layout.Stack> | ||
{#key formResetKey} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mentioned the key above |
||
<div bind:this={columnFormWrapper}> | ||
<ColumnForm | ||
columns={$createRow.columns} | ||
bind:customId={$createRow.id} | ||
bind:formValues={$createRow.row} /> | ||
</div> | ||
|
||
<Layout.Stack gap="xl"> | ||
<Typography.Text> | ||
Choose which permission scopes to grant your application. It is best | ||
practice to allow only the permissions you need to meet your project | ||
goals. | ||
</Typography.Text> | ||
{#if table.rowSecurity} | ||
<Alert.Inline status="info"> | ||
<svelte:fragment slot="title" | ||
>Row security is enabled</svelte:fragment> | ||
Users will be able to access this row if they have been granted | ||
<b>either row or table permissions</b>. | ||
</Alert.Inline> | ||
<Permissions bind:permissions={$createRow.permissions} /> | ||
{:else} | ||
<Alert.Inline status="info"> | ||
<svelte:fragment slot="title" | ||
>Row security is disabled</svelte:fragment> | ||
If you want to assign row permissions, navigate to Table settings and | ||
enable row security. Otherwise, only table permissions will be used. | ||
</Alert.Inline> | ||
{/if} | ||
</Layout.Stack> | ||
{/key} | ||
</Layout.Stack> | ||
</SideSheet> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not use the
createRow
variable as a#key
? TheformResetKey += 1
isn't that nice.