forked from apache-superset/superset-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dropGroupByControl (apache-superset#967)
* feat: add dropGroupByControl * control rename to DndColumnSelectControl * add DND feature flag * wip * fix lint * duplicate dnd control
- Loading branch information
1 parent
9e027ef
commit fc29812
Showing
3 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/superset-ui-chart-controls/src/shared-controls/dndControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-disable camelcase */ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { t, validateNonEmpty } from '@superset-ui/core'; | ||
import { ExtraControlProps, SharedControlConfig } from '../types'; | ||
|
||
const timeColumnOption = { | ||
verbose_name: t('Time'), | ||
column_name: '__timestamp', | ||
description: t('A reference to the [Time] configuration, taking granularity into account'), | ||
}; | ||
|
||
export const dndGroupByControl: SharedControlConfig<'DndColumnSelectControl'> = { | ||
type: 'DndColumnSelectControl', | ||
label: t('Group by'), | ||
default: [], | ||
description: t('One or many columns to group by'), | ||
mapStateToProps(state, { includeTime }) { | ||
const newState: ExtraControlProps = {}; | ||
if (state.datasource) { | ||
const options = state.datasource.columns.filter(c => c.groupby); | ||
if (includeTime) { | ||
options.unshift(timeColumnOption); | ||
} | ||
newState.options = Object.fromEntries(options.map(option => [option.column_name, option])); | ||
} | ||
return newState; | ||
}, | ||
}; | ||
|
||
export const dndColumnsControl: typeof dndGroupByControl = { | ||
...dndGroupByControl, | ||
label: t('Columns'), | ||
description: t('One or many columns to pivot as columns'), | ||
}; | ||
|
||
export const dndSeries: typeof dndGroupByControl = { | ||
...dndGroupByControl, | ||
label: t('Series'), | ||
multi: false, | ||
default: null, | ||
description: t( | ||
'Defines the grouping of entities. ' + | ||
'Each series is shown as a specific color on the chart and ' + | ||
'has a legend toggle', | ||
), | ||
}; | ||
|
||
export const dndEntity: typeof dndGroupByControl = { | ||
...dndGroupByControl, | ||
label: t('Entity'), | ||
default: null, | ||
multi: false, | ||
validators: [validateNonEmpty], | ||
description: t('This defines the element to be plotted on the chart'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters