/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React from "react"; import { translate } from "@docusaurus/Translate"; import { ErrorMessage } from "@hookform/error-message"; import FormSelect from "@theme/ApiExplorer/FormSelect"; import { getSchemaEnum } from "@theme/ApiExplorer/ParamOptions"; import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice"; import { useTypedDispatch } from "@theme/ApiItem/hooks"; import { OPENAPI_FORM } from "@theme/translationIds"; import { Controller, useFormContext } from "react-hook-form"; export interface ParamProps { param: Param; label?: string; type?: string; required?: boolean; } export default function ParamSelectFormItem({ param, label, type, required, }: ParamProps) { const { control, formState: { errors }, } = useFormContext(); const showErrorMessage = errors?.paramSelect; const dispatch = useTypedDispatch(); const options = getSchemaEnum(param.schema) ?? []; return ( <> ( ) => { const val = e.target.value; dispatch( setParam({ ...param, value: val === "---" ? undefined : val, }) ); onChange(val); }} /> )} /> {showErrorMessage && ( (
{message}
)} /> )} ); }