← All changes
|
js/components/common/ListTable/ListTable.tsx
+12
-2
3.10.0
→
4.0.0-beta.2
View file →
| @@ -128,8 +128,11 @@ | ||
| 128 | 128 | ListTableRowsProps<T, K> { |
| 129 | 129 | items: T[] |
| 130 | 130 | beforeTable?: ReactNode |
| 131 | 131 | selectAllControl?: boolean |
| 132 | + | |
| 133 | + /** Column and direction to sort by before the reader touches a heading. */ | |
| 134 | + initialSort?: { columnId: string, direction: ListTableSortDirection } | |
| 132 | 135 | } |
| 133 | 136 | |
| 134 | 137 | export const ListTable = <T, K extends Key, A extends string = never>({ |
| 135 | 138 | items, |
| @@ -135,15 +138,22 @@ | ||
| 135 | 138 | items, |
| 136 | 139 | getKey, |
| 137 | 140 | totalPages, |
| 138 | 141 | pageSearchParam = 'paged', |
| 142 | + initialSort, | |
| 139 | 143 | ...tableProps |
| 140 | 144 | }: ListTableProps<T, K, A>) => { |
| 141 | - const [sortColumn, setSortColumn] = useState<ListTableColumn<T>>() | |
| 145 | + const [sortColumn, setSortColumn] = useState<ListTableColumn<T> | undefined>( | |
| 146 | + () => initialSort | |
| 147 | + ? tableProps.columns.find(column => column.id === initialSort.columnId && column.sortedValue) | |
| 148 | + : undefined | |
| 149 | + ) | |
| 142 | 150 | const [currentPage, setCurrentPage] = useState( |
| 143 | 151 | () => pageSearchParam && Number(fetchQueryParam(pageSearchParam)) || 1 |
| 144 | 152 | ) |
| 145 | - const [sortDirection, setSortDirection] = useState<ListTableSortDirection>('asc') | |
| 153 | + const [sortDirection, setSortDirection] = useState<ListTableSortDirection>( | |
| 154 | + () => initialSort?.direction ?? 'asc' | |
| 155 | + ) | |
| 146 | 156 | |
| 147 | 157 | const visibleItems: T[] = useMemo( |
| 148 | 158 | () => pageItems(sortTableItems(items, sortColumn, sortDirection), { currentPage, totalPages }), |
| 149 | 159 | [items, sortColumn, sortDirection, currentPage, totalPages]) |