This is an automated email from the ASF dual-hosted git repository.
bzp2010 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new df0452e3 feat: add search functionality for id, host, and description
fields (#2750)
df0452e3 is described below
commit df0452e3e8af28eb9fbac000cbab723b9b85d01b
Author: Anil Baki Durmus <[email protected]>
AuthorDate: Thu Mar 9 08:39:55 2023 +0200
feat: add search functionality for id, host, and description fields (#2750)
Co-authored-by: Anil Durmus <[email protected]>
---
api/internal/handler/route/route.go | 17 +++++++++++++++++
api/internal/handler/service/service.go | 10 ++++++++++
api/internal/handler/upstream/upstream.go | 9 +++++++++
web/cypress/e2e/route/search-route.cy.js | 3 +++
web/src/pages/Route/List.tsx | 4 +---
web/src/pages/Route/service.ts | 5 ++++-
web/src/pages/Service/List.tsx | 4 +---
web/src/pages/Service/service.ts | 2 ++
web/src/pages/Upstream/List.tsx | 2 --
web/src/pages/Upstream/service.ts | 2 ++
10 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/api/internal/handler/route/route.go
b/api/internal/handler/route/route.go
index fae4429d..d100c85b 100644
--- a/api/internal/handler/route/route.go
+++ b/api/internal/handler/route/route.go
@@ -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
}
@@ -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{} {
diff --git a/api/internal/handler/service/service.go
b/api/internal/handler/service/service.go
index fe382b06..ab94bfd8 100644
--- a/api/internal/handler/service/service.go
+++ b/api/internal/handler/service/service.go
@@ -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
}
@@ -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{} {
diff --git a/api/internal/handler/upstream/upstream.go
b/api/internal/handler/upstream/upstream.go
index 3157fdda..55c08a50 100644
--- a/api/internal/handler/upstream/upstream.go
+++ b/api/internal/handler/upstream/upstream.go
@@ -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
}
@@ -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{} {
diff --git a/web/cypress/e2e/route/search-route.cy.js
b/web/cypress/e2e/route/search-route.cy.js
index d947d977..62288143 100644
--- a/web/cypress/e2e/route/search-route.cy.js
+++ b/web/cypress/e2e/route/search-route.cy.js
@@ -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);
@@ -197,6 +199,7 @@ context('Create and Search Route', () => {
force: true,
multiple: true,
});
+ cy.wait(timeout);
}
});
});
diff --git a/web/src/pages/Route/List.tsx b/web/src/pages/Route/List.tsx
index cbacd4f2..7ff4d7de 100755
--- a/web/src/pages/Route/List.tsx
+++ b/web/src/pages/Route/List.tsx
@@ -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]) || [];
@@ -361,7 +360,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'component.global.description' }),
dataIndex: 'desc',
- hideInSearch: true,
ellipsis: true,
width: 200,
},
diff --git a/web/src/pages/Route/service.ts b/web/src/pages/Route/service.ts
index dbd182a5..794db915 100644
--- a/web/src/pages/Route/service.ts
+++ b/web/src/pages/Route/service.ts
@@ -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: {
@@ -51,6 +51,9 @@ export const fetchList = ({ current = 1, pageSize = 10,
...res }) => {
page: current,
page_size: pageSize,
status,
+ host,
+ desc,
+ id,
},
}).then(({ data }) => {
return {
diff --git a/web/src/pages/Service/List.tsx b/web/src/pages/Service/List.tsx
index c509a95b..05feb47a 100644
--- a/web/src/pages/Service/List.tsx
+++ b/web/src/pages/Service/List.tsx
@@ -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' }),
@@ -53,7 +52,6 @@ const Page: React.FC = () => {
{
title: formatMessage({ id: 'component.global.description' }),
dataIndex: 'desc',
- hideInSearch: true,
},
{
title: formatMessage({ id: 'component.global.operation' }),
diff --git a/web/src/pages/Service/service.ts b/web/src/pages/Service/service.ts
index b6523356..def2860b 100644
--- a/web/src/pages/Service/service.ts
+++ b/web/src/pages/Service/service.ts
@@ -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,
diff --git a/web/src/pages/Upstream/List.tsx b/web/src/pages/Upstream/List.tsx
index c593b1ea..5c31749d 100644
--- a/web/src/pages/Upstream/List.tsx
+++ b/web/src/pages/Upstream/List.tsx
@@ -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' }),
@@ -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' }),
diff --git a/web/src/pages/Upstream/service.ts
b/web/src/pages/Upstream/service.ts
index a04925fd..a4d5ffef 100644
--- a/web/src/pages/Upstream/service.ts
+++ b/web/src/pages/Upstream/service.ts
@@ -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,