Skip to content

Commit

Permalink
chore: rename property
Browse files Browse the repository at this point in the history
  • Loading branch information
stampaaaron committed Dec 17, 2024
1 parent aa1e62f commit 7f04161
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/frontend/src/components/EntitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const messages = i18n("entitySelect", {
actionCreateNew: params('Create new "{value}"'),
});

export function EntitySelect<T extends { id: number }>({ value, onChange, data, labelKey: inputKey, onAddNew, ...rest }: Props<T>) {
export function EntitySelect<T extends { id: number }>({ value, onChange, data, labelKey, onAddNew, ...rest }: Props<T>) {
const t = useStore(messages);

const combobox = useCombobox({
Expand All @@ -33,23 +33,23 @@ export function EntitySelect<T extends { id: number }>({ value, onChange, data,

const [searchValue, setSearchValue] = useState("");

const shouldFilterOptions = !data?.some((item) => item[inputKey] === searchValue);
const shouldFilterOptions = !data?.some((item) => item[labelKey] === searchValue);
const filteredOptions =
(shouldFilterOptions
? data?.filter((item) => (item[inputKey] as string)?.toLowerCase().includes(searchValue.toLowerCase().trim()))
? data?.filter((item) => (item[labelKey] as string)?.toLowerCase().includes(searchValue.toLowerCase().trim()))
: data) ?? [];

const options = filteredOptions?.map((item) => (
<Combobox.Option key={item.id} value={item.id.toString()}>
{item[inputKey] as string}
{item[labelKey] as string}
</Combobox.Option>
));

useEffect(() => {
if (value && data) {
const index = data.findIndex((item) => item.id === value);
if (index !== -1) {
setSearchValue(data[index][inputKey] as string);
setSearchValue(data[index][labelKey] as string);
combobox.selectOption(index);
}
}
Expand Down

0 comments on commit 7f04161

Please sign in to comment.