forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opensearch-project:main' into main
- Loading branch information
Showing
216 changed files
with
1,842 additions
and
11,680 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
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,12 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
module.exports = { | ||
root: true, | ||
extends: ['@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended'], | ||
rules: { | ||
'@osd/eslint/require-license-header': 'off', | ||
}, | ||
}; |
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,7 @@ | ||
{ | ||
"prefix": "expressionsExample", | ||
"paths": { | ||
"expressionsExample": "." | ||
}, | ||
"translations": ["translations/ja-JP.json"] | ||
} |
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 @@ | ||
# expressions_example | ||
|
||
An OpenSearch Dashboards example plugin to demonstrate the expressions plugin | ||
|
||
--- | ||
|
||
## Development | ||
|
||
See the [OpenSearch Dashboards contributing | ||
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/master/CONTRIBUTING.md) for instructions | ||
setting up your development environment. |
7 changes: 7 additions & 0 deletions
7
examples/expressions_example/common/expression_functions/action/index.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,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './quick_form_fn'; | ||
export * from './quick_form_renderer'; |
53 changes: 53 additions & 0 deletions
53
examples/expressions_example/common/expression_functions/action/quick_form_fn.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,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { | ||
ExpressionFunctionDefinition, | ||
Render, | ||
} from '../../../../../src/plugins/expressions/public'; | ||
import { QuickFormRenderValue } from './quick_form_renderer'; | ||
|
||
type Arguments = QuickFormRenderValue; | ||
|
||
export const quickFormFn = (): ExpressionFunctionDefinition< | ||
'quick-form', | ||
unknown, | ||
Arguments, | ||
Render<QuickFormRenderValue> | ||
> => ({ | ||
name: 'quick-form', | ||
type: 'render', | ||
help: i18n.translate('expressionsExample.function.avatar.help', { | ||
defaultMessage: 'Render a simple form that sends the value back as an event on click', | ||
}), | ||
args: { | ||
label: { | ||
types: ['string'], | ||
help: i18n.translate('expressionsExample.function.form.args.label.help', { | ||
defaultMessage: 'Form label', | ||
}), | ||
default: i18n.translate('expressionsExample.function.form.args.label.default', { | ||
defaultMessage: 'Input', | ||
}), | ||
}, | ||
buttonLabel: { | ||
types: ['string'], | ||
help: i18n.translate('expressionsExample.function.form.args.buttonLabel.help', { | ||
defaultMessage: 'Button label', | ||
}), | ||
default: i18n.translate('expressionsExample.function.form.args.buttonLabel.default', { | ||
defaultMessage: 'Submit', | ||
}), | ||
}, | ||
}, | ||
fn: (input, args) => { | ||
return { | ||
type: 'render', | ||
as: 'quick-form-renderer', | ||
value: { ...args }, | ||
}; | ||
}, | ||
}); |
61 changes: 61 additions & 0 deletions
61
examples/expressions_example/common/expression_functions/action/quick_form_renderer.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,61 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useCallback, useState } from 'react'; | ||
import { EuiForm, EuiFormRow, EuiButton, EuiFieldText } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { ExpressionRenderDefinition } from '../../../../../src/plugins/expressions/public'; | ||
|
||
export interface QuickFormRenderValue { | ||
label: string; | ||
buttonLabel: string; | ||
} | ||
|
||
export const quickFormRenderer: ExpressionRenderDefinition<QuickFormRenderValue> = { | ||
name: 'quick-form-renderer', | ||
displayName: i18n.translate('expressionsExample.form.render.help', { | ||
defaultMessage: 'Render a simple input form', | ||
}), | ||
reuseDomNode: true, | ||
render: (domNode, config, handlers) => { | ||
handlers.onDestroy(() => { | ||
unmountComponentAtNode(domNode); | ||
}); | ||
|
||
render( | ||
<QuickForm | ||
{...config} | ||
onSubmit={(value) => | ||
handlers.event({ | ||
data: value, | ||
}) | ||
} | ||
/>, | ||
domNode, | ||
handlers.done | ||
); | ||
}, | ||
}; | ||
|
||
interface QuickFormProps extends QuickFormRenderValue { | ||
onSubmit: Function; | ||
} | ||
|
||
const QuickForm = ({ onSubmit, buttonLabel, label }: QuickFormProps) => { | ||
const [value, setValue] = useState(''); | ||
const handleClick = useCallback(() => { | ||
onSubmit(value); | ||
}, [onSubmit, value]); | ||
|
||
return ( | ||
<EuiForm> | ||
<EuiFormRow label={label}> | ||
<EuiFieldText value={value} onChange={(e) => setValue(e.target.value)} /> | ||
</EuiFormRow> | ||
<EuiButton onClick={handleClick}>{buttonLabel}</EuiButton> | ||
</EuiForm> | ||
); | ||
}; |
7 changes: 7 additions & 0 deletions
7
examples/expressions_example/common/expression_functions/basic/index.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,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './sleep'; | ||
export * from './square'; |
31 changes: 31 additions & 0 deletions
31
examples/expressions_example/common/expression_functions/basic/sleep.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,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { ExpressionFunctionDefinition } from '../../../../../src/plugins/expressions/public'; | ||
|
||
interface Arguments { | ||
time: number; | ||
} | ||
|
||
export const sleep = (): ExpressionFunctionDefinition<'sleep', any, Arguments, any> => ({ | ||
name: 'sleep', | ||
help: i18n.translate('expressionsExample.function.sleep.help', { | ||
defaultMessage: 'Generates range object', | ||
}), | ||
args: { | ||
time: { | ||
types: ['number'], | ||
help: i18n.translate('expressionsExample.function.sleep.time.help', { | ||
defaultMessage: 'Time for settimeout', | ||
}), | ||
required: false, | ||
}, | ||
}, | ||
fn: async (input, args, context) => { | ||
await new Promise((r) => setTimeout(r, args.time)); | ||
return input; | ||
}, | ||
}); |
18 changes: 18 additions & 0 deletions
18
examples/expressions_example/common/expression_functions/basic/square.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,18 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { ExpressionFunctionDefinition } from '../../../../../src/plugins/expressions/public'; | ||
|
||
export const square = (): ExpressionFunctionDefinition<'square', number, {}, any> => ({ | ||
name: 'square', | ||
help: i18n.translate('expressionsExample.function.square.help', { | ||
defaultMessage: 'Squares the input', | ||
}), | ||
args: {}, | ||
fn: async (input, args, context) => { | ||
return input * input; | ||
}, | ||
}); |
8 changes: 8 additions & 0 deletions
8
examples/expressions_example/common/expression_functions/index.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,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './basic'; | ||
export * from './render'; | ||
export * from './action'; |
52 changes: 52 additions & 0 deletions
52
examples/expressions_example/common/expression_functions/render/avatar_fn.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,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { | ||
ExpressionFunctionDefinition, | ||
Render, | ||
} from '../../../../../src/plugins/expressions/public'; | ||
import { AvatarRenderValue } from './avatar_renderer'; | ||
|
||
type Arguments = AvatarRenderValue; | ||
|
||
export const avatarFn = (): ExpressionFunctionDefinition< | ||
'avatar', | ||
unknown, | ||
Arguments, | ||
Render<AvatarRenderValue> | ||
> => ({ | ||
name: 'avatar', | ||
type: 'render', | ||
help: i18n.translate('expressionsExample.function.avatar.help', { | ||
defaultMessage: 'Avatar expression function', | ||
}), | ||
args: { | ||
name: { | ||
types: ['string'], | ||
help: i18n.translate('expressionsExample.function.avatar.args.name.help', { | ||
defaultMessage: 'Enter Name', | ||
}), | ||
required: true, | ||
}, | ||
size: { | ||
types: ['string'], | ||
help: i18n.translate('expressionsExample.function.avatar.args.size.help', { | ||
defaultMessage: 'Size of the avatar', | ||
}), | ||
default: 'l', | ||
}, | ||
}, | ||
fn: (input, args) => { | ||
return { | ||
type: 'render', | ||
as: 'avatar', | ||
value: { | ||
name: args.name, | ||
size: args.size, | ||
}, | ||
}; | ||
}, | ||
}); |
30 changes: 30 additions & 0 deletions
30
examples/expressions_example/common/expression_functions/render/avatar_renderer.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,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiAvatar, EuiAvatarProps } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { ExpressionRenderDefinition } from '../../../../../src/plugins/expressions/public'; | ||
|
||
export interface AvatarRenderValue { | ||
name: string; | ||
size: EuiAvatarProps['size']; | ||
} | ||
|
||
export const avatar: ExpressionRenderDefinition<AvatarRenderValue> = { | ||
name: 'avatar', | ||
displayName: i18n.translate('expressionsExample.render.help', { | ||
defaultMessage: 'Render an avatar', | ||
}), | ||
reuseDomNode: true, | ||
render: (domNode, { name, size }, handlers) => { | ||
handlers.onDestroy(() => { | ||
unmountComponentAtNode(domNode); | ||
}); | ||
|
||
render(<EuiAvatar size={size} name={name} />, domNode, handlers.done); | ||
}, | ||
}; |
Oops, something went wrong.