-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Canvas] By-Value Embeddables (#113827)
* [Canvas] Generic embeddable function (#104499) * Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment * [Canvas] Adds Save and Return Workflow (#111411) * [Canvas] Adds editor menu to Canvas (#113194) * Merge existing embeddable input with incoming embeddable input (#116026) * [Canvas] Extract and inject references for by-value embeddables (#115124) * Extract/inject references for by-value embeddables in embeddable function Fixed server interpreter setup Register external functions in canvas_plugin_src plugin def * Fixed ref name in embeddable.inject * Fixed ts errors * Fix missing type error Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
01292ce
commit bacd7f9
Showing
60 changed files
with
1,345 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 27 additions & 7 deletions
34
src/plugins/presentation_util/public/components/solution_toolbar/items/quick_group.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
.quickButtonGroup { | ||
.quickButtonGroup__button { | ||
background-color: $euiColorEmptyShade; | ||
@include kbnThemeStyle('v8') { | ||
// sass-lint:disable-block no-important | ||
border-width: $euiBorderWidthThin !important; | ||
border-style: solid !important; | ||
border-color: $euiBorderColor !important; | ||
.euiButtonGroup__buttons { | ||
border-radius: $euiBorderRadius; | ||
|
||
.quickButtonGroup__button { | ||
background-color: $euiColorEmptyShade; | ||
@include kbnThemeStyle('v8') { | ||
// sass-lint:disable-block no-important | ||
border-width: $euiBorderWidthThin !important; | ||
border-style: solid !important; | ||
border-color: $euiBorderColor !important; | ||
} | ||
} | ||
|
||
.quickButtonGroup__button:first-of-type { | ||
@include kbnThemeStyle('v8') { | ||
// sass-lint:disable-block no-important | ||
border-top-left-radius: $euiBorderRadius !important; | ||
border-bottom-left-radius: $euiBorderRadius !important; | ||
} | ||
} | ||
|
||
.quickButtonGroup__button:last-of-type { | ||
@include kbnThemeStyle('v8') { | ||
// sass-lint:disable-block no-important | ||
border-top-right-radius: $euiBorderRadius !important; | ||
border-bottom-right-radius: $euiBorderRadius !important; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/canvas/canvas_plugin_src/functions/external/embeddable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { embeddableFunctionFactory } from './embeddable'; | ||
import { getQueryFilters } from '../../../common/lib/build_embeddable_filters'; | ||
import { ExpressionValueFilter } from '../../../types'; | ||
import { encode } from '../../../common/lib/embeddable_dataurl'; | ||
import { InitializeArguments } from '.'; | ||
|
||
const filterContext: ExpressionValueFilter = { | ||
type: 'filter', | ||
and: [ | ||
{ | ||
type: 'filter', | ||
and: [], | ||
value: 'filter-value', | ||
column: 'filter-column', | ||
filterType: 'exactly', | ||
}, | ||
{ | ||
type: 'filter', | ||
and: [], | ||
column: 'time-column', | ||
filterType: 'time', | ||
from: '2019-06-04T04:00:00.000Z', | ||
to: '2019-06-05T04:00:00.000Z', | ||
}, | ||
], | ||
}; | ||
|
||
describe('embeddable', () => { | ||
const fn = embeddableFunctionFactory({} as InitializeArguments)().fn; | ||
const config = { | ||
id: 'some-id', | ||
timerange: { from: '15m', to: 'now' }, | ||
title: 'test embeddable', | ||
}; | ||
|
||
const args = { | ||
config: encode(config), | ||
type: 'visualization', | ||
}; | ||
|
||
it('accepts null context', () => { | ||
const expression = fn(null, args, {} as any); | ||
|
||
expect(expression.input.filters).toEqual([]); | ||
}); | ||
|
||
it('accepts filter context', () => { | ||
const expression = fn(filterContext, args, {} as any); | ||
const embeddableFilters = getQueryFilters(filterContext.and); | ||
|
||
expect(expression.input.filters).toEqual(embeddableFilters); | ||
}); | ||
}); |
145 changes: 145 additions & 0 deletions
145
x-pack/plugins/canvas/canvas_plugin_src/functions/external/embeddable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; | ||
import { ExpressionValueFilter, EmbeddableInput } from '../../../types'; | ||
import { EmbeddableExpressionType, EmbeddableExpression } from '../../expression_types'; | ||
import { getFunctionHelp } from '../../../i18n'; | ||
import { SavedObjectReference } from '../../../../../../src/core/types'; | ||
import { getQueryFilters } from '../../../common/lib/build_embeddable_filters'; | ||
import { decode, encode } from '../../../common/lib/embeddable_dataurl'; | ||
import { InitializeArguments } from '.'; | ||
|
||
export interface Arguments { | ||
config: string; | ||
type: string; | ||
} | ||
|
||
const defaultTimeRange = { | ||
from: 'now-15m', | ||
to: 'now', | ||
}; | ||
|
||
const baseEmbeddableInput = { | ||
timeRange: defaultTimeRange, | ||
disableTriggers: true, | ||
renderMode: 'noInteractivity', | ||
}; | ||
|
||
type Return = EmbeddableExpression<EmbeddableInput>; | ||
|
||
type EmbeddableFunction = ExpressionFunctionDefinition< | ||
'embeddable', | ||
ExpressionValueFilter | null, | ||
Arguments, | ||
Return | ||
>; | ||
|
||
export function embeddableFunctionFactory({ | ||
embeddablePersistableStateService, | ||
}: InitializeArguments): () => EmbeddableFunction { | ||
return function embeddable(): EmbeddableFunction { | ||
const { help, args: argHelp } = getFunctionHelp().embeddable; | ||
|
||
return { | ||
name: 'embeddable', | ||
help, | ||
args: { | ||
config: { | ||
aliases: ['_'], | ||
types: ['string'], | ||
required: true, | ||
help: argHelp.config, | ||
}, | ||
type: { | ||
types: ['string'], | ||
required: true, | ||
help: argHelp.type, | ||
}, | ||
}, | ||
context: { | ||
types: ['filter'], | ||
}, | ||
type: EmbeddableExpressionType, | ||
fn: (input, args) => { | ||
const filters = input ? input.and : []; | ||
|
||
const embeddableInput = decode(args.config) as EmbeddableInput; | ||
|
||
return { | ||
type: EmbeddableExpressionType, | ||
input: { | ||
...baseEmbeddableInput, | ||
...embeddableInput, | ||
filters: getQueryFilters(filters), | ||
}, | ||
generatedAt: Date.now(), | ||
embeddableType: args.type, | ||
}; | ||
}, | ||
|
||
extract(state) { | ||
const input = decode(state.config[0] as string); | ||
|
||
// extracts references for by-reference embeddables | ||
if (input.savedObjectId) { | ||
const refName = 'embeddable.savedObjectId'; | ||
|
||
const references: SavedObjectReference[] = [ | ||
{ | ||
name: refName, | ||
type: state.type[0] as string, | ||
id: input.savedObjectId as string, | ||
}, | ||
]; | ||
|
||
return { | ||
state, | ||
references, | ||
}; | ||
} | ||
|
||
// extracts references for by-value embeddables | ||
const { state: extractedState, references: extractedReferences } = | ||
embeddablePersistableStateService.extract({ | ||
...input, | ||
type: state.type[0], | ||
}); | ||
|
||
const { type, ...extractedInput } = extractedState; | ||
|
||
return { | ||
state: { ...state, config: [encode(extractedInput)], type: [type] }, | ||
references: extractedReferences, | ||
}; | ||
}, | ||
|
||
inject(state, references) { | ||
const input = decode(state.config[0] as string); | ||
const savedObjectReference = references.find( | ||
(ref) => ref.name === 'embeddable.savedObjectId' | ||
); | ||
|
||
// injects saved object id for by-references embeddable | ||
if (savedObjectReference) { | ||
input.savedObjectId = savedObjectReference.id; | ||
state.config[0] = encode(input); | ||
state.type[0] = savedObjectReference.type; | ||
} else { | ||
// injects references for by-value embeddables | ||
const { type, ...injectedInput } = embeddablePersistableStateService.inject( | ||
{ ...input, type: state.type[0] }, | ||
references | ||
); | ||
state.config[0] = encode(injectedInput); | ||
state.type[0] = type; | ||
} | ||
return state; | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.