add: copy url, make divider full-width.

This commit is contained in:
Darshan committed 2025-08-29 10:42:28 +05:30
1 parent 36df7d42b4
commit 9be909f6c2
5 files changed
+96 -19

No files matched your search

@@ -60,8 +60,9 @@
import CreateIndex from './indexes/createIndex.svelte';
import { hash } from '$lib/helpers/string';
import { preferences } from '$lib/stores/preferences';
import { isRelationship } from './rows/store';
import { buildRowUrl, isRelationship } from './rows/store';
import { chunks } from '$lib/helpers/array';
import { copy } from '$lib/helpers/copy';
let editRow: EditRow;
let editRelatedRow: EditRelatedRow;
@@ -382,6 +383,12 @@
text: 'Update',
disabled: editRow?.isDisabled(),
onClick: async () => await editRow?.update()
}}
topAction={{
mode: 'copy-tag',
text: 'Row URL',
show: !!($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id),
value: buildRowUrl($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id)
}}>
<EditRow
bind:this={editRow}
@@ -1,7 +1,15 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { Button, Form } from '$lib/elements/forms';
import { Badge, Divider, Layout, Sheet, Typography } from '@appwrite.io/pink-svelte';
import {
Badge,
Divider,
Layout,
Sheet,
Tag,
Typography
} from '@appwrite.io/pink-svelte';
import { Copy } from '$lib/components';
let {
show = $bindable(false),
@@ -10,12 +18,22 @@
submit,
children = null,
footer = null,
titleBadge = null
titleBadge = null,
topAction = null
}: {
show: boolean;
title: string;
titleBadge?: string;
closeOnBlur?: boolean;
topAction?:
| {
text: string;
value: string;
show?: boolean;
mode?: 'copy-tag' | 'plaintext';
onClick?: () => string | Promise<string>;
}
| undefined;
submit?:
| {
text: string;
@@ -26,6 +44,8 @@
children?: Snippet;
footer?: Snippet | null;
} = $props();
let copyText = $state(undefined);
</script>
<div class="sheet-container">
@@ -37,6 +57,24 @@
{#if titleBadge}
<Badge variant="secondary" content={titleBadge} size="s" />
{/if}
{#if topAction && topAction.text && topAction.show}
{#if topAction.mode === 'copy-tag'}
<Copy value={topAction.value} {copyText}>
<Tag size="xs" variant="code">
{topAction.text}
</Tag>
</Copy>
{:else}
<Button
extraCompact
text
size="xs"
on:click={topAction.onClick ?? undefined}>
{topAction.text}
</Button>
{/if}
{/if}
</Layout.Stack>
</Layout.Stack>
</div>
@@ -1,3 +1,4 @@
import { page } from '$app/state';
import type { Columns } from '../store';
import { type Models, Query } from '@appwrite.io/console';
@@ -33,3 +34,7 @@ export function buildWildcardColumnsQuery(table: Models.Table | null = null): st
Query.select(['*'])
];
}
export function buildRowUrl(rowId: string) {
return `${page.url}/row-${rowId}`;
}
@@ -14,6 +14,7 @@
| 'duplicate-row'
| 'permissions'
| 'activity'
| 'copy-url'
| 'copy-json'
// | 'copy-snippet'
| 'delete';
@@ -29,6 +30,7 @@
IconClipboardCopy,
IconDuplicate,
IconKey,
IconLink,
IconPencil,
IconSortAscending,
IconSortDescending,
@@ -67,6 +69,7 @@
{ label: 'Manage permissions', icon: IconKey, action: 'permissions' },
{ label: 'View activity', icon: IconChartBar, action: 'activity' },
{ divider: true },
{ label: 'Copy URL', icon: IconLink, action: 'copy-url' },
{ label: 'Copy as JSON', icon: IconClipboardCopy, action: 'copy-json' },
{ divider: true },
{ label: 'Delete', icon: IconTrash, action: 'delete', danger: true }
@@ -156,21 +159,29 @@
<!-- hacky, i know! -->
<span bind:this={htmlSpanElement}> </span>
<ActionMenu.Root width="180px">
{#each menuItems as item, index (index)}
{#if item.divider}
<div style:padding-block="0.25rem">
<Divider />
</div>
{:else if shouldShow(item)}
<ActionMenu.Item.Button
leadingIcon={item.icon}
status={item.danger ? 'danger' : undefined}
on:click={() => item.action && handleSelect(item.action, hide)}>
{item.label}
</ActionMenu.Item.Button>
{/if}
{/each}
</ActionMenu.Root>
<div class="action-menu-root">
<ActionMenu.Root width="180px">
{#each menuItems as item, index (index)}
{#if item.divider}
<div style:padding-block="0.5rem" style:margin-inline="-1rem;">
<Divider />
</div>
{:else if shouldShow(item)}
<ActionMenu.Item.Button
leadingIcon={item.icon}
status={item.danger ? 'danger' : undefined}
on:click={() => item.action && handleSelect(item.action, hide)}>
{item.label}
</ActionMenu.Item.Button>
{/if}
{/each}
</ActionMenu.Root>
</div>
</svelte:fragment>
</Popover>
<style>
.action-menu-root :global(:first-child) {
overflow: visible;
}
</style>
@@ -12,6 +12,7 @@
import { type ComponentType, onDestroy, onMount } from 'svelte';
import type { PageData } from './$types';
import {
buildRowUrl,
buildWildcardColumnsQuery,
isRelationship,
isRelationshipToMany,
@@ -530,6 +531,21 @@
$rowPermissionSheet.show = true;
}
if (action === 'copy-url') {
try {
await copy(buildRowUrl(row.$id));
addNotification({
type: 'success',
message: 'Row url copied'
});
} catch (e) {
addNotification({
type: 'error',
message: e.message
});
}
}
if (action === 'copy-json') {
const stringified = JSON.stringify(row, null, 2);
try {