diff --git a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java index e5d61a3fd..dbc558376 100644 --- a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java +++ b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java @@ -162,4 +162,6 @@ public class Constants { public static final String NULL_STRING = "null"; public static final String NUMBER_PATTERN = "^\\d+$"; + + public static final String ANY_PATTERN = ".*"; } diff --git a/console/src/main/resources/static/console-fe/src/locales/en-US.js b/console/src/main/resources/static/console-fe/src/locales/en-US.js index 111db3f97..f1315f082 100644 --- a/console/src/main/resources/static/console-fe/src/locales/en-US.js +++ b/console/src/main/resources/static/console-fe/src/locales/en-US.js @@ -97,6 +97,7 @@ const I18N_CONF = { pubNoData: 'No results found.', columnServiceName: 'Service Name', groupName: 'Group Name', + groupNamePlaceholder: 'Enter Group Name', columnClusterCount: 'Cluster Count', columnIpCount: 'Instance Count', columnHealthyInstanceCount: 'Healthy Instance Count', diff --git a/console/src/main/resources/static/console-fe/src/locales/zh-CN.js b/console/src/main/resources/static/console-fe/src/locales/zh-CN.js index e46795482..9218da10a 100644 --- a/console/src/main/resources/static/console-fe/src/locales/zh-CN.js +++ b/console/src/main/resources/static/console-fe/src/locales/zh-CN.js @@ -96,7 +96,8 @@ const I18N_CONF = { query: '查询', pubNoData: '没有数据', columnServiceName: '服务名', - groupName: '分组', + groupName: '分组名称', + groupNamePlaceholder: '请输入分组名称', columnClusterCount: '集群数目', columnIpCount: '实例数', columnHealthyInstanceCount: '健康实例数', diff --git a/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceList/ServiceList.js b/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceList/ServiceList.js index bd38442e0..642130fda 100644 --- a/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceList/ServiceList.js +++ b/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceList/ServiceList.js @@ -56,8 +56,11 @@ class ServiceList extends React.Component { total: 0, pageSize: 10, currentPage: 1, - keyword: '', dataSource: [], + search: { + serviceName: '', + groupName: '', + }, hasIpCount: !(localStorage.getItem('hasIpCount') === 'false'), }; this.field = new Field(this); @@ -78,13 +81,14 @@ class ServiceList extends React.Component { } queryServiceList() { - const { currentPage, pageSize, keyword, withInstances = false, hasIpCount } = this.state; + const { currentPage, pageSize, search, withInstances = false, hasIpCount } = this.state; const parameter = [ `hasIpCount=${hasIpCount}`, `withInstances=${withInstances}`, `pageNo=${currentPage}`, `pageSize=${pageSize}`, - `keyword=${keyword}`, + `serviceNameParam=${search.serviceName}`, + `groupNameParam=${search.groupName}`, ]; request({ url: `v1/ns/catalog/services?${parameter.join('&')}`, @@ -164,6 +168,8 @@ class ServiceList extends React.Component { serviceList, serviceName, serviceNamePlaceholder, + groupName, + groupNamePlaceholder, hiddenEmptyService, query, create, @@ -172,7 +178,7 @@ class ServiceList extends React.Component { sampleCode, deleteAction, } = locale; - const { keyword, nowNamespaceName, nowNamespaceId, hasIpCount } = this.state; + const { search, nowNamespaceName, nowNamespaceId, hasIpCount } = this.state; const { init, getValue } = this.field; this.init = init; this.getValue = getValue; @@ -214,8 +220,19 @@ class ServiceList extends React.Component { this.setState({ keyword })} + value={search.serviceName} + onChange={serviceName => this.setState({ search: { ...search, serviceName } })} + onPressEnter={() => + this.setState({ currentPage: 1 }, () => this.queryServiceList()) + } + /> + + + this.setState({ search: { ...search, groupName } })} onPressEnter={() => this.setState({ currentPage: 1 }, () => this.queryServiceList()) } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java index 4ebe8a835..6d47e67e5 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java @@ -150,10 +150,13 @@ public class CatalogController { List serviceDetailInfoList = new ArrayList<>(); int pageNo = Integer.parseInt(WebUtils.required(request, "pageNo")); int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize")); - String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY); + String serviceName = WebUtils.optional(request, "serviceNameParam", StringUtils.EMPTY); + String groupName = WebUtils.optional(request, "groupNameParam", StringUtils.EMPTY); + String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ? + StringUtils.EMPTY : NamingUtils.getGroupedName(serviceName, groupName); List serviceList = new ArrayList<>(8); - serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList, false); + serviceManager.getPagedService(namespaceId, pageNo, pageSize, param, StringUtils.EMPTY, serviceList, false); for (Service service : serviceList) { ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo(); @@ -257,12 +260,16 @@ public class CatalogController { int page = Integer.parseInt(WebUtils.required(request, "pageNo")); int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize")); - String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY); + String serviceName = WebUtils.optional(request, "serviceNameParam", StringUtils.EMPTY); + String groupName = WebUtils.optional(request, "groupNameParam", StringUtils.EMPTY); + String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ? + StringUtils.EMPTY : NamingUtils.getGroupedName(serviceName, groupName); + String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY); boolean hasIpCount = Boolean.parseBoolean(WebUtils.optional(request, "hasIpCount", "false")); List services = new ArrayList<>(); - int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services, hasIpCount); + int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, param, containedInstance, services, hasIpCount); if (CollectionUtils.isEmpty(services)) { result.put("serviceList", Collections.emptyList()); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java index b5dc8bad7..28870a624 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java @@ -269,10 +269,10 @@ public class ServiceController { Map> services = new HashMap<>(16); if (StringUtils.isNotBlank(namespaceId)) { - services.put(namespaceId, serviceManager.searchServices(namespaceId, ".*" + expr + ".*")); + services.put(namespaceId, serviceManager.searchServices(namespaceId, Constants.ANY_PATTERN + expr + Constants.ANY_PATTERN)); } else { for (String namespace : serviceManager.getAllNamespaces()) { - services.put(namespace, serviceManager.searchServices(namespace, ".*" + expr + ".*")); + services.put(namespace, serviceManager.searchServices(namespace, Constants.ANY_PATTERN + expr + Constants.ANY_PATTERN)); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 11b7ccedf..bc34fce45 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -675,7 +675,7 @@ public class ServiceManager implements RecordListener { return serviceMap.get(namespaceId); } - public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List serviceList, boolean hasIpCount) { + public int getPagedService(String namespaceId, int startPage, int pageSize, String param, String containedInstance, List serviceList, boolean hasIpCount) { List matchList; @@ -683,8 +683,12 @@ public class ServiceManager implements RecordListener { return 0; } - if (StringUtils.isNotBlank(keyword)) { - matchList = searchServices(namespaceId, ".*" + keyword + ".*"); + if (StringUtils.isNotBlank(param)) { + StringJoiner regex = new StringJoiner(Constants.SERVICE_INFO_SPLITER); + for (String s : param.split(Constants.SERVICE_INFO_SPLITER)) { + regex.add(StringUtils.isBlank(s) ? Constants.ANY_PATTERN : Constants.ANY_PATTERN + s + Constants.ANY_PATTERN); + } + matchList = searchServices(namespaceId, regex.toString()); } else { matchList = new ArrayList<>(chooseServiceMap(namespaceId).values()); }