Skip to content

Commit b65b4cb

Browse files
authored
Only include restricted items in the approval form (#103)
* Filter items by restricted status * Filter types by restricted status * Filter gear by restricted status
1 parent 458589d commit b65b4cb

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

src/apiClient/gear.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface GearTypeWithFee extends GearTypeBase {
5959
export interface GearType extends GearTypeWithShorthand {
6060
defaultDeposit: number;
6161
shouldInventory: boolean;
62+
restricted: boolean;
6263
}
6364

6465
export interface GearLocation {

src/components/GearItemSelect.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ type Props = {
4343
onChange: (person: GearSummary | null | undefined) => void;
4444
className?: string;
4545
invalid?: boolean;
46+
filters?: { restricted?: boolean };
4647
};
4748

48-
export function GearItemSelect({ value, onChange, className, invalid }: Props) {
49+
export function GearItemSelect({
50+
className,
51+
filters,
52+
invalid,
53+
onChange,
54+
value,
55+
}: Props) {
4956
const [query, setInput] = useState<string>("");
5057
const { pending, fn: debouncedSetInput } = useDebounce(setInput, 250);
5158
const { gearList, isFetching } = useGearList({
5259
q: query,
5360
retired: false,
61+
...filters,
5462
});
5563

5664
const options: GearOption[] =

src/components/GearTypeSelect.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useCallback } from "react";
22
import ReactSelect, { MultiValue } from "react-select";
33

4-
import { useGetGearTypesQuery } from "src/redux/api";
54
import { GearType as APIGearType } from "src/apiClient/gear";
5+
import { useGetGearTypesQuery } from "src/redux/api";
66

77
import { Select } from "./Select";
88

@@ -17,17 +17,22 @@ export function GearTypeSelect({
1717
value,
1818
onChange,
1919
invalid,
20+
restrictedOnly,
2021
}: {
2122
value: number | null | undefined;
2223
onChange: (value: GearType | null) => void;
2324
invalid?: boolean;
25+
restrictedOnly?: boolean;
2426
}) {
25-
const gearTypeOptions = useGearTypesOptions();
26-
const selectedOption = gearTypeOptions.find((o) => o.id === value);
27+
const allGearTypeOptions = useGearTypesOptions();
28+
const filteredOptions = !restrictedOnly
29+
? allGearTypeOptions
30+
: allGearTypeOptions.filter((t) => t.restricted);
31+
const selectedOption = filteredOptions.find((o) => o.id === value);
2732
return (
2833
<Select
2934
className="flex-grow-1"
30-
options={gearTypeOptions}
35+
options={filteredOptions}
3136
value={selectedOption}
3237
onChange={onChange}
3338
invalid={invalid}

src/pages/Approvals/ApprovalItemsPicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function ApprovalItemsPicker() {
7373
value={value ?? null}
7474
onChange={(val) => onChange(val?.id)}
7575
invalid={invalid}
76+
restrictedOnly={true}
7677
/>
7778
);
7879
}}
@@ -100,6 +101,7 @@ export function ApprovalItemsPicker() {
100101
value={value ?? null}
101102
onChange={(val) => onChange(val?.id)}
102103
invalid={invalid}
104+
filters={{ restricted: true }}
103105
/>
104106
);
105107
}}

src/pages/Gear/AllGearPage/AllGearPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export function AllGearPage() {
2323
const [showFilters, setShowFilters] = useState<boolean>(
2424
!isEqual(filters, { retired: GearStatusFilter.exclude }), // Open the panel if filters are not the default
2525
);
26-
const { gearTypes, broken, missing, retired, q, locations } = filters;
26+
const { gearTypes, broken, missing, retired, q, locations, restricted } =
27+
filters;
2728
const query = q ?? "";
2829
const setQuery = (q: string) => setFilters((filters) => ({ ...filters, q }));
2930

@@ -34,6 +35,7 @@ export function AllGearPage() {
3435
broken: gearStatusToBoolean(broken),
3536
missing: gearStatusToBoolean(missing),
3637
retired: gearStatusToBoolean(retired),
38+
restricted: gearStatusToBoolean(restricted),
3739
locations: locations,
3840
});
3941

src/pages/Gear/AllGearPage/GearFilters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum GearStatusFilter {
1313
export type Filters = {
1414
q?: string;
1515
gearTypes?: number[];
16+
restricted?: GearStatusFilter;
1617
broken?: GearStatusFilter;
1718
retired?: GearStatusFilter;
1819
missing?: GearStatusFilter;
@@ -65,7 +66,7 @@ export function GearFilters({ filters, setFilters }: Props) {
6566
);
6667
}
6768

68-
const gearStatus = ["broken", "missing", "retired"] as const;
69+
const gearStatus = ["restricted", "broken", "missing", "retired"] as const;
6970

7071
const gearStatusOptions = [
7172
{ value: GearStatusFilter.include, label: "Include" },

src/pages/Gear/AllGearPage/useGearFilter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ function serialize({
2121
missing,
2222
retired,
2323
locations,
24+
restricted,
2425
}: Filters): Record<string, string> {
2526
return {
2627
...(q && { q }),
2728
...(broken != null && { broken: String(broken) }),
2829
...(missing != null && { missing: String(missing) }),
30+
...(restricted != null && { restricted: String(restricted) }),
2931
...(retired != null &&
3032
retired !== GearStatusFilter.exclude && { retired: String(retired) }),
3133
...(!isEmpty(gearTypes) && { gearTypes: gearTypes!.map(String).join(",") }),
@@ -40,6 +42,7 @@ function parse(params: URLSearchParams): Filters {
4042
const retired =
4143
parseStatus(params.get("retired")) ?? GearStatusFilter.exclude;
4244
const broken = parseStatus(params.get("broken"));
45+
const restricted = parseStatus(params.get("restricted"));
4346
const q = params.get("q") ?? "";
4447
const locations = params.get("locations") ?? "";
4548

@@ -48,6 +51,7 @@ function parse(params: URLSearchParams): Filters {
4851
...(retired !== null && { retired }),
4952
...(broken != null && { broken }),
5053
...(missing != null && { missing }),
54+
...(restricted != null && { restricted }),
5155
...(!isEmpty(gearTypes) && {
5256
gearTypes: gearTypes!.split(",").map(Number),
5357
}),

src/redux/api.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,29 @@ export const gearDbApi = createApi({
7070
broken?: boolean;
7171
missing?: boolean;
7272
retired?: boolean;
73+
restricted?: boolean;
7374
gearTypes?: number[];
7475
locations?: number[];
7576
}
7677
>({
77-
query: ({ q, page, gearTypes, broken, missing, retired, locations }) => ({
78+
query: ({
79+
q,
80+
page,
81+
gearTypes,
82+
broken,
83+
missing,
84+
retired,
85+
restricted,
86+
locations,
87+
}) => ({
7888
url: "gear/",
7989
params: {
8090
...(q && { q }),
8191
...(page && { page }),
8292
...(broken != null && { broken }),
8393
...(missing != null && { missing }),
8494
...(retired != null && { retired }),
95+
...(restricted != null && { restricted }),
8596
...(!isEmpty(gearTypes) && { gearTypes }),
8697
...(!isEmpty(locations) && { locations }),
8798
},
@@ -200,12 +211,14 @@ export function useGearList({
200211
missing,
201212
retired,
202213
locations,
214+
restricted,
203215
}: {
204216
q: string;
205217
page?: number;
206218
gearTypes?: number[];
207219
broken?: boolean;
208220
missing?: boolean;
221+
restricted?: boolean;
209222
retired?: boolean;
210223
locations?: number[];
211224
}) {
@@ -217,6 +230,7 @@ export function useGearList({
217230
missing,
218231
retired,
219232
locations,
233+
restricted,
220234
});
221235
const data = result.data;
222236
const gearList = data?.results;

0 commit comments

Comments
 (0)