feat(web): use searchable combobox for term/authority fields on the object form (#27)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { components } from "../api/schema";
|
||||
import { labelText } from "../lib/labels";
|
||||
import {
|
||||
ComboboxRoot,
|
||||
ComboboxInputGroup,
|
||||
@@ -16,15 +17,6 @@ type LabelView = components["schemas"]["LabelView"];
|
||||
|
||||
export type Option = { id: string; labels: LabelView[] };
|
||||
|
||||
export function labelIn(labels: LabelView[], lang: string): string {
|
||||
return (
|
||||
labels.find((l) => l.lang === lang)?.label ??
|
||||
labels.find((l) => l.lang === "en")?.label ??
|
||||
labels[0]?.label ??
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
export function OptionsCombobox({
|
||||
id,
|
||||
value,
|
||||
@@ -47,7 +39,7 @@ export function OptionsCombobox({
|
||||
items={options}
|
||||
value={selected}
|
||||
onValueChange={(option) => onChange(option?.id ?? "")}
|
||||
itemToStringLabel={(option) => (option ? labelIn(option.labels, lang) : "")}
|
||||
itemToStringLabel={(option) => (option ? labelText(option.labels, lang) : "")}
|
||||
isItemEqualToValue={(a, b) => a?.id === b?.id}
|
||||
>
|
||||
<ComboboxInputGroup>
|
||||
@@ -62,7 +54,7 @@ export function OptionsCombobox({
|
||||
{(option: Option) => (
|
||||
<ComboboxItem key={option.id} value={option}>
|
||||
<ComboboxItemIndicator className="text-indigo-600">✓</ComboboxItemIndicator>
|
||||
{labelIn(option.labels, lang)}
|
||||
{labelText(option.labels, lang)}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxList>
|
||||
|
||||
Reference in New Issue
Block a user