Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/components/Forms/Formik/FormikResourceSelectorDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type FormikConfigsDropdownProps = {
className?: string;
valueField?: "id" | "name";
disabled?: boolean;
onValueChange?: (
value: any,
option: FormikSelectDropdownOption | null
) => void;
};

export default function FormikResourceSelectorDropdown({
Expand All @@ -43,7 +47,8 @@ export default function FormikResourceSelectorDropdown({
playbookResourceSelector,
className = "flex flex-col space-y-2 py-2",
valueField = "id",
disabled = false
disabled = false,
onValueChange
}: FormikConfigsDropdownProps) {
const [inputText, setInputText] = useState<string>("");
const [searchText, setSearchText] = useState<string>();
Expand Down Expand Up @@ -262,6 +267,7 @@ export default function FormikResourceSelectorDropdown({
),
value: playbook[valueField],
search: playbook.name,
name: playbook.name,
label: (
<div className="flex flex-wrap gap-1">
<span className="mr-2"> {playbook.name}</span>
Expand Down Expand Up @@ -312,14 +318,18 @@ export default function FormikResourceSelectorDropdown({
isClearable
value={value}
onChange={(value: any) => {
const selectedValue = Array.isArray(value)
? value.map((item) => item.value)
: value?.value;

field.onChange({
target: {
name: field.name,
value: Array.isArray(value)
? value.map((item) => item.value)
: value?.value
value: selectedValue
}
});

onValueChange?.(selectedValue, value);
}}
onInputChange={handleInputChange}
inputValue={inputText ?? value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ export default function FormikPermissionSelectResourceFields() {
required
name="playbook_id"
playbookResourceSelector={[{}]}
onValueChange={(value, option) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary fix until we hadd resource selector to the form

if (option && (option as any).name) {
setFieldValue("object_selector", {
playbooks: [{ name: (option as any).name }],
configs: [{ name: "*" }]
});
} else {
setFieldValue("object_selector", undefined);
}
}}
/>
)}

Expand Down
Loading