Skip to content

Commit

Permalink
show warning
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed May 31, 2021
1 parent fc2c3c9 commit 3637ee6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EuiText,
EuiTabs,
EuiTab,
EuiCallOut,
} from '@elastic/eui';
import { IndexPatternDimensionEditorProps } from './dimension_panel';
import { OperationSupportMatrix } from './operation_support';
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
Expand Down Expand Up @@ -339,6 +349,24 @@ export function DimensionEditor(props: DimensionEditorProps) {
const quickFunctions = (
<>
<div className="lnsIndexPatternDimensionEditor__section lnsIndexPatternDimensionEditor__section--padded lnsIndexPatternDimensionEditor__section--shaded">
{temporaryQuickFunction && changedFormula && (
<>
<EuiCallOut
size="s"
title={i18n.translate('xpack.lens.indexPattern.formulaWarning', {
defaultMessage: 'Staged formula',
})}
color="warning"
>
<p>
{i18n.translate('xpack.lens.indexPattern.formulaWarningText', {
defaultMessage: 'Picking a quick function will erase your formula.',
})}
</p>
</EuiCallOut>
<EuiSpacer size="s" />
</>
)}
<EuiFormLabel>
{i18n.translate('xpack.lens.indexPattern.functionsLabel', {
defaultMessage: 'Select a function',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function FormulaEditor({
},
// Make it validate on flyout open in case of a broken formula left over
// from a previous edit
{ skipFirstRender: text == null },
{ skipFirstRender: true },
256,
[text]
);
Expand Down

0 comments on commit 3637ee6

Please sign in to comment.