-
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.
[examples] expressions explorer (#88344)
- Loading branch information
Showing
31 changed files
with
1,085 additions
and
3 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...lic/kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.ast.md
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsInspectorAdapter](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.md) > [ast](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.ast.md) | ||
|
||
## ExpressionsInspectorAdapter.ast property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
get ast(): any; | ||
``` |
22 changes: 22 additions & 0 deletions
22
.../kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.logast.md
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,22 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsInspectorAdapter](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.md) > [logAST](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.logast.md) | ||
|
||
## ExpressionsInspectorAdapter.logAST() method | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
logAST(ast: any): void; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| ast | <code>any</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`void` | ||
|
24 changes: 24 additions & 0 deletions
24
.../public/kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.md
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,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsInspectorAdapter](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.md) | ||
|
||
## ExpressionsInspectorAdapter class | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class ExpressionsInspectorAdapter extends EventEmitter | ||
``` | ||
## Properties | ||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [ast](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.ast.md) | | <code>any</code> | | | ||
## Methods | ||
| Method | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [logAST(ast)](./kibana-plugin-plugins-expressions-public.expressionsinspectoradapter.logast.md) | | | | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## expressions explorer | ||
|
||
This example expressions explorer app shows how to: | ||
- to run expression | ||
- to render expression output | ||
- emit events from expression renderer and handle them | ||
|
||
To run this example, use the command `yarn start --run-examples`. |
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,10 @@ | ||
{ | ||
"id": "expressionsExplorer", | ||
"version": "0.0.1", | ||
"kibanaVersion": "kibana", | ||
"server": false, | ||
"ui": true, | ||
"requiredPlugins": ["expressions", "inspector", "uiActions", "developerExamples"], | ||
"optionalPlugins": [], | ||
"requiredBundles": [] | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/expressions_explorer/public/actions/navigate_action.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,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { createAction } from '../../../../src/plugins/ui_actions/public'; | ||
|
||
export const ACTION_NAVIGATE = 'ACTION_NAVIGATE'; | ||
|
||
export const createNavigateAction = () => | ||
createAction({ | ||
id: ACTION_NAVIGATE, | ||
type: ACTION_NAVIGATE, | ||
getDisplayName: () => 'Navigate', | ||
execute: async (event: any) => { | ||
window.location.href = event.href; | ||
}, | ||
}); |
15 changes: 15 additions & 0 deletions
15
examples/expressions_explorer/public/actions/navigate_trigger.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,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { Trigger } from '../../../../src/plugins/ui_actions/public'; | ||
|
||
export const NAVIGATE_TRIGGER_ID = 'NAVIGATE_TRIGGER_ID'; | ||
|
||
export const navigateTrigger: Trigger = { | ||
id: NAVIGATE_TRIGGER_ID, | ||
}; |
102 changes: 102 additions & 0 deletions
102
examples/expressions_explorer/public/actions_and_expressions.tsx
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,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiFlexItem, | ||
EuiFlexGroup, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiPageHeader, | ||
EuiPageHeaderSection, | ||
EuiPanel, | ||
EuiText, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { | ||
ExpressionsStart, | ||
ReactExpressionRenderer, | ||
ExpressionsInspectorAdapter, | ||
} from '../../../src/plugins/expressions/public'; | ||
import { ExpressionEditor } from './editor/expression_editor'; | ||
import { UiActionsStart } from '../../../src/plugins/ui_actions/public'; | ||
import { NAVIGATE_TRIGGER_ID } from './actions/navigate_trigger'; | ||
|
||
interface Props { | ||
expressions: ExpressionsStart; | ||
actions: UiActionsStart; | ||
} | ||
|
||
export function ActionsExpressionsExample({ expressions, actions }: Props) { | ||
const [expression, updateExpression] = useState( | ||
'button name="click me" href="http://www.google.com"' | ||
); | ||
|
||
const expressionChanged = (value: string) => { | ||
updateExpression(value); | ||
}; | ||
|
||
const inspectorAdapters = { | ||
expression: new ExpressionsInspectorAdapter(), | ||
}; | ||
|
||
const handleEvents = (event: any) => { | ||
if (event.id !== 'NAVIGATE') return; | ||
// enrich event context with some extra data | ||
event.baseUrl = 'http://www.google.com'; | ||
|
||
actions.executeTriggerActions(NAVIGATE_TRIGGER_ID, event.value); | ||
}; | ||
|
||
return ( | ||
<EuiPageBody> | ||
<EuiPageHeader> | ||
<EuiPageHeaderSection> | ||
<EuiTitle size="l"> | ||
<h1>Actions from expression renderers</h1> | ||
</EuiTitle> | ||
</EuiPageHeaderSection> | ||
</EuiPageHeader> | ||
<EuiPageContent> | ||
<EuiPageContentBody> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<EuiText> | ||
Here you can play with sample `button` which takes a url as configuration and | ||
displays a button which emits custom BUTTON_CLICK trigger to which we have attached | ||
a custom action which performs the navigation. | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
||
<EuiFlexGroup gutterSize="l"> | ||
<EuiFlexItem> | ||
<EuiPanel data-test-subj="expressionEditor" paddingSize="none" role="figure"> | ||
<ExpressionEditor value={expression} onChange={expressionChanged} /> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiPanel paddingSize="none" role="figure"> | ||
<ReactExpressionRenderer | ||
expression={expression} | ||
debug={true} | ||
inspectorAdapters={inspectorAdapters} | ||
onEvent={handleEvents} | ||
renderError={(message: any) => { | ||
return <div>{message}</div>; | ||
}} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
); | ||
} |
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,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { | ||
EuiPage, | ||
EuiPageHeader, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiSpacer, | ||
EuiText, | ||
EuiLink, | ||
} from '@elastic/eui'; | ||
import { AppMountParameters } from '../../../src/core/public'; | ||
import { ExpressionsStart } from '../../../src/plugins/expressions/public'; | ||
import { Start as InspectorStart } from '../../../src/plugins/inspector/public'; | ||
import { RunExpressionsExample } from './run_expressions'; | ||
import { RenderExpressionsExample } from './render_expressions'; | ||
import { ActionsExpressionsExample } from './actions_and_expressions'; | ||
import { UiActionsStart } from '../../../src/plugins/ui_actions/public'; | ||
|
||
interface Props { | ||
expressions: ExpressionsStart; | ||
inspector: InspectorStart; | ||
actions: UiActionsStart; | ||
} | ||
|
||
const ExpressionsExplorer = ({ expressions, inspector, actions }: Props) => { | ||
return ( | ||
<EuiPage> | ||
<EuiPageBody> | ||
<EuiPageHeader>Expressions Explorer</EuiPageHeader> | ||
<EuiPageContent> | ||
<EuiPageContentBody> | ||
<EuiText> | ||
<p> | ||
There are a couple of ways to run the expressions. Below some of the options are | ||
demonstrated. You can read more about it{' '} | ||
<EuiLink | ||
href={ | ||
'https://github.com/elastic/kibana/blob/master/src/plugins/expressions/README.asciidoc' | ||
} | ||
> | ||
here | ||
</EuiLink> | ||
</p> | ||
</EuiText> | ||
|
||
<EuiSpacer /> | ||
|
||
<RunExpressionsExample expressions={expressions} inspector={inspector} /> | ||
|
||
<EuiSpacer /> | ||
|
||
<RenderExpressionsExample expressions={expressions} inspector={inspector} /> | ||
|
||
<EuiSpacer /> | ||
|
||
<ActionsExpressionsExample expressions={expressions} actions={actions} /> | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</EuiPage> | ||
); | ||
}; | ||
|
||
export const renderApp = (props: Props, { element }: AppMountParameters) => { | ||
ReactDOM.render(<ExpressionsExplorer {...props} />, element); | ||
|
||
return () => ReactDOM.unmountComponentAtNode(element); | ||
}; |
35 changes: 35 additions & 0 deletions
35
examples/expressions_explorer/public/editor/expression_editor.tsx
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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCodeEditor } from '@elastic/eui'; | ||
|
||
interface Props { | ||
value: string; | ||
onChange: (value: string) => void; | ||
} | ||
|
||
export function ExpressionEditor({ value, onChange }: Props) { | ||
return ( | ||
<EuiCodeEditor | ||
mode="javascript" | ||
theme="github" | ||
width="100%" | ||
value={value} | ||
onChange={onChange} | ||
setOptions={{ | ||
fontSize: '14px', | ||
enableBasicAutocompletion: true, | ||
enableSnippets: true, | ||
enableLiveAutocompletion: true, | ||
}} | ||
onBlur={() => {}} | ||
aria-label="Code Editor" | ||
/> | ||
); | ||
} |
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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { ExpressionFunctionDefinition } from '../../../../src/plugins/expressions/common'; | ||
|
||
interface Arguments { | ||
href: string; | ||
name: string; | ||
} | ||
|
||
export type ExpressionFunctionButton = ExpressionFunctionDefinition< | ||
'button', | ||
unknown, | ||
Arguments, | ||
unknown | ||
>; | ||
|
||
export const buttonFn: ExpressionFunctionButton = { | ||
name: 'button', | ||
args: { | ||
href: { | ||
help: i18n.translate('expressions.functions.font.args.href', { | ||
defaultMessage: 'Link to which to navigate', | ||
}), | ||
types: ['string'], | ||
required: true, | ||
}, | ||
name: { | ||
help: i18n.translate('expressions.functions.font.args.name', { | ||
defaultMessage: 'Name of the button', | ||
}), | ||
types: ['string'], | ||
default: 'button', | ||
}, | ||
}, | ||
help: 'Configures the button', | ||
fn: (input: unknown, args: Arguments) => { | ||
return { | ||
type: 'render', | ||
as: 'button', | ||
value: args, | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.