IndexPatternFieldEditor => DataViewFieldEditor (#119261)
* rename indexPatternFieldEditor
2
.github/CODEOWNERS
vendored
|
@ -76,7 +76,7 @@
|
||||||
/src/plugins/navigation/ @elastic/kibana-app-services
|
/src/plugins/navigation/ @elastic/kibana-app-services
|
||||||
/src/plugins/share/ @elastic/kibana-app-services
|
/src/plugins/share/ @elastic/kibana-app-services
|
||||||
/src/plugins/ui_actions/ @elastic/kibana-app-services
|
/src/plugins/ui_actions/ @elastic/kibana-app-services
|
||||||
/src/plugins/index_pattern_field_editor @elastic/kibana-app-services
|
/src/plugins/data_view_field_editor @elastic/kibana-app-services
|
||||||
/src/plugins/screenshot_mode @elastic/kibana-app-services
|
/src/plugins/screenshot_mode @elastic/kibana-app-services
|
||||||
/src/plugins/bfetch/ @elastic/kibana-app-services
|
/src/plugins/bfetch/ @elastic/kibana-app-services
|
||||||
/src/plugins/index_pattern_management/ @elastic/kibana-app-services
|
/src/plugins/index_pattern_management/ @elastic/kibana-app-services
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
"home": "src/plugins/home",
|
"home": "src/plugins/home",
|
||||||
"flot": "packages/kbn-ui-shared-deps-src/src/flot_charts",
|
"flot": "packages/kbn-ui-shared-deps-src/src/flot_charts",
|
||||||
"charts": "src/plugins/charts",
|
"charts": "src/plugins/charts",
|
||||||
"customIntegrations": "src/plugins/custom_integrations",
|
|
||||||
"esUi": "src/plugins/es_ui_shared",
|
"esUi": "src/plugins/es_ui_shared",
|
||||||
"devTools": "src/plugins/dev_tools",
|
"devTools": "src/plugins/dev_tools",
|
||||||
"expressions": "src/plugins/expressions",
|
"expressions": "src/plugins/expressions",
|
||||||
|
@ -43,7 +42,7 @@
|
||||||
"esQuery": "packages/kbn-es-query/src",
|
"esQuery": "packages/kbn-es-query/src",
|
||||||
"presentationUtil": "src/plugins/presentation_util",
|
"presentationUtil": "src/plugins/presentation_util",
|
||||||
"indexPatternEditor": "src/plugins/index_pattern_editor",
|
"indexPatternEditor": "src/plugins/index_pattern_editor",
|
||||||
"indexPatternFieldEditor": "src/plugins/index_pattern_field_editor",
|
"indexPatternFieldEditor": "src/plugins/data_view_field_editor",
|
||||||
"indexPatternManagement": "src/plugins/index_pattern_management",
|
"indexPatternManagement": "src/plugins/index_pattern_management",
|
||||||
"interactiveSetup": "src/plugins/interactive_setup",
|
"interactiveSetup": "src/plugins/interactive_setup",
|
||||||
"advancedSettings": "src/plugins/advanced_settings",
|
"advancedSettings": "src/plugins/advanced_settings",
|
||||||
|
|
|
@ -53,6 +53,10 @@ as uiSettings within the code.
|
||||||
|The data plugin provides common data access services, such as search and query, for solutions and application developers.
|
|The data plugin provides common data access services, such as search and query, for solutions and application developers.
|
||||||
|
|
||||||
|
|
||||||
|
|{kib-repo}blob/{branch}/src/plugins/data_view_field_editor/README.md[dataViewFieldEditor]
|
||||||
|
|The reusable field editor across Kibana!
|
||||||
|
|
||||||
|
|
||||||
|{kib-repo}blob/{branch}/src/plugins/data_views/README.mdx[dataViews]
|
|{kib-repo}blob/{branch}/src/plugins/data_views/README.mdx[dataViews]
|
||||||
|The data views API provides a consistent method of structuring and formatting documents
|
|The data views API provides a consistent method of structuring and formatting documents
|
||||||
and field lists across the various Kibana apps. Its typically used in conjunction with
|
and field lists across the various Kibana apps. Its typically used in conjunction with
|
||||||
|
@ -141,10 +145,6 @@ for use in their own application.
|
||||||
|Create index patterns from within Kibana apps.
|
|Create index patterns from within Kibana apps.
|
||||||
|
|
||||||
|
|
||||||
|{kib-repo}blob/{branch}/src/plugins/index_pattern_field_editor/README.md[indexPatternFieldEditor]
|
|
||||||
|The reusable field editor across Kibana!
|
|
||||||
|
|
||||||
|
|
||||||
|{kib-repo}blob/{branch}/src/plugins/index_pattern_management[indexPatternManagement]
|
|{kib-repo}blob/{branch}/src/plugins/index_pattern_management[indexPatternManagement]
|
||||||
|WARNING: Missing README.
|
|WARNING: Missing README.
|
||||||
|
|
||||||
|
|
7
examples/data_view_field_editor_example/README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
## Data view field editor example
|
||||||
|
|
||||||
|
This example data view field editor app shows how to:
|
||||||
|
- Edit data view fields via flyout
|
||||||
|
- Delete data view runtime fields with modal confirm prompt
|
||||||
|
|
||||||
|
To run this example, use the command `yarn start --run-examples`.
|
|
@ -1,15 +1,15 @@
|
||||||
{
|
{
|
||||||
"id": "indexPatternFieldEditorExample",
|
"id": "dataViewFieldEditorExample",
|
||||||
"kibanaVersion": "kibana",
|
"kibanaVersion": "kibana",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"server": false,
|
"server": false,
|
||||||
"ui": true,
|
"ui": true,
|
||||||
"requiredPlugins": ["data", "indexPatternFieldEditor", "developerExamples"],
|
"requiredPlugins": ["data", "dataViewFieldEditor", "developerExamples"],
|
||||||
"optionalPlugins": [],
|
"optionalPlugins": [],
|
||||||
"requiredBundles": [],
|
"requiredBundles": [],
|
||||||
"owner": {
|
"owner": {
|
||||||
"name": "App Services",
|
"name": "App Services",
|
||||||
"githubTeam": "kibana-app-services"
|
"githubTeam": "kibana-app-services"
|
||||||
},
|
},
|
||||||
"description": "Index pattern field editor example app"
|
"description": "Data view field editor example app"
|
||||||
}
|
}
|
|
@ -25,14 +25,14 @@ import {
|
||||||
IndexPattern,
|
IndexPattern,
|
||||||
IndexPatternField,
|
IndexPatternField,
|
||||||
} from '../../../src/plugins/data/public';
|
} from '../../../src/plugins/data/public';
|
||||||
import { IndexPatternFieldEditorStart } from '../../../src/plugins/index_pattern_field_editor/public';
|
import { IndexPatternFieldEditorStart } from '../../../src/plugins/data_view_field_editor/public';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
indexPattern?: IndexPattern;
|
indexPattern?: IndexPattern;
|
||||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor }: Props) => {
|
const IndexPatternFieldEditorExample = ({ indexPattern, dataViewFieldEditor }: Props) => {
|
||||||
const [fields, setFields] = useState<IndexPatternField[]>(
|
const [fields, setFields] = useState<IndexPatternField[]>(
|
||||||
indexPattern?.getNonScriptedFields() || []
|
indexPattern?.getNonScriptedFields() || []
|
||||||
);
|
);
|
||||||
|
@ -52,8 +52,8 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
||||||
type: 'icon',
|
type: 'icon',
|
||||||
'data-test-subj': 'editField',
|
'data-test-subj': 'editField',
|
||||||
onClick: (fld: IndexPatternField) =>
|
onClick: (fld: IndexPatternField) =>
|
||||||
indexPatternFieldEditor.openEditor({
|
dataViewFieldEditor.openEditor({
|
||||||
ctx: { indexPattern: indexPattern! },
|
ctx: { dataView: indexPattern! },
|
||||||
fieldName: fld.name,
|
fieldName: fld.name,
|
||||||
onSave: refreshFields,
|
onSave: refreshFields,
|
||||||
}),
|
}),
|
||||||
|
@ -66,10 +66,10 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
||||||
'data-test-subj': 'deleteField',
|
'data-test-subj': 'deleteField',
|
||||||
available: (fld) => !!fld.runtimeField,
|
available: (fld) => !!fld.runtimeField,
|
||||||
onClick: (fld: IndexPatternField) =>
|
onClick: (fld: IndexPatternField) =>
|
||||||
indexPatternFieldEditor.openDeleteModal({
|
dataViewFieldEditor.openDeleteModal({
|
||||||
fieldName: fld.name,
|
fieldName: fld.name,
|
||||||
ctx: {
|
ctx: {
|
||||||
indexPattern: indexPattern!,
|
dataView: indexPattern!,
|
||||||
},
|
},
|
||||||
onDelete: refreshFields,
|
onDelete: refreshFields,
|
||||||
}),
|
}),
|
||||||
|
@ -84,8 +84,8 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
||||||
<div>
|
<div>
|
||||||
<EuiButton
|
<EuiButton
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
indexPatternFieldEditor.openEditor({
|
dataViewFieldEditor.openEditor({
|
||||||
ctx: { indexPattern: indexPattern! },
|
ctx: { dataView: indexPattern! },
|
||||||
onSave: refreshFields,
|
onSave: refreshFields,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -125,18 +125,18 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
||||||
|
|
||||||
interface RenderAppDependencies {
|
interface RenderAppDependencies {
|
||||||
data: DataPublicPluginStart;
|
data: DataPublicPluginStart;
|
||||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const renderApp = async (
|
export const renderApp = async (
|
||||||
{ data, indexPatternFieldEditor }: RenderAppDependencies,
|
{ data, dataViewFieldEditor }: RenderAppDependencies,
|
||||||
{ element }: AppMountParameters
|
{ element }: AppMountParameters
|
||||||
) => {
|
) => {
|
||||||
const indexPattern = (await data.indexPatterns.getDefault()) || undefined;
|
const indexPattern = (await data.indexPatterns.getDefault()) || undefined;
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<IndexPatternFieldEditorExample
|
<IndexPatternFieldEditorExample
|
||||||
indexPattern={indexPattern}
|
indexPattern={indexPattern}
|
||||||
indexPatternFieldEditor={indexPatternFieldEditor}
|
dataViewFieldEditor={dataViewFieldEditor}
|
||||||
/>,
|
/>,
|
||||||
element
|
element
|
||||||
);
|
);
|
|
@ -9,11 +9,11 @@
|
||||||
import { Plugin, CoreSetup, AppMountParameters, AppNavLinkStatus } from '../../../src/core/public';
|
import { Plugin, CoreSetup, AppMountParameters, AppNavLinkStatus } from '../../../src/core/public';
|
||||||
import { DeveloperExamplesSetup } from '../../developer_examples/public';
|
import { DeveloperExamplesSetup } from '../../developer_examples/public';
|
||||||
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
|
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
|
||||||
import { IndexPatternFieldEditorStart } from '../../../src/plugins/index_pattern_field_editor/public';
|
import { IndexPatternFieldEditorStart } from '../../../src/plugins/data_view_field_editor/public';
|
||||||
|
|
||||||
interface StartDeps {
|
interface StartDeps {
|
||||||
data: DataPublicPluginStart;
|
data: DataPublicPluginStart;
|
||||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SetupDeps {
|
interface SetupDeps {
|
|
@ -14,7 +14,7 @@
|
||||||
{ "path": "../../src/core/tsconfig.json" },
|
{ "path": "../../src/core/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
|
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/data/tsconfig.json" },
|
{ "path": "../../src/plugins/data/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/index_pattern_field_editor/tsconfig.json" },
|
{ "path": "../../src/plugins/data_view_field_editor/tsconfig.json" },
|
||||||
{ "path": "../developer_examples/tsconfig.json" },
|
{ "path": "../developer_examples/tsconfig.json" },
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -8,5 +8,5 @@
|
||||||
"githubTeam": "kibana-app-services"
|
"githubTeam": "kibana-app-services"
|
||||||
},
|
},
|
||||||
"description": "A plugin that demonstrates field formats usage",
|
"description": "A plugin that demonstrates field formats usage",
|
||||||
"requiredPlugins": ["developerExamples", "fieldFormats", "indexPatternFieldEditor", "data"]
|
"requiredPlugins": ["developerExamples", "fieldFormats", "dataViewFieldEditor", "data"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {
|
||||||
FieldFormatEditor,
|
FieldFormatEditor,
|
||||||
FieldFormatEditorFactory,
|
FieldFormatEditorFactory,
|
||||||
IndexPatternFieldEditorSetup,
|
IndexPatternFieldEditorSetup,
|
||||||
} from '../../../../src/plugins/index_pattern_field_editor/public';
|
} from '../../../../src/plugins/data_view_field_editor/public';
|
||||||
import { ExampleCurrencyFormat } from './2_creating_custom_formatter';
|
import { ExampleCurrencyFormat } from './2_creating_custom_formatter';
|
||||||
|
|
||||||
// 1. Create an editor component
|
// 1. Create an editor component
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { registerExampleFormat } from './examples/2_creating_custom_formatter';
|
||||||
import {
|
import {
|
||||||
IndexPatternFieldEditorStart,
|
IndexPatternFieldEditorStart,
|
||||||
IndexPatternFieldEditorSetup,
|
IndexPatternFieldEditorSetup,
|
||||||
} from '../../../src/plugins/index_pattern_field_editor/public';
|
} from '../../../src/plugins/data_view_field_editor/public';
|
||||||
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
|
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
|
||||||
import { registerExampleFormatEditor } from './examples/3_creating_custom_format_editor';
|
import { registerExampleFormatEditor } from './examples/3_creating_custom_format_editor';
|
||||||
import img from './formats.png';
|
import img from './formats.png';
|
||||||
|
@ -30,19 +30,19 @@ import img from './formats.png';
|
||||||
interface SetupDeps {
|
interface SetupDeps {
|
||||||
developerExamples: DeveloperExamplesSetup;
|
developerExamples: DeveloperExamplesSetup;
|
||||||
fieldFormats: FieldFormatsSetup;
|
fieldFormats: FieldFormatsSetup;
|
||||||
indexPatternFieldEditor: IndexPatternFieldEditorSetup;
|
dataViewFieldEditor: IndexPatternFieldEditorSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StartDeps {
|
interface StartDeps {
|
||||||
fieldFormats: FieldFormatsStart;
|
fieldFormats: FieldFormatsStart;
|
||||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||||
data: DataPublicPluginStart;
|
data: DataPublicPluginStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FieldFormatsExamplePlugin implements Plugin<void, void, SetupDeps, StartDeps> {
|
export class FieldFormatsExamplePlugin implements Plugin<void, void, SetupDeps, StartDeps> {
|
||||||
public setup(core: CoreSetup<StartDeps>, deps: SetupDeps) {
|
public setup(core: CoreSetup<StartDeps>, deps: SetupDeps) {
|
||||||
registerExampleFormat(deps.fieldFormats);
|
registerExampleFormat(deps.fieldFormats);
|
||||||
registerExampleFormatEditor(deps.indexPatternFieldEditor);
|
registerExampleFormatEditor(deps.dataViewFieldEditor);
|
||||||
|
|
||||||
// just for demonstration purposes:
|
// just for demonstration purposes:
|
||||||
// opens a field editor using default index pattern and first number field
|
// opens a field editor using default index pattern and first number field
|
||||||
|
@ -65,9 +65,9 @@ export class FieldFormatsExamplePlugin implements Plugin<void, void, SetupDeps,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.indexPatternFieldEditor.openEditor({
|
plugins.dataViewFieldEditor.openEditor({
|
||||||
ctx: {
|
ctx: {
|
||||||
indexPattern,
|
dataView: indexPattern,
|
||||||
},
|
},
|
||||||
fieldName: numberField.name,
|
fieldName: numberField.name,
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,6 +18,6 @@
|
||||||
{ "path": "../developer_examples/tsconfig.json" },
|
{ "path": "../developer_examples/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/field_formats/tsconfig.json" },
|
{ "path": "../../src/plugins/field_formats/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/data/tsconfig.json" },
|
{ "path": "../../src/plugins/data/tsconfig.json" },
|
||||||
{ "path": "../../src/plugins/index_pattern_field_editor/tsconfig.json" }
|
{ "path": "../../src/plugins/data_view_field_editor/tsconfig.json" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
## index pattern field editor example
|
|
||||||
|
|
||||||
This example index pattern field editor app shows how to:
|
|
||||||
- Edit index pattern fields via flyout
|
|
||||||
- Delete index pattern runtime fields with modal confirm prompt
|
|
||||||
|
|
||||||
To run this example, use the command `yarn start --run-examples`.
|
|
|
@ -113,6 +113,6 @@ pageLoadAssetSize:
|
||||||
uiActionsEnhanced: 38494
|
uiActionsEnhanced: 38494
|
||||||
urlDrilldown: 30063
|
urlDrilldown: 30063
|
||||||
indexPatternEditor: 19123
|
indexPatternEditor: 19123
|
||||||
indexPatternFieldEditor: 34448
|
dataViewFieldEditor: 20000
|
||||||
indexPatternManagement: 19165
|
indexPatternManagement: 19165
|
||||||
reporting: 57003
|
reporting: 57003
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
# Index pattern field editor
|
# Data view field editor
|
||||||
|
|
||||||
The reusable field editor across Kibana!
|
The reusable field editor across Kibana!
|
||||||
|
|
||||||
This editor can be used to
|
This editor can be used to
|
||||||
|
|
||||||
* create or edit a runtime field inside an index pattern.
|
* create or edit a runtime field inside a data view.
|
||||||
* edit concrete (mapped) fields. In this case certain functionalities will be disabled like the possibility to change the field _type_ or to set the field _value_.
|
* edit concrete (mapped) fields. In this case certain functionalities will be disabled like the possibility to change the field _type_ or to set the field _value_.
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
You first need to add in your kibana.json the "`indexPatternFieldEditor`" plugin as a required dependency of your plugin.
|
You first need to add in your kibana.json the "`dataViewFieldEditor`" plugin as a required dependency of your plugin.
|
||||||
|
|
||||||
You will then receive in the start contract of the indexPatternFieldEditor plugin the following API:
|
You will then receive in the start contract of the dataViewFieldEditor plugin the following API:
|
||||||
|
|
||||||
### `userPermissions.editIndexPattern(): boolean`
|
### `userPermissions.editDataView(): boolean`
|
||||||
|
|
||||||
Convenience method that uses the `core.application.capabilities` api to determine whether the user can edit the index pattern.
|
Convenience method that uses the `core.application.capabilities` api to determine whether the user can edit the data view.
|
||||||
|
|
||||||
### `openEditor(options: OpenFieldEditorOptions): CloseEditor`
|
### `openEditor(options: OpenFieldEditorOptions): CloseEditor`
|
||||||
|
|
||||||
Use this method to open the index pattern field editor to either create (runtime) or edit (concrete | runtime) a field.
|
Use this method to open the data view field editor to either create (runtime) or edit (concrete | runtime) a field.
|
||||||
|
|
||||||
#### `options`
|
#### `options`
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ Use this method to open the index pattern field editor to either create (runtime
|
||||||
|
|
||||||
This is the only required option. You need to provide the context in which the editor is being consumed. This object has the following properties:
|
This is the only required option. You need to provide the context in which the editor is being consumed. This object has the following properties:
|
||||||
|
|
||||||
- `indexPattern: IndexPattern`: the index pattern you want to create/edit the field into.
|
- `dataView: DataView`: the data view you want to create/edit the field into.
|
||||||
|
|
||||||
`onSave(field: IndexPatternField): void` (optional)
|
`onSave(field: DataViewField): void` (optional)
|
||||||
|
|
||||||
You can provide an optional `onSave` handler to be notified when the field has being created/updated. This handler is called after the field has been persisted to the saved object.
|
You can provide an optional `onSave` handler to be notified when the field has being created/updated. This handler is called after the field has been persisted to the saved object.
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ You can optionally pass the name of a field to edit. Leave empty to create a new
|
||||||
|
|
||||||
### `openDeleteModal(options: OpenFieldDeleteModalOptions): CloseEditor`
|
### `openDeleteModal(options: OpenFieldDeleteModalOptions): CloseEditor`
|
||||||
|
|
||||||
Use this method to open a confirmation modal to delete runtime fields from an index pattern.
|
Use this method to open a confirmation modal to delete runtime fields from a data view.
|
||||||
|
|
||||||
#### `options`
|
#### `options`
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ Use this method to open a confirmation modal to delete runtime fields from an in
|
||||||
|
|
||||||
You need to provide the context in which the deletion modal is being consumed. This object has the following properties:
|
You need to provide the context in which the deletion modal is being consumed. This object has the following properties:
|
||||||
|
|
||||||
- `indexPattern: IndexPattern`: the index pattern you want to delete fields from.
|
- `dataView: DataView`: the index pattern you want to delete fields from.
|
||||||
|
|
||||||
`onDelete(fieldNames: string[]): void` (optional)
|
`onDelete(fieldNames: string[]): void` (optional)
|
||||||
|
|
||||||
|
@ -63,14 +63,14 @@ This children func React component provides a handler to delete one or multiple
|
||||||
|
|
||||||
#### Props
|
#### Props
|
||||||
|
|
||||||
* `indexPattern: IndexPattern`: the current index pattern. (**required**)
|
* `dataView: DataView`: the current dataView. (**required**)
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const { DeleteRuntimeFieldProvider } = indexPatternFieldEditor;
|
const { DeleteRuntimeFieldProvider } = dataViewFieldEditor;
|
||||||
|
|
||||||
// Single field
|
// Single field
|
||||||
<DeleteRuntimeFieldProvider indexPattern={indexPattern}>
|
<DeleteRuntimeFieldProvider dataView={dataView}>
|
||||||
{(deleteField) => (
|
{(deleteField) => (
|
||||||
<EuiButton fill color="danger" onClick={() => deleteField('myField')}>
|
<EuiButton fill color="danger" onClick={() => deleteField('myField')}>
|
||||||
Delete
|
Delete
|
||||||
|
@ -79,7 +79,7 @@ const { DeleteRuntimeFieldProvider } = indexPatternFieldEditor;
|
||||||
</DeleteRuntimeFieldProvider>
|
</DeleteRuntimeFieldProvider>
|
||||||
|
|
||||||
// Multiple fields
|
// Multiple fields
|
||||||
<DeleteRuntimeFieldProvider indexPattern={indexPattern}>
|
<DeleteRuntimeFieldProvider dataView={dataView}>
|
||||||
{(deleteFields) => (
|
{(deleteFields) => (
|
||||||
<EuiButton fill color="danger" onClick={() => deleteFields(['field1', 'field2', 'field3'])}>
|
<EuiButton fill color="danger" onClick={() => deleteFields(['field1', 'field2', 'field3'])}>
|
||||||
Delete
|
Delete
|
|
@ -103,7 +103,7 @@ export const WithFieldEditorDependencies =
|
||||||
});
|
});
|
||||||
|
|
||||||
const dependencies: Context = {
|
const dependencies: Context = {
|
||||||
indexPattern: {
|
dataView: {
|
||||||
title: indexPatternNameForTest,
|
title: indexPatternNameForTest,
|
||||||
fields: { getAll: spyIndexPatternGetAllFields },
|
fields: { getAll: spyIndexPatternGetAllFields },
|
||||||
} as any,
|
} as any,
|
|
@ -9,10 +9,10 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
preset: '@kbn/test',
|
preset: '@kbn/test',
|
||||||
rootDir: '../../..',
|
rootDir: '../../..',
|
||||||
roots: ['<rootDir>/src/plugins/index_pattern_field_editor'],
|
roots: ['<rootDir>/src/plugins/data_view_field_editor'],
|
||||||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/index_pattern_field_editor',
|
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/data_view_field_editor',
|
||||||
coverageReporters: ['text', 'html'],
|
coverageReporters: ['text', 'html'],
|
||||||
collectCoverageFrom: [
|
collectCoverageFrom: [
|
||||||
'<rootDir>/src/plugins/index_pattern_field_editor/{common,public,server}/**/*.{ts,tsx}',
|
'<rootDir>/src/plugins/data_view_field_editor/{common,public,server}/**/*.{ts,tsx}',
|
||||||
],
|
],
|
||||||
};
|
};
|
14
src/plugins/data_view_field_editor/kibana.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"id": "dataViewFieldEditor",
|
||||||
|
"version": "kibana",
|
||||||
|
"server": true,
|
||||||
|
"ui": true,
|
||||||
|
"requiredPlugins": ["data", "fieldFormats", "dataViews"],
|
||||||
|
"optionalPlugins": ["usageCollection"],
|
||||||
|
"requiredBundles": ["kibanaReact", "esUiShared"],
|
||||||
|
"owner": {
|
||||||
|
"name": "App Services",
|
||||||
|
"githubTeam": "kibana-app-services"
|
||||||
|
},
|
||||||
|
"description": "Reusable data view field editor across Kibana"
|
||||||
|
}
|
Before Width: | Height: | Size: 802 B After Width: | Height: | Size: 802 B |
Before Width: | Height: | Size: 124 B After Width: | Height: | Size: 124 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 336 B After Width: | Height: | Size: 336 B |
Before Width: | Height: | Size: 919 B After Width: | Height: | Size: 919 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
@ -8,21 +8,21 @@
|
||||||
|
|
||||||
import React, { useCallback, useRef, useEffect } from 'react';
|
import React, { useCallback, useRef, useEffect } from 'react';
|
||||||
|
|
||||||
import { IndexPattern } from '../shared_imports';
|
import { DataView } from '../shared_imports';
|
||||||
import { OpenFieldDeleteModalOptions } from '../open_delete_modal';
|
import { OpenFieldDeleteModalOptions } from '../open_delete_modal';
|
||||||
import { CloseEditor } from '../types';
|
import { CloseEditor } from '../types';
|
||||||
|
|
||||||
type DeleteFieldFunc = (fieldName: string | string[]) => void;
|
type DeleteFieldFunc = (fieldName: string | string[]) => void;
|
||||||
export interface Props {
|
export interface Props {
|
||||||
children: (deleteFieldHandler: DeleteFieldFunc) => React.ReactNode;
|
children: (deleteFieldHandler: DeleteFieldFunc) => React.ReactNode;
|
||||||
indexPattern: IndexPattern;
|
dataView: DataView;
|
||||||
onDelete?: (fieldNames: string[]) => void;
|
onDelete?: (fieldNames: string[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDeleteFieldProvider = (
|
export const getDeleteFieldProvider = (
|
||||||
modalOpener: (options: OpenFieldDeleteModalOptions) => CloseEditor
|
modalOpener: (options: OpenFieldDeleteModalOptions) => CloseEditor
|
||||||
): React.FunctionComponent<Props> => {
|
): React.FunctionComponent<Props> => {
|
||||||
return React.memo(({ indexPattern, children, onDelete }: Props) => {
|
return React.memo(({ dataView, children, onDelete }: Props) => {
|
||||||
const closeModal = useRef<CloseEditor | null>(null);
|
const closeModal = useRef<CloseEditor | null>(null);
|
||||||
const deleteFields = useCallback(
|
const deleteFields = useCallback(
|
||||||
async (fieldName: string | string[]) => {
|
async (fieldName: string | string[]) => {
|
||||||
|
@ -31,13 +31,13 @@ export const getDeleteFieldProvider = (
|
||||||
}
|
}
|
||||||
closeModal.current = modalOpener({
|
closeModal.current = modalOpener({
|
||||||
ctx: {
|
ctx: {
|
||||||
indexPattern,
|
dataView,
|
||||||
},
|
},
|
||||||
fieldName,
|
fieldName,
|
||||||
onDelete,
|
onDelete,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[onDelete, indexPattern]
|
[onDelete, dataView]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
|
@ -15,7 +15,7 @@ import type { FieldFormInternal } from '../field_editor';
|
||||||
import type { FieldFormatConfig } from '../../../types';
|
import type { FieldFormatConfig } from '../../../types';
|
||||||
|
|
||||||
export const FormatField = () => {
|
export const FormatField = () => {
|
||||||
const { indexPattern, uiSettings, fieldFormats, fieldFormatEditors } = useFieldEditorContext();
|
const { dataView, uiSettings, fieldFormats, fieldFormatEditors } = useFieldEditorContext();
|
||||||
const isMounted = useRef(false);
|
const isMounted = useRef(false);
|
||||||
const [{ type }] = useFormData<FieldFormInternal>({ watch: ['name', 'type'] });
|
const [{ type }] = useFormData<FieldFormInternal>({ watch: ['name', 'type'] });
|
||||||
const { getFields, isSubmitted } = useFormContext();
|
const { getFields, isSubmitted } = useFormContext();
|
||||||
|
@ -62,7 +62,7 @@ export const FormatField = () => {
|
||||||
|
|
||||||
<FormatSelectEditor
|
<FormatSelectEditor
|
||||||
esTypes={typeValue || (['keyword'] as ES_FIELD_TYPES[])}
|
esTypes={typeValue || (['keyword'] as ES_FIELD_TYPES[])}
|
||||||
indexPattern={indexPattern}
|
indexPattern={dataView}
|
||||||
fieldFormatEditors={fieldFormatEditors}
|
fieldFormatEditors={fieldFormatEditors}
|
||||||
fieldFormats={fieldFormats}
|
fieldFormats={fieldFormats}
|
||||||
uiSettings={uiSettings}
|
uiSettings={uiSettings}
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
import React, { createContext, useContext, FunctionComponent, useMemo } from 'react';
|
import React, { createContext, useContext, FunctionComponent, useMemo } from 'react';
|
||||||
import { NotificationsStart, CoreStart } from 'src/core/public';
|
import { NotificationsStart, CoreStart } from 'src/core/public';
|
||||||
import type { IndexPattern, DataPublicPluginStart } from '../shared_imports';
|
import type { DataView, DataPublicPluginStart } from '../shared_imports';
|
||||||
import { ApiService } from '../lib/api';
|
import { ApiService } from '../lib/api';
|
||||||
import type { InternalFieldType, PluginStart } from '../types';
|
import type { InternalFieldType, PluginStart } from '../types';
|
||||||
|
|
||||||
export interface Context {
|
export interface Context {
|
||||||
indexPattern: IndexPattern;
|
dataView: DataView;
|
||||||
fieldTypeToProcess: InternalFieldType;
|
fieldTypeToProcess: InternalFieldType;
|
||||||
uiSettings: CoreStart['uiSettings'];
|
uiSettings: CoreStart['uiSettings'];
|
||||||
links: {
|
links: {
|
||||||
|
@ -45,7 +45,7 @@ const fieldEditorContext = createContext<Context | undefined>(undefined);
|
||||||
|
|
||||||
export const FieldEditorProvider: FunctionComponent<Context> = ({
|
export const FieldEditorProvider: FunctionComponent<Context> = ({
|
||||||
services,
|
services,
|
||||||
indexPattern,
|
dataView,
|
||||||
links,
|
links,
|
||||||
uiSettings,
|
uiSettings,
|
||||||
fieldTypeToProcess,
|
fieldTypeToProcess,
|
||||||
|
@ -57,7 +57,7 @@ export const FieldEditorProvider: FunctionComponent<Context> = ({
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useMemo<Context>(
|
const ctx = useMemo<Context>(
|
||||||
() => ({
|
() => ({
|
||||||
indexPattern,
|
dataView,
|
||||||
fieldTypeToProcess,
|
fieldTypeToProcess,
|
||||||
links,
|
links,
|
||||||
uiSettings,
|
uiSettings,
|
||||||
|
@ -68,7 +68,7 @@ export const FieldEditorProvider: FunctionComponent<Context> = ({
|
||||||
existingConcreteFields,
|
existingConcreteFields,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
indexPattern,
|
dataView,
|
||||||
fieldTypeToProcess,
|
fieldTypeToProcess,
|
||||||
services,
|
services,
|
||||||
links,
|
links,
|
|
@ -67,7 +67,7 @@ const FieldEditorFlyoutContentComponent = ({
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const isMounted = useRef(false);
|
const isMounted = useRef(false);
|
||||||
const isEditingExistingField = !!field;
|
const isEditingExistingField = !!field;
|
||||||
const { indexPattern } = useFieldEditorContext();
|
const { dataView } = useFieldEditorContext();
|
||||||
const {
|
const {
|
||||||
panel: { isVisible: isPanelVisible },
|
panel: { isVisible: isPanelVisible },
|
||||||
} = useFieldPreviewContext();
|
} = useFieldPreviewContext();
|
||||||
|
@ -218,7 +218,7 @@ const FieldEditorFlyoutContentComponent = ({
|
||||||
id="indexPatternFieldEditor.editor.flyoutEditFieldSubtitle"
|
id="indexPatternFieldEditor.editor.flyoutEditFieldSubtitle"
|
||||||
defaultMessage="Data view: {patternName}"
|
defaultMessage="Data view: {patternName}"
|
||||||
values={{
|
values={{
|
||||||
patternName: <i>{indexPattern.title}</i>,
|
patternName: <i>{dataView.title}</i>,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
|
@ -12,11 +12,12 @@ import { i18n } from '@kbn/i18n';
|
||||||
import { METRIC_TYPE } from '@kbn/analytics';
|
import { METRIC_TYPE } from '@kbn/analytics';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IndexPatternField,
|
DataViewField,
|
||||||
IndexPattern,
|
DataView,
|
||||||
DataPublicPluginStart,
|
DataPublicPluginStart,
|
||||||
RuntimeType,
|
RuntimeType,
|
||||||
UsageCollectionStart,
|
UsageCollectionStart,
|
||||||
|
DataViewsPublicPluginStart,
|
||||||
} from '../shared_imports';
|
} from '../shared_imports';
|
||||||
import type { Field, PluginStart, InternalFieldType } from '../types';
|
import type { Field, PluginStart, InternalFieldType } from '../types';
|
||||||
import { pluginName } from '../constants';
|
import { pluginName } from '../constants';
|
||||||
|
@ -30,20 +31,20 @@ import { FieldPreviewProvider } from './preview';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
/** Handler for the "save" footer button */
|
/** Handler for the "save" footer button */
|
||||||
onSave: (field: IndexPatternField) => void;
|
onSave: (field: DataViewField) => void;
|
||||||
/** Handler for the "cancel" footer button */
|
/** Handler for the "cancel" footer button */
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
onMounted?: FieldEditorFlyoutContentProps['onMounted'];
|
onMounted?: FieldEditorFlyoutContentProps['onMounted'];
|
||||||
/** The docLinks start service from core */
|
/** The docLinks start service from core */
|
||||||
docLinks: DocLinksStart;
|
docLinks: DocLinksStart;
|
||||||
/** The index pattern where the field will be added */
|
/** The index pattern where the field will be added */
|
||||||
indexPattern: IndexPattern;
|
dataView: DataView;
|
||||||
/** The Kibana field type of the field to create or edit (default: "runtime") */
|
/** The Kibana field type of the field to create or edit (default: "runtime") */
|
||||||
fieldTypeToProcess: InternalFieldType;
|
fieldTypeToProcess: InternalFieldType;
|
||||||
/** Optional field to edit */
|
/** Optional field to edit */
|
||||||
field?: IndexPatternField;
|
field?: DataViewField;
|
||||||
/** Services */
|
/** Services */
|
||||||
indexPatternService: DataPublicPluginStart['indexPatterns'];
|
dataViews: DataViewsPublicPluginStart;
|
||||||
notifications: NotificationsStart;
|
notifications: NotificationsStart;
|
||||||
search: DataPublicPluginStart['search'];
|
search: DataPublicPluginStart['search'];
|
||||||
usageCollection: UsageCollectionStart;
|
usageCollection: UsageCollectionStart;
|
||||||
|
@ -68,8 +69,8 @@ export const FieldEditorFlyoutContentContainer = ({
|
||||||
onMounted,
|
onMounted,
|
||||||
docLinks,
|
docLinks,
|
||||||
fieldTypeToProcess,
|
fieldTypeToProcess,
|
||||||
indexPattern,
|
dataView,
|
||||||
indexPatternService,
|
dataViews,
|
||||||
search,
|
search,
|
||||||
notifications,
|
notifications,
|
||||||
usageCollection,
|
usageCollection,
|
||||||
|
@ -78,10 +79,10 @@ export const FieldEditorFlyoutContentContainer = ({
|
||||||
fieldFormats,
|
fieldFormats,
|
||||||
uiSettings,
|
uiSettings,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const fieldToEdit = deserializeField(indexPattern, field);
|
const fieldToEdit = deserializeField(dataView, field);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
|
||||||
const { fields } = indexPattern;
|
const { fields } = dataView;
|
||||||
|
|
||||||
const namesNotAllowed = useMemo(() => fields.map((fld) => fld.name), [fields]);
|
const namesNotAllowed = useMemo(() => fields.map((fld) => fld.name), [fields]);
|
||||||
|
|
||||||
|
@ -125,10 +126,10 @@ export const FieldEditorFlyoutContentContainer = ({
|
||||||
} catch {}
|
} catch {}
|
||||||
// rename an existing runtime field
|
// rename an existing runtime field
|
||||||
if (field?.name && field.name !== updatedField.name) {
|
if (field?.name && field.name !== updatedField.name) {
|
||||||
indexPattern.removeRuntimeField(field.name);
|
dataView.removeRuntimeField(field.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexPattern.addRuntimeField(updatedField.name, {
|
dataView.addRuntimeField(updatedField.name, {
|
||||||
type: updatedField.type as RuntimeType,
|
type: updatedField.type as RuntimeType,
|
||||||
script,
|
script,
|
||||||
});
|
});
|
||||||
|
@ -139,24 +140,24 @@ export const FieldEditorFlyoutContentContainer = ({
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const editedField = indexPattern.getFieldByName(updatedField.name);
|
const editedField = dataView.getFieldByName(updatedField.name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!editedField) {
|
if (!editedField) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find field named '${updatedField.name}' on index pattern '${indexPattern.title}'`
|
`Unable to find field named '${updatedField.name}' on index pattern '${dataView.title}'`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexPattern.setFieldCustomLabel(updatedField.name, updatedField.customLabel);
|
dataView.setFieldCustomLabel(updatedField.name, updatedField.customLabel);
|
||||||
editedField.count = updatedField.popularity || 0;
|
editedField.count = updatedField.popularity || 0;
|
||||||
if (updatedField.format) {
|
if (updatedField.format) {
|
||||||
indexPattern.setFieldFormat(updatedField.name, updatedField.format);
|
dataView.setFieldFormat(updatedField.name, updatedField.format);
|
||||||
} else {
|
} else {
|
||||||
indexPattern.deleteFieldFormat(updatedField.name);
|
dataView.deleteFieldFormat(updatedField.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
await indexPatternService.updateSavedObject(indexPattern).then(() => {
|
await dataViews.updateSavedObject(dataView).then(() => {
|
||||||
const message = i18n.translate('indexPatternFieldEditor.deleteField.savedHeader', {
|
const message = i18n.translate('indexPatternFieldEditor.deleteField.savedHeader', {
|
||||||
defaultMessage: "Saved '{fieldName}'",
|
defaultMessage: "Saved '{fieldName}'",
|
||||||
values: { fieldName: updatedField.name },
|
values: { fieldName: updatedField.name },
|
||||||
|
@ -173,20 +174,12 @@ export const FieldEditorFlyoutContentContainer = ({
|
||||||
setIsSaving(false);
|
setIsSaving(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[onSave, dataView, dataViews, notifications, fieldTypeToProcess, field?.name, usageCollection]
|
||||||
onSave,
|
|
||||||
indexPattern,
|
|
||||||
indexPatternService,
|
|
||||||
notifications,
|
|
||||||
fieldTypeToProcess,
|
|
||||||
field?.name,
|
|
||||||
usageCollection,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FieldEditorProvider
|
<FieldEditorProvider
|
||||||
indexPattern={indexPattern}
|
dataView={dataView}
|
||||||
uiSettings={uiSettings}
|
uiSettings={uiSettings}
|
||||||
links={getLinks(docLinks)}
|
links={getLinks(docLinks)}
|
||||||
fieldTypeToProcess={fieldTypeToProcess}
|
fieldTypeToProcess={fieldTypeToProcess}
|