Commit 16d72de9 authored by Marjolaine Bodin's avatar Marjolaine Bodin
Browse files

#507 sort order

parent 552842b9
Pipeline #49537 passed with stage
in 2 minutes and 58 seconds
......@@ -68,7 +68,7 @@ function getColumns({ showProposalLinks, showInvestigationStats, showFiles }) {
},
{
text: 'Beamline',
dataField: 'visitId',
dataField: 'instrument',
formatter: (_, investigation) => (
<span style={{ fontWeight: 'bold' }}>
{beamlineFormatter(investigation)}
......@@ -100,7 +100,7 @@ function getColumns({ showProposalLinks, showInvestigationStats, showFiles }) {
{
text: 'Title',
sort: true,
dataField: 'title',
dataField: 'summary',
formatter: (_, investigation) =>
investigation.title.length < 10
? investigation.summary
......@@ -160,33 +160,21 @@ function InvestigationTable(props) {
const [search, setSearch] = React.useState('');
const [startDate, setStartDate] = React.useState(undefined);
const [endDate, setEndDate] = React.useState(undefined);
const [sortField, setSortField] = React.useState('startDate');
const [sortOrder, setSortOrder] = React.useState(-1);
let fetchingParams = {
const fetchingParams = {
limit: sizePerPage,
skip: sizePerPage * (page - 1),
filter,
sortBy: sortField,
sortOrder,
search,
startDate: startDate ? moment(startDate).format('YYYY-MM-DD') : undefined,
endDate: endDate ? moment(endDate).format('YYYY-MM-DD') : undefined,
};
if (filter) {
fetchingParams = { ...fetchingParams, filter };
}
if (search && search.length > 0) {
fetchingParams = { ...fetchingParams, search: search.toString() };
}
if (startDate) {
fetchingParams = {
...fetchingParams,
startDate: moment(startDate).format('YYYY-MM-DD'),
};
}
if (endDate) {
fetchingParams = {
...fetchingParams,
endDate: moment(endDate).format('YYYY-MM-DD'),
};
}
console.log(fetchingParams);
const data = useResource(InvestigationResource.listShape(), fetchingParams);
const totalSize = data && data.length > 0 ? data[0].meta?.page?.total : 0;
const user = useSelector((state) => state.user);
......@@ -212,9 +200,12 @@ function InvestigationTable(props) {
setPage(1);
}
function handleTableChange(page, sizePerPage) {
function handleTableChange(page, sizePerPage, sortField, sortOrder) {
setPage(page);
setSizePerPage(sizePerPage);
setSortField(sortField);
const order = sortOrder ? (sortOrder === 'asc' ? 1 : -1) : undefined;
setSortOrder(order);
}
function onSearch(query) {
......
......@@ -66,9 +66,12 @@ export default function ResponsiveTable(props) {
);
}
function handleTableChange(type, { page, sizePerPage }) {
function handleTableChange(
type,
{ page, sizePerPage, sortField, sortOrder }
) {
if (props.handleTableChange) {
props.handleTableChange(page, sizePerPage);
props.handleTableChange(page, sizePerPage, sortField, sortOrder);
}
}
......
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