Skip to content

Commit

Permalink
fix(console): create strategy endless loop (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-hnny authored Dec 20, 2021
1 parent 565a73a commit 1fb2e73
Showing 1 changed file with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ const columns = [
{
key: 'name',
header: t('Action名称'),
render: (cvm) => <p>{cvm.name}</p>,
render: cvm => <p>{cvm.name}</p>
},
{
key: 'description',
header: t('描述'),
width: 100,
render: (cvm) => {
render: cvm => {
return (
<Bubble content={cvm.description}>
<Text parent="div" overflow>{cvm.description}</Text>
<Text parent="div" overflow>
{cvm.description}
</Text>
</Bubble>
);
},
},
}
}
];

function SourceTable({ dataSource, action, onChange }) {
Expand All @@ -87,8 +89,8 @@ function SourceTable({ dataSource, action, onChange }) {
selectable({
value: action,
onChange,
rowSelect: true,
}),
rowSelect: true
})
]}
/>
);
Expand All @@ -98,8 +100,8 @@ function TargetTable({ dataSource, onRemove }) {
return <Table records={dataSource} recordKey="name" columns={columns} addons={[removeable({ onRemove })]} />;
}

export const StrategyActionPanel = (props) => {
const state = useSelector((state) => state);
export const StrategyActionPanel = props => {
const state = useSelector(state => state);
const dispatch = useDispatch();
const { actions } = bindActionCreators({ actions: allActions }, dispatch);

Expand All @@ -114,26 +116,26 @@ export const StrategyActionPanel = (props) => {
effect: '',
resource: [],
selectService: '',
description: '',
description: ''
});
const [actionParamsValue, setActionParamsValue] = useState({
filterKeyword: '',
action: [],
action: []
});
const [messages, setMessages] = useState({
name: '',
effect: '',
action: '',
resource: [],
description: '',
description: ''
});

// 初始化创建弹窗中的服务选项
useEffect(() => {
if (!formParamsValue.selectService && categoryListRecords) {
if (formParamsValue.selectService === '' && categoryListRecords) {
setFormParamsValue({
...formParamsValue,
selectService: categoryListRecords[0].name,
selectService: categoryListRecords?.[0]?.metadata?.name
});
}
}, [formParamsValue, categoryListRecords]);
Expand All @@ -146,9 +148,9 @@ export const StrategyActionPanel = (props) => {
if (!name || !effect || !action.length || resource.length === 0) {
disabled = true;
}
Object.keys(messages).forEach((item) => {
Object.keys(messages).forEach(item => {
if (Array.isArray(messages[item])) {
messages[item].forEach((m) => {
messages[item].forEach(m => {
if (m) {
disabled = true;
}
Expand All @@ -167,10 +169,10 @@ export const StrategyActionPanel = (props) => {
categoryActions = {};

categoryListRecords &&
categoryListRecords.forEach((item) => {
categoryListRecords.forEach(item => {
options.push({
value: item.metadata.name,
text: item.Spec.displayName,
text: item.Spec.displayName
});
categoryActions[item.metadata.name] = Object.values(item.Spec.actions);
});
Expand Down Expand Up @@ -213,7 +215,7 @@ export const StrategyActionPanel = (props) => {
placeholder={t('请输入策略名称')}
style={{ width: '350px' }}
defaultValue={formParamsValue.name}
onChange={(value) => {
onChange={value => {
let msg = '';
if (!value) {
msg = '请输入策略名称';
Expand All @@ -233,7 +235,7 @@ export const StrategyActionPanel = (props) => {
>
<RadioGroup
value={formParamsValue.effect}
onChange={(value) => {
onChange={value => {
setFormParamsValue({ ...formParamsValue, effect: value });
setMessages({ ...messages, effect: value ? '' : '请选择效果' });
}}
Expand All @@ -252,7 +254,7 @@ export const StrategyActionPanel = (props) => {
size="m"
options={options}
value={formParamsValue.selectService}
onChange={(value) => {
onChange={value => {
// 调用action获取接口
setFormParamsValue({ ...formParamsValue, selectService: value });
}}
Expand All @@ -268,14 +270,14 @@ export const StrategyActionPanel = (props) => {
header={
<SearchBox
value={actionParamsValue.filterKeyword}
onChange={(value) => setActionParamsValue({ ...actionParamsValue, filterKeyword: value })}
onChange={value => setActionParamsValue({ ...actionParamsValue, filterKeyword: value })}
/>
}
>
<SourceTable
dataSource={actionList.filter((i) => i.name.includes(actionParamsValue.filterKeyword))}
dataSource={actionList.filter(i => i.name.includes(actionParamsValue.filterKeyword))}
action={actionParamsValue.action}
onChange={(keys) => {
onChange={keys => {
setActionParamsValue({ ...actionParamsValue, action: keys });
setMessages({ ...messages, action: keys.length ? '' : '请选择Action' });
}}
Expand All @@ -285,9 +287,9 @@ export const StrategyActionPanel = (props) => {
rightCell={
<Transfer.Cell title={t(`已选择 (${actionParamsValue.action.length})个`)}>
<TargetTable
dataSource={actionList.filter((i) => actionParamsValue.action.includes(i.name))}
onRemove={(key) => {
const keys = actionParamsValue.action.filter((i) => i !== key);
dataSource={actionList.filter(i => actionParamsValue.action.includes(i.name))}
onRemove={key => {
const keys = actionParamsValue.action.filter(i => i !== key);
setActionParamsValue({ ...actionParamsValue, action: keys });
setMessages({ ...messages, action: keys.length ? '' : '请选择Action' });
}}
Expand All @@ -310,7 +312,7 @@ export const StrategyActionPanel = (props) => {
placeholder={t('eg. cluster:cls-123/deployment:deploy-123/*')}
style={{ width: '350px' }}
defaultValue={resource}
onChange={(value) => {
onChange={value => {
let msg = '';
if (!value) {
msg = '请输入资源名称';
Expand Down Expand Up @@ -349,7 +351,7 @@ export const StrategyActionPanel = (props) => {
multiline
placeholder={t('介绍一下这个策略')}
style={{ width: '350px' }}
onChange={(value) => {
onChange={value => {
let msg = '';
if (value && value.length > 255) {
msg = '描述不能超过255个字符';
Expand Down Expand Up @@ -395,9 +397,9 @@ export const StrategyActionPanel = (props) => {
statement: {
resources: resource,
effect,
actions: action,
},
},
actions: action
}
}
};

actions.strategy.addStrategy.start([strategyInfo]);
Expand Down

0 comments on commit 1fb2e73

Please sign in to comment.