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


##########
src/routes/services/index.tsx:
##########
@@ -90,60 +87,18 @@ const ServiceList = () => {
   }, [t, refetch]);
 
   return (
-    <AntdConfigProvider>
-      <ProTable
-        locale={{
-          emptyText: (
-            <Empty
-              description={t('services.empty')}
-              image={Empty.PRESENTED_IMAGE_SIMPLE}
-            />
-          ),
-        }}
-        columns={columns}
-        dataSource={data.list}
-        rowKey="id"
-        loading={isLoading}
-        search={false}
-        options={false}
-        pagination={pagination}
-        cardProps={{ bodyStyle: { padding: 0 } }}
-        toolbar={{
-          menu: {
-            type: 'inline',
-            items: [
-              {
-                key: 'add',
-                label: (
-                  <ToAddPageBtn
-                    key="add"
-                    label={t('info.add.title', {
-                      name: t('services.singular'),
-                    })}
-                    to="/services/add"
-                  />
-                ),
-              },
-            ],
-          },
-        }}
-      />
-    </AntdConfigProvider>
+    <ResourceListPage
+      titleKey="sources.services"
+      columns={columns}
+      queryData={{ data, isLoading, pagination, refetch }}
+      rowKey="id"
+      addPageTo="/services/add"
+      resourceNameKey="services.singular"
+      emptyKey="services.empty"
+    />
   );

Review Comment:
   `ResourceListPage`'s `emptyKey` handling only renders translated text, but 
the Services list previously rendered a richer `<Empty />` state (description + 
simple image). If the goal is 1:1 UI preservation, consider extending 
`ResourceListPage` to accept a custom `emptyText` ReactNode (or a render prop) 
so pages like Services can keep the existing Empty component presentation.



##########
src/components/page/ResourceListPage.tsx:
##########
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import type { ProColumns } from '@ant-design/pro-components';
+import { ProTable } from '@ant-design/pro-components';
+import type { TablePaginationConfig } from 'antd';
+import { useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { AntdConfigProvider } from '@/config/antdConfigProvider';
+
+import PageHeader from './PageHeader';
+import { ToAddPageBtn } from './ToAddPageBtn';
+
+interface ResourceListPageProps<T> {
+    titleKey?: string;
+    columns: ProColumns<T>[];
+    queryData: {
+        data?: { list: T[]; total: number;[key: string]: unknown } | undefined;
+        isLoading: boolean;
+        pagination: TablePaginationConfig | false;
+        refetch?: () => void;
+    };
+    rowKey: string;
+    addPageTo?: string;
+    resourceNameKey?: string;
+    emptyKey?: string;
+    pageSizeOptions?: number[] | string[];
+    showTotal?: (total: number, range: [number, number]) => React.ReactNode;
+}
+
+const ResourceListPage = <T extends Record<string, unknown>>(
+    props: ResourceListPageProps<T>
+) => {
+    const {
+        titleKey,
+        columns,
+        queryData,
+        rowKey,
+        addPageTo,
+        resourceNameKey,
+        emptyKey,
+        pageSizeOptions,
+        showTotal: customShowTotal,
+    } = props;
+    const { t } = useTranslation();
+    const { data, isLoading, pagination } = queryData;
+
+    const dataSource = useMemo(() => (data?.list as unknown as T[]) ?? [], 
[data]);
+    const total = (pagination !== false ? pagination?.total : undefined) ?? 
data?.total ?? 0;
+
+    const paginationConfig = useMemo(() => {
+        if (pagination === false) return false;
+
+        return {
+            current: pagination?.current ?? 1,
+            pageSize: pagination?.pageSize ?? 10,
+            total,
+            showSizeChanger: true,
+            pageSizeOptions: pageSizeOptions ?? [10, 20, 50, 100],
+            hideOnSinglePage: false,
+            onChange: pagination?.onChange,
+            showTotal: customShowTotal ?? ((total: number, range: [number, 
number]) =>
+                `${range[0]}-${range[1]} of ${total} items`),
+        };

Review Comment:
   `ResourceListPage` sets a default `showTotal` renderer (and hardcodes the 
text in English). This changes pagination UI compared to AntD/ProTable defaults 
and bypasses i18n. To preserve existing behavior, only pass `showTotal` when 
the caller explicitly provides it (or derive it from an i18n key).



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