Skip to content

Commit 18d9730

Browse files
authored
Merge pull request #93 from JaneliaSciComp/feature/collections-dropdown-descriptions
Show collection descriptions in the /collections dropdown
2 parents e1f434e + 7d30655 commit 18d9730

2 files changed

Lines changed: 69 additions & 18 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.collection-option {
2+
display: flex;
3+
flex-direction: column;
4+
padding: 4px 0;
5+
}
6+
7+
.collection-option-name {
8+
font-weight: 600;
9+
}
10+
11+
.collection-option-description {
12+
font-size: 0.85em;
13+
color: rgba(0, 0, 0, 0.55);
14+
line-height: 1.35;
15+
white-space: normal;
16+
}
17+
18+
/* Let the multi-line option content (name + description) wrap instead of
19+
being truncated to a single line by the default Select styling. */
20+
.collection-select-dropdown .ant-select-item-option-content {
21+
white-space: normal;
22+
}

‎src/components/ImageCollections.jsx‎

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { faExternalLink } from "@fortawesome/pro-regular-svg-icons";
55
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
66
import { AppContext } from "../containers/AppContext";
77
import { libraryFormatter } from "../libs/utils";
8+
import "./ImageCollections.css";
89

910
const { Title, Paragraph } = Typography;
1011

@@ -154,27 +155,41 @@ export default function ImageCollections() {
154155
}))
155156
.filter((collection) => collection.releaseRows.length > 0);
156157

157-
// Group the dropdown options by collection type (e.g. Light Microscopy /
158-
// Electron Microscopy) when a type is provided, otherwise show a flat list.
158+
// Render a dropdown option showing the collection name (in bold) above its
159+
// description, so users see what each collection contains without having to
160+
// parse the name first. `label` is the plain name, used for the selected
161+
// value display (via optionLabelProp) and for search filtering.
162+
const renderCollectionOption = (collection) => (
163+
<Select.Option
164+
key={collection.name}
165+
value={collection.name}
166+
label={collection.name}
167+
>
168+
<div className="collection-option">
169+
<span className="collection-option-name">{collection.name}</span>
170+
{collection.description ? (
171+
<span className="collection-option-description">
172+
{collection.description}
173+
</span>
174+
) : null}
175+
</div>
176+
</Select.Option>
177+
);
178+
179+
// Group the collections by type (e.g. Light Microscopy / Electron
180+
// Microscopy) when a type is provided, otherwise show a flat list.
159181
const hasTypes = collections.some((collection) => collection.type);
160-
let collectionOptions;
182+
const collectionGroups = [];
161183
if (hasTypes) {
162-
const groups = [];
163184
collections.forEach((collection) => {
164185
const groupLabel = collection.type || "Other";
165-
let group = groups.find((g) => g.label === groupLabel);
186+
let group = collectionGroups.find((entry) => entry.label === groupLabel);
166187
if (!group) {
167-
group = { label: groupLabel, options: [] };
168-
groups.push(group);
188+
group = { label: groupLabel, items: [] };
189+
collectionGroups.push(group);
169190
}
170-
group.options.push({ value: collection.name, label: collection.name });
191+
group.items.push(collection);
171192
});
172-
collectionOptions = groups;
173-
} else {
174-
collectionOptions = collections.map((collection) => ({
175-
value: collection.name,
176-
label: collection.name,
177-
}));
178193
}
179194

180195
// Default to the first collection until the user picks one.
@@ -262,14 +277,28 @@ export default function ImageCollections() {
262277
<Select
263278
id="collection-select"
264279
value={activeCollection ? activeCollection.name : undefined}
265-
options={collectionOptions}
266280
onChange={(value) => setSelectedCollection(value)}
267-
style={{ minWidth: 320 }}
268-
listHeight={400}
281+
style={{ width: 460, maxWidth: "100%" }}
282+
listHeight={560}
283+
virtual={false}
284+
popupClassName="collection-select-dropdown"
269285
showSearch
270286
optionFilterProp="label"
287+
optionLabelProp="label"
271288
placeholder="Select a collection"
272-
/>
289+
>
290+
{hasTypes
291+
? collectionGroups.map((group) => (
292+
<Select.OptGroup key={group.label} label={group.label}>
293+
{group.items.map((collection) =>
294+
renderCollectionOption(collection),
295+
)}
296+
</Select.OptGroup>
297+
))
298+
: collections.map((collection) =>
299+
renderCollectionOption(collection),
300+
)}
301+
</Select>
273302
</Paragraph>
274303
{activeCollection ? (
275304
<>

0 commit comments

Comments
 (0)