From 1ae2d16a2e441084bb654edd4beec14905421e1b Mon Sep 17 00:00:00 2001 From: wenxuan70 <625559305@qq.com> Date: Thu, 23 May 2024 16:09:10 +0800 Subject: [PATCH] feat: add switch of hide empty services (#247) * feat: add switch of hide empty services * fix: move Switch hideEmptyService to TagSearchBox * fix: modify parameter name --- web/src/polaris/service/Page.tsx | 17 +++++++++++++++++ web/src/polaris/service/PageDuck.ts | 11 +++++++++-- web/src/polaris/service/model.ts | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/web/src/polaris/service/Page.tsx b/web/src/polaris/service/Page.tsx index bf264809..1b4bb405 100644 --- a/web/src/polaris/service/Page.tsx +++ b/web/src/polaris/service/Page.tsx @@ -34,6 +34,7 @@ export const DefaultServiceTagAttribute = { export const NamespaceTagKey = 'namespace' export const ServiceNameTagKey = 'serviceName' export const MetadataTagKey = 'serviceTag' +export const HideEmptyServiceTagKey = 'hideEmptyService' function getTagAttributes(props: DuckCmpProps) { const { duck, store } = props @@ -80,6 +81,22 @@ function getTagAttributes(props: DuckCmpProps) { ) }, }, + { + type: 'single', + key: HideEmptyServiceTagKey, + name: '隐藏空服务', + values: [ + { + name: '是', + value: true + }, + { + name: '否', + value: false + }, + ], + reusable: false, + } ] } export default function ServicePage(props: DuckCmpProps) { diff --git a/web/src/polaris/service/PageDuck.ts b/web/src/polaris/service/PageDuck.ts index 36da690b..c56dd394 100644 --- a/web/src/polaris/service/PageDuck.ts +++ b/web/src/polaris/service/PageDuck.ts @@ -11,7 +11,7 @@ import { put, select } from 'redux-saga/effects' import { Modal, TagValue } from 'tea-component' import { checkAuth } from '../auth/model' import { KeyValuePair } from '../configuration/fileGroup/types' -import { DefaultServiceTagAttribute, ServiceNameTagKey, MetadataTagKey } from './Page' +import { DefaultServiceTagAttribute, ServiceNameTagKey, MetadataTagKey, HideEmptyServiceTagKey } from './Page' import { PolarisTokenKey } from '../common/util/common' import router from '../common/util/router' @@ -23,6 +23,7 @@ export const EmptyCustomFilter = { searchMethod: 'accurate', department: '', business: '', + hideEmptyService: false, } interface Filter extends BaseFilter { @@ -33,6 +34,7 @@ interface Filter extends BaseFilter { searchMethod?: string department?: string business?: string + hideEmptyService?: boolean } interface CustomFilters { namespace?: string @@ -42,6 +44,7 @@ interface CustomFilters { searchMethod?: string department?: string business?: string + hideEmptyService?: boolean } export interface NamespaceItem extends Namespace { @@ -147,6 +150,7 @@ export default class ServicePageDuck extends GridPageDuck { searchMethod: state.customFilters.searchMethod, department: state.customFilters.department, business: state.customFilters.business, + hideEmptyService: state.customFilters.hideEmptyService, }), customFilters: (state: State) => state.customFilters, selection: (state: State) => state.selection, @@ -213,6 +217,8 @@ export default class ServicePageDuck extends GridPageDuck { const key = tag?.attr?.key || ServiceNameTagKey if (key === MetadataTagKey) { customFilters[key] = tag.values.map(item => ({ key: item.key, value: item.value })) + } else if (key === HideEmptyServiceTagKey) { + customFilters[key] = tag.values[0].value } else { if (tag.attr.type === 'input') customFilters[key] = tag.values[0].name else customFilters[key] = tag.values[0].key || tag.values[0].value @@ -260,7 +266,7 @@ export default class ServicePageDuck extends GridPageDuck { } async getData(filters: this['Filter']) { - const { page, count, namespace, serviceTag, instanceIp, department, business } = filters + const { page, count, namespace, serviceTag, instanceIp, department, business, hideEmptyService } = filters const { key, value } = serviceTag?.[0] || {} const serviceName = filters.serviceName const result = await describeServices({ @@ -273,6 +279,7 @@ export default class ServicePageDuck extends GridPageDuck { host: instanceIp || undefined, department: department || undefined, business: business || undefined, + only_exist_health_instance: hideEmptyService || undefined, }) return { totalCount: result.totalCount, diff --git a/web/src/polaris/service/model.ts b/web/src/polaris/service/model.ts index ff2c1dd8..21075b5c 100644 --- a/web/src/polaris/service/model.ts +++ b/web/src/polaris/service/model.ts @@ -11,6 +11,7 @@ export interface DescribeServicesParams { values?: string business?: string department?: string + only_exist_health_instance?: boolean } export interface OperateServicesResult { amount: number