Skip to content

Commit

Permalink
feat: 仪表盘的where条件需要同步支持空的特殊值 --bug=115017011
Browse files Browse the repository at this point in the history
  • Loading branch information
liangling0628 committed Dec 9, 2023
1 parent fa81561 commit 26c447d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import CloseCircleOutlined from '@ant-design/icons/CloseCircleOutlined';
import { LanguageContext } from '../utils/context';
import { getEnByName } from '../utils/utils';
import DataSource from '../datasource/datasource';
import { DIM_NULL_ID } from '../typings/datasource';
const { Option } = Select;
export interface IProps {
metric: MetricDetail; // 指标
Expand Down Expand Up @@ -256,6 +257,11 @@ export default class ConditionInput extends React.PureComponent<IProps, IState>
const {
metric: { dimensions, agg_condition },
} = this.props;
const needNUll = (key: string) => {
const item = dimensions?.find(item => item.id === key)
if(!item) return false
return typeof item.type === 'undefined' || item.type === 'string'
}
// eslint-disable-next-line max-len
const getMaxWidth = (list: ICommonItem[]) => Math.max(list?.reduce((max, cur) => Math.max(max, +cur?.name?.length), 1) * 10, 100);
return (
Expand Down Expand Up @@ -349,6 +355,9 @@ export default class ConditionInput extends React.PureComponent<IProps, IState>
dropdownMatchSelectWidth={false}
onChange={v => this.handleValueChange(v, index)}
>
{
needNUll(item.key) && <Option value={DIM_NULL_ID} key={DIM_NULL_ID}>{getEnByName('- 空 -')}</Option>
}
{dimensionValueMap[item.key]?.map?.(dim => (
<Option value={dim.id} key={dim.id}>
{dim.name}
Expand Down
8 changes: 4 additions & 4 deletions bkmonitor-timeseries-datasource/src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
import { getBackendSrv, BackendSrvRequest, getTemplateSrv } from '@grafana/runtime';
import { QueryOption } from '../typings/config';
import { IMetric, ITargetData, EditMode, IntervalType } from '../typings/metric';
import { IQueryConfig, QueryData } from '../typings/datasource';
import { DIM_NULL_ID, IQueryConfig, QueryData } from '../typings/datasource';
import { K8sVariableQueryType, ScenarioType, VariableQuery, VariableQueryType } from '../typings/variable';
import apiCacheInstance from '../utils/api-cache';
import { handleTransformOldQuery, handleTransformOldVariableQuery } from '../utils/common';
Expand Down Expand Up @@ -290,11 +290,9 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
return item;
}),
};
console.info(newList, '++++++__________+++++++');
return newList;
}
}
console.info(list, '++++++__________+++++++');
return list;
}
getValueText(responseLength: number, refId = '') {
Expand Down Expand Up @@ -674,7 +672,9 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
const valList = [];
Array.isArray(values)
&& values.forEach((val) => {
if (String(val).match(/^\$/)) {
if(val === DIM_NULL_ID) {
valList.push('')
} else if (String(val).match(/^\$/)) {
let isArrayVal = false;
const list = [];
getTemplateSrv().replace(val, scopedVars, (v) => {
Expand Down
3 changes: 2 additions & 1 deletion bkmonitor-timeseries-datasource/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
"生成自定义指标": "Generate custom metrics",
"采集来源": "Collect source",
"自动查询": "Auto query",
"指标选择": "Metric selection"
"指标选择": "Metric selection",
"- 空 -": "- empty -"
}
2 changes: 2 additions & 0 deletions bkmonitor-timeseries-datasource/src/typings/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ export interface QueryData extends DataQuery {
expressionList?: IExpresionItem[];
only_promql?: boolean
}

export const DIM_NULL_ID = '';

0 comments on commit 26c447d

Please sign in to comment.