Skip to content

Commit b1fea09

Browse files
Orv2 3405 - Sort STOS commodity list alphabetically (#1804)
1 parent f473877 commit b1fea09

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

frontend/public/config/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ const envConfig = (() => {
2525
VITE_POLICY_URL: "",
2626
VITE_RELEASE_NUM: "",
2727
};
28-
})();
28+
})();

frontend/src/common/components/header/components/SearchButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "./SearchButton.scss";
55

66
export const SearchButton = ({ onClick }: { onClick: () => void }) => {
77
return (
8-
<button className="search-button" onClick={onClick}>
8+
<button className="search-button" title="Search" onClick={onClick}>
99
<FontAwesomeIcon icon={faSearch} />
1010
</button>
1111
);

frontend/src/features/permits/helpers/permittedCommodity.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ export const getPermittedCommodityOptions = (
4848
policyEngine?.getCommodities(permitType),
4949
);
5050

51-
return [DEFAULT_COMMODITY_SELECT_OPTION].concat(
52-
[...commodities.entries()]
53-
.map(([commodityType, commodityDescription]) => ({
54-
value: commodityType,
55-
label: commodityDescription,
56-
})),
57-
);
51+
const commodityOptions = [...commodities.entries()]
52+
.map(([commodityType, commodityDescription]) => ({
53+
value: commodityType,
54+
label: commodityDescription,
55+
}))
56+
.sort((a, b) => {
57+
if (a.label === "None") return -1; // Move "none" to the top
58+
if (b.label === "None") return 1;
59+
return a.label.localeCompare(b.label);
60+
});
61+
62+
return [DEFAULT_COMMODITY_SELECT_OPTION].concat(commodityOptions);
5863
};

frontend/src/features/permits/pages/Application/components/form/CommodityDetailsSection/CommodityDetailsSection.tsx

+31-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, MenuItem } from "@mui/material"
1+
import { Box, MenuItem } from "@mui/material";
22
import { useCallback, useMemo, useState } from "react";
33

44
import "./CommodityDetailsSection.scss";
@@ -8,7 +8,10 @@ import { PERMIT_TYPES, PermitType } from "../../../../../types/PermitType";
88
import { Autocomplete } from "../../../../../../../common/components/form/subFormComponents/Autocomplete";
99
import { Controller, useFormContext } from "react-hook-form";
1010
import { Nullable } from "../../../../../../../common/types/common";
11-
import { DEFAULT_COMMODITY_SELECT_OPTION, DEFAULT_COMMODITY_SELECT_VALUE } from "../../../../../constants/constants";
11+
import {
12+
DEFAULT_COMMODITY_SELECT_OPTION,
13+
DEFAULT_COMMODITY_SELECT_VALUE,
14+
} from "../../../../../constants/constants";
1215
import { getDefaultRequiredVal } from "../../../../../../../common/helpers/util";
1316
import { ApplicationFormData } from "../../../../../types/application";
1417
import { ChangeCommodityTypeDialog } from "./ChangeCommodityTypeDialog";
@@ -29,7 +32,9 @@ export const CommodityDetailsSection = ({
2932
selectedCommodityType?: Nullable<string>;
3033
onChangeCommodityType: (commodityType: string) => void;
3134
}) => {
32-
const [newCommodityType, setNewCommodityType] = useState<string | undefined>();
35+
const [newCommodityType, setNewCommodityType] = useState<
36+
string | undefined
37+
>();
3338

3439
const selectedCommodityOption = useMemo(() => {
3540
return getDefaultRequiredVal(
@@ -50,16 +55,19 @@ export const CommodityDetailsSection = ({
5055
trigger("permitData.permittedCommodity.commodityType");
5156
};
5257

53-
const handleCommodityTypeChange = useCallback((updatedCommodityType: string) => {
54-
if (selectedCommodityType === updatedCommodityType) return;
58+
const handleCommodityTypeChange = useCallback(
59+
(updatedCommodityType: string) => {
60+
if (selectedCommodityType === updatedCommodityType) return;
5561

56-
if (selectedCommodityType !== DEFAULT_COMMODITY_SELECT_VALUE) {
57-
setNewCommodityType(updatedCommodityType);
58-
return;
59-
}
62+
if (selectedCommodityType !== DEFAULT_COMMODITY_SELECT_VALUE) {
63+
setNewCommodityType(updatedCommodityType);
64+
return;
65+
}
6066

61-
handleConfirmChangeCommodityType(updatedCommodityType);
62-
}, [selectedCommodityType]);
67+
handleConfirmChangeCommodityType(updatedCommodityType);
68+
},
69+
[selectedCommodityType],
70+
);
6371

6472
return permitType === PERMIT_TYPES.STOS ? (
6573
<Box className="commodity-details-section">
@@ -73,10 +81,11 @@ export const CommodityDetailsSection = ({
7381
rules={{
7482
required: { value: true, message: requiredMessage() },
7583
validate: {
76-
mustSelect: (value) => value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage(),
84+
mustSelect: (value) =>
85+
value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage(),
7786
},
7887
}}
79-
render={({ fieldState: {error} }) => (
88+
render={({ fieldState: { error } }) => (
8089
<Autocomplete
8190
label={{
8291
id: "commodity-type-label",
@@ -100,11 +109,16 @@ export const CommodityDetailsSection = ({
100109
{option.label}
101110
</MenuItem>
102111
),
103-
isOptionEqualToValue: (option, value) => option.value === value.value && option.label === value.label,
112+
isOptionEqualToValue: (option, value) =>
113+
option.value === value.value && option.label === value.label,
104114
}}
105-
helperText={error?.message ? {
106-
errors: [error.message],
107-
} : undefined}
115+
helperText={
116+
error?.message
117+
? {
118+
errors: [error.message],
119+
}
120+
: undefined
121+
}
108122
/>
109123
)}
110124
/>

0 commit comments

Comments
 (0)