Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to set human readable title of data view & ability to edit data view #124191

Merged
merged 57 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
fdd3365
ability to set human readable title of data view & ability to edit da…
shivindera Jan 31, 2022
1aaaccf
add readable data view title to discover
shivindera Jan 31, 2022
18daa04
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Feb 8, 2022
7f9a0fe
fix for failing API test
shivindera Feb 10, 2022
a348bd6
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Feb 22, 2022
56e3578
fix and add functional tests
shivindera Feb 22, 2022
5fb16a5
add missing lens support
shivindera Feb 22, 2022
cd7cf91
update snapshots after name change
shivindera Feb 22, 2022
2295bb0
fix for broken test and type checks
shivindera Feb 22, 2022
54ff3e0
fix condition check
shivindera Feb 23, 2022
2a162cc
Merge branch 'main' into edit-data-view
shivindera Mar 16, 2022
f602a2f
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Mar 16, 2022
f2edd41
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 3, 2022
b839a08
remove description, rename readableTitle to name and fixes
shivindera Apr 4, 2022
eb27e8c
revert kibana.yaml change
shivindera Apr 4, 2022
06208a1
fixes for failed tests
shivindera Apr 4, 2022
dc6f45c
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 11, 2022
a2c75b6
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 11, 2022
9221c42
fixes for broken tests
shivindera Apr 11, 2022
2445b13
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 12, 2022
2a4a6f8
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 17, 2022
9779565
fix functional tests 2
shivindera Apr 18, 2022
01348aa
add confirm modal for edit
shivindera Apr 18, 2022
2abd560
update header to match figma
shivindera Apr 18, 2022
505ff3f
fix data views with index pattern
shivindera Apr 18, 2022
878d18d
fix for badge breaking in test due to index change
shivindera Apr 18, 2022
acfc939
remove unused translations
shivindera Apr 18, 2022
ef4149a
comment fixes and add name to sample data
shivindera Apr 20, 2022
9199f00
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 20, 2022
6548c28
fix test for adding names to sample data
shivindera Apr 20, 2022
17dbe9b
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 20, 2022
0737f5a
some ui changes
shivindera Apr 20, 2022
8424691
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 20, 2022
b0909c6
fix for failing tests for removing Actions
shivindera Apr 20, 2022
4a288cf
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Apr 26, 2022
c13191e
comment fixes, change edit modal, fix breadcrumbs
shivindera Apr 26, 2022
b095590
change copy and fix for failing tests
shivindera May 2, 2022
a27da22
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera May 2, 2022
c857513
change text to have unique key
shivindera May 2, 2022
03f1b90
update jest snapshots
shivindera May 2, 2022
7e3cc93
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera May 2, 2022
1fd668c
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 1, 2022
246c1a1
fixes for unified_search and some ui changes
shivindera Jun 1, 2022
1a3970a
add test fixes and disabled editing data view id when in edit mode
shivindera Jun 1, 2022
d69fa8b
fix for translation bug
shivindera Jun 1, 2022
832eef3
fix for failing tests
shivindera Jun 1, 2022
a749e34
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 2, 2022
860277d
review comment changes
shivindera Jun 7, 2022
073dd23
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 7, 2022
148b7f7
some nit fixes
shivindera Jun 7, 2022
9a9ca8d
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 7, 2022
29f5779
revert the operation change check
shivindera Jun 7, 2022
ef7468c
fixed name not showing in dashboard with visualizations from differen…
shivindera Jun 7, 2022
309aaef
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 7, 2022
3b1cb6d
added a comment for the management breadcrumb
shivindera Jun 8, 2022
9a353f5
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 8, 2022
df92850
Merge remote-tracking branch 'upstream/main' into edit-data-view
shivindera Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/plugins/data_view_editor/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Data view editor

Create data views from within Kibana apps.
Create data views from within Kibana apps.

## How to use

Expand All @@ -10,11 +10,11 @@ You will then receive in the start contract of the dataViewEditor plugin the fol

### `userPermissions.editDataView(): boolean`

Convenience method that uses the `core.application.capabilities` api to determine whether the user can create or edit the data view.
Convenience method that uses the `core.application.capabilities` api to determine whether the user can create or edit the data view.

### `openEditor(options: DataViewEditorProps): CloseEditor`

Use this method to display the data view editor to create an index pattern.
Use this method to display the data view editor to create a data view.

#### `options`

Expand All @@ -34,6 +34,10 @@ The default index pattern type can be optionally specified as `rollup`.

The editor can require a timestamp field on the index pattern.

`editData: DataView` (optional)

Data View object passed to edit an existing Data View.

### IndexPatternEditorComponent

