Merge pull request #1576 from zhaoyuguang/fix-1535-1

FIX close: 1535 Add a button to hide the empty service on console at service list page
This commit is contained in:
Fury Zhu 2019-08-01 15:52:25 +08:00 committed by GitHub
commit bf3e822d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 32 deletions

View File

@ -92,6 +92,7 @@ const I18N_CONF = {
serviceList: 'Service List',
serviceName: 'Service Name',
serviceNamePlaceholder: 'Enter Service Name',
hiddenEmptyService: 'Hidden Empty Service',
query: 'Search',
pubNoData: 'No results found.',
columnServiceName: 'Service Name',

View File

@ -92,6 +92,7 @@ const I18N_CONF = {
serviceList: '服务列表',
serviceName: '服务名称',
serviceNamePlaceholder: '请输入服务名称',
hiddenEmptyService: '隐藏空服务',
query: '查询',
pubNoData: '没有数据',
columnServiceName: '服务名',

View File

@ -25,6 +25,7 @@ import {
Dialog,
Message,
ConfigProvider,
Switch,
} from '@alifd/next';
import { request } from '../../../globalLib';
import RegionGroup from '../../../components/RegionGroup';
@ -57,6 +58,7 @@ class ServiceList extends React.Component {
currentPage: 1,
keyword: '',
dataSource: [],
hasIpCount: !(localStorage.getItem('hasIpCount') === 'false'),
};
this.field = new Field(this);
}
@ -71,15 +73,14 @@ class ServiceList extends React.Component {
openEditServiceDialog() {
try {
this.editServiceDialog.current.getInstance()
.show(this.state.service);
} catch (error) {
}
this.editServiceDialog.current.getInstance().show(this.state.service);
} catch (error) {}
}
queryServiceList() {
const { currentPage, pageSize, keyword, withInstances = false } = this.state;
const { currentPage, pageSize, keyword, withInstances = false, hasIpCount } = this.state;
const parameter = [
`hasIpCount=${hasIpCount}`,
`withInstances=${withInstances}`,
`pageNo=${currentPage}`,
`pageSize=${pageSize}`,
@ -119,8 +120,7 @@ class ServiceList extends React.Component {
*
*/
showSampleCode(record) {
this.showcode.current.getInstance()
.openDialog(record);
this.showcode.current.getInstance().openDialog(record);
}
deleteService(service) {
@ -157,7 +157,6 @@ class ServiceList extends React.Component {
rowColor = row => ({ className: !row.healthyInstanceCount ? 'row-bg-red' : '' });
render() {
const { locale = {} } = this.props;
const {
@ -165,6 +164,7 @@ class ServiceList extends React.Component {
serviceList,
serviceName,
serviceNamePlaceholder,
hiddenEmptyService,
query,
create,
operation,
@ -172,7 +172,7 @@ class ServiceList extends React.Component {
sampleCode,
deleteAction,
} = locale;
const { keyword, nowNamespaceName, nowNamespaceId } = this.state;
const { keyword, nowNamespaceName, nowNamespaceId, hasIpCount } = this.state;
const { init, getValue } = this.field;
this.init = init;
this.getValue = getValue;
@ -221,6 +221,17 @@ class ServiceList extends React.Component {
}
/>
</FormItem>
<Form.Item label={`${hiddenEmptyService}:`}>
<Switch
checked={hasIpCount}
onChange={hasIpCount =>
this.setState({ hasIpCount, currentPage: 1 }, () => {
localStorage.setItem('hasIpCount', hasIpCount);
this.queryServiceList();
})
}
/>
</Form.Item>
<FormItem label="">
<Button
type="primary"
@ -266,8 +277,9 @@ class ServiceList extends React.Component {
<a
onClick={() =>
this.props.history.push(
`/serviceDetail?name=${record.name}&groupName=${record.groupName}`,
)}
`/serviceDetail?name=${record.name}&groupName=${record.groupName}`
)
}
style={{ marginRight: 5 }}
>
{detail}
@ -277,10 +289,7 @@ class ServiceList extends React.Component {
{sampleCode}
</a>
<span style={{ marginRight: 5 }}>|</span>
<a
onClick={() => this.deleteService(record)}
style={{ marginRight: 5 }}
>
<a onClick={() => this.deleteService(record)} style={{ marginRight: 5 }}>
{deleteAction}
</a>
</div>
@ -290,10 +299,11 @@ class ServiceList extends React.Component {
</Col>
</Row>
{this.state.total > this.state.pageSize && (
<div style={{
marginTop: 10,
textAlign: 'right',
}}
<div
style={{
marginTop: 10,
textAlign: 'right',
}}
>
<Pagination
current={this.state.currentPage}

View File

@ -26,4 +26,8 @@
color: #000;
margin-right: 8px;
}
.next-switch-off {
background-color: #f2f3f7;
border-color: #c4c6cf;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -153,7 +153,7 @@ public class CatalogController {
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
List<Service> serviceList = new ArrayList<>(8);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList, false);
for (Service service : serviceList) {
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
@ -259,9 +259,10 @@ public class CatalogController {
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
boolean hasIpCount = Boolean.parseBoolean(WebUtils.optional(request, "hasIpCount", "false"));
List<Service> services = new ArrayList<>();
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services);
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services, hasIpCount);
if (CollectionUtils.isEmpty(services)) {
result.put("serviceList", Collections.emptyList());

View File

@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@ -45,6 +46,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/**
* Core manager storing all services in Nacos
@ -637,6 +639,7 @@ public class ServiceManager implements RecordListener<Service> {
Loggers.SRV_LOG.info("[NEW-SERVICE] {}", service.toJSON());
}
public List<Service> searchServices(String namespaceId, String regex) {
List<Service> result = new ArrayList<>();
for (Map.Entry<String, Service> entry : chooseServiceMap(namespaceId).entrySet()) {
@ -672,7 +675,7 @@ public class ServiceManager implements RecordListener<Service> {
return serviceMap.get(namespaceId);
}
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList) {
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList, boolean hasIpCount) {
List<Service> matchList;
@ -686,6 +689,10 @@ public class ServiceManager implements RecordListener<Service> {
matchList = new ArrayList<>(chooseServiceMap(namespaceId).values());
}
if (!CollectionUtils.isEmpty(matchList) && hasIpCount) {
matchList = matchList.stream().filter(s -> !CollectionUtils.isEmpty(s.allIPs())).collect(Collectors.toList());
}
if (StringUtils.isNotBlank(containedInstance)) {
boolean contained;