Skip to content

Commit 62850cd

Browse files
committed
refactor(SearchForm): remove placeholder text from input fields
feat(RouteList): add RouteDetailButton component and refactor search parameter handling fix(clientSideFilter): improve filtering logic for plugins and labels
1 parent b95810a commit 62850cd

File tree

4 files changed

+38
-60
lines changed

4 files changed

+38
-60
lines changed

src/components/form/SearchForm.tsx

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,14 @@ export const SearchForm = (props: SearchFormProps) => {
124124
label={t('form.searchForm.fields.name')}
125125
style={{ marginBottom: '16px' }}
126126
>
127-
<Input
128-
placeholder={t('form.searchForm.placeholders.name')}
129-
allowClear
130-
/>
127+
<Input allowClear />
131128
</Form.Item>
132129
<Form.Item<SearchFormValues>
133130
name="id"
134131
label={t('form.searchForm.fields.id')}
135132
style={{ marginBottom: '16px' }}
136133
>
137-
<Input
138-
placeholder={t('form.searchForm.placeholders.id')}
139-
allowClear
140-
/>
134+
<Input allowClear />
141135
</Form.Item>
142136
</Col>
143137

@@ -148,21 +142,15 @@ export const SearchForm = (props: SearchFormProps) => {
148142
label={t('form.searchForm.fields.host')}
149143
style={{ marginBottom: '16px' }}
150144
>
151-
<Input
152-
placeholder={t('form.searchForm.placeholders.host')}
153-
allowClear
154-
/>
145+
<Input allowClear />
155146
</Form.Item>
156147
{/* Second column - second row */}
157148
<Form.Item<SearchFormValues>
158149
name="plugin"
159150
label={t('form.searchForm.fields.plugin')}
160151
style={{ marginBottom: '16px' }}
161152
>
162-
<Input
163-
placeholder={t('form.searchForm.placeholders.plugin')}
164-
allowClear
165-
/>
153+
<Input allowClear />
166154
</Form.Item>
167155
</Col>
168156

@@ -173,10 +161,7 @@ export const SearchForm = (props: SearchFormProps) => {
173161
label={t('form.searchForm.fields.path')}
174162
style={{ marginBottom: '16px' }}
175163
>
176-
<Input
177-
placeholder={t('form.searchForm.placeholders.path')}
178-
allowClear
179-
/>
164+
<Input allowClear />
180165
</Form.Item>
181166
{/* Third column - second row */}
182167
<Form.Item<SearchFormValues>
@@ -200,10 +185,7 @@ export const SearchForm = (props: SearchFormProps) => {
200185
label={t('form.searchForm.fields.description')}
201186
style={{ marginBottom: '16px' }}
202187
>
203-
<Input
204-
placeholder={t('form.searchForm.placeholders.description')}
205-
allowClear
206-
/>
188+
<Input allowClear />
207189
</Form.Item>
208190
{/* Fourth column - second row */}
209191
<Form.Item<SearchFormValues>

src/locales/en/common.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@
101101
"status": "Status"
102102
},
103103
"placeholders": {
104-
"name": "Name",
105-
"id": "ID",
106-
"host": "Host",
107-
"path": "Path",
108-
"description": "Description",
109-
"plugin": "Plugin",
110104
"labels": "Select labels",
111105
"version": "Select version",
112106
"status": "Select status"

src/routes/routes/index.tsx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ export type RouteListProps = {
4646
}) => React.ReactNode;
4747
};
4848

49+
const RouteDetailButton = ({
50+
record,
51+
}: {
52+
record: APISIXType['RespRouteItem'];
53+
}) => (
54+
<ToDetailPageBtn
55+
key="detail"
56+
to="/routes/detail/$id"
57+
params={{ id: record.value.id }}
58+
/>
59+
);
60+
61+
const SEARCH_PARAM_KEYS: (keyof SearchFormValues)[] = [
62+
'name',
63+
'id',
64+
'host',
65+
'path',
66+
'description',
67+
'plugin',
68+
'labels',
69+
'version',
70+
'status',
71+
];
72+
73+
const mapSearchParams = (values: Partial<SearchFormValues>) =>
74+
Object.fromEntries(SEARCH_PARAM_KEYS.map((key) => [key, values[key]])) as Partial<SearchFormValues>;
75+
4976
export const RouteList = (props: RouteListProps) => {
5077
const { routeKey, ToDetailBtn, defaultParams } = props;
5178
const { data, isLoading, refetch, pagination, setParams } = useRouteList(
@@ -59,30 +86,14 @@ export const RouteList = (props: RouteListProps) => {
5986
// Send name filter to backend, keep others for client-side filtering
6087
setParams({
6188
page: 1,
62-
name: values.name,
63-
id: values.id,
64-
host: values.host,
65-
path: values.path,
66-
description: values.description,
67-
plugin: values.plugin,
68-
labels: values.labels,
69-
version: values.version,
70-
status: values.status,
89+
...mapSearchParams(values),
7190
});
7291
};
7392

7493
const handleReset = () => {
7594
setParams({
7695
page: 1,
77-
name: undefined,
78-
id: undefined,
79-
host: undefined,
80-
path: undefined,
81-
description: undefined,
82-
plugin: undefined,
83-
labels: undefined,
84-
version: undefined,
85-
status: undefined,
96+
...mapSearchParams({}),
8697
});
8798
};
8899

@@ -187,16 +198,7 @@ function RouteComponent() {
187198
return (
188199
<>
189200
<PageHeader title={t('sources.routes')} />
190-
<RouteList
191-
routeKey="/routes/"
192-
ToDetailBtn={({ record }) => (
193-
<ToDetailPageBtn
194-
key="detail"
195-
to="/routes/detail/$id"
196-
params={{ id: record.value.id }}
197-
/>
198-
)}
199-
/>
201+
<RouteList routeKey="/routes/" ToDetailBtn={RouteDetailButton} />
200202
</>
201203
);
202204
}

src/utils/clientSideFilter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ export const filterRoutes = (
7676
if (!descMatch) return false;
7777
}
7878

79-
// Filter by plugin
79+
// Filter by plugin: treat the filter text as a substring across all plugin names
8080
if (filters.plugin && routeData.plugins) {
8181
const pluginNames = Object.keys(routeData.plugins).join(',').toLowerCase();
8282
const pluginMatch = pluginNames.includes(filters.plugin.toLowerCase());
8383
if (!pluginMatch) return false;
8484
}
8585

86-
// Filter by labels
86+
// Filter by labels: match provided label key:value tokens against route label pairs
8787
if (filters.labels && filters.labels.length > 0 && routeData.labels) {
8888
const routeLabels = Object.keys(routeData.labels).map((key) =>
8989
`${key}:${routeData.labels![key]}`.toLowerCase()

0 commit comments

Comments
 (0)