This the React component interface equivalent to `openEditor`. It takes the same arguments -
Expand All @@ -44,5 +48,6 @@ This the React component interface equivalent to `openEditor`. It takes the same
onCancel={...}
defaultTypeIsRollup={false}
requireTimestampField={false}
editData={...}
/>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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, { useState } from 'react';
import { EuiCallOut, EuiSpacer, EuiConfirmModal, EuiFieldText, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

const geti18nTexts = (dataViewName?: string) => ({
cancelButtonText: i18n.translate(
'indexPatternEditor.editDataView.editConfirmationModal.cancelButtonLabel',
{
defaultMessage: 'Cancel',
}
),
confirmButtonText: i18n.translate(
shivindera marked this conversation as resolved.
Show resolved Hide resolved
'indexPatternEditor.editDataView.editConfirmationModal.saveButtonLabel',
{
defaultMessage: 'Save',
}
),
warningEditingDataView: i18n.translate(
'indexPatternEditor.editDataView.editConfirmationModal.warningEditingDataView',
{
defaultMessage:
'Are you sure you want to edit this data view? Anything that depends upon this might not work as expected.',
}
),
typeConfirm: i18n.translate('indexPatternEditor.editDataView.editConfirmationModal.typeConfirm', {
defaultMessage: 'Enter CHANGE to continue',
}),
titleConfirmChanges: i18n.translate(
'indexPatternEditor.editDataView.editConfirmationModal.title',
{
defaultMessage: `Edit {name}`,
values: {
name: dataViewName ? `'${dataViewName}'` : 'data view',
},
}
),
});

interface Props {
dataViewName?: string;
onConfirm: () => void;
onCancel: () => void;
}

export const EditDataViewChangedModal: React.FC<Props> = ({
dataViewName,
onCancel,
onConfirm,
}) => {
const i18nTexts = geti18nTexts(dataViewName);
const [confirmContent, setConfirmContent] = useState<string>('');

return (
<EuiConfirmModal
title={i18nTexts.titleConfirmChanges}
data-test-subj="runtimeFieldSaveConfirmModal"
cancelButtonText={i18nTexts.cancelButtonText}
confirmButtonText={i18nTexts.confirmButtonText}
confirmButtonDisabled={confirmContent?.toUpperCase() !== 'CHANGE'}
shivindera marked this conversation as resolved.
Show resolved Hide resolved
onCancel={onCancel}
onConfirm={onConfirm}
>
<EuiCallOut
color="warning"
title={i18nTexts.warningEditingDataView}
iconType="alert"
size="s"
data-test-subj="editDataViewWarning"
/>
<EuiSpacer />
<EuiFormRow label={i18nTexts.typeConfirm}>
<EuiFieldText
value={confirmContent}
onChange={(e) => setConfirmContent(e.target.value)}
data-test-subj="saveModalConfirmText"
/>
</EuiFormRow>
</EuiConfirmModal>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DataViewEditor = ({
services,
defaultTypeIsRollup = false,
requireTimestampField = false,
editData,
}: DataViewEditorPropsWithServices) => {
const { Provider: KibanaReactContextProvider } =
createKibanaReactContext<DataViewEditorContext>(services);
Expand All @@ -35,6 +36,7 @@ export const DataViewEditor = ({
onCancel={onCancel}
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
editData={editData}
/>
</EuiFlyout>
</KibanaReactContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import memoizeOne from 'memoize-one';
import { DataViewField } from '@kbn/data-views-plugin/public';

import {
DataView,
DataViewSpec,
Form,
useForm,
Expand All @@ -23,6 +24,7 @@ import {

import { ensureMinimumTime, getIndices, extractTimeFields, getMatchedIndices } from '../lib';
import { FlyoutPanels } from './flyout_panels';
import { EditDataViewChangedModal } from './confirm_modals/edit_data_view_changed_modal';

import {
MatchedItem,
Expand All @@ -39,6 +41,7 @@ import {
TimestampField,
TypeField,
TitleField,
NameField,
schema,
Footer,
AdvancedParamsContent,
Expand All @@ -58,25 +61,44 @@ export interface Props {
onCancel: () => void;
defaultTypeIsRollup?: boolean;
requireTimestampField?: boolean;
editData?: DataView;
}

const editorTitle = i18n.translate('indexPatternEditor.title', {
defaultMessage: 'Create data view',
});

const editorTitleEditMode = i18n.translate('indexPatternEditor.titleEditMode', {
defaultMessage: 'Edit data view',
});

const IndexPatternEditorFlyoutContentComponent = ({
onSave,
onCancel,
defaultTypeIsRollup,
requireTimestampField = false,
editData,
}: Props) => {
const {
services: { http, dataViews, uiSettings, searchClient },
} = useKibana<DataViewEditorContext>();

const { form } = useForm<IndexPatternConfig, FormInternal>({
// Prefill with data if editData exists
defaultValue: {
type: defaultTypeIsRollup ? INDEX_PATTERN_TYPE.ROLLUP : INDEX_PATTERN_TYPE.DEFAULT,
...(editData
? {
title: editData.title,
id: editData.id,
name: editData.name,
...(editData.timeFieldName
? {
timestampField: { label: editData.timeFieldName, value: editData.timeFieldName },
}
: {}),
}
: {}),
},
schema,
onSubmit: async (formData, isValid) => {
Expand All @@ -88,6 +110,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
title: formData.title,
timeFieldName: formData.timestampField?.value,
id: formData.id,
name: formData.name,
};

if (type === INDEX_PATTERN_TYPE.ROLLUP && rollupIndex) {
Expand All @@ -100,7 +123,15 @@ const IndexPatternEditorFlyoutContentComponent = ({
};
}

await onSave(indexPatternStub);
if (
editData &&
editData.title !== form.getFields().title.value &&
shivindera marked this conversation as resolved.
Show resolved Hide resolved
!editDataViewChangedModal
) {
setEditDataViewChangedModal(true);
} else {
await onSave(indexPatternStub);
}
},
});

Expand Down Expand Up @@ -135,6 +166,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
partialMatchedIndices: [],
visibleIndices: [],
});
const [editDataViewChangedModal, setEditDataViewChangedModal] = useState(false);

// load all data sources and set initial matchedIndices
const loadSources = useCallback(() => {
Expand All @@ -157,11 +189,13 @@ const IndexPatternEditorFlyoutContentComponent = ({
const getTitles = async () => {
const indexPatternTitles = await dataViews.getTitles();

setExistingIndexPatterns(indexPatternTitles);
setExistingIndexPatterns(
editData ? indexPatternTitles.filter((v) => v !== editData.title) : indexPatternTitles
shivindera marked this conversation as resolved.
Show resolved Hide resolved
);
setIsLoadingIndexPatterns(false);
};
getTitles();
}, [http, dataViews, loadSources]);
}, [http, dataViews, editData, loadSources]);

// loading rollup info
useEffect(() => {
Expand Down Expand Up @@ -219,11 +253,6 @@ const IndexPatternEditorFlyoutContentComponent = ({
]
);

useEffect(() => {
loadTimestampFieldOptions(title);
getFields().timestampField?.setValue('');
}, [loadTimestampFieldOptions, title, getFields]);

const reloadMatchedIndices = useCallback(
async (newTitle: string) => {
const isRollupIndex = (indexName: string) =>
Expand Down Expand Up @@ -273,9 +302,24 @@ const IndexPatternEditorFlyoutContentComponent = ({
[http, allowHidden, allSources, type, rollupIndicesCapabilities, searchClient, isLoadingSources]
);

// If editData exists, loadSources so that MatchedIndices can be loaded for the Timestampfields
useEffect(() => {
if (editData) loadSources();
}, [editData, loadSources]);

useEffect(() => {
if (editData) reloadMatchedIndices(editData.title);
}, [editData, allSources, reloadMatchedIndices]);

useEffect(() => {
shivindera marked this conversation as resolved.
Show resolved Hide resolved
loadTimestampFieldOptions(editData ? editData.title : title);
if (!editData) getFields().timestampField?.setValue('');
}, [loadTimestampFieldOptions, title, getFields, editData]);

const onTypeChange = useCallback(
(newType) => {
form.setFieldValue('title', '');
form.setFieldValue('name', '');
form.setFieldValue('timestampField', '');
if (newType === INDEX_PATTERN_TYPE.ROLLUP) {
form.setFieldValue('allowHidden', false);
Expand All @@ -295,7 +339,7 @@ const IndexPatternEditorFlyoutContentComponent = ({

const indexPatternTypeSelect = showIndexPatternTypeSelect() ? (
<>
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TypeField onChange={onTypeChange} />
Expand All @@ -315,16 +359,40 @@ const IndexPatternEditorFlyoutContentComponent = ({
<></>
);

const renderModal = () => {
if (editDataViewChangedModal) {
return (
<EditDataViewChangedModal
dataViewName={form.getFields().name.value as string}
onConfirm={() => {
form.submit();
}}
onCancel={() => {
setEditDataViewChangedModal(false);
}}
/>
);
}

return null;
};

return (
<EmptyPrompts onCancel={onCancel} allSources={allSources} loadSources={loadSources}>
<FlyoutPanels.Group flyoutClassName={'indexPatternEditorFlyout'} maxWidth={1180}>
<FlyoutPanels.Item className="fieldEditor__mainFlyoutPanel" border="right">
<EuiTitle data-test-subj="flyoutTitle">
<h2>{editorTitle}</h2>
<h2>{editData ? editorTitleEditMode : editorTitle}</h2>
</EuiTitle>
<Form form={form} className="indexPatternEditor__form">
{indexPatternTypeSelect}
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<NameField editData={editData} />
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TitleField
Expand All @@ -336,7 +404,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TimestampField
Expand All @@ -354,6 +422,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
onCancel={onCancel}
onSubmit={() => form.submit()}
submitDisabled={form.isSubmitted && !form.isValid}
isEdit={!!editData}
/>
</FlyoutPanels.Item>
<FlyoutPanels.Item>
Expand All @@ -369,6 +438,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
)}
</FlyoutPanels.Item>
</FlyoutPanels.Group>
{renderModal()}
</EmptyPrompts>
);
};
Expand Down
Loading