Commit e7966b02 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: allow sorting users

parent 7e0ff978
...@@ -38,7 +38,6 @@ import Breadcrumbs from '@/modules/ui/Breadcrumbs' ...@@ -38,7 +38,6 @@ import Breadcrumbs from '@/modules/ui/Breadcrumbs'
import Header from '@/modules/ui/Header' import Header from '@/modules/ui/Header'
import Triangle from '@/modules/ui/Triangle' import Triangle from '@/modules/ui/Triangle'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import { ensureArray } from '@/utils/ensureArray'
import { ensureScalar } from '@/utils/ensureScalar' import { ensureScalar } from '@/utils/ensureScalar'
import usePagination from '@/utils/usePagination' import usePagination from '@/utils/usePagination'
...@@ -539,12 +538,10 @@ function sanitizeQuery(params?: ParsedUrlQuery): GetSources.QueryParameters { ...@@ -539,12 +538,10 @@ function sanitizeQuery(params?: ParsedUrlQuery): GetSources.QueryParameters {
} }
if (params.order !== undefined) { if (params.order !== undefined) {
const order = ensureArray( const order = ensureScalar(params.order)
params.order, if (itemSortOrders.includes(order as ItemSortOrder)) {
).filter((sortOrder): sortOrder is ItemSortOrder => sanitized.push(['order', order])
itemSortOrders.includes(sortOrder as ItemSortOrder), }
)
sanitized.push(['order', order])
} }
if (params.page !== undefined) { if (params.page !== undefined) {
......
...@@ -37,13 +37,12 @@ import Breadcrumbs from '@/modules/ui/Breadcrumbs' ...@@ -37,13 +37,12 @@ import Breadcrumbs from '@/modules/ui/Breadcrumbs'
import Header from '@/modules/ui/Header' import Header from '@/modules/ui/Header'
import Triangle from '@/modules/ui/Triangle' import Triangle from '@/modules/ui/Triangle'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import { ensureArray } from '@/utils/ensureArray'
import { ensureScalar } from '@/utils/ensureScalar' import { ensureScalar } from '@/utils/ensureScalar'
import usePagination from '@/utils/usePagination' import usePagination from '@/utils/usePagination'
const itemSortOrders = ['label', 'modified-on'] as const const itemSortOrders = ['username', 'date'] as const
type ItemSortOrder = typeof itemSortOrders[number] type ItemSortOrder = typeof itemSortOrders[number]
const defaultItemSortOrder: ItemSortOrder = 'modified-on' const defaultItemSortOrder: ItemSortOrder = 'username'
/** /**
* Users screen. * Users screen.
...@@ -117,8 +116,8 @@ export default function UsersScreen(): JSX.Element { ...@@ -117,8 +116,8 @@ export default function UsersScreen(): JSX.Element {
) : ( ) : (
<Fragment> <Fragment>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="space-x-8"> <div className="flex items-center space-x-8">
{/* <ItemSortOrder filter={query} /> */} <ItemSortOrder filter={query} />
<ItemSearch filter={query} /> <ItemSearch filter={query} />
</div> </div>
<ItemPagination filter={query} results={users.data} /> <ItemPagination filter={query} results={users.data} />
...@@ -225,49 +224,49 @@ interface ItemSortOrderProps { ...@@ -225,49 +224,49 @@ interface ItemSortOrderProps {
/** /**
* Sort order. * Sort order.
*/ */
// function ItemSortOrder(props: ItemSortOrderProps) { function ItemSortOrder(props: ItemSortOrderProps) {
// const { filter } = props const { filter } = props
// const router = useRouter() const router = useRouter()
// const currentSortOrder = const currentSortOrder =
// filter.order === undefined filter.order === undefined
// ? defaultItemSortOrder ? defaultItemSortOrder
// : (filter.order[0] as ItemSortOrder) : (filter.order as ItemSortOrder)
// function onSubmit(order: Key) { function onSubmit(order: Key) {
// const query = { ...filter } const query = { ...filter }
// if (order === defaultItemSortOrder) { if (order === defaultItemSortOrder) {
// delete query.order delete query.order
// } else { } else {
// query.order = [order as ItemSortOrder] query.order = order as ItemSortOrder
// } }
// router.push({ query }) router.push({ query })
// } }
// /** we don't get labels for sort order from the backend */ /** we don't get labels for sort order from the backend */
// const labels: Record<ItemSortOrder, string> = { const labels: Record<ItemSortOrder, string> = {
// label: 'name', username: 'username',
// 'modified-on': 'last modification', date: 'registration date',
// } }
// const items = itemSortOrders.map((id) => ({ id, label: labels[id] })) const items = itemSortOrders.map((id) => ({ id, label: labels[id] }))
// return ( return (
// <Select <Select
// aria-label="Sort order" aria-label="Sort order"
// items={items} items={items}
// onSelectionChange={onSubmit} onSelectionChange={onSubmit}
// selectedKey={currentSortOrder} selectedKey={currentSortOrder}
// > >
// {(item) => ( {(item) => (
// <Select.Item key={item.id} textValue={item.label}> <Select.Item key={item.id} textValue={item.label}>
// Sort by {item.label} Sort by {item.label}
// </Select.Item> </Select.Item>
// )} )}
// </Select> </Select>
// ) )
// } }
interface ItemSearchProps { interface ItemSearchProps {
filter: GetUsers.QueryParameters filter: GetUsers.QueryParameters
...@@ -534,12 +533,10 @@ function sanitizeQuery(params?: ParsedUrlQuery): GetUsers.QueryParameters { ...@@ -534,12 +533,10 @@ function sanitizeQuery(params?: ParsedUrlQuery): GetUsers.QueryParameters {
} }
if (params.order !== undefined) { if (params.order !== undefined) {
const order = ensureArray( const order = ensureScalar(params.order)
params.order, if (itemSortOrders.includes(order as ItemSortOrder)) {
).filter((sortOrder): sortOrder is ItemSortOrder => sanitized.push(['order', order])
itemSortOrders.includes(sortOrder as ItemSortOrder), }
)
sanitized.push(['order', order])
} }
if (params.page !== undefined) { if (params.page !== undefined) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment