This is an automated email from the ASF dual-hosted git repository.

young pushed a commit to branch young/feat/service-list-add
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git

commit 2b0897b9248e09475e2777cc95f32ce79d07d4da
Author: Skye Young <[email protected]>
AuthorDate: Tue May 6 00:46:22 2025 +0800

    feat: service list page
---
 src/locales/en/common.json    |   5 +-
 src/routes/services/index.tsx | 140 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 140 insertions(+), 5 deletions(-)

diff --git a/src/locales/en/common.json b/src/locales/en/common.json
index aa3692dab..a6fc808ec 100644
--- a/src/locales/en/common.json
+++ b/src/locales/en/common.json
@@ -63,8 +63,8 @@
     "search": "Search",
     "service": {
       "enableWebsocket": "Enable WebSocket",
-      "script": "Script",
       "hosts": "Hosts",
+      "script": "Script",
       "settings": "Service Settings"
     },
     "streamRoute": {
@@ -289,6 +289,9 @@
     },
     "title": "Services"
   },
+  "services": {
+    "title": "Services"
+  },
   "setting": {
     "adminKey": "Admin Key",
     "title": "Setting"
diff --git a/src/routes/services/index.tsx b/src/routes/services/index.tsx
index c0be9da7e..aa11d4630 100644
--- a/src/routes/services/index.tsx
+++ b/src/routes/services/index.tsx
@@ -1,9 +1,141 @@
+import { queryClient } from '@/config/global';
+import { useSuspenseQuery } from '@tanstack/react-query';
 import { createFileRoute } from '@tanstack/react-router';
+import { useTranslation } from 'react-i18next';
+import type { APISIXType } from '@/types/schema/apisix';
+import { ProTable } from '@ant-design/pro-components';
+import type { ProColumns } from '@ant-design/pro-components';
+import { useEffect, useMemo } from 'react';
+import { ToDetailPageBtn, ToAddPageBtn } from '@/components/page/ToAddPageBtn';
+import { pageSearchSchema } from '@/types/schema/pageSearch';
+import { getServiceListQueryOptions } from '@/apis/services';
+import { usePagination } from '@/utils/usePagination';
+import { AntdConfigProvider } from '@/config/antdConfigProvider';
+import PageHeader from '@/components/page/PageHeader';
 
-export const Route = createFileRoute('/services/')({
-  component: RouteComponent,
-});
+const ServiceList = () => {
+  const { pagination, handlePageChange, updateTotal } = usePagination({
+    queryKey: 'services',
+  });
+
+  const query = useSuspenseQuery(getServiceListQueryOptions(pagination));
+  const { data, isLoading } = query;
+  const { t } = useTranslation();
+
+  useEffect(() => {
+    if (data?.total) {
+      updateTotal(data.total);
+    }
+  }, [data?.total, updateTotal]);
+
+  const columns = useMemo<ProColumns<APISIXType['RespServiceItem']>[]>(() => {
+    return [
+      {
+        dataIndex: ['value', 'id'],
+        title: 'ID',
+        key: 'id',
+        valueType: 'text',
+      },
+      {
+        dataIndex: ['value', 'name'],
+        title: t('form.basic.name'),
+        key: 'name',
+        valueType: 'text',
+      },
+      {
+        dataIndex: ['value', 'desc'],
+        title: t('form.basic.desc'),
+        key: 'desc',
+        valueType: 'text',
+      },
+      {
+        dataIndex: ['value', 'enable_websocket'],
+        title: t('form.service.enableWebsocket'),
+        key: 'enable_websocket',
+        valueType: 'boolean',
+      },
+      {
+        dataIndex: ['value', 'update_time'],
+        title: t('form.info.update_time'),
+        key: 'update_time',
+        valueType: 'dateTime',
+        sorter: true,
+        renderText: (text) => {
+          if (!text) return '-';
+          return new Date(Number(text) * 1000).toISOString();
+        },
+      },
+      {
+        title: t('actions'),
+        valueType: 'option',
+        key: 'option',
+        width: 120,
+        render: (_, record) => [
+          <ToDetailPageBtn
+            key="detail"
+            to="/services/detail/$id"
+            id={record.value.id}
+          />,
+        ],
+      },
+    ];
+  }, [t]);
+
+  return (
+    <AntdConfigProvider>
+      <ProTable
+        columns={columns}
+        dataSource={data.list}
+        rowKey="id"
+        loading={isLoading}
+        search={false}
+        options={false}
+        pagination={{
+          current: pagination.page,
+          pageSize: pagination.pageSize,
+          total: pagination.total,
+          showSizeChanger: true,
+          onChange: handlePageChange,
+        }}
+        cardProps={{ bodyStyle: { padding: 0 } }}
+        toolbar={{
+          menu: {
+            type: 'inline',
+            items: [
+              {
+                key: 'add',
+                label: (
+                  <ToAddPageBtn
+                    key="add"
+                    label={t('service.add.title')}
+                    to="/services/add"
+                  />
+                ),
+              },
+            ],
+          },
+        }}
+      />
+    </AntdConfigProvider>
+  );
+};
 
 function RouteComponent() {
-  return <div>Hello "/service/"!</div>;
+  const { t } = useTranslation();
+  return (
+    <>
+      <PageHeader title={t('services.title')} />
+      <AntdConfigProvider>
+        <ServiceList />
+      </AntdConfigProvider>
+    </>
+  );
 }
+
+export const Route = createFileRoute('/services/')({
+  component: RouteComponent,
+  validateSearch: pageSearchSchema,
+  loaderDeps: ({ search }) => search,
+  loader: ({ deps }) =>
+    queryClient.ensureQueryData(getServiceListQueryOptions(deps)),
+});

Reply via email to