Skip to content

Commit 54cc5d2

Browse files
committed
update handleChange function to support grouped selections
1 parent 597aa73 commit 54cc5d2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/features/common/components/debugger-picker/debugger-picker.component.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
22
import styles from "./debugger-picker.module.scss";
33
import Select, { SingleValue } from "react-select";
44
import { DebuggerPickerOptionModel } from "@/features/common/models/debugger-picker-option.model";
5+
import { LibraryFilterLabel } from "@/features/libraries/models/library-filters.model";
56

67
interface PickerLabelProps {
78
label: string | null;
@@ -19,8 +20,8 @@ interface DebuggerPickerComponentProps {
1920
label: string | null;
2021
languageCode: string;
2122
options: DebuggerPickerOptionModel[];
22-
selectedOptionCode: DebuggerPickerOptionModel | null;
23-
handleSelection: (value: string) => void;
23+
selectedOptionCode: DebuggerPickerOptionModel["options"][0] | null;
24+
handleSelection: (selection: string, parentLabel?: LibraryFilterLabel) => void
2425
placeholder: string | null;
2526
minWidth: string | null;
2627
}
@@ -37,12 +38,14 @@ export const DebuggerPickerComponent: React.FC<
3738
}) => {
3839
const [isClient, setIsClient] = useState(false);
3940

40-
const handleChange = (selection: SingleValue<DebuggerPickerOptionModel>) => {
41+
const handleChange = (
42+
selection: SingleValue<DebuggerPickerOptionModel["options"][0]>
43+
) => {
4144
if (!selection) {
4245
return;
4346
}
44-
45-
handleSelection(selection.value);
47+
const parentLabel = options.find(group => group.options.some(opt => opt.value === selection.value))?.label
48+
handleSelection(selection.value, parentLabel);
4649
};
4750

4851
useEffect(() => {

0 commit comments

Comments
 (0)