From 5cf58efbc20fefe8911d36ee5cabbb53f94a9e33 Mon Sep 17 00:00:00 2001 From: Katherine Thiessen Date: Wed, 10 Aug 2022 15:06:55 -0500 Subject: [PATCH] redoing --- src/main/resources/i18n/messages.properties | 1 + .../js/pages/projects/share/ShareProject.jsx | 56 +++++++++++++------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index b21a9da6de6..885aef97d90 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -361,6 +361,7 @@ ShareLayout.previous=Previous ShareLayout.next=Next ShareNoSamples.description=You have no samples selected to share, please go back to the project samples page and select some samples ShareNoSamples.link=Go to Project Samples Page +ShareProject.label.id=id: {0} ShareSamples.title=Share Samples with Another Project ShareSamples.projects=Select a project to share samples with ShareSamples.ready=These samples are ready to copy diff --git a/src/main/webapp/resources/js/pages/projects/share/ShareProject.jsx b/src/main/webapp/resources/js/pages/projects/share/ShareProject.jsx index 8f87661c4b0..4dc5ac4671d 100644 --- a/src/main/webapp/resources/js/pages/projects/share/ShareProject.jsx +++ b/src/main/webapp/resources/js/pages/projects/share/ShareProject.jsx @@ -3,8 +3,6 @@ import React from "react"; import { useDispatch, useSelector } from "react-redux"; import { setProject } from "./shareSlice"; -const { Text } = Typography; - /** * React component for selecting the project to share a sample with. * @param {list} projects - list of projects that the user is a manager on @@ -14,14 +12,45 @@ const { Text } = Typography; export function ShareProject({ projects }) { const dispatch = useDispatch(); const { targetProject } = useSelector((state) => state.shareReducer); - const [selectList, setSelectList] = React.useState(() => projects); + const [options, setOptions] = React.useState(() => formatOptions(projects)); + + function formatOptions(values) { + if (!values) return []; + return values.map((project) => ({ + label: ( +
+ + {project.name} + + + {i18n("ShareProject.label.id", project.identifier)} + +
+ ), + value: project.identifier, + selected: project.name, + })); + } + + React.useEffect(() => { + setOptions(formatOptions(projects)); + }, [projects]); const handleSearch = (value) => { const lowerValue = value.toLowerCase(); - const filteredProjects = projects.filter((project) => - project.name.toLowerCase().includes(lowerValue) + const available = projects.filter( + (project) => + project.name.toLowerCase().includes(lowerValue) || + project.identifier === value ); - setSelectList(filteredProjects); + const formatted = formatOptions(available); + setOptions(formatted); }; function onChange(projectId) { @@ -29,33 +58,24 @@ export function ShareProject({ projects }) { dispatch(setProject(project)); } - const options = selectList.map((project) => ( - - <> - {project.name} - {project.identifier} - - - )); - return ( {i18n("ShareSamples.projects")} + /> ); }