Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lens formula improvements #89457

Closed
wants to merge 123 commits into from
Closed
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
5941b55
Lens formula
flash1293 Jan 21, 2021
c175dd9
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Jan 27, 2021
71b0812
:alembic: Adding basic error handling + transferable
dej611 Jan 27, 2021
c89bbf7
:sparkles: Implement new features
dej611 Jan 28, 2021
7e0b149
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Jan 29, 2021
cd83321
:bug: Fix isTransferable from Formula
dej611 Jan 29, 2021
7df6c2d
:sparkles: Add all fullReferences ops + initial params
dej611 Jan 29, 2021
0473cb8
Expand Tinymath grammar, including named arguments
wylieconlon Jan 29, 2021
7897563
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Feb 1, 2021
aaf5664
:sparkles: Add enhanced validation for fields, operations and parameters
dej611 Feb 1, 2021
66b7dde
Add tsconfig project
wylieconlon Feb 1, 2021
0e8a7be
Fix tests
wylieconlon Feb 1, 2021
af6da20
:sparkles: Add id and name (optional) decoupling
dej611 Feb 2, 2021
7e5b825
:sparkles: Give Formula column custom label
dej611 Feb 2, 2021
d6df1e2
Merge branch 'pr/89795' into lens/formula-named-params
dej611 Feb 2, 2021
c558744
Merge branch 'master' into tinymath-named-arguments
kibanamachine Feb 2, 2021
bde55d3
Allow named arguments with numeric types
wylieconlon Feb 3, 2021
bf8f8c4
:label: Migrate AST to new format + types fix + extended validation
dej611 Feb 3, 2021
d02ee52
:bug: Improved validation
dej611 Feb 3, 2021
03b1bd4
:white_check_mark: Add first batch of validation tests
dej611 Feb 3, 2021
3f8d248
Merge branch 'pr/89795' into lens/formula-error-handling
dej611 Feb 3, 2021
b5ee6ab
:white_check_mark: Add more validation tests for formula
dej611 Feb 3, 2021
9c45213
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Feb 4, 2021
d71c30c
:bug: Fix parsing issues + tests
dej611 Feb 4, 2021
973a569
Merge remote-tracking branch 'origin/master' into tinymath-named-argu…
wylieconlon Feb 4, 2021
c87277d
Merge branch 'tinymath-named-arguments' into HEAD
wylieconlon Feb 4, 2021
abcb1a4
Reorganize code to support autocomplete
wylieconlon Feb 4, 2021
6c4855e
:sparkles: Refactor validation
dej611 Feb 4, 2021
1f9ebb9
Refactoring by dej611
wylieconlon Feb 4, 2021
8ecde1d
Use real fields
wylieconlon Feb 5, 2021
17f49fa
:bug: Fix most of test issues + hide Math op
dej611 Feb 5, 2021
c919670
Show errors in formula editor
wylieconlon Feb 5, 2021
155a986
:label: fix types
dej611 Feb 9, 2021
8720257
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Feb 9, 2021
a53d074
Fix types and parsing
wylieconlon Feb 10, 2021
844692a
Merge branch lens/formula-error-handling-2 into lens/formula-error-ha…
dej611 Feb 10, 2021
d4c5998
:lipstick: Hack to fix suggestion box
dej611 Feb 10, 2021
bb37b7f
Merge branch 'master' into lens/formula-error-handling
kibanamachine Feb 15, 2021
2420565
Merge branch 'master' into lens/formula-error-handling
kibanamachine Feb 18, 2021
036415a
Merge branch 'master' into lens/formula-error-handling
kibanamachine Feb 19, 2021
4d5dca2
:bug: Fix validation messages
dej611 Feb 19, 2021
7c38af3
:bug: Relax operations check for managedReferences
dej611 Feb 19, 2021
e90a5df
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Feb 19, 2021
a695329
Change completion params
wylieconlon Feb 19, 2021
ea574f7
:label: Fix missing arg issue
dej611 Feb 22, 2021
28c0427
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Mar 2, 2021
417edff
:sparkles: Add more tinymath fns
dej611 Mar 3, 2021
fcbdc74
:bug: Improved validation around math operations + multiple named arg…
dej611 Mar 3, 2021
55d3bc6
:bug: Use new onError feature in math expression
dej611 Mar 3, 2021
642fa53
:recycle: Refactor namedArguments validation
dej611 Mar 3, 2021
08b9b6f
:bug: Fix circular dependency issue in tests + minor fixes
dej611 Mar 3, 2021
530226c
Merge remote-tracking branch 'upstream/master' into lens/formula-erro…
dej611 Mar 3, 2021
586f6ef
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 3, 2021
7832aeb
Move formula into a tab
wylieconlon Mar 4, 2021
f05c647
:fire: Leftovers from previous merge
dej611 Mar 4, 2021
d050e6f
:sparkles: Move over namedArgs from previous function
dej611 Mar 4, 2021
37c9c5f
:white_check_mark: Add tests for transferable scenarios
dej611 Mar 4, 2021
006f569
Merge branch 'lens/formula-error-handling' of github.com:dej611/kiban…
dej611 Mar 4, 2021
135987c
:white_check_mark: Fixed broken test
dej611 Mar 4, 2021
28847f1
:sparkles: Use custom label for axis
dej611 Mar 4, 2021
5524cf2
Allow switching back and forth to formula tab
wylieconlon Mar 4, 2021
6650f67
Add a section for the function reference
wylieconlon Mar 4, 2021
1e32e0a
Add modal editor and markdown docs
wylieconlon Mar 5, 2021
cacf486
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 5, 2021
2bc7f6c
Change the way math nodes are validated
wylieconlon Mar 5, 2021
367de12
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 8, 2021
d42d02e
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 9, 2021
e0cd7d4
Use custom portal to fix monaco positioning
wylieconlon Mar 10, 2021
a1e8412
Fix model sharing issues
wylieconlon Mar 10, 2021
039a5c2
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 10, 2021
86f36dd
Provide signature help
wylieconlon Mar 11, 2021
dba216c
:bug: Fix small test issue
dej611 Mar 11, 2021
4d5ce24
:bug: Mark pow arguments as required
dej611 Mar 11, 2021
f47c5db
:bug: validate on first render only if a formula is present
dej611 Mar 11, 2021
e102ad2
:fire: Remove log10 fn for now
dej611 Mar 11, 2021
1483d9d
:sparkles: Improved math validation + add tests for math functions
dej611 Mar 11, 2021
1e510cc
Merge remote-tracking branch upstream/master into lens/formula-error-…
dej611 Mar 17, 2021
9069161
Merge branch 'master' into lens/formula-error-handling
kibanamachine Mar 18, 2021
c4e6be8
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 23, 2021
89bf4d2
Fix mount/unmount issues with Monaco
wylieconlon Mar 24, 2021
2334c1b
[Lens] Fully unmount React when flyout closes
wylieconlon Mar 24, 2021
3f2b10f
Merge remote-tracking branch 'origin/master' into lens/unmount-bug
wylieconlon Mar 25, 2021
502f74d
Fix bug with editor frame unmounting
wylieconlon Mar 25, 2021
5df313c
Fix type
wylieconlon Mar 25, 2021
dc20489
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 25, 2021
5c4b75f
Merge branch 'lens/unmount-bug' into lens/formulas
wylieconlon Mar 25, 2021
7dfed34
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 26, 2021
2382797
Add tests for monaco providers, add hover provider
wylieconlon Mar 26, 2021
f746acf
Add test for last_value
wylieconlon Mar 26, 2021
81eace1
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 29, 2021
387059e
Usability improvements
wylieconlon Mar 29, 2021
1065a76
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 30, 2021
46bd80f
Add KQL and Lucene named parameters
wylieconlon Mar 30, 2021
14ec327
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Mar 31, 2021
bbf55a2
Add kql, lucene completion and validation
wylieconlon Mar 31, 2021
9351572
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 1, 2021
c7e4154
Fix autocomplete on weird characters and properly connect KQL
wylieconlon Apr 1, 2021
15ccac2
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 2, 2021
08a985c
Highlight functions that have additional requirements after validating
wylieconlon Apr 2, 2021
daa5685
Fix type error and move help text to popover
wylieconlon Apr 2, 2021
ccf7266
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 5, 2021
0c1cfa9
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 5, 2021
239c72d
Fix escape characters inside KQL
wylieconlon Apr 5, 2021
fa57951
:bug: Fix dataType issue when moving over to Formula
dej611 Apr 6, 2021
3da8f82
Merge branch 'lens/formula-error-handling' of github.com:dej611/kiban…
dej611 Apr 6, 2021
1fd06bf
Automatically insert single quotes on every named param
wylieconlon Apr 6, 2021
b62f96e
Only insert single quotes when typing kql= or lucene=
wylieconlon Apr 8, 2021
d563cb5
Reorganize help popover
wylieconlon Apr 8, 2021
32fdfbf
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 21, 2021
c81b47c
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 21, 2021
edb522d
Fix merge issues
wylieconlon Apr 21, 2021
87b435b
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 27, 2021
7169655
Update grammar for formulas
wylieconlon Apr 27, 2021
e01bca8
Fix bad merge
wylieconlon Apr 27, 2021
ec493d1
Rough fullscreen mode
wylieconlon Apr 28, 2021
255a40f
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon Apr 28, 2021
90cff4a
Type updates
wylieconlon Apr 28, 2021
12391f6
Pass through fullscreen state
wylieconlon Apr 28, 2021
83ae9bf
Remove more chrome from full screen mode
wylieconlon Apr 29, 2021
f520d2f
Fix minor bugs in formula typing
wylieconlon Apr 30, 2021
23f65d8
Merge remote-tracking branch 'origin/master' into lens/formulas
wylieconlon May 4, 2021
5a26025
🐛 Decouple column order of references and output
wylieconlon May 4, 2021
e6ff6d7
🔧 Fix tests and types
wylieconlon May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/plugins/kibana_react/public/code_editor/code_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export interface Props {
/**
* Options for the Monaco Code Editor
* Documentation of options can be found here:
* https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html
* https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandaloneeditorconstructionoptions.html
*/
options?: monaco.editor.IEditorConstructionOptions;
options?: monaco.editor.IStandaloneEditorConstructionOptions;

/**
* Suggestion provider for autocompletion
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/kibana_react/public/code_editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const Fallback = () => (
</EuiDelayRender>
);

export type CodeEditorProps = Props;

export const CodeEditor: React.FunctionComponent<Props> = (props) => {
const darkMode = useUiSetting<boolean>('theme:darkMode');
return (
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/shareable_runtime/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
'src/plugins/data/public/expressions/interpreter'
),
'kbn/interpreter': path.resolve(KIBANA_ROOT, 'packages/kbn-interpreter/target/common'),
tinymath: path.resolve(KIBANA_ROOT, 'node_modules/tinymath/lib/tinymath.es5.js'),
tinymath: path.resolve(KIBANA_ROOT, 'node_modules/tinymath/lib/tinymath.min.js'),
core_app_image_assets: path.resolve(KIBANA_ROOT, 'src/core/public/core_app/images'),
},
extensions: ['.js', '.json', '.ts', '.tsx', '.scss'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function DimensionContainer({
}: {
isOpen: boolean;
handleClose: () => void;
panel: React.ReactElement;
panel: React.ReactElement | null;
groupLabel: string;
}) {
const [focusTrapIsEnabled, setFocusTrapIsEnabled] = useState(false);
Expand All @@ -51,7 +51,19 @@ export function DimensionContainer({

return isOpen ? (
<EuiFocusTrap disabled={!focusTrapIsEnabled} clickOutsideDisables={true}>
<EuiOutsideClickDetector onOutsideClick={closeFlyout} isDisabled={!isOpen}>
<EuiOutsideClickDetector
onOutsideClick={(e) => {
let current = e.target as HTMLElement;
while (current) {
if (current?.getAttribute?.('data-test-subj') === 'lnsFormulaWidget') {
return;
}
current = current.parentNode as HTMLElement;
}
closeFlyout();
}}
isDisabled={!isOpen}
>
<div
role="dialog"
aria-labelledby="lnsDimensionContainerTitle"
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/id_generator/id_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import uuid from 'uuid/v4';

export function generateId() {
return uuid();
return 'c' + uuid().replaceAll(/-/g, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this as a quick-fix to get the feature working - I guess it's fine to keep it in the long run, but we have to make sure there are no issues if an existing Lens vis already uses classical uuid ids and the user transitions to formula

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiFormLabel,
EuiToolTip,
EuiText,
EuiTabbedContent,
} from '@elastic/eui';
import { IndexPatternDimensionEditorProps } from './dimension_panel';
import { OperationSupportMatrix } from './operation_support';
Expand Down Expand Up @@ -150,8 +151,11 @@ export function DimensionEditor(props: DimensionEditorProps) {

const ParamEditor = selectedOperationDefinition?.paramEditor;

const [temporaryQuickFunction, setQuickFunction] = useState(false);

const possibleOperations = useMemo(() => {
return Object.values(operationDefinitionMap)
.filter(({ hidden }) => !hidden)
.sort((op1, op2) => {
return op1.displayName.localeCompare(op2.displayName);
})
Expand Down Expand Up @@ -243,6 +247,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
onClick() {
if (
operationDefinitionMap[operationType].input === 'none' ||
operationDefinitionMap[operationType].input === 'managedReference' ||
operationDefinitionMap[operationType].input === 'fullReference'
) {
// Clear invalid state because we are reseting to a valid column
Expand Down Expand Up @@ -320,7 +325,8 @@ export function DimensionEditor(props: DimensionEditorProps) {

// Need to workout early on the error to decide whether to show this or an help text
const fieldErrorMessage =
(selectedOperationDefinition?.input !== 'fullReference' ||
((selectedOperationDefinition?.input !== 'fullReference' &&
selectedOperationDefinition?.input !== 'managedReference') ||
(incompleteOperation && operationDefinitionMap[incompleteOperation].input === 'field')) &&
getErrorMessage(
selectedColumn,
Expand All @@ -329,8 +335,14 @@ export function DimensionEditor(props: DimensionEditorProps) {
currentFieldIsInvalid
);

return (
<div id={columnId}>
const shouldDisplayExtraOptions =
!currentFieldIsInvalid &&
!incompleteInfo &&
selectedColumn &&
selectedColumn.operationType !== 'formula';

const quickFunctions = (
<>
<div className="lnsIndexPatternDimensionEditor__section lnsIndexPatternDimensionEditor__section--shaded">
<EuiFormLabel>
{i18n.translate('xpack.lens.indexPattern.functionsLabel', {
Expand Down Expand Up @@ -388,7 +400,8 @@ export function DimensionEditor(props: DimensionEditorProps) {

{!selectedColumn ||
selectedOperationDefinition?.input === 'field' ||
(incompleteOperation && operationDefinitionMap[incompleteOperation].input === 'field') ? (
(incompleteOperation && operationDefinitionMap[incompleteOperation].input === 'field') ||
temporaryQuickFunction ? (
<EuiFormRow
data-test-subj="indexPattern-field-selection-row"
label={i18n.translate('xpack.lens.indexPattern.chooseField', {
Expand Down Expand Up @@ -448,18 +461,17 @@ export function DimensionEditor(props: DimensionEditorProps) {
</EuiFormRow>
) : null}

{!currentFieldIsInvalid && !incompleteInfo && selectedColumn && ParamEditor && (
<>
<ParamEditor
layer={state.layers[layerId]}
updateLayer={setStateWrapper}
columnId={columnId}
currentColumn={state.layers[layerId].columns[columnId]}
dateRange={dateRange}
indexPattern={currentIndexPattern}
{...services}
/>
</>
{shouldDisplayExtraOptions && ParamEditor && (
<ParamEditor
layer={state.layers[layerId]}
updateLayer={setStateWrapper}
columnId={columnId}
currentColumn={state.layers[layerId].columns[columnId]}
dateRange={dateRange}
indexPattern={currentIndexPattern}
operationDefinitionMap={operationDefinitionMap}
{...services}
/>
)}

{!currentFieldIsInvalid && !incompleteInfo && selectedColumn && (
Expand Down Expand Up @@ -525,6 +537,77 @@ export function DimensionEditor(props: DimensionEditorProps) {
</div>

<EuiSpacer size="s" />
</>
);

const tabs = [
{
id: 'quickFunctions',
name: i18n.translate('xpack.lens.indexPattern.quickFunctionsLabel', {
defaultMessage: 'Quick functions',
}),
content: quickFunctions,
},
{
id: 'formula',
name: i18n.translate('xpack.lens.indexPattern.formulaLabel', {
defaultMessage: 'Formula',
}),
content: ParamEditor && (
<>
<ParamEditor
layer={state.layers[layerId]}
updateLayer={setStateWrapper}
columnId={columnId}
currentColumn={state.layers[layerId].columns[columnId]}
dateRange={dateRange}
indexPattern={currentIndexPattern}
operationDefinitionMap={operationDefinitionMap}
{...services}
/>
</>
),
},
];

return (
<div id={columnId}>
{operationSupportMatrix.operationWithoutField.has('formula') ? (
<EuiTabbedContent
tabs={tabs}
selectedTab={
selectedOperationDefinition?.type === 'formula' && !temporaryQuickFunction
? tabs[1]
: tabs[0]
}
onTabClick={(selectedTab) => {
if (
selectedTab.id === 'quickFunctions' &&
selectedColumn?.operationType === 'formula'
) {
// Temporary switch to quick function ui
setQuickFunction(true);
} else if (selectedColumn?.operationType !== 'formula') {
setQuickFunction(false);
const newLayer = insertOrReplaceColumn({
layer: props.state.layers[props.layerId],
indexPattern: currentIndexPattern,
columnId,
op: 'formula',
visualizationGroups: dimensionGroups,
});
setStateWrapper(newLayer);
trackUiEvent(`indexpattern_dimension_operation_formula`);
return;
} else if (selectedTab.id === 'formula') {
setQuickFunction(false);
}
}}
size="s"
/>
) : (
quickFunctions
)}

{!currentFieldIsInvalid && (
<div className="lnsIndexPatternDimensionEditor__section">
Expand Down Expand Up @@ -591,7 +674,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
function getErrorMessage(
selectedColumn: IndexPatternColumn | undefined,
incompleteOperation: boolean,
input: 'none' | 'field' | 'fullReference' | undefined,
input: 'none' | 'field' | 'fullReference' | 'managedReference' | undefined,
fieldInvalid: boolean
) {
if (selectedColumn && incompleteOperation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const operationPanels = getOperationDisplay();

export interface ReferenceEditorProps {
layer: IndexPatternLayer;
selectionStyle: 'full' | 'field';
selectionStyle: 'full' | 'field' | 'hidden';
validation: RequiredReference;
columnId: string;
updateLayer: (newLayer: IndexPatternLayer) => void;
Expand Down Expand Up @@ -197,6 +197,10 @@ export function ReferenceEditor(props: ReferenceEditorProps) {
return;
}

if (selectionStyle === 'hidden') {
return null;
}

const selectedOption = incompleteOperation
? [functionOptions.find(({ value }) => value === incompleteOperation)!]
: column
Expand Down Expand Up @@ -340,6 +344,7 @@ export function ReferenceEditor(props: ReferenceEditorProps) {
columnId={columnId}
indexPattern={currentIndexPattern}
dateRange={dateRange}
operationDefinitionMap={operationDefinitionMap}
{...services}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const counterRateOperation: OperationDefinition<
selectionStyle: 'field',
requiredReferences: [
{
input: ['field'],
input: ['field', 'managedReference'],
specificOperations: ['max'],
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const cumulativeSumOperation: OperationDefinition<
selectionStyle: 'field',
requiredReferences: [
{
input: ['field'],
input: ['field', 'managedReference'],
specificOperations: ['count', 'sum'],
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const derivativeOperation: OperationDefinition<
selectionStyle: 'full',
requiredReferences: [
{
input: ['field'],
input: ['field', 'managedReference'],
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const ofName = buildLabelFunction((name?: string) => {
});
});

const WINDOW_DEFAULT_VALUE = 5;

export type MovingAverageIndexPatternColumn = FormattedIndexPatternColumn &
ReferenceBasedIndexPatternColumn & {
operationType: 'moving_average';
Expand All @@ -58,10 +60,11 @@ export const movingAverageOperation: OperationDefinition<
selectionStyle: 'full',
requiredReferences: [
{
input: ['field'],
input: ['field', 'managedReference'],
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed,
},
],
operationParams: [{ name: 'window', type: 'number', required: true }],
getPossibleOperation: (indexPattern) => {
if (hasDateField(indexPattern)) {
return {
Expand All @@ -79,8 +82,12 @@ export const movingAverageOperation: OperationDefinition<
window: [(layer.columns[columnId] as MovingAverageIndexPatternColumn).params.window],
});
},
buildColumn: ({ referenceIds, previousColumn, layer }) => {
buildColumn: (
{ referenceIds, previousColumn, layer },
columnParams = { window: WINDOW_DEFAULT_VALUE }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a default value for window, do we want to keep the named argument in the formula mandatory? I guess it would be OK to omit it and fall back to this default

) => {
const metric = layer.columns[referenceIds[0]];
const { window = WINDOW_DEFAULT_VALUE } = columnParams;
return {
label: ofName(metric?.label, previousColumn?.timeScale),
dataType: 'number',
Expand All @@ -91,7 +98,7 @@ export const movingAverageOperation: OperationDefinition<
timeScale: previousColumn?.timeScale,
filter: previousColumn?.filter,
params: {
window: 5,
window,
...getFormatFromPreviousColumn(previousColumn),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const defaultOptions = {
data: dataStart,
http: {} as HttpSetup,
indexPattern: indexPattern1,
operationDefinitionMap: {},
};

describe('date_histogram', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const dateHistogramOperation: OperationDefinition<
}),
input: 'field',
priority: 5, // Highest priority level used
operationParams: [{ name: 'interval', type: 'string', required: false }],
getErrorMessage: (layer, columnId, indexPattern) =>
getInvalidFieldMessage(layer.columns[columnId] as FieldBasedIndexPatternColumn, indexPattern),
getHelpMessage: (props) => <AutoDateHistogramPopover {...props} />,
Expand All @@ -75,8 +76,8 @@ export const dateHistogramOperation: OperationDefinition<
}
},
getDefaultLabel: (column, indexPattern) => getSafeName(column.sourceField, indexPattern),
buildColumn({ field }) {
let interval = autoInterval;
buildColumn({ field }, columnParams) {
let interval = columnParams?.interval ?? autoInterval;
let timeZone: string | undefined;
if (field.aggregationRestrictions && field.aggregationRestrictions.date_histogram) {
interval = restrictedInterval(field.aggregationRestrictions) as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const defaultProps = {
data: dataPluginMock.createStartContract(),
http: {} as HttpSetup,
indexPattern: createMockedIndexPattern(),
operationDefinitionMap: {},
};

// mocking random id generator function
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.lnsFormulaOverflow {
// Needs to be higher than the modal and all flyouts
z-index: $euiZLevel9 + 1;
}
Loading