From e49a508b2b996be7ba350198c7231c5cceae4b74 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 2 Jan 2024 14:24:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=81=B0=E5=BA=A6=E7=9A=84=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=85=8D=E7=BD=AE=20(#260)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accessLimiting/operations/Create.tsx | 18 ++- .../polaris/common/components/TagTable.tsx | 4 +- .../fileGroup/detail/file/Page.tsx | 1 + .../file/operation/BetaReleaseConfig.tsx | 104 ++++++++++++------ .../file/operation/BetaReleaseConfigDuck.ts | 15 ++- .../fileGroup/detail/version/Page.tsx | 21 +++- .../fileGroup/detail/version/getColumns.tsx | 7 ++ .../polaris/configuration/fileGroup/types.ts | 16 ++- .../service/detail/interface/getColumns.tsx | 5 + .../polaris/service/operation/CreateDuck.ts | 3 + 10 files changed, 149 insertions(+), 45 deletions(-) diff --git a/web/src/polaris/administration/accessLimiting/operations/Create.tsx b/web/src/polaris/administration/accessLimiting/operations/Create.tsx index 55a8c483..57caed2e 100644 --- a/web/src/polaris/administration/accessLimiting/operations/Create.tsx +++ b/web/src/polaris/administration/accessLimiting/operations/Create.tsx @@ -618,7 +618,23 @@ export default purify(function LimitRuleCreatePage(props: DuckCmpProps - + { + const timeWindow = amountsField.getValue().map((item, index) => { + let seconds = 1 + if (item.validDurationUnit === LimitAmountsValidationUnit.m) { + seconds = 60 + } + if (item.validDurationUnit === LimitAmountsValidationUnit.h) { + seconds = 3600 + } + return (item.validDurationNum * seconds) / item.maxAmount + }).sort((a, b) => { + return a - b + }).pop() + if (timeWindow < max_queue_delay_Field.getValue()) { + max_queue_delay_Field.setError("排队时长非法, 必须大于等于最小请求间隔窗口(窗口时长/请求数阈值)") + } + }} /> )} diff --git a/web/src/polaris/common/components/TagTable.tsx b/web/src/polaris/common/components/TagTable.tsx index 50cf1aeb..ae828a88 100644 --- a/web/src/polaris/common/components/TagTable.tsx +++ b/web/src/polaris/common/components/TagTable.tsx @@ -17,7 +17,7 @@ export function TagTable(props: ITagTableProps) { { key: 'tagName', header: '标签名', - width: '150px', + width: '250px', render: item => { const { key } = item.getFields(['key']) const validate = key.getTouched() && key.getError() @@ -58,7 +58,7 @@ export function TagTable(props: ITagTableProps) { { key: 'close', header: '删除', - width: '80px', + width: '50px', render: (item, rowKey, recordIndex) => { const index = Number(recordIndex) // const length = [...props.tags.asArray()].length diff --git a/web/src/polaris/configuration/fileGroup/detail/file/Page.tsx b/web/src/polaris/configuration/fileGroup/detail/file/Page.tsx index 71224aba..8aad9513 100644 --- a/web/src/polaris/configuration/fileGroup/detail/file/Page.tsx +++ b/web/src/polaris/configuration/fileGroup/detail/file/Page.tsx @@ -457,6 +457,7 @@ function getFileNameContext(fileName, status, file) {
{splitArray[splitArray.length - 1]} {FileStatus.Edited === status && 待发布} + {FileStatus.Betaing === status && 灰度发布中} {file.isEncrypt && 已加密}
) diff --git a/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfig.tsx b/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfig.tsx index 5a386fa6..bbef7fca 100644 --- a/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfig.tsx +++ b/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfig.tsx @@ -4,7 +4,7 @@ import Duck from './BetaReleaseConfigDuck' import FileDiff from '../FileDiff' import Dialog from '@src/polaris/common/duckComponents/Dialog' import FormField from '@src/polaris/common/duckComponents/form/Field' -import { Form, FormItem, FormControl, FormText, Button, Stepper, Select, Table, Text } from 'tea-component' +import { Icon, Form, FormItem, FormControl, FormText, Button, Stepper, Select, Table, Text } from 'tea-component' import Input from '@src/polaris/common/duckComponents/form/Input' import { scrollable, autotip } from 'tea-component/lib/table/addons' import { @@ -12,6 +12,8 @@ import { ClientLabelType, ClientLabelMatchTypeOptions, ClientLabelMatchType, + ClientLabelTextMap, + ClientLabelMatchMap, } from '../../../types' import TagSelectOrInput, { checkNeedTagInput } from '@src/polaris/common/components/TagSelectOrInput' @@ -24,7 +26,7 @@ const addTag = field => { field.setValue([...(field.getValue() || []), { key: '', value: '' }]) } -export default purify(function(props: DuckCmpProps) { +export default purify(function (props: DuckCmpProps) { const { duck, store, dispatch } = props const { ducks, selector } = duck const formApi = ducks.form.getAPI(store, dispatch) @@ -54,27 +56,40 @@ export default purify(function(props: DuckCmpProps) { message={'标签键的长度不能超过128字符,标签值的长度不能超过4096个字符'} > + + + + } records={[...clientLabels.asArray()]} columns={[ { - key: 'key', - header: '标签键', + key: 'type', + header: '类型', width: 150, render: field => { - const key = field.getField('key') + const key_type = field.getField('key_type') return ( key.setValue(value)}> + ) + }, + }, + { + key: 'value_type', header: '匹配方式', - width: 120, + width: 80, render: field => { - const { value } = field.getFields(['value']) + const { type } = field.getFields(['type']) + const { value_type } = field.getFields(['value_type']) return (
@@ -211,3 +235,11 @@ export default purify(function(props: DuckCmpProps) { ) }) + +const getEmptyLabel = () => ({ + type: "TEXT", + key_type: ClientLabelType.CUSTOM, + key: '', + value: '', + value_type: ClientLabelMatchType.EXACT, +}) diff --git a/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfigDuck.ts b/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfigDuck.ts index cfa0d7b2..6ea09c81 100644 --- a/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfigDuck.ts +++ b/web/src/polaris/configuration/fileGroup/detail/file/operation/BetaReleaseConfigDuck.ts @@ -3,7 +3,7 @@ import FormDuck from '@src/polaris/common/ducks/Form' import Base from '@src/polaris/common/ducks/DialogPure' import Create from './BetaReleaseConfig' import { showDialog } from '@src/polaris/common//helpers/showDialog' -import { ClientLabel, ConfigFileRelease } from '../../../types' +import { ClientLabel, ClientLabelView, ConfigFileRelease } from '../../../types' import { releaseConfigFile } from '../../../model' interface Data { @@ -56,7 +56,7 @@ export interface Fvalues { namespace: string group: string name: string - clientLabels?: ClientLabel[] + clientLabels?: ClientLabelView[] } export class BetaCreateFormDuck extends FormDuck { @@ -79,7 +79,16 @@ export class BetaCreateFormDuck extends FormDuck { fileName: name, name: releaseVersion, releaseDescription: comment, - betaLabels: clientLabels, + betaLabels: clientLabels.map(l => { + return { + key: l.key, + value: { + value: l.value, + type: l.type, + value_type: l.value_type + }, + } + }), releaseType: 'gray', }) return result diff --git a/web/src/polaris/configuration/fileGroup/detail/version/Page.tsx b/web/src/polaris/configuration/fileGroup/detail/version/Page.tsx index 2474f00a..f5f228c4 100644 --- a/web/src/polaris/configuration/fileGroup/detail/version/Page.tsx +++ b/web/src/polaris/configuration/fileGroup/detail/version/Page.tsx @@ -25,6 +25,7 @@ import GridPagePagination from '@src/polaris/common/duckComponents/GridPagePagin import insertCSS from '@src/polaris/common/helpers/insertCSS' import { scrollable } from 'tea-component/lib/table/addons' import MonacoEditor from '@src/polaris/common/components/MocacoEditor' +import { ClientLabel, ClientLabelTextMap, ClientLabelType, ClientLabelMatchMap } from '../../types' insertCSS( 'service', @@ -163,8 +164,8 @@ export default function ServicePage(props: DuckCmpProps) { content={ currentSelected.tags.length > 3 ? currentSelected.tags?.map(item => ( - {`${item.key}:${item.value}`} - )) + {`${item.key}:${item.value}`} + )) : null } > @@ -181,6 +182,15 @@ export default function ServicePage(props: DuckCmpProps) { )} + { + (currentSelected.releaseType === 'gray' ? <> +
+ + {formatBetaLabels(currentSelected.betaLabels)} + +
+ : <>) + }
) { ) } + +function formatBetaLabels(labels: ClientLabel[]) { + return labels.map(item => { + return `${item.key} ${ClientLabelMatchMap[item.value.type]} ${item.value.value}` + }).join(';') +} + diff --git a/web/src/polaris/configuration/fileGroup/detail/version/getColumns.tsx b/web/src/polaris/configuration/fileGroup/detail/version/getColumns.tsx index 32c7e2b2..02cf0052 100644 --- a/web/src/polaris/configuration/fileGroup/detail/version/getColumns.tsx +++ b/web/src/polaris/configuration/fileGroup/detail/version/getColumns.tsx @@ -32,6 +32,13 @@ export default ({ ) : ( <> )} + {(!x.active && x.releaseType === 'gray') ? ( + + {'灰度版本'} + + ) : ( + <> + )} ), }, diff --git a/web/src/polaris/configuration/fileGroup/types.ts b/web/src/polaris/configuration/fileGroup/types.ts index 92822a2d..a0a31fde 100644 --- a/web/src/polaris/configuration/fileGroup/types.ts +++ b/web/src/polaris/configuration/fileGroup/types.ts @@ -54,6 +54,7 @@ export interface ConfigFileRelease { active: string releaseType?: string format: string + betaLabels: ClientLabel[] } export interface ConfigFileReleaseHistory { id: string @@ -90,11 +91,20 @@ export interface ClientLabel { } } +export interface ClientLabelView { + key_type: string + key: string + type: string + value: string + value_type: string +} + // 匹配规则类型 export enum ClientLabelType { CLIENT_ID = 'CLIENT_ID', // CLIENT_LANGUAGE = 'CLIENT_LANGUAGE', CLIENT_IP = 'CLIENT_IP', + CUSTOM = 'CUSTOM', } export const ClientLabelTypeOptions = [ @@ -110,6 +120,10 @@ export const ClientLabelTypeOptions = [ // value: ClientLabelType.CLIENT_LANGUAGE, // text: '请求头(HEADER)', // }, + { + value: ClientLabelType.CUSTOM, + text: '自定义', + }, ] export const ClientLabelTextMap = ClientLabelTypeOptions.reduce((map, curr) => { map[curr.value] = curr.text @@ -146,7 +160,7 @@ export const ClientLabelMatchTypeOptions = [ text: '不包含', }, ] -export const RouteLabelTextMap = ClientLabelMatchTypeOptions.reduce((map, curr) => { +export const ClientLabelMatchMap = ClientLabelMatchTypeOptions.reduce((map, curr) => { map[curr.value] = curr.text return map }, {}) diff --git a/web/src/polaris/service/detail/interface/getColumns.tsx b/web/src/polaris/service/detail/interface/getColumns.tsx index b5eedf24..f400b99e 100644 --- a/web/src/polaris/service/detail/interface/getColumns.tsx +++ b/web/src/polaris/service/detail/interface/getColumns.tsx @@ -32,6 +32,11 @@ export default ({ header: '协议', render: x => {x.protocol}, }, + { + key: 'source', + header: '来源', + render: x => {x.source}, + }, { key: 'action', header: '操作', diff --git a/web/src/polaris/service/operation/CreateDuck.ts b/web/src/polaris/service/operation/CreateDuck.ts index 40c883d1..8171cacb 100644 --- a/web/src/polaris/service/operation/CreateDuck.ts +++ b/web/src/polaris/service/operation/CreateDuck.ts @@ -22,6 +22,9 @@ export const VisibilityModeMap = { [VisibilityMode.All]: '全部命名空间可见(包括新增)', } export const CheckVisibilityMode = (exportTo = [], namespace) => { + if (exportTo === null) { + return VisibilityMode.Single + } return exportTo?.includes('*') ? VisibilityMode.All : (exportTo.length === 1 && exportTo?.[0] === namespace) || exportTo.length === 0