saleor-dashboard/src/utils/sort.ts
dominik-zeglen c231de44b5 Code cleanup
2019-09-16 17:11:07 +02:00

28 lines
682 B
TypeScript

import { TableCellHeaderArrowDirection } from "../components/TableCellHeader";
import { Sort } from "../types";
import { OrderDirection } from "../types/globalTypes";
export function getSortUrlVariables<TSortKey extends string>(
field: TSortKey,
params: Sort<TSortKey>
): Sort<TSortKey> {
if (field === params.sort) {
return {
asc: !params.asc,
sort: field
};
}
return {
asc: true,
sort: field
};
}
export function getOrderDirection(asc: boolean): OrderDirection {
return asc ? OrderDirection.ASC : OrderDirection.DESC;
}
export function getArrowDirection(asc: boolean): TableCellHeaderArrowDirection {
return asc ? "asc" : "desc";
}