mirror of https://github.com/apache/superset.git
fix: remove unused time column when update dataset (#14969)
* fix: remove unused time column when update dataset * fix lint * set dttm to first datatime column
This commit is contained in:
parent
eda38a758e
commit
11b0249803
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable camelcase */
|
||||||
/**
|
/**
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
@ -35,6 +36,7 @@ const propTypes = {
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
datasource: PropTypes.object.isRequired,
|
datasource: PropTypes.object.isRequired,
|
||||||
|
form_data: PropTypes.object.isRequired,
|
||||||
isEditable: PropTypes.bool,
|
isEditable: PropTypes.bool,
|
||||||
onDatasourceSave: PropTypes.func,
|
onDatasourceSave: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
@ -122,6 +124,19 @@ class DatasourceControl extends React.PureComponent {
|
||||||
|
|
||||||
onDatasourceSave(datasource) {
|
onDatasourceSave(datasource) {
|
||||||
this.props.actions.setDatasource(datasource);
|
this.props.actions.setDatasource(datasource);
|
||||||
|
const timeCol = this.props.form_data?.granularity_sqla;
|
||||||
|
const { columns } = this.props.datasource;
|
||||||
|
const firstDttmCol = columns.find(column => column.is_dttm);
|
||||||
|
if (
|
||||||
|
datasource.type === 'table' &&
|
||||||
|
!columns.find(({ column_name }) => column_name === timeCol)?.is_dttm
|
||||||
|
) {
|
||||||
|
// set `granularity_sqla` to first datatime column name or null
|
||||||
|
this.props.actions.setControlValue(
|
||||||
|
'granularity_sqla',
|
||||||
|
firstDttmCol ? firstDttmCol.column_name : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (this.props.onDatasourceSave) {
|
if (this.props.onDatasourceSave) {
|
||||||
this.props.onDatasourceSave(datasource);
|
this.props.onDatasourceSave(datasource);
|
||||||
}
|
}
|
||||||
|
@ -211,9 +226,9 @@ class DatasourceControl extends React.PureComponent {
|
||||||
<Icons.AlertSolid iconColor={supersetTheme.colors.warning.base} />
|
<Icons.AlertSolid iconColor={supersetTheme.colors.warning.base} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{extra?.warning_markdown && ( // eslint-disable-line camelcase
|
{extra?.warning_markdown && (
|
||||||
<WarningIconWithTooltip
|
<WarningIconWithTooltip
|
||||||
warningMarkdown={extra.warning_markdown} // eslint-disable-line camelcase
|
warningMarkdown={extra.warning_markdown}
|
||||||
size={30}
|
size={30}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1032,7 +1032,7 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
|
||||||
metrics = metrics or []
|
metrics = metrics or []
|
||||||
|
|
||||||
# For backward compatibility
|
# For backward compatibility
|
||||||
if granularity not in self.dttm_cols:
|
if granularity not in self.dttm_cols and granularity is not None:
|
||||||
granularity = self.main_dttm_col
|
granularity = self.main_dttm_col
|
||||||
|
|
||||||
# Database spec supports join-free timeslot grouping
|
# Database spec supports join-free timeslot grouping
|
||||||
|
|
Loading…
Reference in New Issue