mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
- Unify the metric interface (absorb the current plain string metric for built-in metric keys into the format used by adhoc metric) - Port the logic in adhocMetric on the client and process_metrics in the backend to the new typed Metrics class - Omit hasCustomLabel and formFromData properties from the new metric interface as their value can be inferred from label and optionName - Expose from the Metrics class both metrics and their labels as public methods to match the all_metrics and metric_labels fields in the backend code - Provide defaut values for filters, metrics and groupby in the backend
22 lines
898 B
TypeScript
22 lines
898 B
TypeScript
import FormData, { getGranularity } from './FormData';
|
|
import Metric, { Metrics } from './Metric';
|
|
|
|
// TODO: fill out the rest of the query object
|
|
export interface QueryObject {
|
|
granularity: string;
|
|
groupby?: string[];
|
|
metrics?: Metric[];
|
|
}
|
|
|
|
// Build the common segments of all query objects (e.g. the granularity field derived from
|
|
// either sql alchemy or druid). The segments specific to each viz type is constructed in the
|
|
// buildQuery method for each viz type (see `wordcloud/buildQuery.ts` for an example).
|
|
// Note the type of the formData argument passed in here is the type of the formData for a
|
|
// specific viz, which is a subtype of the generic formData shared among all viz types.
|
|
export default function buildQueryObject<T extends FormData>(formData: T): QueryObject {
|
|
return {
|
|
granularity: getGranularity(formData),
|
|
metrics: new Metrics(formData).getMetrics(),
|
|
};
|
|
}
|