-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed telemetry Updates expression on input change Fixed ts errors
- Loading branch information
Showing
14 changed files
with
289 additions
and
24 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
133 changes: 133 additions & 0 deletions
133
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,133 @@ | ||
/* | ||
* 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 { PaletteOutput } from 'src/plugins/charts/common'; | ||
import { TimeRange } from 'src/plugins/data/public'; | ||
import { EmbeddableInput as Input } from 'src/plugins/embeddable/public'; | ||
import { Filter } from '@kbn/es-query'; | ||
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters'; | ||
import { ExpressionValueFilter, TimeRange as TimeRangeArg } from '../../../types'; | ||
import { EmbeddableExpressionType, EmbeddableExpression } from '../../expression_types'; | ||
import { getFunctionHelp } from '../../../i18n'; | ||
import { SavedObjectReference } from '../../../../../../src/core/types'; | ||
|
||
interface Arguments { | ||
id: string; | ||
title: string | null; | ||
type: string; | ||
timerange: TimeRangeArg | null; | ||
palette?: PaletteOutput; | ||
hideTitle?: boolean; | ||
} | ||
|
||
const defaultTimeRange = { | ||
from: 'now-15m', | ||
to: 'now', | ||
}; | ||
|
||
export type EmbeddableInput = Input & { | ||
id: string; | ||
timeRange?: TimeRange; | ||
filters?: Filter[]; | ||
palette?: PaletteOutput; | ||
}; | ||
|
||
type Return = EmbeddableExpression<EmbeddableInput>; | ||
|
||
export function embeddable(): ExpressionFunctionDefinition< | ||
'embeddable', | ||
ExpressionValueFilter | null, | ||
Arguments, | ||
Return | ||
> { | ||
// TODO: write help text | ||
const { help, args: argHelp } = getFunctionHelp().embeddable; | ||
|
||
return { | ||
name: 'embeddable', | ||
help, | ||
args: { | ||
id: { | ||
types: ['string'], | ||
required: false, | ||
help: argHelp.id, | ||
}, | ||
type: { | ||
types: ['string'], | ||
required: true, | ||
help: argHelp.id, | ||
}, | ||
timerange: { | ||
types: ['timerange'], | ||
help: argHelp.timerange, | ||
required: false, | ||
}, | ||
title: { | ||
types: ['string'], | ||
help: argHelp.title, | ||
required: false, | ||
}, | ||
hideTitle: { | ||
types: ['boolean'], | ||
help: argHelp.hideTitle as string, | ||
}, | ||
palette: { | ||
types: ['palette'], | ||
help: argHelp.palette!, | ||
required: false, | ||
}, | ||
}, | ||
type: EmbeddableExpressionType, | ||
fn: (input, args) => { | ||
const filters = input ? input.and : []; | ||
|
||
return { | ||
type: EmbeddableExpressionType, | ||
input: { | ||
id: args.id, | ||
filters: getQueryFilters(filters), | ||
timeRange: args.timerange || defaultTimeRange, | ||
title: args.title === null ? undefined : args.title, | ||
hidePanelTitles: args.hideTitle, | ||
disableTriggers: true, | ||
palette: args.palette, | ||
renderMode: 'noInteractivity', | ||
}, | ||
generatedAt: Date.now(), | ||
embeddableType: args.type, | ||
}; | ||
}, | ||
|
||
extract(state) { | ||
const refName = 'embeddable.id'; | ||
const refType = 'embeddable.embeddableType'; | ||
const references: SavedObjectReference[] = [ | ||
{ | ||
name: refName, | ||
type: refType, | ||
id: state.id[0] as string, | ||
}, | ||
]; | ||
return { | ||
state: { | ||
...state, | ||
id: [refName], | ||
}, | ||
references, | ||
}; | ||
}, | ||
|
||
inject(state, references) { | ||
const reference = references.find((ref) => ref.name === 'embeddable.id'); | ||
if (reference) { | ||
state.id[0] = reference.id; | ||
} | ||
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
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
48 changes: 48 additions & 0 deletions
48
...gins/canvas/canvas_plugin_src/renderers/embeddable/input_type_to_expression/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,48 @@ | ||
/* | ||
* 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 { toExpression as toExpressionString } from '@kbn/interpreter/common'; | ||
import { PaletteRegistry } from 'src/plugins/charts/public'; | ||
import { EmbeddableInput } from '../../../functions/external/embeddable'; | ||
|
||
export function toExpression( | ||
input: EmbeddableInput, | ||
embeddableType: string, | ||
palettes: PaletteRegistry | ||
): string { | ||
const expressionParts = [] as string[]; | ||
|
||
expressionParts.push('embeddable'); | ||
|
||
expressionParts.push(`id="${input.id}"`); | ||
|
||
expressionParts.push(`type="${embeddableType}"`); | ||
|
||
if (input.title !== undefined) { | ||
expressionParts.push(`title="${input.title}"`); | ||
} | ||
|
||
if (input.timeRange) { | ||
expressionParts.push( | ||
`timerange={timerange from="${input.timeRange.from}" to="${input.timeRange.to}"}` | ||
); | ||
} | ||
|
||
if (input.palette) { | ||
expressionParts.push( | ||
`palette={${toExpressionString( | ||
palettes.get(input.palette.name).toExpression(input.palette.params) | ||
)}}` | ||
); | ||
} | ||
|
||
if (input.hidePanelTitles !== undefined) { | ||
expressionParts.push(`hideTitle=${input.hidePanelTitles}`); | ||
} | ||
|
||
return expressionParts.join(' '); | ||
} |
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,37 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { embeddable } from '../../../canvas_plugin_src/functions/external/embeddable'; | ||
import { FunctionHelp } from '../function_help'; | ||
import { FunctionFactory } from '../../../types'; | ||
|
||
export const help: FunctionHelp<FunctionFactory<typeof embeddable>> = { | ||
help: i18n.translate('xpack.canvas.functions.embeddableHelpText', { | ||
defaultMessage: `Returns an embeddable`, | ||
}), | ||
args: { | ||
id: i18n.translate('xpack.canvas.functions.embeddable.args.idHelpText', { | ||
defaultMessage: `The ID of the embeddable saved object`, | ||
}), | ||
type: i18n.translate('xpack.canvas.functions.embeddable.args.typeHelpText', { | ||
defaultMessage: `The embeddable type`, | ||
}), | ||
timerange: i18n.translate('xpack.canvas.functions.embeddable.args.timerangeHelpText', { | ||
defaultMessage: `The timerange of data that should be included`, | ||
}), | ||
title: i18n.translate('xpack.canvas.functions.embeddable.args.titleHelpText', { | ||
defaultMessage: `The title for the Lens visualization object`, | ||
}), | ||
hideTitle: i18n.translate('xpack.canvas.functions.embeddable.args.titleHelpText', { | ||
defaultMessage: `The title for the Lens visualization object`, | ||
}), | ||
palette: i18n.translate('xpack.canvas.functions.embeddable.args.paletteHelpText', { | ||
defaultMessage: `The palette used for the Lens visualization`, | ||
}), | ||
}, | ||
}; |
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.