refactor: getGroups

This commit is contained in:
Ibrahima G. Coulibaly
2025-07-10 16:04:55 +01:00
parent 9045eb1bab
commit 425102415a
5 changed files with 194 additions and 178 deletions

View File

@@ -46,6 +46,9 @@ interface ToolContentProps<Options, Input> extends ToolComponentProps {
setFieldValue: (fieldName: string, value: any) => void
) => ReactNode;
initialValues: Options;
/**
* should return non-empty array or null
*/
getGroups: GetGroupsType<Options> | null;
compute: (optionsValues: Options, input: Input) => void;
toolInfo?: {

View File

@@ -6,10 +6,10 @@ import { FormikProps, FormikValues, useFormikContext } from 'formik';
import ToolOptionGroups, { ToolOptionGroup } from './ToolOptionGroups';
export type UpdateField<T> = <Y extends keyof T>(field: Y, value: T[Y]) => void;
type NonEmptyArray<T> = [T, ...T[]];
export type GetGroupsType<T> = (
formikProps: FormikProps<T> & { updateField: UpdateField<T> }
) => ToolOptionGroup[];
) => NonEmptyArray<ToolOptionGroup>;
export default function ToolOptions<T extends FormikValues>({
children,
@@ -50,7 +50,7 @@ export default function ToolOptions<T extends FormikValues>({
<Box mt={2}>
<Stack direction={'row'} spacing={2}>
<ToolOptionGroups
groups={getGroups({ ...formikContext, updateField }) ?? []}
groups={getGroups({ ...formikContext, updateField }) ?? null}
vertical={vertical}
/>
{children}