IndexPatternFieldEditor => DataViewFieldEditor (#119261)
* rename indexPatternFieldEditor
2
.github/CODEOWNERS
vendored
|
@ -76,7 +76,7 @@
|
|||
/src/plugins/navigation/ @elastic/kibana-app-services
|
||||
/src/plugins/share/ @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/bfetch/ @elastic/kibana-app-services
|
||||
/src/plugins/index_pattern_management/ @elastic/kibana-app-services
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
"home": "src/plugins/home",
|
||||
"flot": "packages/kbn-ui-shared-deps-src/src/flot_charts",
|
||||
"charts": "src/plugins/charts",
|
||||
"customIntegrations": "src/plugins/custom_integrations",
|
||||
"esUi": "src/plugins/es_ui_shared",
|
||||
"devTools": "src/plugins/dev_tools",
|
||||
"expressions": "src/plugins/expressions",
|
||||
|
@ -43,7 +42,7 @@
|
|||
"esQuery": "packages/kbn-es-query/src",
|
||||
"presentationUtil": "src/plugins/presentation_util",
|
||||
"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",
|
||||
"interactiveSetup": "src/plugins/interactive_setup",
|
||||
"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.
|
||||
|
||||
|
||||
|{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]
|
||||
|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
|
||||
|
@ -141,10 +145,6 @@ for use in their own application.
|
|||
|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]
|
||||
|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",
|
||||
"version": "0.0.1",
|
||||
"server": false,
|
||||
"ui": true,
|
||||
"requiredPlugins": ["data", "indexPatternFieldEditor", "developerExamples"],
|
||||
"requiredPlugins": ["data", "dataViewFieldEditor", "developerExamples"],
|
||||
"optionalPlugins": [],
|
||||
"requiredBundles": [],
|
||||
"owner": {
|
||||
"name": "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,
|
||||
IndexPatternField,
|
||||
} 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 {
|
||||
indexPattern?: IndexPattern;
|
||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
||||
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||
}
|
||||
|
||||
const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor }: Props) => {
|
||||
const IndexPatternFieldEditorExample = ({ indexPattern, dataViewFieldEditor }: Props) => {
|
||||
const [fields, setFields] = useState<IndexPatternField[]>(
|
||||
indexPattern?.getNonScriptedFields() || []
|
||||
);
|
||||
|
@ -52,8 +52,8 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
|||
type: 'icon',
|
||||
'data-test-subj': 'editField',
|
||||
onClick: (fld: IndexPatternField) =>
|
||||
indexPatternFieldEditor.openEditor({
|
||||
ctx: { indexPattern: indexPattern! },
|
||||
dataViewFieldEditor.openEditor({
|
||||
ctx: { dataView: indexPattern! },
|
||||
fieldName: fld.name,
|
||||
onSave: refreshFields,
|
||||
}),
|
||||
|
@ -66,10 +66,10 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
|||
'data-test-subj': 'deleteField',
|
||||
available: (fld) => !!fld.runtimeField,
|
||||
onClick: (fld: IndexPatternField) =>
|
||||
indexPatternFieldEditor.openDeleteModal({
|
||||
dataViewFieldEditor.openDeleteModal({
|
||||
fieldName: fld.name,
|
||||
ctx: {
|
||||
indexPattern: indexPattern!,
|
||||
dataView: indexPattern!,
|
||||
},
|
||||
onDelete: refreshFields,
|
||||
}),
|
||||
|
@ -84,8 +84,8 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
|||
<div>
|
||||
<EuiButton
|
||||
onClick={() =>
|
||||
indexPatternFieldEditor.openEditor({
|
||||
ctx: { indexPattern: indexPattern! },
|
||||
dataViewFieldEditor.openEditor({
|
||||
ctx: { dataView: indexPattern! },
|
||||
onSave: refreshFields,
|
||||
})
|
||||
}
|
||||
|
@ -125,18 +125,18 @@ const IndexPatternFieldEditorExample = ({ indexPattern, indexPatternFieldEditor
|
|||
|
||||
interface RenderAppDependencies {
|
||||
data: DataPublicPluginStart;
|
||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
||||
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||
}
|
||||
|
||||
export const renderApp = async (
|
||||
{ data, indexPatternFieldEditor }: RenderAppDependencies,
|
||||
{ data, dataViewFieldEditor }: RenderAppDependencies,
|
||||
{ element }: AppMountParameters
|
||||
) => {
|
||||
const indexPattern = (await data.indexPatterns.getDefault()) || undefined;
|
||||
ReactDOM.render(
|
||||
<IndexPatternFieldEditorExample
|
||||
indexPattern={indexPattern}
|
||||
indexPatternFieldEditor={indexPatternFieldEditor}
|
||||
dataViewFieldEditor={dataViewFieldEditor}
|
||||
/>,
|
||||
element
|
||||
);
|
|
@ -9,11 +9,11 @@
|
|||
import { Plugin, CoreSetup, AppMountParameters, AppNavLinkStatus } from '../../../src/core/public';
|
||||
import { DeveloperExamplesSetup } from '../../developer_examples/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 {
|
||||
data: DataPublicPluginStart;
|
||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
||||
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||
}
|
||||
|
||||
interface SetupDeps {
|
|
@ -14,7 +14,7 @@
|
|||
{ "path": "../../src/core/tsconfig.json" },
|
||||
{ "path": "../../src/plugins/kibana_react/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" },
|
||||
]
|
||||
}
|
|
@ -8,5 +8,5 @@
|
|||
"githubTeam": "kibana-app-services"
|
||||
},
|
||||
"description": "A plugin that demonstrates field formats usage",
|
||||
"requiredPlugins": ["developerExamples", "fieldFormats", "indexPatternFieldEditor", "data"]
|
||||
"requiredPlugins": ["developerExamples", "fieldFormats", "dataViewFieldEditor", "data"]
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
FieldFormatEditor,
|
||||
FieldFormatEditorFactory,
|
||||
IndexPatternFieldEditorSetup,
|
||||
} from '../../../../src/plugins/index_pattern_field_editor/public';
|
||||
} from '../../../../src/plugins/data_view_field_editor/public';
|
||||
import { ExampleCurrencyFormat } from './2_creating_custom_formatter';
|
||||
|
||||
// 1. Create an editor component
|
||||
|
|
|
@ -22,7 +22,7 @@ import { registerExampleFormat } from './examples/2_creating_custom_formatter';
|
|||
import {
|
||||
IndexPatternFieldEditorStart,
|
||||
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 { registerExampleFormatEditor } from './examples/3_creating_custom_format_editor';
|
||||
import img from './formats.png';
|
||||
|
@ -30,19 +30,19 @@ import img from './formats.png';
|
|||
interface SetupDeps {
|
||||
developerExamples: DeveloperExamplesSetup;
|
||||
fieldFormats: FieldFormatsSetup;
|
||||
indexPatternFieldEditor: IndexPatternFieldEditorSetup;
|
||||
dataViewFieldEditor: IndexPatternFieldEditorSetup;
|
||||
}
|
||||
|
||||
interface StartDeps {
|
||||
fieldFormats: FieldFormatsStart;
|
||||
indexPatternFieldEditor: IndexPatternFieldEditorStart;
|
||||
dataViewFieldEditor: IndexPatternFieldEditorStart;
|
||||
data: DataPublicPluginStart;
|
||||
}
|
||||
|
||||
export class FieldFormatsExamplePlugin implements Plugin<void, void, SetupDeps, StartDeps> {
|
||||
public setup(core: CoreSetup<StartDeps>, deps: SetupDeps) {
|
||||
registerExampleFormat(deps.fieldFormats);
|
||||
registerExampleFormatEditor(deps.indexPatternFieldEditor);
|
||||
registerExampleFormatEditor(deps.dataViewFieldEditor);
|
||||
|
||||
// just for demonstration purposes:
|
||||
// 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;
|
||||
}
|
||||
|
||||
plugins.indexPatternFieldEditor.openEditor({
|
||||
plugins.dataViewFieldEditor.openEditor({
|
||||
ctx: {
|
||||
indexPattern,
|
||||
dataView: indexPattern,
|
||||
},
|
||||
fieldName: numberField.name,
|
||||
});
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
{ "path": "../developer_examples/tsconfig.json" },
|
||||
{ "path": "../../src/plugins/field_formats/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
|
||||
urlDrilldown: 30063
|
||||
indexPatternEditor: 19123
|
||||
indexPatternFieldEditor: 34448
|
||||
dataViewFieldEditor: 20000
|
||||
indexPatternManagement: 19165
|
||||
reporting: 57003
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
# Index pattern field editor
|
||||
# Data view field editor
|
||||
|
||||
The reusable field editor across Kibana!
|
||||
|
||||
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_.
|
||||
|
||||
## 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`
|
||||
|
||||
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`
|
||||
|
||||
|
@ -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:
|
||||
|
||||
- `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.
|
||||
|
||||
|
@ -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`
|
||||
|
||||
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`
|
||||
|
||||
|
@ -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:
|
||||
|
||||
- `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)
|
||||
|
||||
|
@ -63,14 +63,14 @@ This children func React component provides a handler to delete one or multiple
|
|||
|
||||
#### Props
|
||||
|
||||
* `indexPattern: IndexPattern`: the current index pattern. (**required**)
|
||||
* `dataView: DataView`: the current dataView. (**required**)
|
||||
|
||||
```js
|
||||
|
||||
const { DeleteRuntimeFieldProvider } = indexPatternFieldEditor;
|
||||
const { DeleteRuntimeFieldProvider } = dataViewFieldEditor;
|
||||
|
||||
// Single field
|
||||
<DeleteRuntimeFieldProvider indexPattern={indexPattern}>
|
||||
<DeleteRuntimeFieldProvider dataView={dataView}>
|
||||
{(deleteField) => (
|
||||
<EuiButton fill color="danger" onClick={() => deleteField('myField')}>
|
||||
Delete
|
||||
|
@ -79,7 +79,7 @@ const { DeleteRuntimeFieldProvider } = indexPatternFieldEditor;
|
|||
</DeleteRuntimeFieldProvider>
|
||||
|
||||
// Multiple fields
|
||||
<DeleteRuntimeFieldProvider indexPattern={indexPattern}>
|
||||
<DeleteRuntimeFieldProvider dataView={dataView}>
|
||||
{(deleteFields) => (
|
||||
<EuiButton fill color="danger" onClick={() => deleteFields(['field1', 'field2', 'field3'])}>
|
||||
Delete
|
|
@ -103,7 +103,7 @@ export const WithFieldEditorDependencies =
|
|||
});
|
||||
|
||||
const dependencies: Context = {
|
||||
indexPattern: {
|
||||
dataView: {
|
||||
title: indexPatternNameForTest,
|
||||
fields: { getAll: spyIndexPatternGetAllFields },
|
||||
} as any,
|
|
@ -9,10 +9,10 @@
|
|||
module.exports = {
|
||||
preset: '@kbn/test',
|
||||
rootDir: '../../..',
|
||||
roots: ['<rootDir>/src/plugins/index_pattern_field_editor'],
|
||||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/index_pattern_field_editor',
|
||||
roots: ['<rootDir>/src/plugins/data_view_field_editor'],
|
||||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/data_view_field_editor',
|
||||
coverageReporters: ['text', 'html'],
|
||||
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 { IndexPattern } from '../shared_imports';
|
||||
import { DataView } from '../shared_imports';
|
||||
import { OpenFieldDeleteModalOptions } from '../open_delete_modal';
|
||||
import { CloseEditor } from '../types';
|
||||
|
||||
type DeleteFieldFunc = (fieldName: string | string[]) => void;
|
||||
export interface Props {
|
||||
children: (deleteFieldHandler: DeleteFieldFunc) => React.ReactNode;
|
||||
indexPattern: IndexPattern;
|
||||
dataView: DataView;
|
||||
onDelete?: (fieldNames: string[]) => void;
|
||||
}
|
||||
|
||||
export const getDeleteFieldProvider = (
|
||||
modalOpener: (options: OpenFieldDeleteModalOptions) => CloseEditor
|
||||
): React.FunctionComponent<Props> => {
|
||||
return React.memo(({ indexPattern, children, onDelete }: Props) => {
|
||||
return React.memo(({ dataView, children, onDelete }: Props) => {
|
||||
const closeModal = useRef<CloseEditor | null>(null);
|
||||
const deleteFields = useCallback(
|
||||
async (fieldName: string | string[]) => {
|
||||
|
@ -31,13 +31,13 @@ export const getDeleteFieldProvider = (
|
|||
}
|
||||
closeModal.current = modalOpener({
|
||||
ctx: {
|
||||
indexPattern,
|
||||
dataView,
|
||||
},
|
||||
fieldName,
|
||||
onDelete,
|
||||
});
|
||||
},
|
||||
[onDelete, indexPattern]
|
||||
[onDelete, dataView]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
|
@ -15,7 +15,7 @@ import type { FieldFormInternal } from '../field_editor';
|
|||
import type { FieldFormatConfig } from '../../../types';
|
||||
|
||||
export const FormatField = () => {
|
||||
const { indexPattern, uiSettings, fieldFormats, fieldFormatEditors } = useFieldEditorContext();
|
||||
const { dataView, uiSettings, fieldFormats, fieldFormatEditors } = useFieldEditorContext();
|
||||
const isMounted = useRef(false);
|
||||
const [{ type }] = useFormData<FieldFormInternal>({ watch: ['name', 'type'] });
|
||||
const { getFields, isSubmitted } = useFormContext();
|
||||
|
@ -62,7 +62,7 @@ export const FormatField = () => {
|
|||
|
||||
<FormatSelectEditor
|
||||
esTypes={typeValue || (['keyword'] as ES_FIELD_TYPES[])}
|
||||
indexPattern={indexPattern}
|
||||
indexPattern={dataView}
|
||||
fieldFormatEditors={fieldFormatEditors}
|
||||
fieldFormats={fieldFormats}
|
||||
uiSettings={uiSettings}
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
import React, { createContext, useContext, FunctionComponent, useMemo } from 'react';
|
||||
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 type { InternalFieldType, PluginStart } from '../types';
|
||||
|
||||
export interface Context {
|
||||
indexPattern: IndexPattern;
|
||||
dataView: DataView;
|
||||
fieldTypeToProcess: InternalFieldType;
|
||||
uiSettings: CoreStart['uiSettings'];
|
||||
links: {
|
||||
|
@ -45,7 +45,7 @@ const fieldEditorContext = createContext<Context | undefined>(undefined);
|
|||
|
||||
export const FieldEditorProvider: FunctionComponent<Context> = ({
|
||||
services,
|
||||
indexPattern,
|
||||
dataView,
|
||||
links,
|
||||
uiSettings,
|
||||
fieldTypeToProcess,
|
||||
|
@ -57,7 +57,7 @@ export const FieldEditorProvider: FunctionComponent<Context> = ({
|
|||
}) => {
|
||||
const ctx = useMemo<Context>(
|
||||
() => ({
|
||||
indexPattern,
|
||||
dataView,
|
||||
fieldTypeToProcess,
|
||||
links,
|
||||
uiSettings,
|
||||
|
@ -68,7 +68,7 @@ export const FieldEditorProvider: FunctionComponent<Context> = ({
|
|||
existingConcreteFields,
|
||||
}),
|
||||
[
|
||||
indexPattern,
|
||||
dataView,
|
||||
fieldTypeToProcess,
|
||||
services,
|
||||
links,
|
|
@ -67,7 +67,7 @@ const FieldEditorFlyoutContentComponent = ({
|
|||
}: Props) => {
|
||||
const isMounted = useRef(false);
|
||||
const isEditingExistingField = !!field;
|
||||
const { indexPattern } = useFieldEditorContext();
|
||||
const { dataView } = useFieldEditorContext();
|
||||
const {
|
||||
panel: { isVisible: isPanelVisible },
|
||||
} = useFieldPreviewContext();
|
||||
|
@ -218,7 +218,7 @@ const FieldEditorFlyoutContentComponent = ({
|
|||
id="indexPatternFieldEditor.editor.flyoutEditFieldSubtitle"
|
||||
defaultMessage="Data view: {patternName}"
|
||||
values={{
|
||||
patternName: <i>{indexPattern.title}</i>,
|
||||
patternName: <i>{dataView.title}</i>,
|
||||
}}
|
||||
/>
|
||||
</p>
|
|
@ -12,11 +12,12 @@ import { i18n } from '@kbn/i18n';
|
|||
import { METRIC_TYPE } from '@kbn/analytics';
|
||||
|
||||
import {
|
||||
IndexPatternField,
|
||||
IndexPattern,
|
||||
DataViewField,
|
||||
DataView,
|
||||
DataPublicPluginStart,
|
||||
RuntimeType,
|
||||
UsageCollectionStart,
|
||||
DataViewsPublicPluginStart,
|
||||
} from '../shared_imports';
|
||||
import type { Field, PluginStart, InternalFieldType } from '../types';
|
||||
import { pluginName } from '../constants';
|
||||
|
@ -30,20 +31,20 @@ import { FieldPreviewProvider } from './preview';
|
|||
|
||||
export interface Props {
|
||||
/** Handler for the "save" footer button */
|
||||
onSave: (field: IndexPatternField) => void;
|
||||
onSave: (field: DataViewField) => void;
|
||||
/** Handler for the "cancel" footer button */
|
||||
onCancel: () => void;
|
||||
onMounted?: FieldEditorFlyoutContentProps['onMounted'];
|
||||
/** The docLinks start service from core */
|
||||
docLinks: DocLinksStart;
|
||||
/** 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") */
|
||||
fieldTypeToProcess: InternalFieldType;
|
||||
/** Optional field to edit */
|
||||
field?: IndexPatternField;
|
||||
field?: DataViewField;
|
||||
/** Services */
|
||||
indexPatternService: DataPublicPluginStart['indexPatterns'];
|
||||
dataViews: DataViewsPublicPluginStart;
|
||||
notifications: NotificationsStart;
|
||||
search: DataPublicPluginStart['search'];
|
||||
usageCollection: UsageCollectionStart;
|
||||
|
@ -68,8 +69,8 @@ export const FieldEditorFlyoutContentContainer = ({
|
|||
onMounted,
|
||||
docLinks,
|
||||
fieldTypeToProcess,
|
||||
indexPattern,
|
||||
indexPatternService,
|
||||
dataView,
|
||||
dataViews,
|
||||
search,
|
||||
notifications,
|
||||
usageCollection,
|
||||
|
@ -78,10 +79,10 @@ export const FieldEditorFlyoutContentContainer = ({
|
|||
fieldFormats,
|
||||
uiSettings,
|
||||
}: Props) => {
|
||||
const fieldToEdit = deserializeField(indexPattern, field);
|
||||
const fieldToEdit = deserializeField(dataView, field);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const { fields } = indexPattern;
|
||||
const { fields } = dataView;
|
||||
|
||||
const namesNotAllowed = useMemo(() => fields.map((fld) => fld.name), [fields]);
|
||||
|
||||
|
@ -125,10 +126,10 @@ export const FieldEditorFlyoutContentContainer = ({
|
|||
} catch {}
|
||||
// rename an existing runtime field
|
||||
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,
|
||||
script,
|
||||
});
|
||||
|
@ -139,24 +140,24 @@ export const FieldEditorFlyoutContentContainer = ({
|
|||
} catch {}
|
||||
}
|
||||
|
||||
const editedField = indexPattern.getFieldByName(updatedField.name);
|
||||
const editedField = dataView.getFieldByName(updatedField.name);
|
||||
|
||||
try {
|
||||
if (!editedField) {
|
||||
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;
|
||||
if (updatedField.format) {
|
||||
indexPattern.setFieldFormat(updatedField.name, updatedField.format);
|
||||
dataView.setFieldFormat(updatedField.name, updatedField.format);
|
||||
} 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', {
|
||||
defaultMessage: "Saved '{fieldName}'",
|
||||
values: { fieldName: updatedField.name },
|
||||
|
@ -173,20 +174,12 @@ export const FieldEditorFlyoutContentContainer = ({
|
|||
setIsSaving(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
onSave,
|
||||
indexPattern,
|
||||
indexPatternService,
|
||||
notifications,
|
||||
fieldTypeToProcess,
|
||||
field?.name,
|
||||
usageCollection,
|
||||
]
|
||||
[onSave, dataView, dataViews, notifications, fieldTypeToProcess, field?.name, usageCollection]
|
||||
);
|
||||
|
||||
return (
|
||||
<FieldEditorProvider
|
||||
indexPattern={indexPattern}
|
||||
dataView={dataView}
|
||||
uiSettings={uiSettings}
|
||||
links={getLinks(docLinks)}
|
||||
fieldTypeToProcess={fieldTypeToProcess}
|