Skip to content

Commit

Permalink
can now select category for span equipment in edit span equipment (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen authored Nov 6, 2024
1 parent 1734d81 commit c4a6264
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getFilteredManufacturers = (
}

const filtered = bodyItems.filter((x) => {
return spanEquipment.manufacturerRefs.includes(x.value.toString());
return spanEquipment.manufacturerRefs?.includes(x.value.toString());
});

const defaultValue: SelectOption= {
Expand Down Expand Up @@ -341,6 +341,30 @@ function EditSpanEquipment({ spanEquipmentMrid }: EditSpanEquipmentParams) {
setSelectedManufacturer("");
};

const categorySelectOptions = () => {
const categoryOptions = spanEquipmentSpecifications
.map((x) => {
return x.category;
})
.filter((v, i, a) => a.indexOf(v) === i)
.map<SelectOption>((x) => {
return {
text: t(x),
value: x,
};
});

return categoryOptions;
};

const selectCategory = (categoryId: string | number | undefined) => {
if (selectedCategory === categoryId || selectCategory === undefined) return;

setSelectedCategory(categoryId);
setSelectedSpanEquipmentSpecification("");
setSelectedManufacturer("");
};

const update = async () => {
if (!selectedSpanEquipmentSpecification) {
toast.error("ERROR");
Expand Down Expand Up @@ -395,19 +419,29 @@ function EditSpanEquipment({ spanEquipmentMrid }: EditSpanEquipmentParams) {
<div className="edit-span-equipment page-container">
<div className="block">
<p className="block-title">{t("SPAN_EQUIPMENT_INFORMATION")}</p>
<div className="full-row">
<SelectMenu
options={categorySelectOptions()}
removePlaceHolderOnSelect
onSelected={selectCategory}
selected={selectedCategory}
/>
</div>
<div className="full-row">
<SelectMenu
options={filteredSpanEquipmentSpecifications}
onSelected={(x) => selectSpanEquipmentSpecification(x?.toString() ?? "")}
selected={selectedSpanEquipmentSpecification}
enableSearch={true}
autoSelectFirst={true}
/>
</div>
<div className="full-row">
<SelectMenu
options={filteredManufactuers}
onSelected={(x) => setSelectedManufacturer(x?.toString() ?? "")}
selected={selectedManufacturer}
autoSelectFirst={true}
/>
</div>
<div className="full-row">
Expand Down

0 comments on commit c4a6264

Please sign in to comment.