michael-s-molina commented on code in PR #21163:
URL: https://github.com/apache/superset/pull/21163#discussion_r960897709


##########
superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts:
##########
@@ -122,4 +123,50 @@ describe('buildQueryContext', () => {
       },
     ]);
   });
+  it('should call normalizeTimeColumn if enable GENERIC_CHART_AXES', () => {

Review Comment:
   ```suggestion
     it('should call normalizeTimeColumn if GENERIC_CHART_AXES is enabled', () 
=> {
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(
+    col =>
+      (isPhysicalColumn(col) &&
+        isPhysicalColumn(formData.x_axis) &&
+        col === formData.x_axis) ||
+      (isAdhocColumn(col) &&
+        isAdhocColumn(formData.x_axis) &&
+        col.sqlExpression === formData.x_axis.sqlExpression),
+  );
+  if (
+    axisIdx !== undefined &&
+    axisIdx > -1 &&
+    formData.x_axis &&
+    Array.isArray(queryObject.columns)
+  ) {
+    if (isAdhocColumn(queryObject.columns[axisIdx])) {
+      mutatedColumns[axisIdx] = {
+        timeGrain: queryObject?.extras?.time_grain_sqla,

Review Comment:
   ```suggestion
           timeGrain: extras?.time_grain_sqla,
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts:
##########
@@ -17,6 +17,7 @@
  * under the License.
  */
 import { buildQueryContext } from '@superset-ui/core';
+import * as queryMoudle from '../../src/query/normalizeTimeColumn';

Review Comment:
   ```suggestion
   import * as queryModule from '../../src/query/normalizeTimeColumn';
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts:
##########
@@ -122,4 +123,50 @@ describe('buildQueryContext', () => {
       },
     ]);
   });
+  it('should call normalizeTimeColumn if enable GENERIC_CHART_AXES', () => {
+    // @ts-ignore
+    const spy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: true,
+      },
+    }));
+    const spyNormalizeTimeColumn = jest.spyOn(
+      queryMoudle,
+      'normalizeTimeColumn',
+    );
+
+    buildQueryContext(
+      {
+        datasource: '5__table',
+        viz_type: 'table',
+      },
+      () => [{}],
+    );
+    expect(spyNormalizeTimeColumn).toBeCalled();
+    spy.mockRestore();
+    spyNormalizeTimeColumn.mockRestore();
+  });
+  it("shouldn't call normalizeTimeColumn if disable GENERIC_CHART_AXES", () => 
{

Review Comment:
   ```suggestion
     it("shouldn't call normalizeTimeColumn if GENERIC_CHART_AXES is disabled", 
() => {
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }

Review Comment:
   ```suggestion
     if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) || !formData.x_axis) 
{
       return queryObject;
     }
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(
+    col =>
+      (isPhysicalColumn(col) &&
+        isPhysicalColumn(formData.x_axis) &&
+        col === formData.x_axis) ||
+      (isAdhocColumn(col) &&
+        isAdhocColumn(formData.x_axis) &&
+        col.sqlExpression === formData.x_axis.sqlExpression),
+  );
+  if (
+    axisIdx !== undefined &&
+    axisIdx > -1 &&
+    formData.x_axis &&
+    Array.isArray(queryObject.columns)
+  ) {
+    if (isAdhocColumn(queryObject.columns[axisIdx])) {

Review Comment:
   ```suggestion
       if (isAdhocColumn(columns[axisIdx])) {
   ```



##########
superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx:
##########
@@ -323,6 +325,21 @@ const time_grain_sqla: 
SharedControlConfig<'SelectControl'> = {
   mapStateToProps: ({ datasource }) => ({
     choices: (datasource as Dataset)?.time_grain_sqla || null,
   }),
+  visibility: ({ controls }) => {
+    if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+      return true;
+    }
+
+    const xAxisValue = controls?.x_axis?.value;
+    if (xAxisValue === undefined || isAdhocColumn(xAxisValue)) {
+      return true;
+    }
+    if (isPhysicalColumn(xAxisValue)) {
+      const options = controls?.x_axis?.options ?? {};
+      return options[xAxisValue]?.is_dttm;

Review Comment:
   ```suggestion
         return xAxis?.options?.[xAxisValue]?.is_dttm ?? false;
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(

Review Comment:
   ```suggestion
     const { columns, extras } = queryObject;
     const mutatedColumns: QueryFormColumn[] = [...(columns || [])];
     const axisIdx = columns?.findIndex(
   ```



##########
superset/utils/core.py:
##########
@@ -1263,6 +1263,19 @@ def is_adhoc_column(column: Column) -> 
TypeGuard[AdhocColumn]:
     return isinstance(column, dict)
 
 
+def get_axis_column(columns: Optional[List[Column]]) -> Optional[AdhocColumn]:
+    if columns is None:
+        return None
+    axis_cols = [
+        col
+        for col in columns
+        if is_adhoc_column(col)
+        and col.get("columnType")
+        and col.get("columnType") == "AXIS"

Review Comment:
   ```suggestion
           and col.get("columnType") == "AXIS"
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(
+    col =>
+      (isPhysicalColumn(col) &&
+        isPhysicalColumn(formData.x_axis) &&
+        col === formData.x_axis) ||
+      (isAdhocColumn(col) &&
+        isAdhocColumn(formData.x_axis) &&
+        col.sqlExpression === formData.x_axis.sqlExpression),
+  );
+  if (
+    axisIdx !== undefined &&
+    axisIdx > -1 &&
+    formData.x_axis &&
+    Array.isArray(queryObject.columns)
+  ) {
+    if (isAdhocColumn(queryObject.columns[axisIdx])) {
+      mutatedColumns[axisIdx] = {
+        timeGrain: queryObject?.extras?.time_grain_sqla,
+        columnType: 'AXIS',
+        ...(queryObject.columns[axisIdx] as AdhocColumn),
+      };
+    } else {
+      mutatedColumns[axisIdx] = {
+        timeGrain: queryObject?.extras?.time_grain_sqla,

Review Comment:
   ```suggestion
           timeGrain: extras?.time_grain_sqla,
   ```



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(
+    col =>
+      (isPhysicalColumn(col) &&
+        isPhysicalColumn(formData.x_axis) &&
+        col === formData.x_axis) ||
+      (isAdhocColumn(col) &&
+        isAdhocColumn(formData.x_axis) &&
+        col.sqlExpression === formData.x_axis.sqlExpression),
+  );
+  if (
+    axisIdx !== undefined &&
+    axisIdx > -1 &&
+    formData.x_axis &&
+    Array.isArray(queryObject.columns)

Review Comment:
   ```suggestion
       Array.isArray(columns)
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/normalizeTimeColumn.test.ts:
##########
@@ -0,0 +1,247 @@
+/**
+ * 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 {
+  normalizeTimeColumn,
+  QueryObject,
+  SqlaFormData,
+} from '@superset-ui/core';
+
+describe('disabled GENERIC_CHART_AXES', () => {
+  let windowSpy: any;
+
+  beforeAll(() => {
+    // @ts-ignore
+    windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: false,
+      },
+    }));
+  });
+
+  afterAll(() => {
+    windowSpy.mockRestore();
+  });
+
+  it('should return original QueryObject if disabled GENERIC_CHART_AXES', () 
=> {
+    const formData: SqlaFormData = {
+      datasource: '5__table',
+      viz_type: 'table',
+      granularity: 'time_column',
+      time_grain_sqla: 'P1Y',
+      time_range: '1 year ago : 2013',
+      columns: ['col1'],
+      metrics: ['count(*)'],
+      x_axis: 'time_column',
+    };
+    const query: QueryObject = {
+      datasource: '5__table',
+      viz_type: 'table',
+      granularity: 'time_column',
+      extras: {
+        time_grain_sqla: 'P1Y',
+      },
+      time_range: '1 year ago : 2013',
+      orderby: [['count(*)', true]],
+      columns: ['col1'],
+      metrics: ['count(*)'],
+      is_timeseries: true,
+    };
+    expect(normalizeTimeColumn(formData, query)).toEqual(query);
+  });
+});
+
+describe('enabled GENERIC_CHART_AXES', () => {
+  let windowSpy: any;
+
+  beforeAll(() => {
+    // @ts-ignore
+    windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: true,
+      },
+    }));
+  });
+
+  afterAll(() => {
+    windowSpy.mockRestore();
+  });
+
+  it('should return original QueryObject if x_axis is empty', () => {
+    const formData: SqlaFormData = {
+      datasource: '5__table',
+      viz_type: 'table',
+      granularity: 'time_column',
+      time_grain_sqla: 'P1Y',
+      time_range: '1 year ago : 2013',
+      columns: ['col1'],
+      metrics: ['count(*)'],
+    };
+    const query: QueryObject = {
+      datasource: '5__table',
+      viz_type: 'table',
+      granularity: 'time_column',
+      extras: {
+        time_grain_sqla: 'P1Y',
+      },
+      time_range: '1 year ago : 2013',
+      orderby: [['count(*)', true]],
+      columns: ['col1'],
+      metrics: ['count(*)'],
+      is_timeseries: true,
+    };
+    expect(normalizeTimeColumn(formData, query)).toEqual(query);
+  });
+
+  it('should support x-axis and granularity to use different column', () => {

Review Comment:
   ```suggestion
     it('should support different columns for x-axis and granularity', () => {
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts:
##########
@@ -122,4 +123,50 @@ describe('buildQueryContext', () => {
       },
     ]);
   });
+  it('should call normalizeTimeColumn if enable GENERIC_CHART_AXES', () => {
+    // @ts-ignore
+    const spy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: true,
+      },
+    }));
+    const spyNormalizeTimeColumn = jest.spyOn(
+      queryMoudle,

Review Comment:
   ```suggestion
         queryModule,
   ```



##########
superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx:
##########
@@ -323,6 +325,21 @@ const time_grain_sqla: 
SharedControlConfig<'SelectControl'> = {
   mapStateToProps: ({ datasource }) => ({
     choices: (datasource as Dataset)?.time_grain_sqla || null,
   }),
+  visibility: ({ controls }) => {
+    if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+      return true;
+    }
+
+    const xAxisValue = controls?.x_axis?.value;

Review Comment:
   ```suggestion
       const xAxis = controls?.x_axis;
       const xAxisValue = xAxis?.value;
   ```



##########
tests/integration_tests/query_context_tests.py:
##########
@@ -728,3 +730,183 @@ def test_get_label_map(app_context, 
virtual_dataset_comma_in_column_value):
         "count, col2, row2": ["count", "col2, row2"],
         "count, col2, row3": ["count", "col2, row3"],
     }
+
+
+def test_time_column_with_time_grain(app_context, physical_dataset):

Review Comment:
   Nice set of tests!



##########
superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 omit from 'lodash/omit';
+
+import {
+  AdhocColumn,
+  isAdhocColumn,
+  isPhysicalColumn,
+  QueryFormColumn,
+  QueryFormData,
+  QueryObject,
+} from './types';
+import { FeatureFlag, isFeatureEnabled } from '../utils';
+
+export function normalizeTimeColumn(
+  formData: QueryFormData,
+  queryObject: QueryObject,
+): QueryObject {
+  if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
+    return queryObject;
+  }
+  if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && !formData.x_axis) {
+    return queryObject;
+  }
+
+  const mutatedColumns: QueryFormColumn[] = [...(queryObject.columns || [])];
+  const axisIdx = queryObject.columns?.findIndex(
+    col =>
+      (isPhysicalColumn(col) &&
+        isPhysicalColumn(formData.x_axis) &&
+        col === formData.x_axis) ||
+      (isAdhocColumn(col) &&
+        isAdhocColumn(formData.x_axis) &&
+        col.sqlExpression === formData.x_axis.sqlExpression),
+  );
+  if (
+    axisIdx !== undefined &&
+    axisIdx > -1 &&
+    formData.x_axis &&
+    Array.isArray(queryObject.columns)
+  ) {
+    if (isAdhocColumn(queryObject.columns[axisIdx])) {
+      mutatedColumns[axisIdx] = {
+        timeGrain: queryObject?.extras?.time_grain_sqla,
+        columnType: 'AXIS',
+        ...(queryObject.columns[axisIdx] as AdhocColumn),

Review Comment:
   ```suggestion
           ...(columns[axisIdx] as AdhocColumn),
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts:
##########
@@ -122,4 +123,50 @@ describe('buildQueryContext', () => {
       },
     ]);
   });
+  it('should call normalizeTimeColumn if enable GENERIC_CHART_AXES', () => {
+    // @ts-ignore
+    const spy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: true,
+      },
+    }));
+    const spyNormalizeTimeColumn = jest.spyOn(
+      queryMoudle,
+      'normalizeTimeColumn',
+    );
+
+    buildQueryContext(
+      {
+        datasource: '5__table',
+        viz_type: 'table',
+      },
+      () => [{}],
+    );
+    expect(spyNormalizeTimeColumn).toBeCalled();
+    spy.mockRestore();
+    spyNormalizeTimeColumn.mockRestore();
+  });
+  it("shouldn't call normalizeTimeColumn if disable GENERIC_CHART_AXES", () => 
{
+    // @ts-ignore
+    const spy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: false,
+      },
+    }));
+    const spyNormalizeTimeColumn = jest.spyOn(
+      queryMoudle,

Review Comment:
   ```suggestion
         queryModule,
   ```



##########
superset-frontend/packages/superset-ui-core/test/query/normalizeTimeColumn.test.ts:
##########
@@ -0,0 +1,247 @@
+/**
+ * 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 {
+  normalizeTimeColumn,
+  QueryObject,
+  SqlaFormData,
+} from '@superset-ui/core';
+
+describe('disabled GENERIC_CHART_AXES', () => {
+  let windowSpy: any;
+
+  beforeAll(() => {
+    // @ts-ignore
+    windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
+      featureFlags: {
+        GENERIC_CHART_AXES: false,
+      },
+    }));
+  });
+
+  afterAll(() => {
+    windowSpy.mockRestore();
+  });
+
+  it('should return original QueryObject if disabled GENERIC_CHART_AXES', () 
=> {

Review Comment:
   ```suggestion
     it('should return original QueryObject if GENERIC_CHART_AXES is disabled', 
() => {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to