mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
add: nice seekbar component, fake data logic, multi attribute deletion.
This commit is contained in:
1 parent
c35582f6ce
commit
6a3fe2848e
10 files changed
+372
-231
No files matched your search
@@ -27,6 +27,7 @@
|
||||
"@appwrite.io/pink-icons-svelte": "^2.0.0-RC.1",
|
||||
"@appwrite.io/pink-legacy": "^1.0.3",
|
||||
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5",
|
||||
"@faker-js/faker": "^9.9.0",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@sentry/sveltekit": "^8.38.0",
|
||||
"@stripe/stripe-js": "^3.5.0",
|
||||
|
||||
Generated
+9
@@ -26,6 +26,9 @@ importers:
|
||||
'@appwrite.io/pink-svelte':
|
||||
specifier: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5
|
||||
version: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5(svelte@5.25.3)
|
||||
'@faker-js/faker':
|
||||
specifier: ^9.9.0
|
||||
version: 9.9.0
|
||||
'@popperjs/core':
|
||||
specifier: ^2.11.8
|
||||
version: 2.11.8
|
||||
@@ -586,6 +589,10 @@ packages:
|
||||
resolution: {integrity: sha512-1+WqvgNMhmlAambTvT3KPtCl/Ibr68VldY2XY40SL1CE0ZXiakFR/cbTspaF5HsnpDMvcYYoJHfl4980NBjGag==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@faker-js/faker@9.9.0':
|
||||
resolution: {integrity: sha512-OEl393iCOoo/z8bMezRlJu+GlRGlsKbUAN7jKB6LhnKoqKve5DXRpalbItIIcwnCjs1k/FOPjFzcA6Qn+H+YbA==}
|
||||
engines: {node: '>=18.0.0', npm: '>=9.0.0'}
|
||||
|
||||
'@floating-ui/core@1.6.9':
|
||||
resolution: {integrity: sha512-uMXCuQ3BItDUbAMhIXw7UPXRfAlOAvZzdK9BWpE60MCn+Svt3aLn9jsPTi/WNGlRUu2uI0v5S7JiIUsbsvh3fw==}
|
||||
|
||||
@@ -3950,6 +3957,8 @@ snapshots:
|
||||
'@eslint/core': 0.15.1
|
||||
levn: 0.4.1
|
||||
|
||||
'@faker-js/faker@9.9.0': {}
|
||||
|
||||
'@floating-ui/core@1.6.9':
|
||||
dependencies:
|
||||
'@floating-ui/utils': 0.2.9
|
||||
|
||||
@@ -30,3 +30,4 @@ export { default as InputTime } from './inputTime.svelte';
|
||||
export { default as InputDigits } from './inputDigits.svelte';
|
||||
export { default as InputSelectCheckbox } from './inputSelectCheckbox.svelte';
|
||||
export { default as InputFilePicker } from './inputFilePicker.svelte';
|
||||
export { default as Seekbar } from './Seekbar.svelte';
|
||||
+70
-3
@@ -1,4 +1,6 @@
|
||||
<script lang="ts" context="module">
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
const createAttributeArgs = writable({
|
||||
showCreate: false,
|
||||
selectedOption: null as Option['name'] | null
|
||||
@@ -17,7 +19,7 @@
|
||||
<script lang="ts">
|
||||
import { goto, invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { realtime } from '$lib/stores/sdk';
|
||||
import { realtime, sdk } from '$lib/stores/sdk';
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
collection,
|
||||
@@ -25,16 +27,16 @@
|
||||
columnsOrder,
|
||||
databaseColumnSheetOptions,
|
||||
databaseRowSheetOptions,
|
||||
randomDataModalState,
|
||||
reorderItems,
|
||||
showCreateAttributeSheet
|
||||
} from './store';
|
||||
import { addSubPanel, registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
|
||||
import CreateAttribute from './createAttribute.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Option } from './attributes/store';
|
||||
import { CreateAttributePanel } from '$lib/commandCenter/panels';
|
||||
import { database } from '../store';
|
||||
import { project } from '$routes/(console)/project-[region]-[project]/store';
|
||||
import { project } from '../../../store';
|
||||
import { page } from '$app/state';
|
||||
import { base } from '$app/paths';
|
||||
import { canWriteCollections } from '$lib/stores/roles';
|
||||
@@ -42,6 +44,10 @@
|
||||
import SideSheet from './layout/sidesheet.svelte';
|
||||
import EditDocument from './editDocument.svelte';
|
||||
import EditAttribute from './attributes/edit.svelte';
|
||||
import { Dialog, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Button, Seekbar } from '$lib/elements/forms';
|
||||
import { generateFakeDocuments, generateAttributes } from '$lib/helpers/faker';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
|
||||
let editDocument: EditDocument;
|
||||
let createAttribute: CreateAttribute;
|
||||
@@ -208,6 +214,49 @@
|
||||
collections: 800,
|
||||
indexes: 700
|
||||
});
|
||||
|
||||
async function createFakeData() {
|
||||
$randomDataModalState.show = false;
|
||||
|
||||
let attributes = $collection.attributes;
|
||||
if (!attributes.length) {
|
||||
try {
|
||||
attributes = await generateAttributes(
|
||||
$project,
|
||||
page.params.database,
|
||||
page.params.collection
|
||||
);
|
||||
|
||||
await invalidate(Dependencies.COLLECTION);
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const documents = generateFakeDocuments(attributes, $randomDataModalState.value);
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.databases.createDocuments(page.params.database, page.params.collection, documents);
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Random data added successfully'
|
||||
});
|
||||
|
||||
await invalidate(Dependencies.DOCUMENTS);
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -263,3 +312,21 @@
|
||||
}}>
|
||||
<EditDocument bind:document={$databaseRowSheetOptions.document} bind:this={editDocument} />
|
||||
</SideSheet>
|
||||
|
||||
<Dialog title="Generate random data" bind:open={$randomDataModalState.show}>
|
||||
<Layout.Stack gap="xl">
|
||||
<Typography.Text>
|
||||
Select how many random records to generate for testing. This won't delete or replace
|
||||
your existing records.
|
||||
</Typography.Text>
|
||||
|
||||
<Seekbar max={100} breakpointCount={5} bind:value={$randomDataModalState.value} />
|
||||
</Layout.Stack>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Layout.Stack direction="row" gap="s" justifyContent="flex-end">
|
||||
<Button text on:click={() => ($randomDataModalState.show = false)}>Cancel</Button>
|
||||
<Button on:click={createFakeData}>Create</Button>
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
</Dialog>
|
||||
+12
-1
@@ -15,7 +15,8 @@
|
||||
isCsvImportInProgress,
|
||||
showRecordsCreateSheet,
|
||||
showCreateAttributeSheet,
|
||||
type Attributes
|
||||
type Attributes,
|
||||
randomDataModalState
|
||||
} from './store';
|
||||
import SpreadSheet from './spreadsheet.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
@@ -190,6 +191,11 @@
|
||||
onClick: () => {
|
||||
$showRecordsCreateSheet.show = true;
|
||||
}
|
||||
},
|
||||
random: {
|
||||
onClick: () => {
|
||||
$randomDataModalState.show = true;
|
||||
}
|
||||
}
|
||||
}} />
|
||||
{/if}
|
||||
@@ -204,6 +210,11 @@
|
||||
onClick: async () => {
|
||||
$showCreateAttributeSheet.show = true;
|
||||
}
|
||||
},
|
||||
random: {
|
||||
onClick: () => {
|
||||
$randomDataModalState.show = true;
|
||||
}
|
||||
}
|
||||
}} />
|
||||
{/if}
|
||||
|
||||
+195
-186
@@ -5,6 +5,7 @@
|
||||
import {
|
||||
ActionMenu,
|
||||
Badge,
|
||||
FloatingActionBar,
|
||||
Icon,
|
||||
Layout,
|
||||
Link,
|
||||
@@ -46,7 +47,6 @@
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import SideSheet from '../layout/sidesheet.svelte';
|
||||
import SpreadsheetContainer from '../layout/spreadsheet.svelte';
|
||||
import EmptySheet from '../layout/emptySheet.svelte';
|
||||
import { showCreateAttributeSheet } from '../store';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
@@ -100,6 +100,7 @@
|
||||
let showDropdown = $state([]);
|
||||
let showFailed = $state(false);
|
||||
let showDelete = $state(false);
|
||||
let selectedAttributes = $state([]);
|
||||
let showCreateIndex = $state(false);
|
||||
let selectedAttribute: Attributes = $state(null);
|
||||
|
||||
@@ -161,205 +162,213 @@
|
||||
</Container>
|
||||
|
||||
<div class="databases-spreadsheet">
|
||||
{#if updatedAttributes.length}
|
||||
<SpreadsheetContainer>
|
||||
<Spreadsheet.Root
|
||||
let:root
|
||||
allowSelection
|
||||
height="100%"
|
||||
emptyCells={emptyCellsCount}
|
||||
columns={[
|
||||
{ id: 'key', width: { min: 200 } },
|
||||
{ id: 'indexed', width: { min: 150 } },
|
||||
{ id: 'default', width: { min: 200 } },
|
||||
{ id: 'actions', width: 40, isAction: true }
|
||||
]}>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<Spreadsheet.Header.Cell column="key" {root}
|
||||
>Column name</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="indexed" {root}
|
||||
>Indexed</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="default" {root}
|
||||
>Default value</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="actions" {root} />
|
||||
</svelte:fragment>
|
||||
<SpreadsheetContainer>
|
||||
<Spreadsheet.Root
|
||||
let:root
|
||||
allowSelection
|
||||
height="100%"
|
||||
emptyCells={emptyCellsCount}
|
||||
bind:selectedRows={selectedAttributes}
|
||||
columns={[
|
||||
{ id: 'key', width: { min: 200 } },
|
||||
{ id: 'indexed', width: { min: 150 } },
|
||||
{ id: 'default', width: { min: 200 } },
|
||||
{ id: 'actions', width: 40, isAction: true }
|
||||
]}>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<Spreadsheet.Header.Cell column="key" {root}>Column name</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="indexed" {root}>Indexed</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="default" {root}
|
||||
>Default value</Spreadsheet.Header.Cell>
|
||||
<Spreadsheet.Header.Cell column="actions" {root} />
|
||||
</svelte:fragment>
|
||||
|
||||
{#each updatedAttributes as attribute, index}
|
||||
{@const option = attributeOptions.find(
|
||||
(option) => option.type === attribute.type
|
||||
)}
|
||||
<Spreadsheet.Row.Base {root} select={attribute['system'] ? 'disabled' : true}>
|
||||
<Spreadsheet.Cell column="key" {root} isEditable={false}>
|
||||
<Layout.Stack direction="row" alignItems="center">
|
||||
{#if isRelationship(attribute)}
|
||||
<Icon
|
||||
size="s"
|
||||
icon={attribute?.twoWay
|
||||
? IconSwitchHorizontal
|
||||
: IconArrowSmRight} />
|
||||
{:else if 'format' in attribute && attribute.format}
|
||||
{@const icon = attributeFormatIcon[attribute?.format]}
|
||||
<Icon {icon} size="s" />
|
||||
{:else if attribute.key === '$id'}
|
||||
<Icon icon={IconFingerPrint} size="s" />
|
||||
{:else}
|
||||
<Icon icon={option.icon} size="s" />
|
||||
{/if}
|
||||
{#each updatedAttributes as attribute, index}
|
||||
{@const option = attributeOptions.find((option) => option.type === attribute.type)}
|
||||
{@const isSelectable =
|
||||
attribute['system'] || attribute.type === 'relationship' ? 'disabled' : true}
|
||||
<Spreadsheet.Row.Base {root} select={isSelectable} id={attribute.key}>
|
||||
<Spreadsheet.Cell column="key" {root} isEditable={false}>
|
||||
<Layout.Stack direction="row" alignItems="center">
|
||||
{#if isRelationship(attribute)}
|
||||
<Icon
|
||||
size="s"
|
||||
icon={attribute?.twoWay
|
||||
? IconSwitchHorizontal
|
||||
: IconArrowSmRight} />
|
||||
{:else if 'format' in attribute && attribute.format}
|
||||
{@const icon = attributeFormatIcon[attribute?.format]}
|
||||
<Icon {icon} size="s" />
|
||||
{:else if attribute.key === '$id'}
|
||||
<Icon icon={IconFingerPrint} size="s" />
|
||||
{:else}
|
||||
<Icon icon={option.icon} size="s" />
|
||||
{/if}
|
||||
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
<Layout.Stack
|
||||
inline
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
gap="xxs">
|
||||
<span class="text u-trim-1" data-private>
|
||||
{#if attribute.key === '$id' || attribute.key === '$createdAt' || attribute.key === '$updatedAt'}
|
||||
{attribute['name']}
|
||||
{#if attribute.key === '$id'}
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
content="Primary key" />
|
||||
{/if}
|
||||
{:else}
|
||||
{attribute.key}
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
<Layout.Stack inline direction="row" alignItems="center" gap="xxs">
|
||||
<span class="text u-trim-1" data-private>
|
||||
{#if attribute.key === '$id' || attribute.key === '$createdAt' || attribute.key === '$updatedAt'}
|
||||
{attribute['name']}
|
||||
{#if attribute.key === '$id'}
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
content="Primary key" />
|
||||
{/if}
|
||||
</span>
|
||||
{#if isString(attribute) && attribute.encrypt}
|
||||
<Tooltip>
|
||||
<Icon
|
||||
size="s"
|
||||
icon={IconLockClosed}
|
||||
color="--fgcolor-neutral-tertiary" />
|
||||
<div slot="tooltip">Encrypted</div>
|
||||
</Tooltip>
|
||||
{:else}
|
||||
{attribute.key}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
{#if attribute.status !== 'available'}
|
||||
<Badge
|
||||
size="s"
|
||||
variant="secondary"
|
||||
content={attribute.status}
|
||||
type={getAttributeStatusBadge(attribute.status)} />
|
||||
{#if attribute.error}
|
||||
<Link.Button
|
||||
variant="muted"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
error = attribute.error;
|
||||
showFailed = true;
|
||||
}}>Details</Link.Button>
|
||||
{/if}
|
||||
{:else if attribute.required}
|
||||
<Badge size="xs" variant="secondary" content="required" />
|
||||
</span>
|
||||
{#if isString(attribute) && attribute.encrypt}
|
||||
<Tooltip>
|
||||
<Icon
|
||||
size="s"
|
||||
icon={IconLockClosed}
|
||||
color="--fgcolor-neutral-tertiary" />
|
||||
<div slot="tooltip">Encrypted</div>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
{#if attribute.status !== 'available'}
|
||||
<Badge
|
||||
size="s"
|
||||
variant="secondary"
|
||||
content={attribute.status}
|
||||
type={getAttributeStatusBadge(attribute.status)} />
|
||||
{#if attribute.error}
|
||||
<Link.Button
|
||||
variant="muted"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
error = attribute.error;
|
||||
showFailed = true;
|
||||
}}>Details</Link.Button>
|
||||
{/if}
|
||||
{:else if attribute.required}
|
||||
<Badge size="xs" variant="secondary" content="required" />
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="indexed" {root} isEditable={false}>
|
||||
{@const isIndexed = $indexes.some((index) =>
|
||||
index.attributes.includes(attribute.key)
|
||||
)}
|
||||
<Selector.Checkbox size="s" checked={isIndexed} disabled />
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="default" {root} isEditable={false}>
|
||||
{@const _default =
|
||||
attribute?.default !== null && attribute?.default !== undefined
|
||||
? attribute?.default
|
||||
: null}
|
||||
</Layout.Stack>
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="indexed" {root} isEditable={false}>
|
||||
{@const isIndexed = $indexes.some((index) =>
|
||||
index.attributes.includes(attribute.key)
|
||||
)}
|
||||
<Selector.Checkbox size="s" checked={isIndexed} disabled />
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="default" {root} isEditable={false}>
|
||||
{@const _default =
|
||||
attribute?.default !== null && attribute?.default !== undefined
|
||||
? attribute?.default
|
||||
: null}
|
||||
|
||||
{#if _default === null}
|
||||
<Badge variant="secondary" content="NULL" size="xs" />
|
||||
{:else}
|
||||
{_default}
|
||||
{/if}
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="actions" {root} isEditable={false}>
|
||||
{#if $isCsvImportInProgress}
|
||||
<CsvDisabled>
|
||||
<Button disabled text icon ariaLabel="more options">
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
</CsvDisabled>
|
||||
{:else}
|
||||
<!-- TODO: no portal, rather see if we can fix the cell -->
|
||||
<Popover let:toggle padding="none" placement="bottom-end" portal>
|
||||
<Button text icon ariaLabel="more options" on:click={toggle}>
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
<ActionMenu.Root slot="tooltip" let:toggle>
|
||||
{#if !attribute['system']}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconPencil}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
showEdit = true;
|
||||
selectedAttribute = attribute;
|
||||
showDropdown[index] = false;
|
||||
}}>
|
||||
Update
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{#if !isRelationship(attribute)}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconPlus}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
selectedAttribute = attribute;
|
||||
showCreateIndex = true;
|
||||
showDropdown[index] = false;
|
||||
}}>
|
||||
Create index
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{#if attribute.status !== 'processing' && !attribute['system']}
|
||||
<ActionMenu.Item.Button
|
||||
status="danger"
|
||||
leadingIcon={IconTrash}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
showDelete = true;
|
||||
showDropdown[index] = false;
|
||||
selectedAttribute = attribute;
|
||||
trackEvent(Click.DatabaseAttributeDelete);
|
||||
}}>
|
||||
Delete
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
</ActionMenu.Root>
|
||||
</Popover>
|
||||
{/if}
|
||||
</Spreadsheet.Cell>
|
||||
</Spreadsheet.Row.Base>
|
||||
{/each}
|
||||
{#if _default === null}
|
||||
<Badge variant="secondary" content="NULL" size="xs" />
|
||||
{:else}
|
||||
{_default}
|
||||
{/if}
|
||||
</Spreadsheet.Cell>
|
||||
<Spreadsheet.Cell column="actions" {root} isEditable={false}>
|
||||
{#if $isCsvImportInProgress}
|
||||
<CsvDisabled>
|
||||
<Button disabled text icon ariaLabel="more options">
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
</CsvDisabled>
|
||||
{:else}
|
||||
<!-- TODO: no portal, rather see if we can fix the cell -->
|
||||
<Popover let:toggle padding="none" placement="bottom-end" portal>
|
||||
<Button text icon ariaLabel="more options" on:click={toggle}>
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
<ActionMenu.Root slot="tooltip" let:toggle>
|
||||
{#if !attribute['system']}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconPencil}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
showEdit = true;
|
||||
selectedAttribute = attribute;
|
||||
showDropdown[index] = false;
|
||||
}}>
|
||||
Update
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{#if !isRelationship(attribute)}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconPlus}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
selectedAttribute = attribute;
|
||||
showCreateIndex = true;
|
||||
showDropdown[index] = false;
|
||||
}}>
|
||||
Create index
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{#if attribute.status !== 'processing' && !attribute['system']}
|
||||
<ActionMenu.Item.Button
|
||||
status="danger"
|
||||
leadingIcon={IconTrash}
|
||||
on:click={(event) => {
|
||||
toggle(event);
|
||||
showDelete = true;
|
||||
showDropdown[index] = false;
|
||||
selectedAttribute = attribute;
|
||||
trackEvent(Click.DatabaseAttributeDelete);
|
||||
}}>
|
||||
Delete
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
</ActionMenu.Root>
|
||||
</Popover>
|
||||
{/if}
|
||||
</Spreadsheet.Cell>
|
||||
</Spreadsheet.Row.Base>
|
||||
{/each}
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
alignContent="center"
|
||||
alignItems="center"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text variant="m-400" color="--fgcolor-neutral-secondary">
|
||||
{updatedAttributes.length} columns
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<svelte:fragment slot="footer">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
alignContent="center"
|
||||
alignItems="center"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text variant="m-400" color="--fgcolor-neutral-secondary">
|
||||
{updatedAttributes.length} columns
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
</Spreadsheet.Root>
|
||||
</SpreadsheetContainer>
|
||||
|
||||
{#if selectedAttributes.length > 0}
|
||||
<div class="floating-action-bar">
|
||||
<FloatingActionBar>
|
||||
<svelte:fragment slot="start">
|
||||
<div style:width="max-content">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="m">
|
||||
<Badge content={selectedAttributes.length.toString()} />
|
||||
<span style:font-size="14px">
|
||||
{selectedAttributes.length > 1 ? 'attributes' : 'attribute'}
|
||||
selected
|
||||
</span>
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</Spreadsheet.Root>
|
||||
</SpreadsheetContainer>
|
||||
{:else}
|
||||
<EmptySheet
|
||||
mode="columns"
|
||||
showActions={$canWriteCollections}
|
||||
actions={{
|
||||
primary: {
|
||||
onClick: () => ($showCreateAttributeSheet.show = true)
|
||||
}
|
||||
}} />
|
||||
<svelte:fragment slot="end">
|
||||
<Button text on:click={() => (selectedAttributes = [])}>Cancel</Button>
|
||||
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</FloatingActionBar>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if showDelete}
|
||||
{#if selectedAttribute}
|
||||
<Delete bind:showDelete {selectedAttribute} />
|
||||
{:else if selectedAttributes && selectedAttributes.length}
|
||||
<Delete bind:showDelete bind:selectedAttribute={selectedAttributes} />
|
||||
{/if}
|
||||
|
||||
<SideSheet
|
||||
|
||||
+65
-29
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
import { InputChoice } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
@@ -10,38 +9,65 @@
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { isRelationship } from '../document-[document]/attributes/store';
|
||||
import Confirm from '$lib/components/confirm.svelte';
|
||||
import { Layout } from '@appwrite.io/pink-svelte';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
|
||||
export let showDelete = false;
|
||||
export let selectedAttribute: Attributes;
|
||||
const databaseId = page.params.database;
|
||||
let {
|
||||
showDelete = $bindable(false),
|
||||
selectedAttribute = $bindable(null)
|
||||
}: {
|
||||
showDelete: boolean;
|
||||
selectedAttribute: Attributes | string[];
|
||||
} = $props();
|
||||
|
||||
let error: string;
|
||||
let checked = false;
|
||||
let checked = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
const selectedAttributes = $derived(
|
||||
Array.isArray(selectedAttribute) ? selectedAttribute : [selectedAttribute]
|
||||
);
|
||||
|
||||
const selectedKeys = $derived(getKeys(selectedAttribute));
|
||||
|
||||
const requiresTwoWayConfirm = $derived(
|
||||
selectedAttributes.some((attr: string | Attributes) => {
|
||||
typeof attr === 'string' ? false : isRelationship(attr) && attr.twoWay;
|
||||
})
|
||||
);
|
||||
|
||||
const isDeleteBtnDisabled = $derived(requiresTwoWayConfirm && !checked);
|
||||
|
||||
function getKeys(selected: Attributes | string[]): string[] {
|
||||
return Array.isArray(selected) ? selected : [selected.key];
|
||||
}
|
||||
|
||||
// TODO: sync the columnsOrder here as well.
|
||||
async function handleDelete() {
|
||||
try {
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.databases.deleteAttribute(databaseId, $collection.$id, selectedAttribute.key);
|
||||
const client = sdk.forProject(page.params.region, page.params.project);
|
||||
|
||||
showDelete = false;
|
||||
await Promise.all(
|
||||
selectedAttributes.map((key) =>
|
||||
client.databases.deleteAttribute(page.params.database, $collection.$id, key)
|
||||
)
|
||||
);
|
||||
|
||||
trackEvent(Submit.AttributeDelete);
|
||||
invalidate(Dependencies.COLLECTION);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `Attribute has been deleted`
|
||||
message:
|
||||
selectedAttributes.length === 1
|
||||
? 'Attribute has been deleted'
|
||||
: `${selectedAttributes.length} attributes have been deleted`
|
||||
});
|
||||
trackEvent(Submit.AttributeDelete);
|
||||
await goto(
|
||||
`${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/collection-${page.params.collection}/attributes`
|
||||
);
|
||||
|
||||
showDelete = false;
|
||||
selectedAttribute = [];
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
trackError(e, Submit.AttributeDelete);
|
||||
}
|
||||
}
|
||||
|
||||
$: isDeleteBtnDisabled =
|
||||
isRelationship(selectedAttribute) && selectedAttribute?.twoWay && !checked;
|
||||
</script>
|
||||
|
||||
<Confirm
|
||||
@@ -50,12 +76,22 @@
|
||||
title="Delete attribute"
|
||||
bind:error
|
||||
disabled={isDeleteBtnDisabled}>
|
||||
<p>
|
||||
Are you sure you want to delete <b data-private>{selectedAttribute?.key}</b> from
|
||||
<b data-private>{$collection?.name}</b>?
|
||||
</p>
|
||||
{#if isRelationship(selectedAttribute) && selectedAttribute?.twoWay}
|
||||
<div class="u-flex u-flex-vertical u-gap-24">
|
||||
{#if selectedAttributes.length === 1}
|
||||
<p>
|
||||
Are you sure you want to delete <b data-private>{selectedKeys[0]}</b> from
|
||||
<b data-private>{$collection?.name}</b>?
|
||||
</p>
|
||||
{:else}
|
||||
<p>
|
||||
Are you sure you want to delete <b data-private>{selectedKeys.join(', ')}</b> from
|
||||
<b data-private>{$collection?.name}</b>?
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if requiresTwoWayConfirm}
|
||||
<!-- not allowed on multi selections, safe to assume that this isn't a string! -->
|
||||
{@const attribute = selectedAttribute[0]}
|
||||
<Layout.Stack direction="column" gap="xl">
|
||||
<p>
|
||||
This is a two way relationship and the corresponding relationship will also be
|
||||
deleted.
|
||||
@@ -63,10 +99,10 @@
|
||||
<p><b>This action is irreversible.</b></p>
|
||||
<ul>
|
||||
<InputChoice id="delete" label="Delete" showLabel={false} bind:value={checked}>
|
||||
Delete relationship between <b data-private>{selectedAttribute.key}</b> to
|
||||
<b data-private>{selectedAttribute.twoWayKey}</b>
|
||||
Delete relationship between <b data-private>{attribute.key}</b> to
|
||||
<b data-private>{attribute.twoWayKey}</b>
|
||||
</InputChoice>
|
||||
</ul>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Confirm>
|
||||
+7
-10
@@ -167,16 +167,13 @@
|
||||
</Button.Button>
|
||||
|
||||
{#if mode === 'records'}
|
||||
<Tooltip>
|
||||
<Button.Button
|
||||
size="s"
|
||||
variant="secondary"
|
||||
disabled={actions?.random?.disabled}
|
||||
onclick={actions?.random?.onClick}>
|
||||
{actions?.random?.text ?? `Generate random data`}
|
||||
</Button.Button>
|
||||
<span slot="tooltip">Yet to be added</span>
|
||||
</Tooltip>
|
||||
<Button.Button
|
||||
size="s"
|
||||
variant="secondary"
|
||||
disabled={actions?.random?.disabled}
|
||||
onclick={actions?.random?.onClick}>
|
||||
{actions?.random?.text ?? `Generate random data`}
|
||||
</Button.Button>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
|
||||
+7
-2
@@ -27,7 +27,8 @@
|
||||
showCreateAttributeSheet,
|
||||
reorderItems,
|
||||
columnsOrder,
|
||||
columnsWidth
|
||||
columnsWidth,
|
||||
randomDataModalState
|
||||
} from './store';
|
||||
import RelationshipsModal from './relationshipsModal.svelte';
|
||||
import type { Column, ColumnType } from '$lib/helpers/types';
|
||||
@@ -649,7 +650,11 @@
|
||||
</Typography.Text>
|
||||
|
||||
<div style:margin-right="var(--space-6)">
|
||||
<Button.Button variant="extra-compact">Generate random data</Button.Button>
|
||||
<Button.Button
|
||||
variant="extra-compact"
|
||||
on:click={() => {
|
||||
$randomDataModalState.show = true;
|
||||
}}>Generate random data</Button.Button>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
|
||||
+5
@@ -117,3 +117,8 @@ export function reorderItems<T extends { id: string } | { key: string }>(
|
||||
...items.filter((item) => !orderSet.has(getItemId(item)))
|
||||
];
|
||||
}
|
||||
|
||||
export const randomDataModalState = writable({
|
||||
show: false,
|
||||
value: 25 // initial value!
|
||||
});
|
||||
Reference in new issue
Block a user