Skip to content

Commit

Permalink
set dttm to first datatime column
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Jul 26, 2021
1 parent d6a8a5a commit d55db8c
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -123,14 +124,18 @@ class DatasourceControl extends React.PureComponent {

onDatasourceSave(datasource) {
this.props.actions.setDatasource(datasource);
// remove time column in the form_data
const timeCol = this.props.form_data?.granularity_sqla; // eslint-disable-line camelcase
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 // eslint-disable-line camelcase
!columns.find(({ column_name }) => column_name === timeCol)?.is_dttm
) {
this.props.actions.setControlValue('granularity_sqla', null);
// 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) {
this.props.onDatasourceSave(datasource);
Expand Down Expand Up @@ -221,9 +226,9 @@ class DatasourceControl extends React.PureComponent {
<Icons.AlertSolid iconColor={supersetTheme.colors.warning.base} />
</Tooltip>
)}
{extra?.warning_markdown && ( // eslint-disable-line camelcase
{extra?.warning_markdown && (
<WarningIconWithTooltip
warningMarkdown={extra.warning_markdown} // eslint-disable-line camelcase
warningMarkdown={extra.warning_markdown}
size={30}
/>
)}
Expand Down

0 comments on commit d55db8c

Please sign in to comment.