fix(legacy-preset-chart-nvd3): bar chart unexpected error (#1276)

* fix(legacy-preset-chart-nvd3): bar chart unexpected error

* Add null checks
This commit is contained in:
Kamil Gabryjelski
2021-08-06 12:35:50 +02:00
committed by Yongjie Zhao
parent e50f28000f
commit adff00922a

View File

@@ -16,8 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, validateNonEmpty } from '@superset-ui/core';
import { ControlPanelConfig, sections } from '@superset-ui/chart-controls';
import { ensureIsArray, t, validateNonEmpty } from '@superset-ui/core';
import {
ColumnMeta,
ControlPanelConfig,
sections,
sharedControls,
} from '@superset-ui/chart-controls';
import {
showLegend,
showControls,
@@ -107,10 +112,24 @@ const config: ControlPanelConfig = {
groupby: {
label: t('Series'),
validators: [validateNonEmpty],
mapStateToProps: (state, controlState) => {
const groupbyProps = sharedControls.groupby.mapStateToProps?.(state, controlState) || {};
groupbyProps.canDropValue = (column: ColumnMeta) =>
!ensureIsArray(state.controls?.columns?.value).includes(column.column_name);
return groupbyProps;
},
rerender: ['columns'],
},
columns: {
label: t('Breakdowns'),
description: t('Defines how each series is broken down'),
mapStateToProps: (state, controlState) => {
const columnsProps = sharedControls.columns.mapStateToProps?.(state, controlState) || {};
columnsProps.canDropValue = (column: ColumnMeta) =>
!ensureIsArray(state.controls?.groupby?.value).includes(column.column_name);
return columnsProps;
},
rerender: ['groupby'],
},
},
};