Skip to content

Commit

Permalink
🐛 Use initialSort property (#1962)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rszwajko authored Jun 17, 2024
1 parent 7717dd6 commit f66bee0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions client/src/app/hooks/table-controls/sorting/useSortState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ export const useSortState = <
): ISortState<TSortableColumnKey> => {
const { isSortEnabled, persistTo = "state", persistenceKeyPrefix } = args;
const sortableColumns = (isSortEnabled && args.sortableColumns) || [];
const initialSort: IActiveSort<TSortableColumnKey> | null = sortableColumns[0]
? { columnKey: sortableColumns[0], direction: "asc" }
: null;
const initialSort = (isSortEnabled && args.initialSort) || null;
const defaultInitialSort: IActiveSort<TSortableColumnKey> | 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
Expand All @@ -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"),
Expand Down

0 comments on commit f66bee0

Please sign in to comment.