Files
superset2/superset/assets/src/query/FormData.ts
Christine Chambers c11e9c8b67 [SIP-5] Build metrics in query_object in the client
- 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
2018-11-28 19:39:18 -05:00

31 lines
1021 B
TypeScript

import { AdhocMetric, MetricKey } from './Metric';
// Type signature and utility functions for formData shared by all viz types
// It will be gradually filled out as we build out the query object
// Define mapped type separately to work around a limitation of TypeScript
// https://github.com/Microsoft/TypeScript/issues/13573
// The Metrics in formData is either a string or a proper metric. It will be
// unified into a proper Metric type during buildQuery (see `/query/Metrics.ts`).
type Metrics = Partial<Record<MetricKey, AdhocMetric | string>>;
type BaseFormData = {
datasource: string;
} & Metrics;
// FormData is either sqla-based or druid-based
type SqlaFormData = {
granularity_sqla: string;
} & BaseFormData;
type DruidFormData = {
granularity: string;
} & BaseFormData;
type FormData = SqlaFormData | DruidFormData;
export default FormData;
export function getGranularity(formData: FormData): string {
return 'granularity_sqla' in formData ? formData.granularity_sqla : formData.granularity;
}