Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Use initialSort property #1962

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading