Skip to content

Commit

Permalink
feat: 大盘变量将options存入,all 需要拼接替换;
Browse files Browse the repository at this point in the history
如果multi没选则隐藏allOption
  • Loading branch information
guguji5 committed Dec 13, 2021
1 parent 4033010 commit 2e1e35a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/pages/dashboard/VariableConfig/DisplayItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Props {
cluster: string;
index: number;
data: Variable[];
onChange: (index: number, value: string | string[]) => void;
onChange: (index: number, value: string | string[], options?) => void;
}

const stringToRegex = (str) => {
Expand Down Expand Up @@ -40,10 +40,10 @@ const DisplayItem: React.FC<Props> = ({ expression, index, data, onChange, clust
setOptions(res);
// 逻辑上只有导入大盘后初始化那一次 selected会为空
if (res.length > 0 && !selected) {
onChange(index, multi ? [res[0]] : res[0]);
onChange(index, multi ? [res[0]] : res[0], res);
}
if (exp && newExpression && exp !== newExpression) {
onChange(index, multi ? [] : '');
onChange(index, multi ? [] : '', res);
}
});
}
Expand All @@ -52,15 +52,15 @@ const DisplayItem: React.FC<Props> = ({ expression, index, data, onChange, clust

const handleChange = (v) => {
if (multi && allOption && v.includes('all')) {
onChange(index, ['all']);
onChange(index, ['all'], options);
} else if (multi && !allOption) {
let allIndex = v.indexOf('all');
if (allIndex !== -1) {
v.splice(allIndex, 1);
}
onChange(index, v);
onChange(index, v, options);
} else {
onChange(index, v);
onChange(index, v, options);
}
};

Expand Down
12 changes: 10 additions & 2 deletions src/pages/dashboard/VariableConfig/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ export default function EditItem(props: Props) {
</Form.Item>
</Col>
<Col span={2}>
<Form.Item {...restField} name={[name, 'allOption']} fieldKey={[fieldKey, 'allOption']} valuePropName='checked'>
<Switch />
<Form.Item shouldUpdate style={{ margin: 0 }}>
{() => {
return (
form.getFieldValue(['var', name, 'multi']) && (
<Form.Item {...restField} name={[name, 'allOption']} fieldKey={[fieldKey, 'allOption']} valuePropName='checked'>
<Switch />
</Form.Item>
)
);
}}
</Form.Item>
</Col>
<Form.Item {...restField} name={[name, 'selected']} fieldKey={[fieldKey, 'selected']} hidden>
Expand Down
9 changes: 6 additions & 3 deletions src/pages/dashboard/VariableConfig/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ export const convertExpressionToQuery = (expression: string) => {

export const replaceExpressionVars = (expression: string, formData: FormType, limit: number) => {
var newExpression = expression;

const vars = newExpression.match(/\$[0-9a-zA-Z]+/g);
if (vars && vars.length > 0) {
for (let i = 0; i < limit; i++) {
const { selected, name } = formData.var[i];
const { selected, name, options } = formData.var[i];
if (vars.includes('$' + name) && selected) {
if (Array.isArray(selected)) {
newExpression = newExpression.replaceAll('$' + name, `(${(selected as string[]).join('|')})`);
if (selected.includes('all') && options) {
newExpression = newExpression.replaceAll('$' + name, `(${(options as string[]).join('|')})`);
} else {
newExpression = newExpression.replaceAll('$' + name, `(${(selected as string[]).join('|')})`);
}
} else if (typeof selected === 'string') {
newExpression = newExpression.replaceAll('$' + name, selected as string);
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/VariableConfig/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface Variable {
selected?: string | string[];
multi: boolean;
allOption: boolean;
options?: string[]
}
3 changes: 2 additions & 1 deletion src/pages/dashboard/VariableConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const TagFilter: React.ForwardRefRenderFunction<any, ITagFilterProps> = ({ isOpe
value && setData(value);
}, [value]);

const handleVariableChange = (index: number, v: string) => {
const handleVariableChange = (index: number, v: string | string[], options) => {
const newData = data ? { var: [...data.var] } : { var: [] };
newData.var[index].selected = v;
options && (newData.var[index].options = options);
setData(newData);
onChange(newData);
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/historyEvents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ const Event: React.FC = () => {
},
},
{
title: t('触发时间'),
dataIndex: 'trigger_time',
title: t('计算时间'),
dataIndex: 'last_eval_time',
width: 140,
render(value) {
return moment(value * 1000).format('YYYY-MM-DD HH:mm:ss');
return moment((value ? value : 0) * 1000).format('YYYY-MM-DD HH:mm:ss');
},
},
];
Expand Down
1 change: 1 addition & 0 deletions src/pages/metric/explorer/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
}
.right {
padding-right: 4%;
white-space: nowrap;
}
.bold-text {
color: #000;
Expand Down

0 comments on commit 2e1e35a

Please sign in to comment.