Skip to content

Commit

Permalink
refactor(alert-subscribes): update busi_groups selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jsers committed Aug 11, 2023
1 parent 30fb02a commit f9b0bcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/pages/warning/subscribe/components/operateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,22 @@ const OperateForm: React.FC<Props> = ({ detail = {} as subscribeItem, type }) =>
{!!ruleCur?.id && <DeleteOutlined style={{ cursor: 'pointer', fontSize: '18px', marginLeft: 5 }} onClick={() => subscribeRule({})} />}
</Form.Item>

<Form.List name='busi_groups' initialValue={[]}>
{(fields, { add, remove }) => (
<Form.List
name='busi_groups'
initialValue={[]}
rules={[
{
validator: (rule, value, callback) => {
const tags = form.getFieldValue('tags');
if (_.isEmpty(value) && _.isEmpty(tags)) {
return Promise.reject(new Error(t('tags_groups_require')));
}
return Promise.resolve();
},
},
]}
>
{(fields, { add, remove }, { errors }) => (
<>
<Row gutter={[10, 10]} style={{ marginBottom: '8px' }}>
<Col span={5}>
Expand All @@ -265,12 +279,27 @@ const OperateForm: React.FC<Props> = ({ detail = {} as subscribeItem, type }) =>
{fields.map((field, index) => (
<BusiGroupsTagItem field={field} fields={fields} key={index} remove={remove} add={add} form={form} />
))}
<Form.ErrorList errors={errors} />
</>
)}
</Form.List>

<Form.List name='tags' initialValue={[{}]}>
{(fields, { add, remove }) => (
<Form.List
name='tags'
initialValue={[]}
rules={[
{
validator: (rule, value, callback) => {
const busiGroups = form.getFieldValue('busi_groups');
if (_.isEmpty(value) && _.isEmpty(busiGroups)) {
return Promise.reject(new Error(t('tags_groups_require')));
}
return Promise.resolve();
},
},
]}
>
{(fields, { add, remove }, { errors }) => (
<>
<Row gutter={[10, 10]} style={{ marginBottom: '8px' }}>
<Col span={5}>
Expand All @@ -288,6 +317,7 @@ const OperateForm: React.FC<Props> = ({ detail = {} as subscribeItem, type }) =>
{fields.map((field, index) => (
<TagItem field={field} fields={fields} key={index} remove={remove} add={add} form={form} />
))}
<Form.ErrorList errors={errors} />
</>
)}
</Form.List>
Expand Down
1 change: 1 addition & 0 deletions src/pages/warning/subscribe/locale/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ const en_US = {
basic_configs: 'Basic',
severities: 'Severity',
severities_msg: 'Severity is required',
tags_groups_require: 'Tags and receiving groups must fill in at least one item',
};
export default en_US;
1 change: 1 addition & 0 deletions src/pages/warning/subscribe/locale/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ const zh_CN = {
basic_configs: '基础配置',
severities: '订阅事件等级',
severities_msg: '订阅事件等级不能为空',
tags_groups_require: '标签和接收组至少填写一项',
};
export default zh_CN;
1 change: 1 addition & 0 deletions src/pages/warning/subscribe/locale/zh_HK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const zh_HK = {
basic_configs: '基礎配置',
severities: '訂閱事件等級',
severities_msg: '訂閱事件等級不能為空',
tags_groups_require: '標籤和接收組至少填寫一項',
};

export default zh_HK;

0 comments on commit f9b0bcf

Please sign in to comment.