-
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.
Browse files
Browse the repository at this point in the history
…117613) * Revert "Revert "[Canvas] By-Value Embeddables (#113827)" (#116527)" This reverts commit 9e6e845. * Fix ts error Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
416182a
commit 8a0e544
Showing
60 changed files
with
1,329 additions
and
127 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
28 changes: 22 additions & 6 deletions
28
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,9 +1,25 @@ | ||
.quickButtonGroup { | ||
.quickButtonGroup__button { | ||
background-color: $euiColorEmptyShade; | ||
// 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; | ||
// sass-lint:disable-block no-important | ||
border-width: $euiBorderWidthThin !important; | ||
border-style: solid !important; | ||
border-color: $euiBorderColor !important; | ||
} | ||
|
||
.quickButtonGroup__button:first-of-type { | ||
// sass-lint:disable-block no-important | ||
border-top-left-radius: $euiBorderRadius !important; | ||
border-bottom-left-radius: $euiBorderRadius !important; | ||
} | ||
|
||
.quickButtonGroup__button:last-of-type { | ||
// 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.