Skip to content

Commit

Permalink
Merge branch 'develop' into feature/free-text-search-#1152
Browse files Browse the repository at this point in the history
  • Loading branch information
louise-davies committed Sep 13, 2023
2 parents 8cfd1c7 + 48e434d commit 7ed1118
Show file tree
Hide file tree
Showing 102 changed files with 3,440 additions and 5,439 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
with:
repository: ral-facilities/datagateway-api
path: datagateway-api
ref: v7.1.0
ref: v9.0.1

# DataGateway API file setup
- name: Create search_api_mapping.json
Expand Down Expand Up @@ -288,7 +288,7 @@ jobs:
with:
repository: ral-facilities/datagateway-api
path: datagateway-api
ref: v7.1.0
ref: v9.0.1

# DataGateway API file setup
- name: Create search_api_mapping.json
Expand Down Expand Up @@ -418,7 +418,7 @@ jobs:
with:
repository: ral-facilities/datagateway-api
path: datagateway-api
ref: v7.1.0
ref: v9.0.1

# DataGateway API file setup
- name: Create search_api_mapping.json
Expand Down
2 changes: 1 addition & 1 deletion packages/datagateway-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@date-io/date-fns": "2.16.0",
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@mui/x-date-pickers": "5.0.9",
"@mui/x-date-pickers": "6.11.2",
"@types/lodash.debounce": "4.0.6",
"axios": "0.27.2",
"connected-react-router": "6.9.1",
Expand Down
28 changes: 25 additions & 3 deletions packages/datagateway-common/src/api/dataPublications.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('data publications api functions', () => {
];
history = createMemoryHistory({
initialEntries: [
'/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
'/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
],
});
params = new URLSearchParams();
Expand All @@ -53,7 +53,7 @@ describe('data publications api functions', () => {
data: mockData,
});

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDataPublicationsPaginated([
{
Expand All @@ -74,6 +74,7 @@ describe('data publications api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand Down Expand Up @@ -103,6 +104,16 @@ describe('data publications api functions', () => {
params.toString()
);
expect(result.current.data).toEqual(mockData);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2);
});

it('sends axios request to fetch paginated data publications and calls handleICATError on failure', async () => {
Expand Down Expand Up @@ -143,7 +154,7 @@ describe('data publications api functions', () => {
: Promise.resolve({ data: mockData[1] })
);

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDataPublicationsInfinite([
{
Expand All @@ -164,6 +175,7 @@ describe('data publications api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand Down Expand Up @@ -219,6 +231,16 @@ describe('data publications api functions', () => {
mockData[0],
mockData[1],
]);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3);
});

it('sends axios request to fetch infinite data publications and calls handleICATError on failure', async () => {
Expand Down
25 changes: 14 additions & 11 deletions packages/datagateway-common/src/api/dataPublications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useDataPublicationsPaginated = (
[
string,
{
sort: SortType;
sort: string;
filters: FiltersType;
page: number;
results: number;
Expand All @@ -77,11 +77,16 @@ export const useDataPublicationsPaginated = (
>(
[
'dataPublication',
{ sort, filters, page: page ?? 1, results: results ?? 10 },
{
sort: JSON.stringify(sort), // need to stringify sort as property order is important!
filters,
page: page ?? 1,
results: results ?? 10,
},
additionalFilters,
],
(params) => {
const { sort, filters, page, results } = params.queryKey[1];
const { page, results } = params.queryKey[1];
const startIndex = (page - 1) * results;
const stopIndex = startIndex + results - 1;
return fetchDataPublications(
Expand Down Expand Up @@ -110,15 +115,13 @@ export const useDataPublicationsInfinite = (
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);

return useInfiniteQuery<
DataPublication[],
AxiosError,
DataPublication[],
[string, { sort: SortType; filters: FiltersType }, AdditionalFilters?]
>(
['dataPublication', { sort, filters }, additionalFilters],
return useInfiniteQuery(
[
'dataPublication',
{ sort: JSON.stringify(sort), filters }, // need to stringify sort as property order is important!
additionalFilters,
],
(params) => {
const { sort, filters } = params.queryKey[1];
const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 };
return fetchDataPublications(
apiUrl,
Expand Down
28 changes: 25 additions & 3 deletions packages/datagateway-common/src/api/datafiles.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('datafile api functions', () => {
];
history = createMemoryHistory({
initialEntries: [
'/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
'/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
],
});
params = new URLSearchParams();
Expand All @@ -58,7 +58,7 @@ describe('datafile api functions', () => {
data: mockData,
});

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDatafilesPaginated([
{
Expand All @@ -76,6 +76,7 @@ describe('datafile api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand All @@ -102,6 +103,16 @@ describe('datafile api functions', () => {
params.toString()
);
expect(result.current.data).toEqual(mockData);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2);
});

it('sends axios request to fetch paginated datafiles and calls handleICATError on failure', async () => {
Expand Down Expand Up @@ -139,7 +150,7 @@ describe('datafile api functions', () => {
: Promise.resolve({ data: mockData[1] })
);

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDatafilesInfinite([
{
Expand All @@ -157,6 +168,7 @@ describe('datafile api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand Down Expand Up @@ -209,6 +221,16 @@ describe('datafile api functions', () => {
mockData[0],
mockData[1],
]);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3);
});

it('sends axios request to fetch infinite datafiles and calls handleICATError on failure', async () => {
Expand Down
21 changes: 10 additions & 11 deletions packages/datagateway-common/src/api/datafiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const useDatafilesPaginated = (
[
string,
{
sort: SortType;
sort: string;
filters: FiltersType;
page: number;
results: number;
Expand All @@ -79,11 +79,16 @@ export const useDatafilesPaginated = (
>(
[
'datafile',
{ sort, filters, page: page ?? 1, results: results ?? 10 },
{
sort: JSON.stringify(sort), // need to stringify sort as property order is important!
filters,
page: page ?? 1,
results: results ?? 10,
},
additionalFilters,
],
(params) => {
const { sort, filters, page, results } = params.queryKey[1];
const { page, results } = params.queryKey[1];
const startIndex = (page - 1) * results;
const stopIndex = startIndex + results - 1;
return fetchDatafiles(apiUrl, { sort, filters }, additionalFilters, {
Expand All @@ -107,15 +112,9 @@ export const useDatafilesInfinite = (
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);

return useInfiniteQuery<
Datafile[],
AxiosError,
Datafile[],
[string, { sort: SortType; filters: FiltersType }, AdditionalFilters?]
>(
['datafile', { sort, filters }, additionalFilters],
return useInfiniteQuery(
['datafile', { sort: JSON.stringify(sort), filters }, additionalFilters], // need to stringify sort as property order is important!
(params) => {
const { sort, filters } = params.queryKey[1];
const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 };
return fetchDatafiles(
apiUrl,
Expand Down
28 changes: 25 additions & 3 deletions packages/datagateway-common/src/api/datasets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('dataset api functions', () => {
];
history = createMemoryHistory({
initialEntries: [
'/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
'/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20',
],
});
params = new URLSearchParams();
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('dataset api functions', () => {
data: mockData,
});

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDatasetsPaginated([
{
Expand All @@ -144,6 +144,7 @@ describe('dataset api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand All @@ -170,6 +171,16 @@ describe('dataset api functions', () => {
params.toString()
);
expect(result.current.data).toEqual(mockData);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2);
});

it('sends axios request to fetch paginated datasets and calls handleICATError on failure', async () => {
Expand Down Expand Up @@ -207,7 +218,7 @@ describe('dataset api functions', () => {
: Promise.resolve({ data: mockData[1] })
);

const { result, waitFor } = renderHook(
const { result, waitFor, rerender } = renderHook(
() =>
useDatasetsInfinite([
{
Expand All @@ -225,6 +236,7 @@ describe('dataset api functions', () => {
await waitFor(() => result.current.isSuccess);

params.append('order', JSON.stringify('name asc'));
params.append('order', JSON.stringify('title desc'));
params.append('order', JSON.stringify('id asc'));
params.append(
'where',
Expand Down Expand Up @@ -277,6 +289,16 @@ describe('dataset api functions', () => {
mockData[0],
mockData[1],
]);

// test that order of sort object triggers new query
history.push(
'/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}'
);
rerender();

await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3);
});

it('sends axios request to fetch infinite datasets and calls handleICATError on failure', async () => {
Expand Down
Loading

0 comments on commit 7ed1118

Please sign in to comment.