Skip to content

Commit e22527f

Browse files
committed
fix: column selector logic.
1 parent aa8a3b2 commit e22527f

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/lib/components/columnSelector.svelte

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
let maxHeight = $state('none');
2222
let containerRef = $state<HTMLElement>(null);
23+
const collectionId = $derived(page.params.collection);
2324
2425
const calcMaxHeight = () => {
2526
if (containerRef) {
@@ -32,38 +33,47 @@
3233
};
3334
3435
const saveColumnPreferences = () => {
35-
const shownColumns = $columns.filter((n) => n.hide !== true).map((n) => n.id);
36+
const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
3637
3738
if (isCustomCollection) {
38-
preferences.setCustomCollectionColumns(page.params.collection, shownColumns);
39+
preferences.setCustomCollectionColumns(collectionId, shownColumns);
3940
} else {
4041
preferences.setColumns(shownColumns);
4142
}
4243
};
4344
4445
onMount(() => {
4546
if (isCustomCollection) {
46-
const shownColumns = preferences.getCustomCollectionColumns(page.params.collection);
47+
const shownColumns = preferences.getCustomCollectionColumns(collectionId);
4748
48-
columns.update((columns) => {
49-
return columns.map((column) => {
50-
column.hide = !shownColumns.includes(column.id);
49+
columns.set(
50+
$columns.map((column) => {
51+
column.hide = shownColumns?.includes(column.id) ?? false;
5152
return column;
52-
});
53-
});
53+
})
54+
);
5455
} else {
5556
const prefs = preferences.get(page.route);
5657
57-
if (prefs?.columns && prefs.columns.length > 0) {
58-
columns.update((cols) => {
59-
return cols.map((column) => {
60-
column.hide = !prefs.columns.includes(column.id);
58+
if (prefs?.columns) {
59+
columns.set(
60+
$columns.map((column) => {
61+
column.hide = prefs.columns?.includes(column.id) ?? false;
6162
return column;
62-
});
63-
});
63+
})
64+
);
6465
}
6566
}
6667
68+
columns.subscribe((ctx) => {
69+
const columns = ctx.filter((n) => n.hide === true).map((n) => n.id);
70+
if (isCustomCollection) {
71+
preferences.setCustomCollectionColumns(collectionId, columns);
72+
} else {
73+
preferences.setColumns(columns);
74+
}
75+
});
76+
6777
calcMaxHeight();
6878
});
6979
@@ -79,7 +89,7 @@
7989
columns.update((cols) =>
8090
cols.map((col) => {
8191
if (col.id === column.id) {
82-
col.hide = !column.hide;
92+
column.hide = !column.hide;
8393
}
8494
return col;
8595
})

src/lib/stores/preferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function createPreferences() {
176176
names: TeamPreferences['names']
177177
) => {
178178
let teamPrefs: Models.Preferences;
179-
update((n) => {
179+
await updateAndSync((n) => {
180180
if (!n?.displayNames) {
181181
n ??= {};
182182
n.displayNames ??= {};

src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
const filterColumns = writable<Column[]>([]);
3535
3636
$: selected = preferences.getCustomCollectionColumns(page.params.collection);
37+
3738
$: columns.set(
3839
$collection.attributes.map((attribute) => ({
3940
id: attribute.key,
4041
title: attribute.key,
4142
type: attribute.type as ColumnType,
42-
hide: !selected?.includes(attribute.key),
43+
show: selected?.includes(attribute.key) ?? true,
4344
array: attribute?.array,
4445
format: 'format' in attribute && attribute?.format === 'enum' ? attribute.format : null,
4546
elements: 'elements' in attribute ? attribute.elements : null
@@ -50,7 +51,7 @@
5051
...['$id', '$createdAt', '$updatedAt'].map((id) => ({
5152
id,
5253
title: id,
53-
hide: false,
54+
show: true,
5455
type: (id === '$id' ? 'string' : 'datetime') as ColumnType
5556
}))
5657
]);

src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@
3838
3939
const databaseId = page.params.database;
4040
const collectionId = page.params.collection;
41+
42+
let displayNames = {};
4143
let showRelationships = false;
4244
let selectedRelationship: Models.AttributeRelationship = null;
4345
let relationshipData: Partial<Models.Document>[];
44-
let displayNames = {};
4546
4647
onMount(async () => {
4748
displayNames = preferences.getDisplayNames();
4849
updateMaxWidth();
4950
});
5051
52+
// replace with `$effect` later!
5153
afterUpdate(() => updateMaxWidth());
5254
5355
function updateMaxWidth() {
@@ -108,7 +110,7 @@
108110
id: attribute.key,
109111
title: attribute.key,
110112
type: attribute.type as ColumnType,
111-
hide: !selected?.includes(attribute.key),
113+
show: selected?.includes(attribute.key) ?? true,
112114
array: attribute?.array,
113115
width: { min: 168 },
114116
format:

0 commit comments

Comments
 (0)