Skip to content

Commit

Permalink
feat: 【产品功能】仪表盘支持dimisions_transaltion自动变量配置 --Story=118899761
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 13316
  • Loading branch information
liangling0628 committed Jul 29, 2024
1 parent c370081 commit 5fbab45
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/timeseries/src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
scopedVars: ScopedVars,
metric: IMetric,
aliasData: IAliasData,
dimensions: Record<string, string>,
serie: Record<string, any>,
) {
const regex = /\$([\w]+)|\[\[([\s\S]+?)\]\]/g;
const tagRegx = /(\$(tag_|dim_)\$[\w.]+)/gm;
const tagRegx = /(\$(tag_|dim_)\$[\w._]+)/gm;
let aliasNew = alias;
const { dimensions, dimensions_translation } = serie || { dimensions: {}, dimensions_translation: {} };
aliasNew = alias.replace(tagRegx, (match: any, g1: any, g2: any) => {
const group = g1 || g2;
let tag = group.replace('$tag_', '').replace('$dim_', '');
Expand All @@ -153,6 +154,10 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
const tag = group.replace('tag_', '').replace('dim_', '');
return typeof dimensions[tag] === 'undefined' ? match : dimensions[tag];
}
if (/^(trans_)/im.test(group)) {
const tag = group.replace('trans_', '');
return typeof dimensions_translation[tag] === 'undefined' ? match : dimensions_translation[tag];
}
if (/^(metric_)/im.test(group)) {
const tag = group.replace('metric_', '');
const matchList = tag.match(/(_[a-zA-Z])/g);
Expand Down Expand Up @@ -323,7 +328,7 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
const newSerie = {
...serie,
target: hasVariateAlias
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie.dimensions)
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie)
: alias || serie.target,
};
const fields: Field[] = [];
Expand Down Expand Up @@ -395,7 +400,7 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
const newSerie = {
...serie,
target: hasVariateAlias
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie.dimensions)
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie)
: alias || serie.target,
};
ValueField.config.unit = newSerie.unit;
Expand Down Expand Up @@ -428,7 +433,7 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
delete serie.unit;
}
const target = hasVariateAlias
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie.dimensions)
? this.buildAlaisVariables(alias, scopedVars, metric, aliasData, serie)
: alias || serie.target;
const newSerie = {
...serie,
Expand Down

0 comments on commit 5fbab45

Please sign in to comment.