(
`/api/v1/user?take=${currentPageSize}&skip=${
pageIndex * currentPageSize
- }&sort=${currentSort}`
+ }&sort=${currentSort}&sortDirection=${sortDirection}`
);
+ const handleSortChange = (sortKey: Sort) => {
+ if (currentSort === sortKey) {
+ setSortDirection(sortDirection === 'asc' ? 'desc' : 'asc');
+ } else {
+ setCurrentSort(sortKey);
+ setSortDirection('desc');
+ }
+ };
+
const [isDeleting, setDeleting] = useState(false);
const [showImportModal, setShowImportModal] = useState(false);
const [deleteModal, setDeleteModal] = useState<{
@@ -133,6 +160,9 @@ const UserList = () => {
setCurrentSort(filterSettings.currentSort);
setCurrentPageSize(filterSettings.currentPageSize);
+ if (filterSettings.sortDirection) {
+ setSortDirection(filterSettings.sortDirection);
+ }
}
}, []);
@@ -142,9 +172,74 @@ const UserList = () => {
JSON.stringify({
currentSort,
currentPageSize,
+ sortDirection,
})
);
- }, [currentSort, currentPageSize]);
+ }, [currentSort, currentPageSize, sortDirection]);
+
+ const SortableColumnHeader = ({
+ sortKey,
+ currentSort,
+ sortDirection,
+ onSortChange,
+ children,
+ }: {
+ sortKey: Sort;
+ currentSort: Sort;
+ sortDirection: SortDirection;
+ onSortChange: (sortKey: Sort) => void;
+ children: React.ReactNode;
+ }) => {
+ const intl = useIntl();
+
+ const getTooltip = () => {
+ if (currentSort === sortKey) {
+ return intl.formatMessage(messages.toggleSortDirection, {
+ direction:
+ sortDirection === 'asc'
+ ? intl.formatMessage(messages.descending)
+ : intl.formatMessage(messages.ascending),
+ });
+ }
+
+ switch (sortKey) {
+ case 'displayname':
+ return intl.formatMessage(messages.sortByUser);
+ case 'requests':
+ return intl.formatMessage(messages.sortByRequests);
+ case 'usertype':
+ return intl.formatMessage(messages.sortByType);
+ case 'role':
+ return intl.formatMessage(messages.sortByRole);
+ case 'created':
+ return intl.formatMessage(messages.sortByJoined);
+ default:
+ return intl.formatMessage(messages.sortBy, { field: sortKey });
+ }
+ };
+
+ return (
+ onSortChange(sortKey)}
+ data-testid={`column-header-${sortKey}`}
+ title={getTooltip()}
+ >
+
+ {children}
+ {currentSort === sortKey && (
+
+ {sortDirection === 'asc' ? (
+
+ ) : (
+
+ )}
+
+ )}
+
+
+ );
+ };
const isUserPermsEditable = (userId: number) =>
userId !== 1 && userId !== currentUser?.id;
@@ -519,7 +614,7 @@ const UserList = () => {
{intl.formatMessage(messages.createlocaluser)}
-
-
-
-
-
-
@@ -584,11 +654,46 @@ const UserList = () => {
/>
)}
- {intl.formatMessage(messages.user)}
- {intl.formatMessage(messages.totalrequests)}
- {intl.formatMessage(messages.accounttype)}
- {intl.formatMessage(messages.role)}
- {intl.formatMessage(messages.created)}
+
+ {intl.formatMessage(messages.user)}
+
+
+ {intl.formatMessage(messages.totalrequests)}
+
+
+ {intl.formatMessage(messages.accounttype)}
+
+
+ {intl.formatMessage(messages.role)}
+
+
+ {intl.formatMessage(messages.created)}
+
{(data.results ?? []).length > 1 && (