Skip to content

Commit

Permalink
feat: add switch of hide empty services (#247)
Browse files Browse the repository at this point in the history
* feat: add switch of hide empty services

* fix: move Switch hideEmptyService to TagSearchBox

* fix: modify parameter name
  • Loading branch information
wenxuan70 committed May 23, 2024
1 parent a45741c commit 1ae2d16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions web/src/polaris/service/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServicePageDuck>) {
const { duck, store } = props
Expand Down Expand Up @@ -80,6 +81,22 @@ function getTagAttributes(props: DuckCmpProps<ServicePageDuck>) {
)
},
},
{
type: 'single',
key: HideEmptyServiceTagKey,
name: '隐藏空服务',
values: [
{
name: '是',
value: true
},
{
name: '否',
value: false
},
],
reusable: false,
}
]
}
export default function ServicePage(props: DuckCmpProps<ServicePageDuck>) {
Expand Down
11 changes: 9 additions & 2 deletions web/src/polaris/service/PageDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -23,6 +23,7 @@ export const EmptyCustomFilter = {
searchMethod: 'accurate',
department: '',
business: '',
hideEmptyService: false,
}

interface Filter extends BaseFilter {
Expand All @@ -33,6 +34,7 @@ interface Filter extends BaseFilter {
searchMethod?: string
department?: string
business?: string
hideEmptyService?: boolean
}
interface CustomFilters {
namespace?: string
Expand All @@ -42,6 +44,7 @@ interface CustomFilters {
searchMethod?: string
department?: string
business?: string
hideEmptyService?: boolean
}

export interface NamespaceItem extends Namespace {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions web/src/polaris/service/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface DescribeServicesParams {
values?: string
business?: string
department?: string
only_exist_health_instance?: boolean
}
export interface OperateServicesResult {
amount: number
Expand Down

0 comments on commit 1ae2d16

Please # to comment.