-
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.
Merge branch 'master' into config-breaking/remove-deprecated-configs-…
…misc
- Loading branch information
Showing
336 changed files
with
18,128 additions
and
4,528 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
Validating CODEOWNERS rules …
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
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,9 @@ | ||
## Partial Results Example | ||
|
||
The partial results is a feature of the expressions plugin allowing to emit intermediate execution results over time. | ||
|
||
This example plugin demonstrates: | ||
|
||
1. An expression function emitting a datatable with intermediate results (`getEvents`). | ||
2. An expression function emitting an infinite number of results (`countEvent`). | ||
3. A combination of those two functions using the `mapColumn` function that continuously updates the resulting table. |
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,12 @@ | ||
{ | ||
"id": "paertialResultsExample", | ||
"version": "0.1.0", | ||
"kibanaVersion": "kibana", | ||
"ui": true, | ||
"owner": { | ||
"name": "App Services", | ||
"githubTeam": "kibana-app-services" | ||
}, | ||
"description": "A plugin demonstrating partial results in the expressions plugin", | ||
"requiredPlugins": ["developerExamples", "expressions"] | ||
} |
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,90 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { pluck } from 'rxjs/operators'; | ||
import { | ||
EuiBasicTable, | ||
EuiCallOut, | ||
EuiCodeBlock, | ||
EuiPage, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiPageHeader, | ||
EuiPageHeaderSection, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import type { Datatable } from 'src/plugins/expressions'; | ||
import { ExpressionsContext } from './expressions_context'; | ||
|
||
const expression = `getEvents | ||
| mapColumn name="Count" expression={ | ||
countEvent {pluck "event"} | ||
} | ||
`; | ||
|
||
export function App() { | ||
const expressions = useContext(ExpressionsContext); | ||
const [datatable, setDatatable] = useState<Datatable>(); | ||
|
||
useEffect(() => { | ||
const subscription = expressions | ||
?.execute<null, Datatable>(expression, null) | ||
.getData() | ||
.pipe(pluck('result')) | ||
.subscribe((value) => setDatatable(value as Datatable)); | ||
|
||
return () => subscription?.unsubscribe(); | ||
}, [expressions]); | ||
|
||
return ( | ||
<EuiPage> | ||
<EuiPageBody style={{ maxWidth: 1200, margin: '0 auto' }}> | ||
<EuiPageHeader> | ||
<EuiPageHeaderSection> | ||
<EuiTitle size="l"> | ||
<h1>Partial Results Demo</h1> | ||
</EuiTitle> | ||
</EuiPageHeaderSection> | ||
</EuiPageHeader> | ||
<EuiPageContent> | ||
<EuiPageContentBody style={{ maxWidth: 800, margin: '0 auto' }}> | ||
<EuiText data-test-subj="example-help"> | ||
<p> | ||
This example listens for the window events and adds them to the table along with a | ||
trigger counter. | ||
</p> | ||
</EuiText> | ||
<EuiSpacer size={'m'} /> | ||
<EuiCodeBlock>{expression}</EuiCodeBlock> | ||
<EuiSpacer size={'m'} /> | ||
{datatable ? ( | ||
<EuiBasicTable | ||
textOnly={true} | ||
data-test-subj={'example-table'} | ||
columns={datatable.columns?.map(({ id: field, name }) => ({ | ||
field, | ||
name, | ||
'data-test-subj': `example-column-${field.toLowerCase()}`, | ||
}))} | ||
items={datatable.rows ?? []} | ||
/> | ||
) : ( | ||
<EuiCallOut color="success"> | ||
<p>Click or press any key.</p> | ||
</EuiCallOut> | ||
)} | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</EuiPage> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/partial_results_example/public/app/expressions_context.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,12 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { createContext } from 'react'; | ||
import type { ExpressionsServiceStart } from 'src/plugins/expressions'; | ||
|
||
export const ExpressionsContext = createContext<ExpressionsServiceStart | undefined>(undefined); |
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
40 changes: 40 additions & 0 deletions
40
examples/partial_results_example/public/functions/count_event.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,40 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Observable, fromEvent } from 'rxjs'; | ||
import { scan, startWith } from 'rxjs/operators'; | ||
import type { ExpressionFunctionDefinition } from 'src/plugins/expressions'; | ||
|
||
export interface CountEventArguments { | ||
event: string; | ||
} | ||
|
||
export const countEvent: ExpressionFunctionDefinition< | ||
'countEvent', | ||
null, | ||
CountEventArguments, | ||
Observable<number> | ||
> = { | ||
name: 'countEvent', | ||
type: 'number', | ||
help: 'Subscribes for an event and counts a number of triggers.', | ||
args: { | ||
event: { | ||
aliases: ['_'], | ||
types: ['string'], | ||
help: 'The event name.', | ||
required: true, | ||
}, | ||
}, | ||
fn(input, { event }) { | ||
return fromEvent(window, event).pipe( | ||
scan((count) => count + 1, 1), | ||
startWith(1) | ||
); | ||
}, | ||
}; |
51 changes: 51 additions & 0 deletions
51
examples/partial_results_example/public/functions/get_events.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,51 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Observable, fromEvent, merge } from 'rxjs'; | ||
import { distinct, map, pluck, scan, take } from 'rxjs/operators'; | ||
import type { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions'; | ||
|
||
const EVENTS: Array<keyof WindowEventMap> = [ | ||
'mousedown', | ||
'mouseup', | ||
'click', | ||
'keydown', | ||
'keyup', | ||
'keypress', | ||
]; | ||
|
||
export const getEvents: ExpressionFunctionDefinition< | ||
'getEvents', | ||
null, | ||
{}, | ||
Observable<Datatable> | ||
> = { | ||
name: 'getEvents', | ||
type: 'datatable', | ||
help: 'Listens for the window events and returns a table with the triggered ones.', | ||
args: {}, | ||
fn() { | ||
return merge(...EVENTS.map((event) => fromEvent(window, event))).pipe( | ||
pluck('type'), | ||
distinct(), | ||
take(EVENTS.length), | ||
scan((events, event) => [...events, event], [] as string[]), | ||
map((events) => ({ | ||
type: 'datatable', | ||
columns: [ | ||
{ | ||
id: 'event', | ||
meta: { type: 'string' }, | ||
name: 'Event', | ||
}, | ||
], | ||
rows: Array.from(events).map((event) => ({ event })), | ||
})) | ||
); | ||
}, | ||
}; |
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
32 changes: 32 additions & 0 deletions
32
examples/partial_results_example/public/functions/pluck.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,32 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions'; | ||
|
||
export interface PluckArguments { | ||
key: string; | ||
} | ||
|
||
export const pluck: ExpressionFunctionDefinition<'pluck', Datatable, PluckArguments, unknown> = { | ||
name: 'pluck', | ||
inputTypes: ['datatable'], | ||
help: 'Takes a cell from the first table row.', | ||
args: { | ||
key: { | ||
aliases: ['_'], | ||
types: ['string'], | ||
help: 'The column id.', | ||
required: true, | ||
}, | ||
}, | ||
fn({ rows }, { key }) { | ||
const [{ [key]: value }] = rows; | ||
|
||
return value; | ||
}, | ||
}; |
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,12 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { PartialResultsExamplePlugin } from './plugin'; | ||
|
||
export function plugin() { | ||
return new PartialResultsExamplePlugin(); | ||
} |
Oops, something went wrong.