SkyeYoung commented on code in PR #3222:
URL: https://github.com/apache/apisix-dashboard/pull/3222#discussion_r2450138604


##########
src/utils/clientSideFilter.ts:
##########
@@ -0,0 +1,143 @@
+/**
+ * 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 { APISIXType } from '@/types/schema/apisix';
+
+import type { SearchFormValues } from '../components/form/SearchForm';
+
+/**
+ * Client-side filtering utility for routes
+ * Used as a fallback when backend doesn't support certain filter parameters
+ */
+
+export const filterRoutes = (
+  routes: APISIXType['RespRouteItem'][],
+  filters: SearchFormValues
+): APISIXType['RespRouteItem'][] => {
+  return routes.filter((route) => {
+    const routeData = route.value;
+
+    // Filter by name
+    if (filters.name && routeData.name) {
+      const nameMatch = routeData.name
+        .toLowerCase()
+        .includes(filters.name.toLowerCase());
+      if (!nameMatch) return false;
+    }
+
+    // Filter by ID
+    if (filters.id) {
+      const idMatch = String(routeData.id)
+        .toLowerCase()
+        .includes(filters.id.toLowerCase());
+      if (!idMatch) return false;
+    }
+
+    // Filter by host
+    if (filters.host) {
+      const host = Array.isArray(routeData.host)
+        ? routeData.host.join(',')
+        : routeData.host || '';
+      const hostMatch = 
host.toLowerCase().includes(filters.host.toLowerCase());
+      if (!hostMatch) return false;
+    }
+
+    // Filter by path/URI
+    if (filters.path) {
+      const uri = Array.isArray(routeData.uri)
+        ? routeData.uri.join(',')
+        : routeData.uri || '';
+      const uris = Array.isArray(routeData.uris)
+        ? routeData.uris.join(',')
+        : '';
+      const combinedPath = `${uri} ${uris}`.toLowerCase();
+      const pathMatch = combinedPath.includes(filters.path.toLowerCase());
+      if (!pathMatch) return false;
+    }
+
+    // Filter by description
+    if (filters.description && routeData.desc) {
+      const descMatch = routeData.desc
+        .toLowerCase()
+        .includes(filters.description.toLowerCase());
+      if (!descMatch) return false;
+    }
+
+    // Filter by plugin
+    if (filters.plugin && routeData.plugins) {
+      const pluginNames = 
Object.keys(routeData.plugins).join(',').toLowerCase();
+      const pluginMatch = pluginNames.includes(filters.plugin.toLowerCase());
+      if (!pluginMatch) return false;
+    }
+
+    // Filter by labels
+    if (filters.labels && filters.labels.length > 0 && routeData.labels) {
+      const routeLabels = Object.keys(routeData.labels).map((key) =>
+        `${key}:${routeData.labels![key]}`.toLowerCase()
+      );

Review Comment:
   It's best to comment on the effects of these methods to prevent future 
maintainers from misunderstanding them.



##########
src/routes/routes/index.tsx:
##########
@@ -42,12 +48,57 @@ export type RouteListProps = {
 
 export const RouteList = (props: RouteListProps) => {
   const { routeKey, ToDetailBtn, defaultParams } = props;
-  const { data, isLoading, refetch, pagination } = useRouteList(
+  const { data, isLoading, refetch, pagination, setParams } = useRouteList(
     routeKey,
     defaultParams
   );
+  const { params } = useSearchParams(routeKey);
   const { t } = useTranslation();
 
+  const handleSearch = (values: SearchFormValues) => {
+    // Send name filter to backend, keep others for client-side filtering
+    setParams({
+      page: 1,
+      name: values.name,
+      id: values.id,
+      host: values.host,
+      path: values.path,
+      description: values.description,
+      plugin: values.plugin,
+      labels: values.labels,
+      version: values.version,
+      status: values.status,
+    });
+  };
+
+  const handleReset = () => {
+    setParams({
+      page: 1,
+      name: undefined,
+      id: undefined,
+      host: undefined,
+      path: undefined,
+      description: undefined,
+      plugin: undefined,
+      labels: undefined,
+      version: undefined,
+      status: undefined,
+    });
+  };

Review Comment:
   Is there a way to make it less bloated? 🤔 



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