Copilot commented on code in PR #3100:
URL: https://github.com/apache/apisix-dashboard/pull/3100#discussion_r2126042450


##########
src/routes/services/detail.$id.tsx:
##########
@@ -14,134 +14,64 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import { zodResolver } from '@hookform/resolvers/zod';
-import { Button, Group,Skeleton } from '@mantine/core';
-import { notifications } from '@mantine/notifications';
-import { useMutation, useSuspenseQuery } from '@tanstack/react-query';
+
 import {
   createFileRoute,
+  Outlet,
+  useLocation,
   useNavigate,
   useParams,
 } from '@tanstack/react-router';
-import { useEffect } from 'react';
-import { FormProvider, useForm } from 'react-hook-form';
+import { useMemo } from 'react';
 import { useTranslation } from 'react-i18next';
-import { useBoolean } from 'react-use';
-
-import { getServiceQueryOptions } from '@/apis/hooks';
-import { putServiceReq } from '@/apis/services';
-import { FormSubmitBtn } from '@/components/form/Btn';
-import { FormPartService } from '@/components/form-slice/FormPartService';
-import { FormTOCBox } from '@/components/form-slice/FormSection';
-import { FormSectionGeneral } from 
'@/components/form-slice/FormSectionGeneral';
-import { DeleteResourceBtn } from '@/components/page/DeleteResourceBtn';
-import PageHeader from '@/components/page/PageHeader';
-import { API_SERVICES } from '@/config/constant';
-import { req } from '@/config/req';
-import { APISIX, type APISIXType } from '@/types/schema/apisix';
-import { produceRmUpstreamWhenHas } from '@/utils/form-producer';
-import { pipeProduce } from '@/utils/producer';
 
-type Props = {
-  readOnly: boolean;
-  setReadOnly: (v: boolean) => void;
-};
+import { Tabs, type TabsItem } from '@/components/page/Tabs';
 
-const ServiceDetailForm = (props: Props) => {
-  const { readOnly, setReadOnly } = props;
+const defaultTab = 'detail';
+export const DetailTabs = () => {
   const { t } = useTranslation();
-  const { id } = useParams({ from: '/services/detail/$id' });
-
-  const serviceQuery = useSuspenseQuery(getServiceQueryOptions(id));
-  const { data: serviceData, isLoading, refetch } = serviceQuery;
-
-  const form = useForm({
-    resolver: zodResolver(APISIX.Service),
-    shouldUnregister: true,
-    shouldFocusError: true,
-    mode: 'all',
-    disabled: readOnly,
-  });
-
-  useEffect(() => {
-    if (serviceData?.value && !isLoading) {
-      form.reset(serviceData.value);
-    }
-  }, [serviceData, form, isLoading]);
-
-  const putService = useMutation({
-    mutationFn: (d: APISIXType['Service']) =>
-      putServiceReq(
-        req,
-        pipeProduce(produceRmUpstreamWhenHas('upstream_id'))(d)
-      ),
-    async onSuccess() {
-      notifications.show({
-        message: t('info.edit.success', { name: t('services.singular') }),
-        color: 'green',
-      });
-      await refetch();
-      setReadOnly(true);
-    },
+  const { id } = useParams({ strict: false });
+  const navigate = useNavigate();
+  const lastPath = useLocation({
+    select: (location) => location.pathname.split('/').pop() || '',
   });
 
-  if (isLoading) {
-    return <Skeleton height={400} />;
-  }
-
+  const items = useMemo(
+    (): TabsItem[] => [
+      {
+        value: defaultTab,
+        label: t('info.detail.title', { name: t('services.singular') }),
+      },
+      {
+        value: 'routes',
+        label: t('sources.routes'),
+      },
+    ],
+    [t]
+  );
   return (
-    <FormProvider {...form}>
-      <form onSubmit={form.handleSubmit((d) => putService.mutateAsync(d))}>
-        <FormSectionGeneral readOnly />
-        <FormPartService />
-        {!readOnly && (
-          <Group>
-            <FormSubmitBtn>{t('form.btn.save')}</FormSubmitBtn>
-            <Button variant="outline" onClick={() => setReadOnly(true)}>
-              {t('form.btn.cancel')}
-            </Button>
-          </Group>
-        )}
-      </form>
-    </FormProvider>
+    <Tabs
+      items={items}
+      variant="outline"
+      value={items.find((v) => lastPath === v.value)?.value || defaultTab}
+      onChange={(v) => {
+        navigate({
+          to:
+            v === defaultTab
+              ? '/services/detail/$id/'

Review Comment:
   [nitpick] Consider using a more robust method to determine the active tab 
rather than relying solely on extracting the last segment of the pathname. 
Explicitly parsing route parameters may improve long-term maintainability.
   ```suggestion
         value={items.find((v) => activeTab === v.value)?.value || defaultTab}
         onChange={(v) => {
           navigate({
             to:
               v === defaultTab
                 ? '/services/detail/$id'
   ```



-- 
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]

Reply via email to