From f66bee006eca9689a27d3de71cf208f7bb4da24d Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Mon, 17 Jun 2024 14:42:53 +0200 Subject: [PATCH] :bug: Use initialSort property (#1962) Before, initialSort property passed as parameter to useTableControlState() hook was not used as default value. Instead the defaults were calculated based on available sortable columns. Signed-off-by: Radoslaw Szwajkowski --- .../app/hooks/table-controls/sorting/useSortState.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/app/hooks/table-controls/sorting/useSortState.ts b/client/src/app/hooks/table-controls/sorting/useSortState.ts index 87fc61904c..fc583142e9 100644 --- a/client/src/app/hooks/table-controls/sorting/useSortState.ts +++ b/client/src/app/hooks/table-controls/sorting/useSortState.ts @@ -73,9 +73,11 @@ export const useSortState = < ): ISortState => { const { isSortEnabled, persistTo = "state", persistenceKeyPrefix } = args; const sortableColumns = (isSortEnabled && args.sortableColumns) || []; - const initialSort: IActiveSort | null = sortableColumns[0] - ? { columnKey: sortableColumns[0], direction: "asc" } - : null; + const initialSort = (isSortEnabled && args.initialSort) || null; + const defaultInitialSort: IActiveSort | null = + sortableColumns[0] + ? { columnKey: sortableColumns[0], direction: "asc" } + : null; // We won't need to pass the latter two type params here if TS adds support for partial inference. // See https://github.com/konveyor/tackle2-ui/issues/1456 @@ -85,7 +87,7 @@ export const useSortState = < "sortColumn" | "sortDirection" >({ isEnabled: !!isSortEnabled, - defaultValue: initialSort, + defaultValue: initialSort ?? defaultInitialSort, persistenceKeyPrefix, // Note: For the discriminated union here to work without TypeScript getting confused // (e.g. require the urlParams-specific options when persistTo === "urlParams"),