diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1ca562203..fcacae0f9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ * [REST]: Updated synchronizing of sample data to remove sequencing objects and assemblies that no longer exist on the remote sample. See [PR 1345](https://github.com/phac-nml/irida/pull/1345) * [UI]: Fixed issue with filtering samples by files using a windows encoded text file causing sample name truncation. See [PR 1346](https://github.com/phac-nml/irida/pull/1346) * [Developer]: Fixed deleting a project with project subscriptions. See [PR 1348](https://github.com/phac-nml/irida/pull/1348) -* [Developer]: Updated OAuth2 implemention to use Spring Security 5 OAuth2 libraries. See [PR 1339](https://github.com/phac-nml/irida/pull/1339) +* [Developer]: Updated OAuth2 implementation to use Spring Security 5 OAuth2 libraries. See [PR 1339](https://github.com/phac-nml/irida/pull/1339) +* [Developer]: Add identifier to project drop-downs. See [PR 1352](https://github.com/phac-nml/irida/pull/1352) ## [22.05.5] - 2022/06/28 * [UI]: Fixed bug preventing export of project samples table due to invalid url. [PR 1331](https://github.com/phac-nml/irida/pull/1331) diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 8e6db7fe9f7..b43b12cc5e5 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -692,6 +692,9 @@ project.nav.details=Recent Activity project.nav.settings=Settings project.nav.samples.import-metadata=Import Sample Metadata +# SearchByNameAndIdSelect +SearchByNameAndIdSelect.label.id=ID: {0} + # KEPT FOR LEGACY PURPOSES (still used on user_details.html and groups.html) project.table.collaborator.name=Name project.table.collaborator.role=Project Role diff --git a/src/main/webapp/resources/js/components/selects/SearchByNameAndIdSelect.tsx b/src/main/webapp/resources/js/components/selects/SearchByNameAndIdSelect.tsx new file mode 100644 index 00000000000..7345da83e72 --- /dev/null +++ b/src/main/webapp/resources/js/components/selects/SearchByNameAndIdSelect.tsx @@ -0,0 +1,83 @@ +import React from "react"; +import { Select, SelectProps, Tag, Typography } from "antd"; +import { LabeledValue } from "antd/lib/select"; +import { IridaBase } from "../../types/irida"; + +export type SelectListItem = Pick; +export interface SelectListProps extends SelectProps { + selectList: SelectListItem[]; +} + +/** + * React component for displaying a drop-down menu. + * @param selectList - list that is to be displayed + * @param className - class name of the select list + * @param onChange - function that is called when select option has changed + * @param defaultValue - identifier of the select list item that is to be displayed by default + * @constructor + */ +export function SearchByNameAndIdSelect({ + selectList, + onChange, + className, + defaultValue = null, +}: SelectListProps): JSX.Element { + const [options, setOptions] = React.useState(() => + formatOptions(selectList) + ); + + function formatOptions(values: SelectListItem[]) { + if (!values) return []; + return values.map((selectListItem) => ({ + label: ( +
+ + {selectListItem.name} + + + {i18n("SearchByNameAndIdSelect.label.id", selectListItem.id)} + +
+ ), + value: selectListItem.id, + })); + } + + React.useEffect(() => { + setOptions(formatOptions(selectList)); + }, [selectList]); + + const handleSearch = (value: string) => { + const lowerValue = value.toLowerCase(); + + const available = selectList.filter( + (selectItem: { name: string; id: { toString: () => string } }) => + selectItem.name.toLowerCase().includes(lowerValue) || + selectItem.id.toString() === value + ); + const formatted = formatOptions(available); + setOptions(formatted); + }; + + return ( + ({ + id: project.identifier, + name: project.name, + }))} onChange={onChange} - defaultValue={targetProject ? targetProject.identifier : null} + defaultValue={targetProject?.identifier} + className="t-project-select" /> ); diff --git a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ShareSamplesPage.java b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ShareSamplesPage.java index 1bf44105fa1..61c3aba4c98 100644 --- a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ShareSamplesPage.java +++ b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ShareSamplesPage.java @@ -11,7 +11,10 @@ import static ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage.waitForTime; public class ShareSamplesPage { - @FindBy(css = ".t-share-project .ant-select-selection-search-input") + @FindBy(css = ".t-project-select .ant-select-selection-search-input") + private WebElement shareProjectSelectSearch; + + @FindBy(css = ".t-project-select .ant-select-selection-item") private WebElement shareProjectSelect; @FindBy(className = "ant-select-dropdown") @@ -76,10 +79,14 @@ public static ShareSamplesPage initPage(WebDriver driver) { } public void searchForProject(String name) { - shareProjectSelect.sendKeys(name); + shareProjectSelectSearch.sendKeys(name); projectDropdown.click(); } + public String getProjectSelectText() { + return shareProjectSelect.getText(); + } + public int getNumberOfSamplesDisplayed() { return shareSampleListItem.size(); } @@ -147,7 +154,7 @@ public boolean isShareSingleSuccessDisplayed() { public boolean isSomeSamplesSameIdsWarningDisplayed() { try { return someSamplesSameIdsWarning.isDisplayed(); - } catch(Exception e) { + } catch (Exception e) { return false; } } @@ -155,7 +162,7 @@ public boolean isSomeSamplesSameIdsWarningDisplayed() { public boolean isSomeSamplesSameNamesWarningDisplayed() { try { return someSamplesSameNamesWarning.isDisplayed(); - } catch(Exception e) { + } catch (Exception e) { return false; } } diff --git a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectShareSamplesIT.java b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectShareSamplesIT.java index 38b2fcc9b18..f2a6e89404d 100644 --- a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectShareSamplesIT.java +++ b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectShareSamplesIT.java @@ -9,6 +9,7 @@ import com.github.springtestdbunit.annotation.DatabaseSetup; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; @DatabaseSetup("/ca/corefacility/bioinformatics/irida/ria/web/projects/ProjectSamplesView.xml") @@ -27,6 +28,9 @@ public void testShareSamplesAsManager() { samplesPage.shareSamples(); assertFalse(shareSamplesPage.isNextButtonEnabled(), ""); + shareSamplesPage.searchForProject("3"); + assertThat(shareSamplesPage.getProjectSelectText()).contains("ID: 3"); + assertTrue(shareSamplesPage.isNextButtonEnabled(), "Next button should be enabled"); shareSamplesPage.searchForProject("project2"); assertTrue(shareSamplesPage.isNextButtonEnabled(), "Next button should be enabled"); shareSamplesPage.gotToNextStep(); @@ -55,7 +59,8 @@ public void testShareSamplesAsManager() { assertTrue(shareSamplesPage.isSomeSamplesSameIdsWarningDisplayed(), "Should display an expandable warning which lists the samples that will not be copied over as the samples with the same identifiers already exist in the target project"); shareSamplesPage.expandSameSampleIdsWarning(); - assertEquals(1, shareSamplesPage.numberOfSamplesWithSameIds(), "There should be one sample listed which exists in the target project with the same identifier"); + assertEquals(1, shareSamplesPage.numberOfSamplesWithSameIds(), + "There should be one sample listed which exists in the target project with the same identifier"); assertFalse(shareSamplesPage.isSomeSamplesSameNamesWarningDisplayed(), "Shouldn't display an expandable warning which lists the samples that will not be copied over as the samples with the same names but different identifiers exist in the target project"); @@ -112,6 +117,7 @@ public void testShareSamplesAsManager() { assertTrue(shareSamplesPage.isSomeSamplesSameNamesWarningDisplayed(), "Should display an expandable warning which lists the samples that will not be copied over as the samples with the same names but different identifiers exist in the target project"); shareSamplesPage.expandSameSampleNamesWarning(); - assertEquals(1, shareSamplesPage.numberOfSamplesWithSameNames(), "There should be one sample listed which exists in the target project with the same name and different identifier"); + assertEquals(1, shareSamplesPage.numberOfSamplesWithSameNames(), + "There should be one sample listed which exists in the target project with the same name and different identifier"); } }