mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
update: array empty column badge;
update: colum selector <> account preferences sync, show count only after a user changed the selection;
This commit is contained in:
1 parent
ae2f45fe2d
commit
13b36fc3c2
6 files changed
+102
-36
No files matched your search
@@ -20,7 +20,8 @@
|
||||
ui = 'legacy',
|
||||
allowNoColumns = false,
|
||||
showAnyway = false,
|
||||
children
|
||||
children,
|
||||
onPreferencesUpdated = null
|
||||
}: {
|
||||
columns: Writable<Column[]>;
|
||||
isCustomTable?: boolean;
|
||||
@@ -28,6 +29,7 @@
|
||||
ui?: 'legacy' | 'new';
|
||||
showAnyway?: boolean;
|
||||
children: Snippet<[toggle: () => void, selectedColumnsNumber: number]>;
|
||||
onPreferencesUpdated?: () => void;
|
||||
} = $props();
|
||||
|
||||
let search = $state('');
|
||||
@@ -60,7 +62,9 @@
|
||||
const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
|
||||
|
||||
if (isCustomTable) {
|
||||
preferences.setCustomTableColumns(page.params.table, shownColumns);
|
||||
preferences.setCustomTableColumns(page.params.table, shownColumns).then(() => {
|
||||
onPreferencesUpdated?.();
|
||||
});
|
||||
} else {
|
||||
preferences.setColumns(shownColumns);
|
||||
}
|
||||
@@ -211,10 +215,8 @@
|
||||
>Deselect all</Button>
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<div style:padding-inline="0.6rem">
|
||||
<Typography.Text>
|
||||
No column named "{search}" was found
|
||||
</Typography.Text>
|
||||
<div style:padding-inline="0.6rem" style:padding-block-end="0.5rem">
|
||||
<Typography.Text>No results found</Typography.Text>
|
||||
</div>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
|
||||
@@ -7,29 +7,72 @@
|
||||
import ViewToggle from './viewToggle.svelte';
|
||||
import ColumnSelector from './columnSelector.svelte';
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { page } from '$app/state';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
|
||||
export let onlyIcon = false;
|
||||
export let ui: 'legacy' | 'new' = 'legacy';
|
||||
export let columns: Writable<Column[]>;
|
||||
export let view: View;
|
||||
export let isCustomTable = false;
|
||||
export let hideView = false;
|
||||
export let hideColumns = false;
|
||||
export let allowNoColumns = false;
|
||||
export let showAnyway = false;
|
||||
interface Props {
|
||||
onlyIcon?: boolean;
|
||||
ui?: 'legacy' | 'new';
|
||||
columns: Writable<Column[]>;
|
||||
view: View;
|
||||
isCustomTable?: boolean;
|
||||
hideView?: boolean;
|
||||
hideColumns?: boolean;
|
||||
allowNoColumns?: boolean;
|
||||
showAnyway?: boolean;
|
||||
}
|
||||
|
||||
let {
|
||||
onlyIcon = false,
|
||||
ui = 'legacy',
|
||||
columns,
|
||||
view = $bindable(),
|
||||
isCustomTable = false,
|
||||
hideView = false,
|
||||
hideColumns = false,
|
||||
allowNoColumns = false,
|
||||
showAnyway = false
|
||||
}: Props = $props();
|
||||
|
||||
let showCountBadge = $state(false);
|
||||
const preferenceKey = $derived(getPreferenceKey());
|
||||
|
||||
function getPreferenceKey(): string {
|
||||
const tableId = page.params.table;
|
||||
const organizationId = page.data.organization?.$id ?? page.data.project?.teamId;
|
||||
return hash([organizationId, tableId].filter(Boolean).join('#'));
|
||||
}
|
||||
|
||||
function updateBadgeState() {
|
||||
if (!preferences.getKey(preferenceKey, false)) {
|
||||
showCountBadge = true;
|
||||
preferences.setKey(preferenceKey, true);
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
showCountBadge = !onlyIcon || !!preferences.getKey(preferenceKey, false);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if !hideColumns && view === View.Table}
|
||||
<ColumnSelector {columns} {isCustomTable} {allowNoColumns} {ui} {showAnyway}>
|
||||
<ColumnSelector
|
||||
{ui}
|
||||
{columns}
|
||||
{showAnyway}
|
||||
{isCustomTable}
|
||||
{allowNoColumns}
|
||||
onPreferencesUpdated={updateBadgeState}>
|
||||
{#snippet children(toggle, selectedColumnsNumber)}
|
||||
<Button.Button
|
||||
size="s"
|
||||
icon={onlyIcon}
|
||||
onclick={toggle}
|
||||
variant="secondary"
|
||||
class={onlyIcon && !$isSmallViewport ? 'width-fix' : undefined}
|
||||
disabled={!$columns.length && showAnyway}
|
||||
badge={selectedColumnsNumber.toString()}
|
||||
on:click={toggle}>
|
||||
class={onlyIcon && !$isSmallViewport ? 'width-fix' : undefined}
|
||||
badge={showCountBadge ? selectedColumnsNumber.toString() : undefined}>
|
||||
<Icon slot="start" icon={IconViewBoards} />
|
||||
</Button.Button>
|
||||
{/snippet}
|
||||
|
||||
@@ -149,7 +149,7 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
return faker.internet.url();
|
||||
}
|
||||
}
|
||||
return ''
|
||||
return '';
|
||||
} else {
|
||||
const stringAttr = column as Models.ColumnString;
|
||||
const maxLength = Math.min(stringAttr.size ?? 255, 1000);
|
||||
|
||||
@@ -43,6 +43,9 @@ type ConsolePreferencesStore = {
|
||||
columnWidths?: {
|
||||
[key: string]: TeamPreferences['widths'];
|
||||
};
|
||||
miscellaneous?: {
|
||||
[key: string]: string | number | boolean;
|
||||
};
|
||||
} & { hideAiDisclaimer?: boolean };
|
||||
|
||||
async function updateConsolePreferences(store: ConsolePreferencesStore): Promise<void> {
|
||||
@@ -294,6 +297,22 @@ function createPreferences() {
|
||||
n.tableHeaderExpanded[tableId] = expanded;
|
||||
return n;
|
||||
});
|
||||
},
|
||||
|
||||
getKey<T>(key: string, _default: T): T {
|
||||
return (preferences?.miscellaneous?.[key] ?? _default) as T;
|
||||
},
|
||||
|
||||
async setKey(key: string, value: string | number | boolean) {
|
||||
await updateAndSync((n) => {
|
||||
if (!n?.miscellaneous) {
|
||||
n ??= {};
|
||||
n.miscellaneous ??= {};
|
||||
}
|
||||
|
||||
n.miscellaneous[key] = value;
|
||||
return n;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+3
-1
@@ -275,7 +275,9 @@
|
||||
</Layout.Stack>
|
||||
{@const minMaxSize = getMinMaxSizeForColumn(column)}
|
||||
{#if minMaxSize}
|
||||
<Typography.Caption variant="400">
|
||||
<Typography.Caption
|
||||
variant="400"
|
||||
color="--fgcolor-neutral-tertiary">
|
||||
{minMaxSize}
|
||||
</Typography.Caption>
|
||||
{/if}
|
||||
|
||||
+15
-15
@@ -264,18 +264,14 @@
|
||||
}
|
||||
|
||||
function formatArray(array: unknown[]) {
|
||||
if (array.length === 0) return '[ ]';
|
||||
if (array.length === 0) return 'Empty';
|
||||
|
||||
let formattedFields: string[] = [];
|
||||
for (const item of array) {
|
||||
if (typeof item === 'string') {
|
||||
formattedFields.push(`"${item}"`);
|
||||
} else {
|
||||
formattedFields.push(`${item}`);
|
||||
}
|
||||
formattedFields.push(`${item}`);
|
||||
}
|
||||
|
||||
return `[${formattedFields.join(', ')}]`;
|
||||
return `${formattedFields.join(', ')}`;
|
||||
}
|
||||
|
||||
function formatColumn(column: unknown) {
|
||||
@@ -342,9 +338,6 @@
|
||||
);
|
||||
}
|
||||
|
||||
// trigger ui update with randomized key!
|
||||
spreadsheetRenderKey.set(`sorted#${Date.now()}`);
|
||||
|
||||
// save > navigate > restore!
|
||||
spreadsheetContainer.saveGridSheetScroll();
|
||||
await goto(`${url.pathname}${url.search}`);
|
||||
@@ -532,9 +525,13 @@
|
||||
Object.entries(row).filter(([key]) => !SYSTEM_KEYS.has(key))
|
||||
);
|
||||
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.grids.updateRow(databaseId, tableId, row.$id, onlyData, row.$permissions);
|
||||
await sdk.forProject(page.params.region, page.params.project).grids.updateRow({
|
||||
databaseId,
|
||||
tableId,
|
||||
rowId: row.$id,
|
||||
data: onlyData,
|
||||
permissions: row.$permissions
|
||||
});
|
||||
|
||||
invalidate(Dependencies.ROW);
|
||||
trackEvent(Submit.RowUpdate);
|
||||
@@ -742,8 +739,8 @@
|
||||
{#if row === null}
|
||||
<Spreadsheet.Row.Base
|
||||
{root}
|
||||
virtualItem={item}
|
||||
{index}
|
||||
virtualItem={item}
|
||||
id={`loading-${index}`}
|
||||
select={rowSelection}>
|
||||
{#each $tableColumns as col}
|
||||
@@ -838,6 +835,7 @@
|
||||
{:else}
|
||||
{@const value = row[columnId]}
|
||||
{@const formatted = formatColumn(row[columnId])}
|
||||
{@const isEmptyArray = formatted === 'Empty'}
|
||||
{@const isDatetimeAttribute = rowColumn.type === 'datetime'}
|
||||
{@const isEncryptedAttribute =
|
||||
isString(rowColumn) && rowColumn.encrypt}
|
||||
@@ -868,6 +866,8 @@
|
||||
</Tooltip>
|
||||
{:else if formatted === 'null'}
|
||||
<Badge variant="secondary" content="NULL" size="xs" />
|
||||
{:else if isEmptyArray}
|
||||
<Badge variant="secondary" content={formatted} size="xs" />
|
||||
{:else}
|
||||
<Typography.Text truncate>
|
||||
{formatted}
|
||||
@@ -1087,7 +1087,7 @@
|
||||
}
|
||||
|
||||
/* TODO: not good! */
|
||||
& :global(input) {
|
||||
& :global(input[type='text']) {
|
||||
padding-inline: 8px !important;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user