From 86af600143f06c941348edbe2e893282e4694853 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 29 Feb 2024 20:37:01 -0800 Subject: [PATCH 1/3] fix(components): only override columns if prefs found Before this, it didn't matter if a column had show = false as it would default to be show if preferences weren't found. --- src/lib/components/viewSelector.svelte | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/components/viewSelector.svelte b/src/lib/components/viewSelector.svelte index 0ece86889..4aeb21dd7 100644 --- a/src/lib/components/viewSelector.svelte +++ b/src/lib/components/viewSelector.svelte @@ -31,12 +31,15 @@ } else { const prefs = preferences.get($page.route); - columns.set( - $columns.map((column) => { - column.show = prefs.columns?.includes(column.id) ?? true; - return column; - }) - ); + // Override the shown columns only if a preference was set + if (prefs?.columns) { + columns.set( + $columns.map((column) => { + column.show = prefs.columns?.includes(column.id) ?? true; + return column; + }) + ); + } } columns.subscribe((ctx) => { From 6991e5bf32a3ca7fcc77c8e3cccf63a8c736d8cb Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 29 Feb 2024 20:46:22 -0800 Subject: [PATCH 2/3] fix(messaging): localize the topics columns When it was global, the state (show values) would persist when switching between different projects rather than resetting back to the default. --- .../messaging/topics/+page.svelte | 23 +++++++++++++++++-- .../messaging/topics/store.ts | 11 --------- .../messaging/topics/table.svelte | 9 ++++---- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/routes/console/project-[project]/messaging/topics/+page.svelte b/src/routes/console/project-[project]/messaging/topics/+page.svelte index 4cd0959c8..118d31a46 100644 --- a/src/routes/console/project-[project]/messaging/topics/+page.svelte +++ b/src/routes/console/project-[project]/messaging/topics/+page.svelte @@ -16,14 +16,33 @@ import { base } from '$app/paths'; import type { Models } from '@appwrite.io/console'; import type { PageData } from './$types'; - import { columns, showCreate } from './store'; + import { showCreate } from './store'; import { View } from '$lib/helpers/load'; import { Filters, hasPageQueries } from '$lib/components/filters'; import Table from './table.svelte'; + import type { Column } from '$lib/helpers/types'; + import { writable } from 'svelte/store'; export let data: PageData; const project = $page.params.project; + const columns = writable([ + { id: '$id', title: 'Topic ID', type: 'string', show: true, width: 140 }, + { id: 'name', title: 'Name', type: 'string', show: true, width: 140 }, + { id: 'emailTotal', title: 'Email Subscribers', type: 'integer', show: false, width: 140 }, + { id: 'smsTotal', title: 'SMS Subscribers', type: 'integer', show: false, width: 140 }, + { id: 'pushTotal', title: 'Push Subscribers', type: 'integer', show: false, width: 140 }, + { + id: 'total', + title: 'Subscribers', + type: 'integer', + show: true, + filter: false, + width: 140 + }, + { id: '$createdAt', title: 'Created', type: 'datetime', show: true, width: 140 } + ]); + const topicCreated = async (event: CustomEvent>>) => { await goto(`${base}/console/project-${project}/messaging/topics/topic-${event.detail.$id}`); }; @@ -73,7 +92,7 @@ {#if data.topics.total} - +
([ - { id: '$id', title: 'Topic ID', type: 'string', show: true, width: 140 }, - { id: 'name', title: 'Name', type: 'string', show: true, width: 140 }, - { id: 'emailTotal', title: 'Email Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'smsTotal', title: 'SMS Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'pushTotal', title: 'Push Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'total', title: 'Subscribers', type: 'integer', show: true, filter: false, width: 140 }, - { id: '$createdAt', title: 'Created', type: 'datetime', show: true, width: 140 } -]); diff --git a/src/routes/console/project-[project]/messaging/topics/table.svelte b/src/routes/console/project-[project]/messaging/topics/table.svelte index 8e611a83b..9ffc0b2eb 100644 --- a/src/routes/console/project-[project]/messaging/topics/table.svelte +++ b/src/routes/console/project-[project]/messaging/topics/table.svelte @@ -16,13 +16,14 @@ } from '$lib/elements/table'; import { addNotification } from '$lib/stores/notifications'; import type { PageData } from './$types'; - import { columns } from './store'; import { project } from '$routes/console/project-[project]/store'; import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; import { toLocaleDateTime } from '$lib/helpers/date'; + import type { Column } from '$lib/helpers/types'; + export let columns: Column[]; export let data: PageData; let selectedIds: string[] = []; @@ -62,7 +63,7 @@ d.$id)} /> - {#each $columns as column} + {#each columns as column} {#if column.show} {column.title} {/if} @@ -74,10 +75,10 @@ href={`${base}/console/project-${$project.$id}/messaging/topics/topic-${topic.$id}`}> - {#each $columns as column (column.id)} + {#each columns as column (column.id)} {#if column.show} {#if column.id === '$id'} - {#key $columns} + {#key column.id} {topic.$id} From 2c8acf343097b8342a15fda8794ad3f6b9361eb3 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 29 Feb 2024 20:49:10 -0800 Subject: [PATCH 3/3] fix(messaging): localize the messages columns When it was global, the state (show values) would persist when switching between different projects rather than resetting back to the default. --- .../console/project-[project]/messaging/+page.svelte | 12 +++++++++++- .../console/project-[project]/messaging/store.ts | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/routes/console/project-[project]/messaging/+page.svelte b/src/routes/console/project-[project]/messaging/+page.svelte index e27bd3f07..ea367ea75 100644 --- a/src/routes/console/project-[project]/messaging/+page.svelte +++ b/src/routes/console/project-[project]/messaging/+page.svelte @@ -34,12 +34,14 @@ import FailedModal from './failedModal.svelte'; import MessageStatusPill from './messageStatusPill.svelte'; import ProviderType from './providerType.svelte'; - import { columns, showCreate } from './store'; + import { showCreate } from './store'; import { sdk } from '$lib/stores/sdk'; import { invalidate } from '$app/navigation'; import { trackEvent, Submit, trackError } from '$lib/actions/analytics'; import { Dependencies } from '$lib/constants'; import { addNotification } from '$lib/stores/notifications'; + import type { Column } from '$lib/helpers/types'; + import { writable } from 'svelte/store'; export let data: PageData; let selected: string[] = []; @@ -50,6 +52,14 @@ let showCreateDropdownMobile = false; let showCreateDropdownDesktop = false; let showCreateDropdownEmpty = false; + const columns = writable([ + { id: '$id', title: 'Message ID', type: 'string', show: true, width: 140 }, + { id: 'message', title: 'Message', type: 'string', show: false, filter: false, width: 140 }, + { id: 'providerType', title: 'Type', type: 'string', show: true, width: 100 }, + { id: 'status', title: 'Status', type: 'string', show: true, width: 120 }, + { id: 'scheduledAt', title: 'Scheduled at', type: 'datetime', show: true, width: 120 }, + { id: 'deliveredAt', title: 'Delivered at', type: 'datetime', show: false, width: 120 } + ]); const project = $page.params.project; diff --git a/src/routes/console/project-[project]/messaging/store.ts b/src/routes/console/project-[project]/messaging/store.ts index bf214f6c3..cdd4bffdc 100644 --- a/src/routes/console/project-[project]/messaging/store.ts +++ b/src/routes/console/project-[project]/messaging/store.ts @@ -1,17 +1,7 @@ -import type { Column } from '$lib/helpers/types'; import type { Models } from '@appwrite.io/console'; import { writable } from 'svelte/store'; export const showCreate = writable(false); -export const columns = writable([ - { id: '$id', title: 'Message ID', type: 'string', show: true, width: 140 }, - { id: 'message', title: 'Message', type: 'string', show: false, filter: false, width: 140 }, - { id: 'providerType', title: 'Type', type: 'string', show: true, width: 100 }, - { id: 'status', title: 'Status', type: 'string', show: true, width: 120 }, - { id: 'scheduledAt', title: 'Scheduled at', type: 'datetime', show: true, width: 120 }, - { id: 'deliveredAt', title: 'Delivered at', type: 'datetime', show: false, width: 120 } -]); - export const targetsById = writable>({}); export const topicsById = writable>({});