Unverified Commit 5d87ce9c authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Fix] Fix compatibility issues with MySQL stored procedures (#3594)

parent d33d97f6
...@@ -15,7 +15,7 @@ SET FOREIGN_KEY_CHECKS = 0; ...@@ -15,7 +15,7 @@ SET FOREIGN_KEY_CHECKS = 0;
DELIMITER $$ DELIMITER $$
DROP PROCEDURE IF EXISTS add_column_if_not_exists$$ DROP PROCEDURE IF EXISTS add_column_if_not_exists$$
CREATE PROCEDURE if not exists add_column_if_not_exists(IN tableName VARCHAR(64), IN columnName VARCHAR(64), IN columnDefinitionType VARCHAR(64), IN columnDefinitionDefaultValue VARCHAR(128), IN columnDefinitionComment VARCHAR(255), in afterColumnName VARCHAR(64)) CREATE PROCEDURE add_column_if_not_exists(IN tableName VARCHAR(64), IN columnName VARCHAR(64), IN columnDefinitionType VARCHAR(64), IN columnDefinitionDefaultValue VARCHAR(128), IN columnDefinitionComment VARCHAR(255), in afterColumnName VARCHAR(64))
BEGIN BEGIN
IF NOT EXISTS ( IF NOT EXISTS (
SELECT * SELECT *
......
...@@ -22,7 +22,7 @@ import { ClusterType } from '@/pages/RegCenter/Cluster/constants'; ...@@ -22,7 +22,7 @@ import { ClusterType } from '@/pages/RegCenter/Cluster/constants';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { CheckboxOptionType } from 'antd/es/checkbox/Group'; import { CheckboxOptionType } from 'antd/es/checkbox/Group';
import { DefaultOptionType } from 'antd/es/select'; import { DefaultOptionType } from 'antd/es/select';
import {RUN_MODE} from "@/services/constants"; import { RUN_MODE } from '@/services/constants';
export enum RuleType { export enum RuleType {
SYSTEM = 'SYSTEM', SYSTEM = 'SYSTEM',
...@@ -41,19 +41,19 @@ export const TriggerType: CheckboxOptionType[] = [ ...@@ -41,19 +41,19 @@ export const TriggerType: CheckboxOptionType[] = [
]; ];
export const AllRuleOperator: DefaultOptionType[] = [ export const AllRuleOperator: DefaultOptionType[] = [
{ label: '>', value: 'GT' , key: 'GT'}, { label: '>', value: 'GT', key: 'GT' },
{ label: '<', value: 'LT' , key: 'LT' }, { label: '<', value: 'LT', key: 'LT' },
{ label: '=', value: 'EQ' , key: 'EQ' }, { label: '=', value: 'EQ', key: 'EQ' },
{ label: '!=', value: 'NE' , key: 'NE' }, { label: '!=', value: 'NE', key: 'NE' },
{ label: '>=', value: 'GE' , key: 'GE' }, { label: '>=', value: 'GE', key: 'GE' },
{ label: '<=', value: 'LE' , key: 'LE'} { label: '<=', value: 'LE', key: 'LE' }
]; ];
export const EqRuleOperator: DefaultOptionType[] = [{ label: '=', value: 'EQ' , key: 'EQ' }]; export const EqRuleOperator: DefaultOptionType[] = [{ label: '=', value: 'EQ', key: 'EQ' }];
export const BOOLEAN_VALUE_ENUM: DefaultOptionType[] = [ export const BOOLEAN_VALUE_ENUM: DefaultOptionType[] = [
{ label: 'True', value: 'true' , key: 'true' }, { label: 'True', value: 'true', key: 'true' },
{ label: 'False', value: 'false' , key: 'false' } { label: 'False', value: 'false', key: 'false' }
]; ];
export const AlertRules: any = { export const AlertRules: any = {
......
...@@ -34,7 +34,7 @@ export const AlertRulesOption = () => { ...@@ -34,7 +34,7 @@ export const AlertRulesOption = () => {
// @ts-ignore // @ts-ignore
label: v.label, label: v.label,
value: k, value: k,
key: k, key: k
}); });
} }
return res; return res;
...@@ -77,7 +77,7 @@ export const buildValueItem = (key: string, isSystem: boolean) => { ...@@ -77,7 +77,7 @@ export const buildValueItem = (key: string, isSystem: boolean) => {
disabled={isSystem} disabled={isSystem}
fieldProps={{ fieldProps={{
defaultActiveFirstOption: true, defaultActiveFirstOption: true,
showSearch: true, showSearch: true
}} }}
name='ruleValue' name='ruleValue'
mode={'single'} mode={'single'}
......
...@@ -17,20 +17,23 @@ ...@@ -17,20 +17,23 @@
* *
*/ */
import {Authorized} from '@/hooks/useAccess'; import { Authorized } from '@/hooks/useAccess';
import {RuleType, TriggerType} from '@/pages/RegCenter/Alert/AlertRule/AlertRuleList/RuleEditForm/constants'; import {
RuleType,
TriggerType
} from '@/pages/RegCenter/Alert/AlertRule/AlertRuleList/RuleEditForm/constants';
import { import {
AlertRulesOption, AlertRulesOption,
buildValueItem, buildValueItem,
getOperatorOptions getOperatorOptions
} from '@/pages/RegCenter/Alert/AlertRule/AlertRuleList/RuleEditForm/function'; } from '@/pages/RegCenter/Alert/AlertRule/AlertRuleList/RuleEditForm/function';
import {getData} from '@/services/api'; import { getData } from '@/services/api';
import {SWITCH_OPTIONS} from '@/services/constants'; import { SWITCH_OPTIONS } from '@/services/constants';
import {API_CONSTANTS} from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
import {Alert} from '@/types/RegCenter/data'; import { Alert } from '@/types/RegCenter/data';
import {AlertRule, AlertRuleCondition} from '@/types/SettingCenter/data'; import { AlertRule, AlertRuleCondition } from '@/types/SettingCenter/data';
import {l} from '@/utils/intl'; import { l } from '@/utils/intl';
import { import {
DrawerForm, DrawerForm,
ProCard, ProCard,
...@@ -43,10 +46,10 @@ import { ...@@ -43,10 +46,10 @@ import {
ProFormText, ProFormText,
ProFormTextArea ProFormTextArea
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import {ProFormDependency} from '@ant-design/pro-form'; import { ProFormDependency } from '@ant-design/pro-form';
import {Button, Divider, Form, Space, Typography} from 'antd'; import { Button, Divider, Form, Space, Typography } from 'antd';
const {Link} = Typography; const { Link } = Typography;
type AlertRuleFormProps = { type AlertRuleFormProps = {
onCancel: (flag?: boolean) => void; onCancel: (flag?: boolean) => void;
...@@ -56,112 +59,112 @@ type AlertRuleFormProps = { ...@@ -56,112 +59,112 @@ type AlertRuleFormProps = {
}; };
const RuleEditForm = (props: AlertRuleFormProps) => { const RuleEditForm = (props: AlertRuleFormProps) => {
const {onSubmit: handleSubmit, onCancel: handleModalVisible, modalVisible, values} = props; const { onSubmit: handleSubmit, onCancel: handleModalVisible, modalVisible, values } = props;
// if is system rule disable edit
const isSystem = values.ruleType == RuleType.SYSTEM;
const [form] = Form.useForm<AlertRule>();
const getAlertTemplate = async () => {
const template: Alert.AlertTemplate[] = (await getData(API_CONSTANTS.ALERT_TEMPLATE)).data;
return template.map((t) => ({label: t.name, value: t.id}));
};
const submit = async () => {
const fieldsValue = await form.validateFields();
return handleSubmit({...values,...fieldsValue});
};
const renderTemplateDropDown = (item: any) => {
return (
<>
{item}
<Authorized key='create' path='/registration/alert/template/add'>
<>
<Divider style={{margin: '8px 0'}}/>
<Link href={'#/registration/alert/template'}>+ {l('rc.alert.template.new')}</Link>
</>
</Authorized>
</>
);
};
const renderFooter = () => {
return [
<Button key={'RuleCancel'} onClick={() => handleModalVisible(false)}>
{l('button.cancel')}
</Button>,
<Button
key={'RuleFinish'}
type='primary'
htmlType={'submit'}
autoFocus
onClick={() => submit()}
>
{l('button.finish')}
</Button>
];
};
return ( // if is system rule disable edit
<DrawerForm const isSystem = values.ruleType == RuleType.SYSTEM;
layout={'vertical'}
form={form}
width={'40%'}
open={modalVisible}
submitter={{render: () => [...renderFooter()]}}
drawerProps={{
onClose: () => handleModalVisible(false),
destroyOnClose: true
}}
initialValues={values}
>
<ProFormGroup>
<ProFormText name='id' hidden={true}/>
<ProFormText name='ruleType' hidden={true}/>
<ProFormText
disabled={isSystem}
rules={[{required: true}]}
name='name'
width='md'
label={l('sys.alert.rule.name')}
placeholder={l('sys.alert.rule.name')}
/>
<ProFormSelect
label={l('sys.alert.rule.template')}
width='md'
name='templateId'
request={async () => getAlertTemplate()}
placeholder={l('sys.alert.rule.template')}
rules={[{required: true, message: l('sys.alert.rule.template')}]}
fieldProps={{dropdownRender: (item) => renderTemplateDropDown(item)}}
/>
</ProFormGroup>
<ProFormGroup> const [form] = Form.useForm<AlertRule>();
<ProFormTextArea width='md' name='description' label={l('global.table.note')}/>
<ProFormSwitch name='enabled' {...SWITCH_OPTIONS()} label={l('global.table.isEnable')}/> const getAlertTemplate = async () => {
</ProFormGroup> const template: Alert.AlertTemplate[] = (await getData(API_CONSTANTS.ALERT_TEMPLATE)).data;
return template.map((t) => ({ label: t.name, value: t.id }));
};
<Divider orientation={'left'}>{l('sys.alert.rule.trigger')}</Divider> const submit = async () => {
const fieldsValue = await form.validateFields();
return handleSubmit({ ...values, ...fieldsValue });
};
<ProFormRadio.Group const renderTemplateDropDown = (item: any) => {
return (
<>
{item}
<Authorized key='create' path='/registration/alert/template/add'>
<>
<Divider style={{ margin: '8px 0' }} />
<Link href={'#/registration/alert/template'}>+ {l('rc.alert.template.new')}</Link>
</>
</Authorized>
</>
);
};
const renderFooter = () => {
return [
<Button key={'RuleCancel'} onClick={() => handleModalVisible(false)}>
{l('button.cancel')}
</Button>,
<Button
key={'RuleFinish'}
type='primary'
htmlType={'submit'}
autoFocus
onClick={() => submit()}
>
{l('button.finish')}
</Button>
];
};
return (
<DrawerForm
layout={'vertical'}
form={form}
width={'40%'}
open={modalVisible}
submitter={{ render: () => [...renderFooter()] }}
drawerProps={{
onClose: () => handleModalVisible(false),
destroyOnClose: true
}}
initialValues={values}
>
<ProFormGroup>
<ProFormText name='id' hidden={true} />
<ProFormText name='ruleType' hidden={true} />
<ProFormText
disabled={isSystem} disabled={isSystem}
name='triggerConditions' rules={[{ required: true }]}
label={l('sys.alert.rule.triggerConditions')} name='name'
rules={[{required: true}]} width='md'
options={TriggerType} label={l('sys.alert.rule.name')}
placeholder={l('sys.alert.rule.name')}
/> />
<ProFormList<AlertRuleCondition> <ProFormSelect
name='rule' label={l('sys.alert.rule.template')}
label={l('sys.alert.rule.triggerRule')} width='md'
creatorButtonProps={ name='templateId'
isSystem request={async () => getAlertTemplate()}
? false placeholder={l('sys.alert.rule.template')}
: { rules={[{ required: true, message: l('sys.alert.rule.template') }]}
fieldProps={{ dropdownRender: (item) => renderTemplateDropDown(item) }}
/>
</ProFormGroup>
<ProFormGroup>
<ProFormTextArea width='md' name='description' label={l('global.table.note')} />
<ProFormSwitch name='enabled' {...SWITCH_OPTIONS()} label={l('global.table.isEnable')} />
</ProFormGroup>
<Divider orientation={'left'}>{l('sys.alert.rule.trigger')}</Divider>
<ProFormRadio.Group
disabled={isSystem}
name='triggerConditions'
label={l('sys.alert.rule.triggerConditions')}
rules={[{ required: true }]}
options={TriggerType}
/>
<ProFormList<AlertRuleCondition>
name='rule'
label={l('sys.alert.rule.triggerRule')}
creatorButtonProps={
isSystem
? false
: {
creatorButtonText: l('sys.alert.rule.addRule') creatorButtonText: l('sys.alert.rule.addRule')
} }
} }
......
...@@ -65,7 +65,7 @@ export type AlertRuleCondition = { ...@@ -65,7 +65,7 @@ export type AlertRuleCondition = {
ruleOperator: string; ruleOperator: string;
ruleValue: string; ruleValue: string;
rulePriority?: number; rulePriority?: number;
} };
// ============================ System Settings ============================ // ============================ System Settings ============================
export type Settings = { export type Settings = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment