From 326481b4d374916d84bd49b17307482749e6acbf Mon Sep 17 00:00:00 2001 From: Baoyuan Date: Sun, 1 Aug 2021 12:17:15 +0800 Subject: [PATCH 1/7] fix(route): add operators --- .../components/Step1/MatchingRulesView.tsx | 116 +++++++++++------- web/src/pages/Route/locales/en-US.ts | 30 +++-- web/src/pages/Route/locales/zh-CN.ts | 15 ++- web/src/pages/Route/typing.d.ts | 20 +-- 4 files changed, 117 insertions(+), 64 deletions(-) diff --git a/web/src/pages/Route/components/Step1/MatchingRulesView.tsx b/web/src/pages/Route/components/Step1/MatchingRulesView.tsx index 81f4dd2f1b..d09e401867 100644 --- a/web/src/pages/Route/components/Step1/MatchingRulesView.tsx +++ b/web/src/pages/Route/components/Step1/MatchingRulesView.tsx @@ -23,14 +23,14 @@ import PanelSection from '@/components/PanelSection'; const MatchingRulesView: React.FC = ({ advancedMatchingRules, disabled, - onChange = () => { }, + onChange = () => {}, }) => { const [visible, setVisible] = useState(false); const [mode, setMode] = useState('CREATE'); const [namePlaceholder, setNamePlaceholder] = useState(''); const [modalForm] = Form.useForm(); - const [operatorValueSample, setOperatorValueSample] = useState("") + const [operatorValueSample, setOperatorValueSample] = useState(''); const { Option } = Select; @@ -38,15 +38,15 @@ const MatchingRulesView: React.FC = ({ const onOk = () => { modalForm.validateFields().then((value: RouteModule.MatchingRule) => { - if (value.operator === "IN") { + if (value.operator === 'IN') { try { - JSON.parse(value.value as string) + JSON.parse(value.value as string); } catch (error) { notification.warning({ message: formatMessage({ id: 'page.route.fields.vars.invalid' }), - description: formatMessage({ id: 'page.route.fields.vars.in.invalid' }) - }) - return + description: formatMessage({ id: 'page.route.fields.vars.in.invalid' }), + }); + return; } } if (mode === 'EDIT') { @@ -136,9 +136,18 @@ const MatchingRulesView: React.FC = ({ case '~~': renderText = formatMessage({ id: 'page.route.regexMatch' }); break; + case '~*': + renderText = formatMessage({ id: 'page.royte.caseInsensitiveRegexMatch' }); + break; case 'IN': renderText = formatMessage({ id: 'page.route.in' }); break; + case 'HAS': + renderText = formatMessage({ id: 'page.route.has' }); + break; + case '!': + renderText = formatMessage({ id: 'page.route.reverse' }); + break; default: renderText = ''; } @@ -153,27 +162,29 @@ const MatchingRulesView: React.FC = ({ disabled ? {} : { - title: formatMessage({ id: 'component.global.operation' }), - key: 'action', - render: (_: any, record: RouteModule.MatchingRule) => ( - - handleEdit(record)}> - {formatMessage({ id: 'component.global.edit' })} - - handleRemove(record.key)}> - {formatMessage({ id: 'component.global.delete' })} - - - ), - }, + title: formatMessage({ id: 'component.global.operation' }), + key: 'action', + render: (_: any, record: RouteModule.MatchingRule) => ( + + handleEdit(record)}> + {formatMessage({ id: 'component.global.edit' })} + + handleRemove(record.key)}> + {formatMessage({ id: 'component.global.delete' })} + + + ), + }, ].filter((item) => Object.keys(item).length); const renderModal = () => { return ( = ({ message: formatMessage({ id: 'component.global.input.ruleMessage.name' }), }, ]} - tooltip={formatMessage({ id: 'page.route.form.itemRulesRequiredMessage.parameterName' })} + tooltip={formatMessage({ + id: 'page.route.form.itemRulesRequiredMessage.parameterName', + })} extra={namePlaceholder} > @@ -245,30 +258,48 @@ const MatchingRulesView: React.FC = ({ rules={[ { required: true, - message: `${formatMessage({ id: 'component.global.pleaseChoose' })} ${formatMessage({ - id: 'page.route.operationalCharacter', - })}`, + message: `${formatMessage({ id: 'component.global.pleaseChoose' })} ${formatMessage( + { + id: 'page.route.operationalCharacter', + }, + )}`, }, ]} > - { + switch (e) { + case 'IN': + setOperatorValueSample( + formatMessage({ id: 'page.route.advanced-match.operator.sample.IN' }), + ); + break; + case '~~': + setOperatorValueSample( + formatMessage({ id: 'page.route.advanced-match.operator.sample.~~' }), + ); + break; + case '~*': + setOperatorValueSample( + formatMessage({ id: 'page.route.advanced-match.operator.sample.~~' }), + ); + break; + default: + setOperatorValueSample(''); + } + }} + > + + + = ({ - ) + ); }; return ( - + {!disabled && (