Skip to content

Commit 9717174

Browse files
committed
add id to dropdowns
1 parent bee09ab commit 9717174

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/components/OptimadeClient/DatabaseSelector.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function DatabaseSelector({
1010
}) {
1111
const [selectedProvider, setSelectedProvider] = useState("");
1212
const [childEntries, setChildEntries] = useState([]);
13-
const [childSelected, setChildSelected] = useState(null); // full object
13+
const [childSelected, setChildSelected] = useState(null);
1414
const [customUrl, setCustomUrl] = useState("");
1515
const [loadingChildren, setLoadingChildren] = useState(false);
1616

@@ -37,7 +37,12 @@ export function DatabaseSelector({
3737
try {
3838
setLoadingChildren(true);
3939
const { children } = await getProviderLinks(selectedProvider);
40-
const entries = children.map((c) => c.attributes || {});
40+
41+
const entries = children.map((c) => ({
42+
id: c.id,
43+
...(c.attributes ?? {}),
44+
}));
45+
4146
setChildEntries(entries);
4247

4348
if (entries.length === 1) {
@@ -88,7 +93,7 @@ export function DatabaseSelector({
8893
key={p.attributes?.id ?? p.id ?? p.attributes?.base_url}
8994
value={p.attributes?.base_url || ""}
9095
>
91-
{p.attributes?.name || p.id}
96+
{`${p.attributes?.name} - ${p.id}`}
9297
</option>
9398
))}
9499
<option value="__custom__">Custom endpoint…</option>
@@ -104,11 +109,9 @@ export function DatabaseSelector({
104109
) : (
105110
<select
106111
className={slateDropdown}
107-
value={childSelected?.base_url || ""}
112+
value={childSelected?.id || ""}
108113
onChange={(e) => {
109-
const selected = childEntries.find(
110-
(c) => c.base_url === e.target.value
111-
);
114+
const selected = childEntries.find((c) => c.id === e.target.value);
112115
setChildSelected(selected || null);
113116
}}
114117
disabled={loadingChildren}
@@ -121,8 +124,8 @@ export function DatabaseSelector({
121124
Select a subdatabase…
122125
</option>
123126
{childEntries.map((c) => (
124-
<option key={c.id ?? c.base_url ?? c.name} value={c.base_url}>
125-
{c.name}
127+
<option key={c.id} value={c.id}>
128+
{`${c.id} - ${c.name}`}
126129
</option>
127130
))}
128131
</>

0 commit comments

Comments
 (0)