Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search functionality for ID, host, and description fields #2750

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ type ListInput struct {
URI string `auto_read:"uri,query"`
Label string `auto_read:"label,query"`
Status string `auto_read:"status,query"`
Host string `auto_read:"host,query"`
ID string `auto_read:"id,query"`
Desc string `auto_read:"desc,query"`
store.Pagination
}

Expand Down Expand Up @@ -236,6 +239,20 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
return false
}

if input.Host != "" && !strings.Contains(obj.(*entity.Route).Host, input.Host) {
return false
}

if input.Desc != "" && !strings.Contains(obj.(*entity.Route).Desc, input.Desc) {
return false
}

if obj != nil && obj.(*entity.Route) != nil && obj.(*entity.Route).ID != nil && input.ID != "" {
if !strings.Contains(utils.InterfaceToString(obj.(*entity.Route).ID), input.ID) {
return false // IDs do not match, so object should not be included in the filtered result
}
}

return true
},
Format: func(obj interface{}) interface{} {
Expand Down
10 changes: 10 additions & 0 deletions api/internal/handler/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func (h *Handler) Get(c droplet.Context) (interface{}, error) {

type ListInput struct {
Name string `auto_read:"name,query"`
ID string `auto_read:"id,query"`
Desc string `auto_read:"desc,query"`
store.Pagination
}

Expand Down Expand Up @@ -135,6 +137,14 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
if input.Name != "" {
return strings.Contains(obj.(*entity.Service).Name, input.Name)
}

if input.Desc != "" {
return strings.Contains(obj.(*entity.Service).Desc, input.Desc)
}

if input.ID != "" {
return strings.Contains(utils.InterfaceToString(obj.(*entity.Service).ID), input.ID)
}
return true
},
Format: func(obj interface{}) interface{} {
Expand Down
9 changes: 9 additions & 0 deletions api/internal/handler/upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (h *Handler) Get(c droplet.Context) (interface{}, error) {

type ListInput struct {
Name string `auto_read:"name,query"`
ID string `auto_read:"id,query"`
Desc string `auto_read:"desc,query"`
store.Pagination
}

Expand Down Expand Up @@ -141,6 +143,13 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
if input.Name != "" {
return strings.Contains(obj.(*entity.Upstream).Name, input.Name)
}

if input.Desc != "" {
return strings.Contains(obj.(*entity.Upstream).Desc, input.Desc)
}
if input.ID != "" {
return strings.Contains(utils.InterfaceToString(obj.(*entity.Upstream).ID), input.ID)
}
return true
},
Format: func(obj interface{}) interface{} {
Expand Down
3 changes: 3 additions & 0 deletions web/cypress/e2e/route/search-route.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ context('Create and Search Route', () => {
cy.contains('Route').click();
cy.wait(timeout);
// full match
// expand search
cy.get(selector.expandSearch).click();
cy.get(selector.pathSearchInput).type(data.uris1);
cy.contains('Search').click();
cy.contains(data.uris1).should('contain', data.uris1);
Expand Down Expand Up @@ -197,6 +199,7 @@ context('Create and Search Route', () => {
force: true,
multiple: true,
});
cy.wait(timeout);
}
});
});
4 changes: 1 addition & 3 deletions web/src/pages/Route/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,12 @@ const Page: React.FC = () => {
},
{
title: formatMessage({ id: 'component.global.id' }),
hideInSearch: true,
dataIndex: 'id',
width: 200,
},
{
title: formatMessage({ id: 'page.route.host' }),
hideInSearch: true,
dataIndex: 'host',
width: 224,
render: (_, record) => {
const list = record.hosts || (record.host && [record.host]) || [];
Expand Down Expand Up @@ -361,7 +360,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'component.global.description' }),
dataIndex: 'desc',
hideInSearch: true,
ellipsis: true,
width: 200,
},
Expand Down
5 changes: 4 additions & 1 deletion web/src/pages/Route/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const fetchItem = (rid: number) =>
request(`/routes/${rid}`).then((data) => transformRouteData(data.data));

export const fetchList = ({ current = 1, pageSize = 10, ...res }) => {
const { labels = [], API_VERSION = [], status } = res;
const { labels = [], API_VERSION = [], host = "", id = "", desc = "", status} = res;

return request<Res<ResListData<RouteModule.ResponseBody>>>('/routes', {
params: {
Expand All @@ -51,6 +51,9 @@ export const fetchList = ({ current = 1, pageSize = 10, ...res }) => {
page: current,
page_size: pageSize,
status,
host,
desc,
id,
},
}).then(({ data }) => {
return {
Expand Down
4 changes: 1 addition & 3 deletions web/src/pages/Service/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ const Page: React.FC = () => {

const columns: ProColumns<ServiceModule.ResponseBody>[] = [
{
title: 'ID',
title: formatMessage({ id: 'component.global.id' }),
dataIndex: 'id',
hideInSearch: true,
},
{
title: formatMessage({ id: 'component.global.name' }),
Expand All @@ -53,7 +52,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'component.global.description' }),
dataIndex: 'desc',
hideInSearch: true,
},
{
title: formatMessage({ id: 'component.global.operation' }),
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { transformData } from './transform';
export const fetchList = ({ current = 1, pageSize = 10, ...res }) =>
request('/services', {
params: {
id: res.id || '',
desc: res.desc || '',
name: res.name,
page: current,
page_size: pageSize,
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/Upstream/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'page.upstream.list.id' }),
dataIndex: 'id',
hideInSearch: true,
},
{
title: formatMessage({ id: 'page.upstream.list.name' }),
Expand All @@ -59,7 +58,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'page.upstream.list.description' }),
dataIndex: 'desc',
hideInSearch: true,
},
{
title: formatMessage({ id: 'page.upstream.list.edit.time' }),
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Upstream/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { convertToFormData } from '@/components/Upstream/service';
export const fetchList = ({ current = 1, pageSize = 10, ...res }) => {
return request<Res<ResListData<UpstreamModule.RequestBody>>>('/upstreams', {
params: {
id: res.id || '',
desc: res.desc || '',
name: res.name,
page: current,
page_size: pageSize,
Expand Down