Copilot commented on code in PR #3013:
URL: https://github.com/apache/apisix-dashboard/pull/3013#discussion_r2074507962
##########
src/components/form-slice/FormPartBasic.tsx:
##########
@@ -7,29 +7,58 @@ import { useFormContext } from 'react-hook-form';
import type { APISIXType } from '@/types/schema/apisix';
import { useNamePrefix } from '@/utils/useNamePrefix';
import type { PropsWithChildren } from 'react';
+import { FormItemSelect } from '../form/Select';
+import { APISIXCommon } from '@/types/schema/apisix/common';
export type FormPartBasicProps = Omit<FormSectionProps, 'form'> &
- PropsWithChildren;
+ PropsWithChildren & {
+ showStatus?: boolean;
+ showName?: boolean;
+ showDesc?: boolean;
+ showLabels?: boolean;
+ };
export const FormPartBasic = (props: FormPartBasicProps) => {
- const { children, ...restProps } = props;
+ const {
+ children,
+ showStatus = false,
+ showName = true,
+ showDesc = true,
+ showLabels = true,
+ ...restProps
+ } = props;
const { control } = useFormContext<APISIXType['Basic']>();
const { t } = useTranslation();
const np = useNamePrefix();
return (
<FormSection legend={t('form.basic.title')} {...restProps}>
- <FormItemTextInput
- name={np('name')}
- label={t('form.basic.name')}
- control={control}
- />
- <FormItemTextarea
- name={np('desc')}
- label={t('form.basic.desc')}
- control={control}
- />
- <FormItemLabels name={np('labels')} control={control} />
+ {showName && (
+ <FormItemTextInput
+ name={np('name')}
+ label={t('form.basic.name')}
+ control={control}
+ />
+ )}
+ {showDesc && (
+ <FormItemTextarea
+ name={np('desc')}
+ label={t('form.basic.desc')}
+ control={control}
+ />
+ )}
+ {showLabels && <FormItemLabels name={np('labels')} control={control} />}
+ {showStatus && (
+ <FormItemSelect
+ control={control}
+ name="status"
+ label={t('form.basic.status')}
+ defaultValue={APISIXCommon.Status.options[1].value.toString()}
+ data={APISIXCommon.Status.options.map((v) => v.value.toString())}
Review Comment:
APISIXCommon.Status is defined as a zod union and does not expose an
'options' property. Consider defining a dedicated options array for status
values or adjust the component usage accordingly to avoid runtime issues.
```suggestion
defaultValue={STATUS_OPTIONS[1].value.toString()}
data={STATUS_OPTIONS.map((v) => v.value.toString())}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]