-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displaying identifiers for project drop downs #1352
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d40aa12
working on showing identifier for share projects drop down
ksierks df7ca7d
working on showing identifier for share projects drop down
ksierks d5ee224
Merge branch 'development' into display-id-for-project-drop-downs
ksierks 5a7c0d2
updating changelog
ksierks 5cf58ef
redoing
ksierks 24d03cf
making into reusable component
ksierks e872b31
converting to typescript
ksierks 76ae170
removing types from jsdoc
ksierks ca4b83f
making id uppercase
ksierks 7f2abe6
fixing default value for onchange
ksierks 7bfbc4e
updating options type
ksierks 3aa96c6
testing searching by id
ksierks 76ba866
using ProjectMinimal type
ksierks 8023bed
removing onchange default
ksierks d19ce2b
generalizing component
ksierks 9942971
generalizing component
ksierks 0d340a1
fixing test
ksierks 5c31979
display id during selection
ksierks ddfd9e6
display id during selection
ksierks ee728de
Merge branch 'development' into display-id-for-project-drop-downs
ksierks 4e51db1
fixing test
ksierks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/webapp/resources/js/components/selects/SearchByNameAndIdSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IridaBase, "id" | "name">; | ||
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<LabeledValue[]>(() => | ||
formatOptions(selectList) | ||
); | ||
|
||
function formatOptions(values: SelectListItem[]) { | ||
if (!values) return []; | ||
return values.map((selectListItem) => ({ | ||
label: ( | ||
<div | ||
style={{ | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
width: "100%", | ||
}} | ||
> | ||
<Typography.Text ellipsis={{ tooltip: true }}> | ||
{selectListItem.name} | ||
</Typography.Text> | ||
<Tag> | ||
{i18n("SearchByNameAndIdSelect.label.id", selectListItem.id)} | ||
</Tag> | ||
</div> | ||
), | ||
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 ( | ||
<Select | ||
autoFocus | ||
showSearch | ||
size="large" | ||
style={{ width: `100%` }} | ||
options={options} | ||
className={className} | ||
filterOption={false} | ||
onSearch={handleSearch} | ||
onChange={onChange} | ||
defaultValue={defaultValue} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add testing for searching for a project by it's identifier please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see 3aa96c6.