Skip to content

Commit

Permalink
Merge pull request #1640 from ral-facilities/release/v1.1.3
Browse files Browse the repository at this point in the history
Release v1.1.3
  • Loading branch information
louise-davies authored Feb 2, 2024
2 parents 4f29f5e + 8e1075a commit 8c0b1b4
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 174 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v1.1.3](https://github.com/ral-facilities/datagateway/tree/v1.1.3) (2024-02-02)

[Full Changelog](https://github.com/ral-facilities/datagateway/compare/v1.1.2...v1.1.3)

**Fixed bugs:**

- Fix performance of datafile table requests by extracting out investigation ID check to ID check functions [ffbb197](https://github.com/ral-facilities/datagateway/commit/ffbb197e333d93d35687252eaaba32fd475a5ffa) ([louise-davies](https://github.com/louise-davies))

## [v1.1.2](https://github.com/ral-facilities/datagateway/tree/v1.1.2) (2023-09-28)

[Full Changelog](https://github.com/ral-facilities/datagateway/compare/v1.1.1...v1.1.2)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "1.1.2",
"version": "1.1.3",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "datagateway",
"private": true,
"version": "1.1.2",
"version": "1.1.3",
"workspaces": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/datagateway-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datagateway-common",
"version": "1.1.2",
"version": "1.1.3",
"private": true,
"files": [
"lib"
Expand Down
4 changes: 2 additions & 2 deletions packages/datagateway-dataview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datagateway-dataview",
"version": "1.1.2",
"version": "1.1.3",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.3",
Expand All @@ -14,7 +14,7 @@
"axios": "^0.26.0",
"connected-react-router": "^6.9.1",
"custom-event-polyfill": "^1.0.7",
"datagateway-common": "^1.1.2",
"datagateway-common": "^1.1.3",
"date-fns": "^2.28.0",
"history": "^4.10.1",
"i18next": "^21.6.13",
Expand Down
42 changes: 27 additions & 15 deletions packages/datagateway-dataview/src/page/idCheckFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ describe('ID check functions', () => {
const store = configureStore()({});

await checkInvestigationId(1, 2);
const params = new URLSearchParams();
params.append(
'where',
JSON.stringify({
id: {
eq: 2,
},
})
);
params.append('where', JSON.stringify({ 'investigation.id': { eq: 1 } }));
expect(axios.get).toHaveBeenCalledWith('/datasets/findone', {
params: {
where: { id: { eq: 2 } },
include: '"investigation"',
},
params,
headers: { Authorization: 'Bearer null' },
});
(axios.get as jest.Mock).mockClear();
Expand All @@ -50,10 +57,7 @@ describe('ID check functions', () => {

await checkInvestigationId(1, 2);
expect(axios.get).toHaveBeenCalledWith('/test/datasets/findone', {
params: {
where: { id: { eq: 2 } },
include: '"investigation"',
},
params,
headers: { Authorization: 'Bearer null' },
});

Expand All @@ -75,24 +79,32 @@ describe('ID check functions', () => {

const result = await checkInvestigationId(1, 2);
expect(result).toBe(true);
const params = new URLSearchParams();
params.append(
'where',
JSON.stringify({
id: {
eq: 2,
},
})
);
params.append('where', JSON.stringify({ 'investigation.id': { eq: 1 } }));
expect(axios.get).toHaveBeenCalledWith('/datasets/findone', {
params: {
where: { id: { eq: 2 } },
include: '"investigation"',
},
params,
headers: { Authorization: 'Bearer null' },
});
});
it('returns false on invalid investigation + dataset pair', async () => {
expect.assertions(1);
expect.assertions(2);
(axios.get as jest.Mock).mockImplementation(() =>
Promise.resolve({
data: { id: 2, name: 'Test dataset', investigation: { id: 3 } },
Promise.reject({
response: { status: 404 },
})
);

const result = await checkInvestigationId(1, 2);
expect(result).toBe(false);
expect(handleICATError).not.toHaveBeenCalled();
});
it('returns false on HTTP error', async () => {
expect.assertions(2);
Expand Down
32 changes: 20 additions & 12 deletions packages/datagateway-dataview/src/page/idCheckFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios, { AxiosResponse } from 'axios';
import axios, { AxiosError, AxiosResponse } from 'axios';
import {
handleICATError,
Dataset,
Investigation,
ConfigureURLsType,
readSciGatewayToken,
Expand All @@ -26,24 +25,33 @@ const unmemoizedCheckInvestigationId = (
investigationId: number,
datasetId: number
): Promise<boolean> => {
const params = new URLSearchParams();
params.append(
'where',
JSON.stringify({
id: {
eq: datasetId,
},
})
);
params.append(
'where',
JSON.stringify({ 'investigation.id': { eq: investigationId } })
);
return axios
.get(`${apiUrl}/datasets/findone`, {
params: {
where: {
id: {
eq: datasetId,
},
},
include: '"investigation"',
},
params,
headers: {
Authorization: `Bearer ${readSciGatewayToken().sessionId}`,
},
})
.then((response: AxiosResponse<Dataset>) => {
return response.data.investigation?.id === investigationId;
.then(() => {
return true;
})
.catch((error) => {
// 404 is valid response from API saying the investigation id is invalid
if ((error as AxiosError).response?.status === 404) return false;
// handle other API errors
handleICATError(error);
return false;
});
Expand Down
29 changes: 11 additions & 18 deletions packages/datagateway-dataview/src/page/pageRouting.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ const SafeDatafileTable = React.memo(
parseInt(props.datasetId)
)
)(DatafileTable);
return (
<SafeDatafileTable
datasetId={props.datasetId}
investigationId={props.investigationId}
/>
);
return <SafeDatafileTable datasetId={props.datasetId} />;
}
);
SafeDatafileTable.displayName = 'SafeDatafileTable';
Expand Down Expand Up @@ -103,15 +98,14 @@ const SafeISISDatafilesTable = React.memo(
parseInt(props.instrumentChildId),
parseInt(props.investigationId)
),
checkInvestigationId(
parseInt(props.investigationId),
parseInt(props.datasetId)
),
]).then((values) => !values.includes(false))
)(ISISDatafilesTable);

return (
<SafeISISDatafilesTable
datasetId={props.datasetId}
investigationId={props.investigationId}
/>
);
return <SafeISISDatafilesTable datasetId={props.datasetId} />;
}
);
SafeISISDatafilesTable.displayName = 'SafeISISDatafilesTable';
Expand Down Expand Up @@ -279,15 +273,14 @@ const SafeDLSDatafilesTable = React.memo(
const SafeDLSDatafilesTable = withIdCheck(
Promise.all([
checkProposalName(props.proposalName, parseInt(props.investigationId)),
checkInvestigationId(
parseInt(props.investigationId),
parseInt(props.datasetId)
),
]).then((values) => !values.includes(false))
)(DLSDatafilesTable);

return (
<SafeDLSDatafilesTable
datasetId={props.datasetId}
investigationId={props.investigationId}
/>
);
return <SafeDLSDatafilesTable datasetId={props.datasetId} />;
}
);
SafeDLSDatafilesTable.displayName = 'SafeDLSDatafilesTable';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Datafile table component', () => {
<Provider store={store}>
<Router history={history}>
<QueryClientProvider client={new QueryClient()}>
<DatafileTable datasetId="1" investigationId="2" />
<DatafileTable datasetId="1" />
</QueryClientProvider>
</Router>
</Provider>
Expand Down Expand Up @@ -114,31 +114,18 @@ describe('Datafile table component', () => {

it('calls the correct data fetching hooks on load', () => {
const datasetId = '1';
const investigationId = '2';
createWrapper();
expect(useDatafileCount).toHaveBeenCalledWith([
{
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
]);
expect(useDatafilesInfinite).toHaveBeenCalledWith([
{
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
]);
expect(useIds).toHaveBeenCalledWith(
'datafile',
Expand All @@ -147,12 +134,6 @@ describe('Datafile table component', () => {
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
],
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import { IndexRange } from 'react-virtualized';

interface DatafileTableProps {
datasetId: string;
investigationId: string;
}

const DatafileTable = (props: DatafileTableProps): React.ReactElement => {
const { datasetId, investigationId } = props;
const { datasetId } = props;

const [t] = useTranslation();

Expand All @@ -59,12 +58,6 @@ const DatafileTable = (props: DatafileTableProps): React.ReactElement => {
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
],
selectAllSetting
);
Expand All @@ -82,25 +75,13 @@ const DatafileTable = (props: DatafileTableProps): React.ReactElement => {
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
]);

const { fetchNextPage, data } = useDatafilesInfinite([
{
filterType: 'where',
filterValue: JSON.stringify({ 'dataset.id': { eq: datasetId } }),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'dataset.investigation.id': { eq: investigationId },
}),
},
]);

const loadMoreRows = React.useCallback(
Expand Down
Loading

0 comments on commit 8c0b1b4

Please sign in to comment.