From c1f94be9b29fdef426c69bd86277abb042d2d7c9 Mon Sep 17 00:00:00 2001 From: itsconquest Date: Wed, 19 Oct 2022 15:25:20 +1300 Subject: [PATCH] fix(notifications): sort by newest first by default [EE-4467] (#7891) --- app/react/components/datatables/types.ts | 5 +++-- app/react/portainer/notifications/NotificationsView.tsx | 2 +- app/react/portainer/notifications/datatable-store.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/react/components/datatables/types.ts b/app/react/components/datatables/types.ts index 021bc6d5b..81a125e27 100644 --- a/app/react/components/datatables/types.ts +++ b/app/react/components/datatables/types.ts @@ -24,10 +24,11 @@ export interface SortableTableSettings { export function sortableSettings( set: Set, - initialSortBy = 'name' + initialSortBy = 'name', + desc = false ): SortableTableSettings { return { - sortBy: { id: initialSortBy, desc: false }, + sortBy: { id: initialSortBy, desc }, setSortBy: (id: string, desc: boolean) => set({ sortBy: { id, desc } }), }; } diff --git a/app/react/portainer/notifications/NotificationsView.tsx b/app/react/portainer/notifications/NotificationsView.tsx index 3b4069500..90dca55b0 100644 --- a/app/react/portainer/notifications/NotificationsView.tsx +++ b/app/react/portainer/notifications/NotificationsView.tsx @@ -18,7 +18,7 @@ import { columns } from './columns'; import { createStore } from './datatable-store'; const storageKey = 'notifications-list'; -const useSettingsStore = createStore(storageKey, 'time'); +const useSettingsStore = createStore(storageKey, 'time', true); export function NotificationsView() { const settingsStore = useSettingsStore(); diff --git a/app/react/portainer/notifications/datatable-store.ts b/app/react/portainer/notifications/datatable-store.ts index acc4e5770..d0e0e4c81 100644 --- a/app/react/portainer/notifications/datatable-store.ts +++ b/app/react/portainer/notifications/datatable-store.ts @@ -19,11 +19,15 @@ interface TableSettings SettableColumnsTableSettings, RefreshableTableSettings {} -export function createStore(storageKey: string, initialSortBy?: string) { +export function createStore( + storageKey: string, + initialSortBy?: string, + desc?: boolean +) { return create()( persist( (set) => ({ - ...sortableSettings(set, initialSortBy), + ...sortableSettings(set, initialSortBy, desc), ...paginationSettings(set), ...hiddenColumnsSettings(set), ...refreshableSettings(set),