Skip to content

Commit 7cd00cb

Browse files
authored
Merge pull request #1780 from merico-dev/preset-metric
feat(metrics): Add isPreset and semanticKey to metric type
2 parents 8c450d7 + c071dc7 commit 7cd00cb

File tree

9 files changed

+592
-3
lines changed

9 files changed

+592
-3
lines changed

.yarn/plugins/@yarnpkg/plugin-version.cjs

Lines changed: 550 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/versions/34a1b820.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
undecided:
2+
- "@devtable/root"
3+
- "@devtable/dashboard"

.yarnrc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
nodeLinker: node-modules
22

3+
plugins:
4+
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
5+
spec: '@yarnpkg/plugin-version'
6+
37
yarnPath: .yarn/releases/yarn-3.6.1.cjs

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/dashboard",
3-
"version": "14.57.2",
3+
"version": "14.57.3",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

dashboard/src/dashboard-editor/model/datasources/mm-info/metrics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type MetricBriefInfo = {
1212
name: string;
1313
description: string;
1414
type: 'derived' | 'combined';
15+
isPreset: boolean;
16+
semanticKey: string;
1517
};
1618

1719
export const MetricsModel = types

dashboard/src/dashboard-editor/ui/settings/content/edit-query/merico-metric-query-editor-form/select-metric.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export const SelectMetric = observer(({ queryModel }: Props) => {
7171
value: d.id,
7272
description: d.description,
7373
type: d.type,
74+
semanticKey: d.semanticKey,
75+
isPreset: d.isPreset,
7476
}));
7577
}, [metrics.data]);
7678

@@ -83,6 +85,9 @@ export const SelectMetric = observer(({ queryModel }: Props) => {
8385
mmInfo.selectMetric(id);
8486
config.setID(id);
8587
config.setType(option.type);
88+
if (option.isPreset) {
89+
config.setSemanticKey(option.semanticKey);
90+
}
8691
},
8792
[mmInfo, config],
8893
);

dashboard/src/model/meta-model/dashboard/content/query/merico-metric-query.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export const MericoMetricQueryMeta = types
118118
}),
119119
useDefaultValues: types.optional(types.boolean, false),
120120
extraCalculations: types.optional(types.array(types.string), []),
121+
/**
122+
* If the metric is preset, this field will be set to the semantic key of the metric.
123+
*/
124+
semanticKey: types.optional(types.string, ''),
121125
})
122126
.views((self) => ({
123127
get query() {
@@ -127,7 +131,18 @@ export const MericoMetricQueryMeta = types
127131
return !!self.id;
128132
},
129133
get json() {
130-
const { id, type, filters, groupBys, timeQuery, useDefaultValues, extraCalculations, _type, sqlVariables } = self;
134+
const {
135+
id,
136+
type,
137+
filters,
138+
groupBys,
139+
timeQuery,
140+
useDefaultValues,
141+
extraCalculations,
142+
_type,
143+
sqlVariables,
144+
semanticKey,
145+
} = self;
131146
return shallowToJS({
132147
id,
133148
type,
@@ -137,6 +152,7 @@ export const MericoMetricQueryMeta = types
137152
useDefaultValues,
138153
extraCalculations,
139154
sqlVariables,
155+
semanticKey,
140156
_type,
141157
});
142158
},
@@ -170,6 +186,7 @@ export const MericoMetricQueryMeta = types
170186
self.useDefaultValues = false;
171187
self.extraCalculations.length = 0;
172188
self.sqlVariables.length = 0;
189+
self.semanticKey = '';
173190
if ('data' in self.query) {
174191
self.query.setData([]);
175192
self.query.setError(null);
@@ -181,6 +198,9 @@ export const MericoMetricQueryMeta = types
181198
}
182199
self.id = v;
183200
},
201+
setSemanticKey(v: string) {
202+
self.semanticKey = v;
203+
},
184204
setType(type: string) {
185205
if (type !== 'derived' && type !== 'combined' && type !== 'sql') {
186206
return;
@@ -259,6 +279,7 @@ export interface IMericoMetricQueryMeta {
259279
};
260280
useDefaultValues: boolean;
261281
extraCalculations: IObservableArray<string>;
282+
semanticKey: string;
262283

263284
// Views
264285
readonly query: IQueryRenderModel;
@@ -281,6 +302,7 @@ export interface IMericoMetricQueryMeta {
281302
sqlVariables: IObservableArray<ISqlMetricVariableMeta>;
282303
useDefaultValues: boolean;
283304
extraCalculations: IObservableArray<string>;
305+
semanticKey: string;
284306
_type: DataSourceType.MericoMetricSystem;
285307
};
286308
readonly usedFilterDimensionKeys: Set<string>;
@@ -303,6 +325,7 @@ export interface IMericoMetricQueryMeta {
303325
setExtraCalculations(v: string[]): void;
304326
addSqlVariable(sqlVar: string, variable: string): void;
305327
removeSqlVariable(sqlVariable: ISqlMetricVariableMeta): void;
328+
setSemanticKey(v: string): void;
306329
}
307330

308331
typeAssert.shouldExtends<IMericoMetricQueryMeta, MericoMetricQueryMetaInstance>();

dashboard/src/model/render-model/dashboard/content/queries/mute-query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type MetricQueryPayload = {
3232
};
3333
useDefaultValues?: boolean;
3434
extraCalculations?: string[];
35+
semanticKey?: string;
3536
};
3637

3738
// Helper function to format date range for timeQuery
@@ -345,6 +346,7 @@ export const MuteQueryModel = QueryMeta.views((self) => ({
345346
filters,
346347
groupBys: config.groupBys,
347348
variables,
349+
semanticKey: config.semanticKey,
348350
};
349351

350352
// sql metric time query

settings-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/settings-form",
3-
"version": "14.57.2",
3+
"version": "14.57.3",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

0 commit comments

Comments
 (0)