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 10 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 an index pattern.
shivindera marked this conversation as resolved.
Show resolved Hide resolved

#### `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
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 '../../../data_views/public';

import {
DataView,
DataViewSpec,
Form,
useForm,
Expand All @@ -39,6 +40,7 @@ import {
TimestampField,
TypeField,
TitleField,
ReadableTitleField,
schema,
Footer,
AdvancedParamsContent,
Expand All @@ -58,25 +60,45 @@ 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,
readableTitle: editData.readableTitle,
readableDescription: editData.readableDescription,
...(editData.timeFieldName
? {
timestampField: { label: editData.timeFieldName, value: editData.timeFieldName },
}
: {}),
}
: {}),
},
schema,
onSubmit: async (formData, isValid) => {
Expand All @@ -88,6 +110,8 @@ const IndexPatternEditorFlyoutContentComponent = ({
title: formData.title,
timeFieldName: formData.timestampField?.value,
id: formData.id,
readableTitle: formData.readableTitle,
readableDescription: formData.readableDescription,
};

if (type === INDEX_PATTERN_TYPE.ROLLUP && rollupIndex) {
Expand Down Expand Up @@ -152,17 +176,19 @@ const IndexPatternEditorFlyoutContentComponent = ({
});
}, [http, allowHidden, searchClient]);

// loading list of index patterns
// loading list of data views
useEffect(() => {
loadSources();
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 @@ -220,11 +246,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 @@ -274,9 +295,25 @@ 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('readableTitle', '');
form.setFieldValue('readableDescription', '');
form.setFieldValue('timestampField', '');
if (newType === INDEX_PATTERN_TYPE.ROLLUP) {
form.setFieldValue('allowHidden', false);
Expand All @@ -296,7 +333,7 @@ const IndexPatternEditorFlyoutContentComponent = ({

const indexPatternTypeSelect = showIndexPatternTypeSelect() ? (
<>
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TypeField onChange={onTypeChange} />
Expand All @@ -321,11 +358,17 @@ const IndexPatternEditorFlyoutContentComponent = ({
<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>
<ReadableTitleField editData={editData} />
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TitleField
Expand All @@ -337,7 +380,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiFlexGroup>
<EuiFlexItem>
<TimestampField
Expand All @@ -355,6 +398,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
onCancel={onCancel}
onSubmit={() => form.submit()}
submitDisabled={form.isSubmitted && !form.isValid}
isEdit={!!editData}
/>
</FlyoutPanels.Item>
<FlyoutPanels.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,39 @@ const IndexPatternFlyoutContentContainer = ({
onCancel = () => {},
defaultTypeIsRollup,
requireTimestampField = false,
editData,
}: DataViewEditorProps) => {
const {
services: { dataViews, notifications },
} = useKibana<DataViewEditorContext>();

const onSaveClick = async (dataViewSpec: DataViewSpec) => {
try {
const indexPattern = await dataViews.createAndSave(dataViewSpec);
let indexPattern;
if (editData) {
const {
readableTitle = '',
readableDescription = '',
timeFieldName,
title = '',
} = dataViewSpec;
editData.title = title;
editData.readableTitle = readableTitle;
editData.readableDescription = readableDescription;
editData.timeFieldName = timeFieldName;
shivindera marked this conversation as resolved.
Show resolved Hide resolved
indexPattern = await dataViews.updateSavedObject(editData);
} else {
indexPattern = await dataViews.createAndSave(dataViewSpec);
}

const message = i18n.translate('indexPatternEditor.saved', {
defaultMessage: "Saved '{indexPatternTitle}'",
values: { indexPatternTitle: indexPattern.title },
});
notifications.toasts.addSuccess(message);
await onSave(indexPattern);
if (indexPattern && !(indexPattern instanceof Error)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... I wonder if the api indeed can return Error or if this is a mistake in types. I'd expect it to throw in case of error. @mattkime

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivindera As best I can tell its not possible for indexPattern to be an instanceof Error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivindera As best I can tell its not possible for indexPattern to be an instanceof Error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is there as await dataViews.updateSavedObject(editData); returns Promise<void | DataView | Error>. I have changed the variable name accordingly to reflect that.

const message = i18n.translate('indexPatternEditor.saved', {
defaultMessage: "Saved '{indexPatternTitle}'",
values: { indexPatternTitle: indexPattern.title },
});
notifications.toasts.addSuccess(message);
await onSave(indexPattern);
}
} catch (e) {
const title = i18n.translate('indexPatternEditor.dataView.unableSaveLabel', {
defaultMessage: 'Failed to save data view.',
Expand All @@ -48,6 +66,7 @@ const IndexPatternFlyoutContentContainer = ({
onCancel={onCancel}
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
editData={editData}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface FooterProps {
onCancel: () => void;
onSubmit: () => void;
submitDisabled: boolean;
isEdit: boolean;
}

const closeButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutCloseButtonLabel', {
Expand All @@ -31,7 +32,11 @@ const saveButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutSaveButt
defaultMessage: 'Create data view',
});

export const Footer = ({ onCancel, onSubmit, submitDisabled }: FooterProps) => {
const editButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutEditButtonLabel', {
defaultMessage: 'Edit data view',
});

export const Footer = ({ onCancel, onSubmit, submitDisabled, isEdit }: FooterProps) => {
return (
<EuiFlyoutFooter className="indexPatternEditor__footer">
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
Expand All @@ -54,7 +59,7 @@ export const Footer = ({ onCancel, onSubmit, submitDisabled }: FooterProps) => {
fill
disabled={submitDisabled}
>
{saveButtonLabel}
{isEdit ? editButtonLabel : saveButtonLabel}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

export { ReadableTitleField } from './readable_title_field';
export { TimestampField } from './timestamp_field';
export { TypeField } from './type_field';
export { TitleField } from './title_field';
Loading