mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge pull request #2076 from appwrite/fix-preferences
This commit is contained in:
7 files changed
+112
-75
No files matched your search
@@ -20,6 +20,7 @@
|
||||
|
||||
let maxHeight = $state('none');
|
||||
let containerRef = $state<HTMLElement>(null);
|
||||
const collectionId = $derived(page.params.collection);
|
||||
|
||||
const calcMaxHeight = () => {
|
||||
if (containerRef) {
|
||||
@@ -32,10 +33,10 @@
|
||||
};
|
||||
|
||||
const saveColumnPreferences = () => {
|
||||
const shownColumns = $columns.filter((n) => n.hide !== true).map((n) => n.id);
|
||||
const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
|
||||
|
||||
if (isCustomCollection) {
|
||||
preferences.setCustomCollectionColumns(page.params.collection, shownColumns);
|
||||
preferences.setCustomCollectionColumns(collectionId, shownColumns);
|
||||
} else {
|
||||
preferences.setColumns(shownColumns);
|
||||
}
|
||||
@@ -43,24 +44,24 @@
|
||||
|
||||
onMount(() => {
|
||||
if (isCustomCollection) {
|
||||
const shownColumns = preferences.getCustomCollectionColumns(page.params.collection);
|
||||
const shownColumns = preferences.getCustomCollectionColumns(collectionId);
|
||||
|
||||
columns.update((columns) => {
|
||||
return columns.map((column) => {
|
||||
column.hide = !shownColumns.includes(column.id);
|
||||
columns.update((n) =>
|
||||
n.map((column) => {
|
||||
column.hide = shownColumns?.includes(column.id) ?? false;
|
||||
return column;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
} else {
|
||||
const prefs = preferences.get(page.route);
|
||||
|
||||
if (prefs?.columns && prefs.columns.length > 0) {
|
||||
columns.update((cols) => {
|
||||
return cols.map((column) => {
|
||||
column.hide = !prefs.columns.includes(column.id);
|
||||
if (prefs?.columns) {
|
||||
columns.update((n) =>
|
||||
n.map((column) => {
|
||||
column.hide = prefs.columns?.includes(column.id) ?? false;
|
||||
return column;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@
|
||||
columns.update((cols) =>
|
||||
cols.map((col) => {
|
||||
if (col.id === column.id) {
|
||||
col.hide = !column.hide;
|
||||
column.hide = !column.hide;
|
||||
}
|
||||
return col;
|
||||
})
|
||||
@@ -90,6 +91,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={calcMaxHeight} />
|
||||
|
||||
{#if $columns?.length}
|
||||
<Popover let:toggle placement="bottom-end" padding="none">
|
||||
{@render children(toggle, selectedColumnsNumber)}
|
||||
|
||||
@@ -176,7 +176,7 @@ function createPreferences() {
|
||||
names: TeamPreferences['names']
|
||||
) => {
|
||||
let teamPrefs: Models.Preferences;
|
||||
update((n) => {
|
||||
await updateAndSync((n) => {
|
||||
if (!n?.displayNames) {
|
||||
n ??= {};
|
||||
n.displayNames ??= {};
|
||||
|
||||
+3
-2
@@ -34,12 +34,13 @@
|
||||
const filterColumns = writable<Column[]>([]);
|
||||
|
||||
$: selected = preferences.getCustomCollectionColumns(page.params.collection);
|
||||
|
||||
$: columns.set(
|
||||
$collection.attributes.map((attribute) => ({
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type as ColumnType,
|
||||
hide: !selected?.includes(attribute.key),
|
||||
hide: !!selected?.includes(attribute.key),
|
||||
array: attribute?.array,
|
||||
format: 'format' in attribute && attribute?.format === 'enum' ? attribute.format : null,
|
||||
elements: 'elements' in attribute ? attribute.elements : null
|
||||
@@ -50,7 +51,7 @@
|
||||
...['$id', '$createdAt', '$updatedAt'].map((id) => ({
|
||||
id,
|
||||
title: id,
|
||||
hide: false,
|
||||
show: true,
|
||||
type: (id === '$id' ? 'string' : 'datetime') as ColumnType
|
||||
}))
|
||||
]);
|
||||
|
||||
+23
-3
@@ -116,9 +116,29 @@
|
||||
$: totalCount = relatedList?.length ?? 0;
|
||||
|
||||
$: options =
|
||||
documentList?.documents?.map((n) => {
|
||||
const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]);
|
||||
return { value: n.$id, label: n.$id, data };
|
||||
documentList?.documents?.map((document) => {
|
||||
const names = displayNames.filter((name) => name !== '$id');
|
||||
const values = names
|
||||
.map((name) => document?.[name])
|
||||
// always supposed to be a string but just being a bit safe here
|
||||
.filter((value) => value != null && typeof value === 'string' && value !== '');
|
||||
|
||||
const displayValues = !editing
|
||||
? values
|
||||
: // on non edit routes like create, there's enough space!
|
||||
values.map((value) => (value.length > 5 ? value.slice(0, 5) + '...' : value));
|
||||
|
||||
const label = !values.length
|
||||
? document.$id
|
||||
: // values are in `$id (a | b)` format
|
||||
// previously used to have a `$id a | b`.
|
||||
`${document.$id} (${displayValues.join(' | ')})`;
|
||||
|
||||
return {
|
||||
label,
|
||||
value: document.$id,
|
||||
data: names.map((name) => document?.[name])
|
||||
};
|
||||
}) ?? [];
|
||||
|
||||
$: hasItems = totalCount > 0;
|
||||
|
||||
+3
-3
@@ -22,15 +22,15 @@
|
||||
data = null;
|
||||
selectedRelationship = null;
|
||||
}
|
||||
|
||||
$: tableColumns = [{ id: '$id', width: 200 }, ...args.map((id) => ({ id }))];
|
||||
</script>
|
||||
|
||||
<Modal bind:show title={selectedRelationship?.key} hideFooter>
|
||||
{#if data?.length}
|
||||
<Paginator items={data} {limit}>
|
||||
{#snippet children(paginatedItems: typeof data)}
|
||||
<Table.Root
|
||||
let:root
|
||||
columns={[{ id: '$id', width: 150 }, ...args.map((id) => ({ id }))]}>
|
||||
<Table.Root let:root columns={tableColumns}>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<Table.Header.Cell column="$id" {root}>Document ID</Table.Header.Cell>
|
||||
{#if args?.length}
|
||||
|
||||
+61
-33
@@ -15,12 +15,24 @@
|
||||
import { organization } from '$lib/stores/organization';
|
||||
|
||||
const collectionId = page.params.collection;
|
||||
let names: string[] = [...(preferences.getDisplayNames()?.[collectionId] ?? [])];
|
||||
|
||||
function getDisplayNames() {
|
||||
return [...(preferences.getDisplayNames()?.[collectionId] ?? [])].filter(
|
||||
(name) => name !== '$id'
|
||||
); // edge case with `$id`? got saved during tests!
|
||||
}
|
||||
|
||||
let names: string[] = $state(getDisplayNames());
|
||||
|
||||
async function updateDisplayName() {
|
||||
try {
|
||||
await preferences.setDisplayNames($organization.$id, collectionId, names);
|
||||
names = [...(preferences.getDisplayNames()?.[collectionId] ?? [])];
|
||||
// $state makes proxy,
|
||||
// structuredClone doesn't work
|
||||
const regularArray = [...names];
|
||||
|
||||
await preferences.setDisplayNames($organization.$id, collectionId, regularArray);
|
||||
names = getDisplayNames();
|
||||
|
||||
await invalidate(Dependencies.TEAM);
|
||||
addNotification({
|
||||
message: 'Display names has been updated',
|
||||
@@ -36,23 +48,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: options = ($attributes as Models.AttributeString[])
|
||||
.filter(
|
||||
(attr) =>
|
||||
attr.type === 'string' && !attr?.array && !names?.some((name) => name === attr.key)
|
||||
)
|
||||
.map((attr) => {
|
||||
return {
|
||||
function getValidAttributes() {
|
||||
return ($attributes as Models.AttributeString[]).filter(
|
||||
(attr) => attr.type === 'string' && !attr?.array
|
||||
);
|
||||
}
|
||||
|
||||
function getOptions(index: number) {
|
||||
const current = names?.[index];
|
||||
return getValidAttributes()
|
||||
.filter((attr) => !names?.includes(attr.key) || attr.key === current)
|
||||
.map((attr) => ({
|
||||
value: attr.key,
|
||||
label: attr.key
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
$: addAttributeDisabled = names?.length >= 5 || (names?.length && !names[names?.length - 1]);
|
||||
const addAttributeDisabled = $derived(
|
||||
names?.length >= 5 || (names?.length && !names[names?.length - 1])
|
||||
);
|
||||
|
||||
$: updateBtnDisabled =
|
||||
const updateBtnDisabled = $derived(
|
||||
!symmetricDifference(names, preferences.getDisplayNames()?.[collectionId] ?? [])?.length ||
|
||||
(names?.length && !last(names));
|
||||
(names?.length && !last(names))
|
||||
);
|
||||
|
||||
const hasExhaustedOptions = $derived(getValidAttributes().length === names?.length);
|
||||
</script>
|
||||
|
||||
<Form onSubmit={updateDisplayName}>
|
||||
@@ -72,19 +93,22 @@
|
||||
</span>
|
||||
</Layout.Stack>
|
||||
{#if names?.length}
|
||||
{#each names as name, i}
|
||||
{#each names as name, index}
|
||||
<Layout.Stack direction="row" gap="xxs">
|
||||
{@const options = getOptions(index)}
|
||||
{@const disabled =
|
||||
(!!names[index] && names.length > index + 1) || hasExhaustedOptions}
|
||||
<InputSelect
|
||||
id={name}
|
||||
placeholder="Select attribute"
|
||||
bind:value={names[i]}
|
||||
disabled={!!names[i] && names.length > i + 1}
|
||||
{options} />
|
||||
{options}
|
||||
{disabled}
|
||||
bind:value={names[index]}
|
||||
placeholder="Select attribute" />
|
||||
<Button
|
||||
icon
|
||||
extraCompact
|
||||
on:click={() => {
|
||||
names.splice(i, 1);
|
||||
names.splice(index, 1);
|
||||
names = names;
|
||||
}}>
|
||||
<Icon icon={IconX} />
|
||||
@@ -92,18 +116,22 @@
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
{/if}
|
||||
<div>
|
||||
<Button
|
||||
compact
|
||||
disabled={addAttributeDisabled}
|
||||
on:click={() => {
|
||||
names[names.length] = null;
|
||||
names = names;
|
||||
}}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Add attribute
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- show only when options don't have all the attributes -->
|
||||
{#if !hasExhaustedOptions}
|
||||
<div>
|
||||
<Button
|
||||
compact
|
||||
disabled={addAttributeDisabled}
|
||||
on:click={() => {
|
||||
names[names.length] = null;
|
||||
names = names;
|
||||
}}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Add attribute
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
+4
-18
@@ -10,7 +10,7 @@
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { afterUpdate, onMount } from 'svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
import {
|
||||
isRelationship,
|
||||
@@ -38,30 +38,16 @@
|
||||
|
||||
const databaseId = page.params.database;
|
||||
const collectionId = page.params.collection;
|
||||
|
||||
let displayNames = {};
|
||||
let showRelationships = false;
|
||||
let selectedRelationship: Models.AttributeRelationship = null;
|
||||
let relationshipData: Partial<Models.Document>[];
|
||||
let displayNames = {};
|
||||
|
||||
onMount(async () => {
|
||||
displayNames = preferences.getDisplayNames();
|
||||
updateMaxWidth();
|
||||
});
|
||||
|
||||
afterUpdate(() => updateMaxWidth());
|
||||
|
||||
function updateMaxWidth() {
|
||||
const tableCells = Array.from(document.querySelectorAll('.less-width-truncated'));
|
||||
|
||||
const visibleColumnsCount = $columns.filter((col) => !col.hide).length;
|
||||
const newMaxWidth = Math.max(50 - (visibleColumnsCount - 1) * 5, 25);
|
||||
|
||||
tableCells.forEach((cell) => {
|
||||
const cellItem = cell as HTMLElement;
|
||||
cellItem.style.maxWidth = `${newMaxWidth}vw`;
|
||||
});
|
||||
}
|
||||
|
||||
function formatArray(array: unknown[]) {
|
||||
if (array.length === 0) return '[ ]';
|
||||
|
||||
@@ -108,7 +94,7 @@
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type as ColumnType,
|
||||
hide: !selected?.includes(attribute.key),
|
||||
hide: !!selected?.includes(attribute.key),
|
||||
array: attribute?.array,
|
||||
width: { min: 168 },
|
||||
format:
|
||||
|
||||
Reference in new issue
Block a user