Skip to content

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

Open
wants to merge 2 commits into
base: spreadsheet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,6 +27,8 @@

let isSubmitting = $state(false);
let columnFormWrapper: HTMLDivElement | null = $state(null);
let createMore = $state(false);
let formResetKey = $state(0);
Copy link
Member

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? The formResetKey += 1 isn't that nice.


type CreateRow = {
id?: string;
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

should we not close the sheet if this option is false?

} catch (error) {
addNotification({
message: error.message,
Expand All @@ -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`}
Expand All @@ -115,36 +130,47 @@
submit={{
text: 'Create',
disabled: isSubmitting,
onClick: () => create()
}}>
onClick: async () => {
await create();
if (createMore) {
throw new Error('Keep open');
Copy link
Member

Choose a reason for hiding this comment

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

why throw an error?

}
}
}}
{footer}>
Copy link
Member

Choose a reason for hiding this comment

The 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}
Copy link
Member

Choose a reason for hiding this comment

The 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
spaced = false,
closeOnBlur = false,
submit,
children = null
children = null,
footer = null
}: {
show: boolean;
title: string;
Expand All @@ -23,6 +24,7 @@
}
| undefined;
children?: Snippet;
footer?: Snippet | null;
} = $props();
</script>

Expand Down Expand Up @@ -56,10 +58,16 @@
<Divider />

<div class="sheet-footer-actions">
<Layout.Stack gap="m" direction="row" justifyContent="flex-end">
<Layout.Stack
gap="m"
direction="row"
justifyContent="flex-end"
alignItems="center">
{#if footer}
{@render footer?.()}
{/if}
<Button size="s" secondary on:click={() => (show = false)}
>Cancel</Button>

<Button size="s" submit disabled={submit.disabled}>
{submit.text}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@
column={rowColumn}
row={paginatedRows.items[index]}
onRowStructureUpdate={updateRowContents}
on:change={(row) =>
paginatedRows.update(index, row.detail)}
on:change={(row) => paginatedRows.update(index, row.detail)}
on:revert={(row) =>
paginatedRows.update(index, row.detail)} />
</svelte:fragment>
Expand Down
Loading