Skip to content

Commit

Permalink
Double request bug fix in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
kaperoo committed Sep 19, 2023
1 parent 48e434d commit 5d882af
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DataHeader = (
labelString: string;
icon?: React.ComponentType<unknown>;
filterComponent?: (label: string, dataKey: string) => React.ReactElement;
defaultSort?: Order;
// defaultSort?: Order;
}
): React.ReactElement => {
const {
Expand All @@ -35,7 +35,7 @@ const DataHeader = (
label,
labelString,
disableSort,
defaultSort,
// defaultSort,
resizeColumn,
icon: Icon,
filterComponent,
Expand All @@ -45,11 +45,11 @@ const DataHeader = (

//Apply default sort on page load (but only if not already defined in URL params)
//This will apply them in the order of the column definitions given to a table
React.useEffect(() => {
if (defaultSort !== undefined && currSortDirection === undefined)
onSort(dataKey, defaultSort, 'replace');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// React.useEffect(() => {
// if (defaultSort !== undefined && currSortDirection === undefined)
// onSort(dataKey, defaultSort, 'replace');
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, []);

let nextSortDirection: Order | null = null;
switch (currSortDirection) {
Expand Down
2 changes: 1 addition & 1 deletion packages/datagateway-common/src/table/table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ const VirtualizedTable = React.memo(
labelString={label}
filterComponent={filterComponent}
resizeColumn={resizeColumn}
defaultSort={defaultSort}
// defaultSort={defaultSort}
/>
)}
className={className}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
useDatafileCount,
useDatafilesInfinite,
parseSearchToQuery,
parseQueryToSearch,
SortType,
useTextFilter,
useDateFilter,
ColumnType,
Expand Down Expand Up @@ -34,9 +36,29 @@ const DLSDatafilesTable = (
const { datasetId, investigationId } = props;

const [t] = useTranslation();

const handleSort = useSort();
const location = useLocation();

// set default sort
const defaultSort: SortType = {
createTime: 'desc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const selectAllSetting = useSelector(
(state: StateType) => state.dgdataview.selectAllSetting
);
Expand All @@ -48,7 +70,6 @@ const DLSDatafilesTable = (

const textFilter = useTextFilter(filters);
const dateFilter = useDateFilter(filters);
const handleSort = useSort();

const { data: allIds, isLoading: allIdsLoading } = useIds(
'datafile',
Expand Down Expand Up @@ -144,7 +165,7 @@ const DLSDatafilesTable = (
label: t('datafiles.create_time'),
dataKey: 'createTime',
filterComponent: dateFilter,
defaultSort: 'desc',
// defaultSort: 'desc',
},
],
[t, dateFilter, textFilter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
useDatasetCount,
useDatasetsInfinite,
parseSearchToQuery,
parseQueryToSearch,
SortType,
useTextFilter,
useDateFilter,
ColumnType,
Expand All @@ -38,9 +40,29 @@ const DLSDatasetsTable = (props: DLSDatasetsTableProps): React.ReactElement => {
const { investigationId, proposalName } = props;

const [t] = useTranslation();

const handleSort = useSort();
const location = useLocation();

// set default sort
const defaultSort: SortType = {
createTime: 'desc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const selectAllSetting = useSelector(
(state: StateType) => state.dgdataview.selectAllSetting
);
Expand All @@ -52,7 +74,6 @@ const DLSDatasetsTable = (props: DLSDatasetsTableProps): React.ReactElement => {

const textFilter = useTextFilter(filters);
const dateFilter = useDateFilter(filters);
const handleSort = useSort();

const { data: allIds, isLoading: allIdsLoading } = useIds(
'dataset',
Expand Down Expand Up @@ -138,7 +159,7 @@ const DLSDatasetsTable = (props: DLSDatasetsTableProps): React.ReactElement => {
label: t('datasets.create_time'),
dataKey: 'createTime',
filterComponent: dateFilter,
defaultSort: 'desc',
// defaultSort: 'desc',
},
{
icon: CalendarToday,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
formatCountOrSize,
Investigation,
parseSearchToQuery,
parseQueryToSearch,
SortType,
readSciGatewayToken,
Table,
tableLink,
Expand Down Expand Up @@ -32,6 +34,27 @@ const DLSMyDataTable = (): React.ReactElement => {
const [t] = useTranslation();
const location = useLocation();
const username = readSciGatewayToken().username || '';
const handleSort = useSort();

// set default sort
const defaultSort: SortType = {
startDate: 'desc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { filters, view, sort } = React.useMemo(
() => parseSearchToQuery(location.search),
Expand Down Expand Up @@ -80,7 +103,6 @@ const DLSMyDataTable = (): React.ReactElement => {

const textFilter = useTextFilter(filters);
const dateFilter = useDateFilter(filters);
const handleSort = useSort();
const pushFilter = usePushFilter();

const loadMoreRows = React.useCallback(
Expand Down Expand Up @@ -148,7 +170,7 @@ const DLSMyDataTable = (): React.ReactElement => {
label: t('investigations.start_date'),
dataKey: 'startDate',
filterComponent: dateFilter,
defaultSort: 'desc',
// defaultSort: 'desc',
},
{
icon: CalendarToday,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
useInvestigationsInfinite,
useInvestigationCount,
parseSearchToQuery,
parseQueryToSearch,
SortType,
useSort,
useTextFilter,
} from 'datagateway-common';
Expand All @@ -18,6 +20,27 @@ import SubjectIcon from '@mui/icons-material/Subject';
const DLSProposalsTable = (): React.ReactElement => {
const location = useLocation();
const [t] = useTranslation();
const handleSort = useSort();

// set default sort
const defaultSort: SortType = {
title: 'asc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { filters, view, sort } = React.useMemo(
() => parseSearchToQuery(location.search),
Expand Down Expand Up @@ -56,7 +79,6 @@ const DLSProposalsTable = (): React.ReactElement => {
}, [data]);

const textFilter = useTextFilter(filters);
const handleSort = useSort();

const loadMoreRows = React.useCallback(
(offsetParams: IndexRange) => fetchNextPage({ pageParam: offsetParams }),
Expand All @@ -81,7 +103,7 @@ const DLSProposalsTable = (): React.ReactElement => {
filterComponent: textFilter,
// Sort to ensure a deterministic order for pagination (ignoreIDSort: true is
// used above in useInvestigationsInfinite)
defaultSort: 'asc',
// defaultSort: 'asc',
disableSort: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
ColumnType,
formatCountOrSize,
parseSearchToQuery,
parseQueryToSearch,
SortType,
useDateFilter,
useInvestigationCount,
useInvestigationsInfinite,
Expand Down Expand Up @@ -33,6 +35,27 @@ const DLSVisitsTable = (props: DLSVisitsTableProps): React.ReactElement => {

const [t] = useTranslation();
const location = useLocation();
const handleSort = useSort();

// set default sort
const defaultSort: SortType = {
startDate: 'desc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { filters, view, sort } = React.useMemo(
() => parseSearchToQuery(location.search),
Expand Down Expand Up @@ -75,7 +98,6 @@ const DLSVisitsTable = (props: DLSVisitsTableProps): React.ReactElement => {

const textFilter = useTextFilter(filters);
const dateFilter = useDateFilter(filters);
const handleSort = useSort();

const loadMoreRows = React.useCallback(
(offsetParams: IndexRange) => fetchNextPage({ pageParam: offsetParams }),
Expand Down Expand Up @@ -127,7 +149,7 @@ const DLSVisitsTable = (props: DLSVisitsTableProps): React.ReactElement => {
label: t('investigations.start_date'),
dataKey: 'startDate',
filterComponent: dateFilter,
defaultSort: 'desc',
// defaultSort: 'desc',
},
{
icon: CalendarToday,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
ColumnType,
externalSiteLink,
parseSearchToQuery,
parseQueryToSearch,
SortType,
DataPublication,
Table,
tableLink,
Expand Down Expand Up @@ -29,6 +31,27 @@ const ISISDataPublicationsTable = (

const location = useLocation();
const [t] = useTranslation();
const handleSort = useSort();

// set default sort
const defaultSort: SortType = {
publicationDate: 'desc',
};
// apply default sort
// had to use useMemo because useEffect doesn't run until the component is mounted
React.useMemo(() => {
if (location.search === '') {
location.search = parseQueryToSearch({
...parseSearchToQuery(location.search),
sort: defaultSort,
}).toString();
// TODO: will have to add shiftDown=true to append sort after improved sort ux pr is merged
for (const [column, order] of Object.entries(defaultSort)) {
handleSort(column, order, 'replace');
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { filters, view, sort } = React.useMemo(
() => parseSearchToQuery(location.search),
Expand Down Expand Up @@ -74,7 +97,6 @@ const ISISDataPublicationsTable = (

const textFilter = useTextFilter(filters);
const dateFilter = useDateFilter(filters);
const handleSort = useSort();

const loadMoreRows = React.useCallback(
(offsetParams: IndexRange) => fetchNextPage({ pageParam: offsetParams }),
Expand Down Expand Up @@ -124,7 +146,7 @@ const ISISDataPublicationsTable = (
10
) ?? '',
filterComponent: dateFilter,
defaultSort: 'desc',
// defaultSort: 'desc',
},
];
}, [t, textFilter, dateFilter, instrumentId, view]);
Expand Down
Loading

0 comments on commit 5d882af

Please sign in to comment.