diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx index a8915ca3fc6cb..0540605eecf12 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx @@ -20,6 +20,7 @@ import { EuiText, EuiTabs, EuiTab, + EuiCallOut, } from '@elastic/eui'; import { IndexPatternDimensionEditorProps } from './dimension_panel'; import { OperationSupportMatrix } from './operation_support'; @@ -105,10 +106,22 @@ export function DimensionEditor(props: DimensionEditorProps) { }; const { fieldByOperation, operationWithoutField } = operationSupportMatrix; + const selectedOperationDefinition = + selectedColumn && operationDefinitionMap[selectedColumn.operationType]; + + const [changedFormula, setChangedFormula] = useState( + Boolean(selectedOperationDefinition?.type === 'formula') + ); + const setStateWrapper = ( setter: IndexPatternLayer | ((prevLayer: IndexPatternLayer) => IndexPatternLayer), shouldClose?: boolean ) => { + if (selectedOperationDefinition?.type === 'formula' && !temporaryQuickFunction) { + setChangedFormula(true); + } else { + setChangedFormula(false); + } const hypotheticalLayer = typeof setter === 'function' ? setter(state.layers[layerId]) : setter; const hasIncompleteColumns = Boolean(hypotheticalLayer.incompleteColumns?.[columnId]); const prevOperationType = @@ -133,9 +146,6 @@ export function DimensionEditor(props: DimensionEditorProps) { setState((prevState) => ({ ...prevState, isDimensionClosePrevented: !isCloseable })); }; - const selectedOperationDefinition = - selectedColumn && operationDefinitionMap[selectedColumn.operationType]; - const incompleteInfo = (state.layers[layerId].incompleteColumns ?? {})[columnId]; const incompleteOperation = incompleteInfo?.operationType; const incompleteField = incompleteInfo?.sourceField ?? null; @@ -339,6 +349,24 @@ export function DimensionEditor(props: DimensionEditorProps) { const quickFunctions = ( <>
+ {i18n.translate('xpack.lens.indexPattern.formulaWarningText', { + defaultMessage: 'Picking a quick function will erase your formula.', + })} +
+