Skip to content

Commit

Permalink
feat: implement Metrics dnd (apache#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored and zhaoyongjie committed Nov 24, 2021
1 parent 0d3537c commit 7273a5b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, validateNonEmpty } from '@superset-ui/core';
import { Metric, t, validateNonEmpty } from '@superset-ui/core';
import { ExtraControlProps, SharedControlConfig } from '../types';
import { mainMetric } from '../utils';
import { TIME_COLUMN_OPTION } from '../constants';

type Control = {
savedMetrics?: Metric[] | null;
default?: unknown;
};

export const dndGroupByControl: SharedControlConfig<'DndColumnSelect'> = {
type: 'DndColumnSelect',
label: t('Group by'),
Expand Down Expand Up @@ -80,3 +86,28 @@ export const dnd_adhoc_filters: SharedControlConfig<'DndFilterSelect'> = {
}),
provideFormDataToProps: true,
};

export const dnd_adhoc_metrics: SharedControlConfig<'DndMetricSelect'> = {
type: 'DndMetricSelect',
multi: true,
label: t('Metrics'),
validators: [validateNonEmpty],
default: (c: Control) => {
const metric = mainMetric(c.savedMetrics);
return metric ? [metric] : null;
},
mapStateToProps: ({ datasource }) => ({
columns: datasource ? datasource.columns : [],
savedMetrics: datasource ? datasource.metrics : [],
datasourceType: datasource?.type,
}),
description: t('One or many metrics to display'),
};

export const dnd_adhoc_metric: SharedControlConfig<'DndMetricSelect'> = {
...dnd_adhoc_metrics,
multi: false,
label: t('Metric'),
description: t('Metric'),
default: (c: Control) => mainMetric(c.savedMetrics),
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import {
import { ColumnOption } from '../components/ColumnOption';
import {
dnd_adhoc_filters,
dnd_adhoc_metric,
dnd_adhoc_metrics,
dndColumnsControl,
dndEntity,
dndGroupByControl,
Expand Down Expand Up @@ -482,8 +484,8 @@ const label_colors: SharedControlConfig<'ColorMapControl'> = {
const enableExploreDnd = isFeatureEnabled(FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP);

const sharedControls = {
metrics,
metric,
metrics: enableExploreDnd ? dnd_adhoc_metrics : metrics,
metric: enableExploreDnd ? dnd_adhoc_metric : metric,
datasource: datasourceControl,
viz_type,
color_picker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export type InternalControlType =
| 'FilterBoxItemControl'
| 'DndColumnSelect'
| 'DndFilterSelect'
| 'DndMetricSelect'
| keyof SharedControlComponents; // expanded in `expandControlConfig`

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 7273a5b

Please sign in to comment.