diff --git a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/AdhocFilter.test.js b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/AdhocFilter.test.js index 20f9576a47aa2..19cc2f783e765 100644 --- a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/AdhocFilter.test.js +++ b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/AdhocFilter.test.js @@ -247,4 +247,36 @@ describe('AdhocFilter', () => { }); expect(adhocFilter2.comparator).toBe(null); }); + it('sets the label properly if subject is a string', () => { + const adhocFilter2 = new AdhocFilter({ + expressionType: EXPRESSION_TYPES.SIMPLE, + subject: 'order_date', + }); + expect(adhocFilter2.getDefaultLabel()).toBe('order_date'); + }); + it('sets the label properly if subject is an object with the column_date property', () => { + const adhocFilter2 = new AdhocFilter({ + expressionType: EXPRESSION_TYPES.SIMPLE, + subject: { + column_name: 'year', + }, + }); + expect(adhocFilter2.getDefaultLabel()).toBe('year'); + }); + it('sets the label to empty is there is no column_name in the object', () => { + const adhocFilter2 = new AdhocFilter({ + expressionType: EXPRESSION_TYPES.SIMPLE, + subject: { + unknown: 'year', + }, + }); + expect(adhocFilter2.getDefaultLabel()).toBe(''); + }); + it('sets the label to empty is there is no subject', () => { + const adhocFilter2 = new AdhocFilter({ + expressionType: EXPRESSION_TYPES.SIMPLE, + subject: undefined, + }); + expect(adhocFilter2.getDefaultLabel()).toBe(''); + }); }); diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js index 1d678427ff3cf..e3e0b4f8ff0ad 100644 --- a/superset-frontend/src/explore/exploreUtils/index.js +++ b/superset-frontend/src/explore/exploreUtils/index.js @@ -295,7 +295,9 @@ export const getSimpleSQLExpression = (subject, operator, comparator) => { [...MULTI_OPERATORS] .map(op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation) .indexOf(operator) >= 0; - let expression = subject ?? ''; + // If returned value is an object after changing dataset + let expression = + typeof subject === 'object' ? subject?.column_name ?? '' : subject ?? ''; if (subject && operator) { expression += ` ${operator}`; const firstValue =