Copilot commented on code in PR #3009:
URL: https://github.com/apache/apisix-dashboard/pull/3009#discussion_r2068367512
##########
src/routes/routes/detail.$id.tsx:
##########
@@ -0,0 +1,116 @@
+import { createFileRoute, useParams } from '@tanstack/react-router';
+import { useTranslation } from 'react-i18next';
+import { useMutation, useQuery } from '@tanstack/react-query';
+import PageHeader from '@/components/page/PageHeader';
+import { FormProvider, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { FormSubmitBtn } from '@/components/form/Btn';
+import { notifications } from '@mantine/notifications';
+import { FormTOCBox } from '@/components/form-slice/FormSection';
+import { Skeleton, Button, Group } from '@mantine/core';
+import { useBoolean } from 'react-use';
+import { useEffect } from 'react';
+import { APISIX } from '@/types/schema/apisix';
+import { getRouteQueryOptions, putRouteReq } from '@/apis/routes';
+import { FormPartRoute } from '@/components/form-slice/FormPartRoute';
+import { pipeProduce } from '@/utils/producer';
+import { FormSectionGeneral } from
'@/components/form-slice/FormSectionGeneral';
+
+type Props = {
+ readOnly: boolean;
+ setReadOnly: (v: boolean) => void;
+};
+
+const RouteDetailForm = (props: Props) => {
+ const { readOnly, setReadOnly } = props;
+ const { t } = useTranslation();
+ const { id } = useParams({ from: '/routes/detail/$id' });
+
+ const routeQuery = useQuery(getRouteQueryOptions(id));
+ const { data: routeData, isLoading, refetch } = routeQuery;
+
+ const form = useForm({
+ resolver: zodResolver(APISIX.Route),
+ shouldUnregister: true,
+ shouldFocusError: true,
+ mode: 'all',
+ disabled: readOnly,
+ });
+
+ // 将API数据加载到表单中
+ useEffect(() => {
+ if (routeData?.value && !isLoading) {
+ form.reset(routeData.value);
+ }
+ }, [routeData, form, isLoading]);
+
+ // 处理表单提交和路由更新
+ const putRoute = useMutation({
+ mutationFn: putRouteReq,
+ async onSuccess() {
+ notifications.show({
+ message: t('route.edit.success'),
+ color: 'green',
+ });
+ await refetch();
+ setReadOnly(true);
+ },
+ });
+
+ if (isLoading) {
+ return <Skeleton height={400} />;
+ }
+
+ return (
+ <FormProvider {...form}>
+ <form
+ onSubmit={form.handleSubmit((d) => {
Review Comment:
[nitpick] When calling pipeProduce without additional functions, consider
adding a comment explaining that the default production functions
(produceRmDoubleUnderscoreKeys, produceTime, produceDeepCleanEmptyKeys) are
applied. This will help future maintainability and clarify its behavior.
```suggestion
onSubmit={form.handleSubmit((d) => {
// By default, pipeProduce applies the following production
functions:
// produceRmDoubleUnderscoreKeys, produceTime,
produceDeepCleanEmptyKeys.
```
--
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]