From 7ef97a54e2197167161e16a4dfd65d68df8b9928 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Wed, 4 Aug 2021 22:12:20 +0300 Subject: [PATCH] feat(explore): add automatic conditional formatter to pivot table v2 (#16045) --- .../ConditionalFormattingControl.tsx | 2 + .../FormattingPopoverContent.tsx | 14 ++- .../ConditionalFormattingControl/types.ts | 1 + ...migrate_pivot_table_v2_heatmaps_to_new_.py | 108 ++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 superset/migrations/versions/143b6f2815da_migrate_pivot_table_v2_heatmaps_to_new_.py diff --git a/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.tsx b/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.tsx index bc72f983a..401364e0d 100644 --- a/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.tsx +++ b/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.tsx @@ -125,6 +125,8 @@ const ConditionalFormattingControl = ({ }: ConditionalFormattingConfig) => { const columnName = (column && verboseMap?.[column]) ?? column; switch (operator) { + case COMPARATOR.NONE: + return `${columnName}`; case COMPARATOR.BETWEEN: return `${targetValueLeft} ${COMPARATOR.LESS_THAN} ${columnName} ${COMPARATOR.LESS_THAN} ${targetValueRight}`; case COMPARATOR.BETWEEN_OR_EQUAL: diff --git a/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/FormattingPopoverContent.tsx b/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/FormattingPopoverContent.tsx index 571131509..b23b456c4 100644 --- a/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/FormattingPopoverContent.tsx +++ b/superset-frontend/src/explore/components/controls/ConditionalFormattingControl/FormattingPopoverContent.tsx @@ -44,6 +44,7 @@ const colorSchemeOptions = [ ]; const operatorOptions = [ + { value: COMPARATOR.NONE, label: 'None' }, { value: COMPARATOR.GREATER_THAN, label: '>' }, { value: COMPARATOR.LESS_THAN, label: '<' }, { value: COMPARATOR.GREATER_OR_EQUAL, label: '≥' }, @@ -68,6 +69,9 @@ export const FormattingPopoverContent = ({ const isOperatorMultiValue = (operator?: COMPARATOR) => operator && MULTIPLE_VALUE_COMPARATORS.includes(operator); + const isOperatorNone = (operator?: COMPARATOR) => + !operator || operator === COMPARATOR.NONE; + const operatorField = useMemo( () => ( + isOperatorNone(prevValues.operator) !== + isOperatorNone(currentValues.operator) || isOperatorMultiValue(prevValues.operator) !== - isOperatorMultiValue(currentValues.operator) + isOperatorMultiValue(currentValues.operator) } > {({ getFieldValue }) => - isOperatorMultiValue(getFieldValue('operator')) ? ( + isOperatorNone(getFieldValue('operator')) ? ( + + {operatorField} + + ) : isOperatorMultiValue(getFieldValue('operator')) ? (