Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/datagateway-common/src/api/lucene.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ describe('Lucene actions', () => {
message: `Unable to complete requested search in under 5 seconds. To ensure searches complete quickly, please try:
- Only searching "my data"
- Only searching the type of entity you need results for
- Using less wildcard characters in the search term(s)
- Using fewer wildcard characters in the search term(s)
- Making the search term(s) more specific
- Using the default relevancy based sorting`,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/datagateway-common/src/api/lucene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const handleLuceneError = (error: AxiosError<LuceneError>): void => {
message: `Unable to complete requested search in under ${timeoutString}. To ensure searches complete quickly, please try:
- Only searching "my data"
- Only searching the type of entity you need results for
- Using less wildcard characters in the search term(s)
- Using fewer wildcard characters in the search term(s)
- Making the search term(s) more specific
- Using the default relevancy based sorting`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ exports[`Select cell component renders correctly when selectedRows parentSelecte
>
<span
aria-disabled="true"
class="MuiButtonBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled PrivateSwitchBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled MuiCheckbox-root MuiCheckbox-colorPrimary tour-dataview-add-to-cart css-12wnr2w-MuiButtonBase-root-MuiCheckbox-root"
class="MuiButtonBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled PrivateSwitchBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-checked Mui-disabled MuiCheckbox-root MuiCheckbox-colorPrimary tour-dataview-add-to-cart css-12wnr2w-MuiButtonBase-root-MuiCheckbox-root"
style="padding: inherit;"
tabindex="-1"
>
<input
aria-label="select row 2"
checked=""
class="PrivateSwitchBase-input css-1m9pwf3"
data-indeterminate="false"
disabled=""
Expand All @@ -147,12 +148,12 @@ exports[`Select cell component renders correctly when selectedRows parentSelecte
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall css-ptiqhd-MuiSvgIcon-root"
data-testid="CheckBoxOutlineBlankIcon"
data-testid="CheckBoxIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
/>
</svg>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const SelectCell = React.memo((props: SelectCellProps): React.ReactElement => {
className="tour-dataview-add-to-cart"
// have to inherit as the padding="checkbox" is on the span
style={{ padding: 'inherit' }}
checked={selectedRows?.includes(rowData.id) ?? false}
checked={
(parentSelected || selectedRows?.includes(rowData.id)) ?? false
}
inputProps={{
'aria-label': `select row ${rowIndex}`,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ exports[`Select column header component renders correctly when selectedRows pare
>
<span
aria-disabled="true"
class="MuiButtonBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled PrivateSwitchBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled MuiCheckbox-root MuiCheckbox-colorPrimary tour-dataview-add-to-cart css-12wnr2w-MuiButtonBase-root-MuiCheckbox-root"
class="MuiButtonBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-disabled PrivateSwitchBase-root MuiCheckbox-root MuiCheckbox-colorPrimary Mui-checked Mui-disabled MuiCheckbox-root MuiCheckbox-colorPrimary tour-dataview-add-to-cart css-12wnr2w-MuiButtonBase-root-MuiCheckbox-root"
style="padding: inherit;"
tabindex="-1"
>
<input
aria-label="select row undefined"
checked=""
class="PrivateSwitchBase-input css-1m9pwf3"
data-indeterminate="false"
disabled=""
Expand All @@ -187,12 +188,12 @@ exports[`Select column header component renders correctly when selectedRows pare
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall css-ptiqhd-MuiSvgIcon-root"
data-testid="CheckBoxOutlineBlankIcon"
data-testid="CheckBoxIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
/>
</svg>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Select column header component', () => {
onUncheck,
allIds: [1, 2, 3],
loading: false,
parentSelected: false,
};

beforeEach(() => {
Expand Down Expand Up @@ -72,7 +73,7 @@ describe('Select column header component', () => {
<SelectCell
{...selectHeaderProps}
parentSelected={true}
selectedRows={undefined}
selectedRows={[1]}
/>
);
expect(asFragment()).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const SelectHeader = React.memo(
<span style={{ margin: 'auto' }}>
<Checkbox
indeterminate={
!parentSelected &&
selectedRows &&
selectedRows.length > 0 &&
selectedRows.length < totalRowCount
Expand All @@ -69,7 +70,8 @@ const SelectHeader = React.memo(
indeterminateIcon={<IndeterminateCheckBox fontSize="small" />}
size="small"
checked={
totalRowCount !== 0 && selectedRows?.length === totalRowCount
parentSelected ||
(totalRowCount !== 0 && selectedRows?.length === totalRowCount)
}
inputProps={{ 'aria-label': 'select all rows' }}
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ describe('Generic add to cart button', () => {
parentId: '1',
});

const addToCartButton = await screen.findByRole('button', {
name: 'buttons.add_to_cart',
const removeFromCartButton = await screen.findByRole('button', {
name: 'buttons.remove_from_cart',
});

expect(addToCartButton).toBeDisabled();
expect(removeFromCartButton).toBeDisabled();

await user.hover(addToCartButton.parentElement);
await user.hover(removeFromCartButton.parentElement);

expect(
await screen.findByText('buttons.parent_selected_tooltip')
Expand Down
42 changes: 26 additions & 16 deletions packages/datagateway-common/src/views/addToCartButton.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,32 @@
placement="bottom"
>
<span style={{ display: 'inherit' }}>
<Button
id={`add-to-cart-btn-${entityType}-${entityId}`}
variant="contained"
color="primary"
disabled={
cartLoading ||
isParentSelected ||
typeof selectedIds === 'undefined'
}
startIcon={<AddCircleOutlineOutlined />}
disableElevation
onClick={() => addToCart([entityId])}
className="tour-dataview-add-to-cart"
>
{t('buttons.add_to_cart')}
</Button>
{isParentSelected || (selectedIds && selectedIds.includes(entityId)) ? (
<Button
id={`remove-from-cart-btn-${entityType}-${entityId}`}
variant="contained"
color="secondary"
startIcon={<RemoveCircleOutlineOutlined />}
disableElevation
disabled={isParentSelected}
onClick={() => removeFromCart([entityId])}

Check warning on line 84 in packages/datagateway-common/src/views/addToCartButton.component.tsx

View check run for this annotation

Codecov / codecov/patch

packages/datagateway-common/src/views/addToCartButton.component.tsx#L84

Added line #L84 was not covered by tests
>
{t('buttons.remove_from_cart')}
</Button>
) : (
<Button
id={`add-to-cart-btn-${entityType}-${entityId}`}
variant="contained"
color="primary"
disabled={cartLoading || typeof selectedIds === 'undefined'}
startIcon={<AddCircleOutlineOutlined />}
disableElevation
onClick={() => addToCart([entityId])}
className="tour-dataview-add-to-cart"
>
{t('buttons.add_to_cart')}
</Button>
)}
</span>
</StyledTooltip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ describe('Datafile table component', () => {
it('selected rows only considers relevant cart items', async () => {
cartItems = [
{
entityId: 1,
entityId: 5,
entityType: 'dataset',
id: 1,
id: 5,
name: 'test',
parentEntities: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ describe('Dataset table component', () => {
it('selected rows only considers relevant cart items', async () => {
cartItems = [
{
entityId: 1,
entityId: 5,
entityType: 'investigation',
id: 1,
id: 5,
name: 'test',
parentEntities: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ describe('ISIS datafiles table component', () => {
it('selected rows only considers relevant cart items', async () => {
cartItems = [
{
entityId: 1,
entityId: 5,
entityType: 'dataset',
id: 1,
id: 5,
name: 'test',
parentEntities: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Investigation - Card View', () => {
);
});

it("renders DLS link correctly and doesn't allow for cart selection or download", async () => {
it("renders DLS link correctly and doesn't allow for cart selection or download or DOI link", async () => {
renderComponent({
hierarchy: FACILITY_NAME.dls,
});
Expand All @@ -188,6 +188,7 @@ describe('Investigation - Card View', () => {
expect(
within(card).queryByRole('button', { name: 'buttons.download' })
).toBeNull();
expect(within(card).queryByRole('link', { name: 'doi 1' })).toBeNull();
});

it('renders ISIS link & file sizes correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,28 @@ const InvestigationCardView: React.FC<InvestigationCardProps> = (props) => {

const information = React.useMemo(
() => [
{
content: function doiFormat(entity: Investigation) {
return (
entity?.doi && (
<MuiLink
href={`https://doi.org/${entity.doi}`}
data-testid="investigation-search-card-doi-link"
>
{entity.doi}
</MuiLink>
)
);
},
icon: Public,
label: t('investigations.doi'),
dataKey: 'doi',
disableSort: true,
},
...(hierarchy !== FACILITY_NAME.dls
? [
{
content: function doiFormat(entity: Investigation) {
return (
entity?.doi && (
<MuiLink
href={`https://doi.org/${entity.doi}`}
data-testid="investigation-search-card-doi-link"
>
{entity.doi}
</MuiLink>
)
);
},
icon: Public,
label: t('investigations.doi'),
dataKey: 'doi',
disableSort: true,
},
]
: []),
{
icon: Fingerprint,
label: t('investigations.visit_id'),
Expand Down Expand Up @@ -297,7 +301,7 @@ const InvestigationCardView: React.FC<InvestigationCardProps> = (props) => {
disableSort: true,
},
],
[t]
[t, hierarchy]
);

const moreInformation = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,15 @@ describe('Investigation Search Table component', () => {
);
});

it("renders DLS link correctly and doesn't allow for cart selection", async () => {
it("renders DLS link correctly and doesn't allow for cart selection or DOI column", async () => {
renderComponent(FACILITY_NAME.dls);

expect(await screen.findByText('Test title 1')).toHaveAttribute(
'href',
'/browse/proposal/Test name 1/investigation/1/dataset'
);
expect(screen.queryByRole('checkbox', { name: 'select row 0' })).toBeNull();
expect(screen.queryByRole('columnheader', { name: 'DOI' })).toBeNull();
});

it('renders ISIS link & file sizes correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,23 @@ const InvestigationSearchTable: React.FC<InvestigationTableProps> = (props) => {
dataKey: 'name',
disableSort: true,
},
{
label: t('investigations.doi'),
dataKey: 'doi',
cellContentRenderer: (cellProps: TableCellProps) => {
const investigation = cellProps.rowData as SearchResultSource;
return externalSiteLink(
`https://doi.org/${investigation.doi}`,
investigation.doi,
'investigation-search-table-doi-link'
);
},
disableSort: true,
},
...(hierarchy !== FACILITY_NAME.dls
? [
{
label: t('investigations.doi'),
dataKey: 'doi',
cellContentRenderer: (cellProps: TableCellProps) => {
const investigation = cellProps.rowData as SearchResultSource;
return externalSiteLink(
`https://doi.org/${investigation.doi}`,
investigation.doi,
'investigation-search-table-doi-link'
);
},
disableSort: true,
},
]
: []),
{
label: t('investigations.size'),
dataKey: 'size',
Expand Down