Skip to content

Commit

Permalink
data view side panel explore button (#135224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Jul 13, 2022
1 parent 978012b commit 6f9d771
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DataViewEditor = ({
defaultTypeIsRollup = false,
requireTimestampField = false,
editData,
allowAdHocDataView,
}: DataViewEditorPropsWithServices) => {
const { Provider: KibanaReactContextProvider } =
createKibanaReactContext<DataViewEditorContext>(services);
Expand All @@ -37,6 +38,7 @@ export const DataViewEditor = ({
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
editData={editData}
allowAdHocDataView={allowAdHocDataView}
/>
</EuiFlyout>
</KibanaReactContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useFormData,
useKibana,
GetFieldsOptions,
UseField,
} from '../shared_imports';

import { ensureMinimumTime, getIndices, extractTimeFields, getMatchedIndices } from '../lib';
Expand Down Expand Up @@ -55,14 +56,15 @@ export interface Props {
/**
* Handler for the "save" footer button
*/
onSave: (dataViewSpec: DataViewSpec) => void;
onSave: (dataViewSpec: DataViewSpec, persist: boolean) => void;
/**
* Handler for the "cancel" footer button
*/
onCancel: () => void;
defaultTypeIsRollup?: boolean;
requireTimestampField?: boolean;
editData?: DataView;
allowAdHoc: boolean;
}

const editorTitle = i18n.translate('indexPatternEditor.title', {
Expand All @@ -79,6 +81,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
defaultTypeIsRollup,
requireTimestampField = false,
editData,
allowAdHoc,
}: Props) => {
const {
services: { http, dataViews, uiSettings, overlays },
Expand All @@ -88,6 +91,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
// Prefill with data if editData exists
defaultValue: {
type: defaultTypeIsRollup ? INDEX_PATTERN_TYPE.ROLLUP : INDEX_PATTERN_TYPE.DEFAULT,
isAdHoc: false,
...(editData
? {
title: editData.title,
Expand Down Expand Up @@ -129,11 +133,11 @@ const IndexPatternEditorFlyoutContentComponent = ({
dataViewName: formData.name || formData.title,
overlays,
onEdit: async () => {
await onSave(indexPatternStub);
await onSave(indexPatternStub, !formData.isAdHoc);
},
});
} else {
await onSave(indexPatternStub);
await onSave(indexPatternStub, !formData.isAdHoc);
}
},
});
Expand Down Expand Up @@ -371,6 +375,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
<h2>{editData ? editorTitleEditMode : editorTitle}</h2>
</EuiTitle>
<Form form={form} className="indexPatternEditor__form">
<UseField path="isAdHoc" />
{indexPatternTypeSelect}
<EuiSpacer size="l" />
<EuiFlexGroup>
Expand Down Expand Up @@ -409,9 +414,13 @@ const IndexPatternEditorFlyoutContentComponent = ({
</Form>
<Footer
onCancel={onCancel}
onSubmit={() => form.submit()}
onSubmit={(adhoc?: boolean) => {
form.setFieldValue('isAdHoc', adhoc || false);
form.submit();
}}
submitDisabled={form.isSubmitted && !form.isValid}
isEdit={!!editData}
allowAdHoc={allowAdHoc}
/>
</FlyoutPanels.Item>
<FlyoutPanels.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const IndexPatternFlyoutContentContainer = ({
defaultTypeIsRollup,
requireTimestampField = false,
editData,
allowAdHocDataView,
}: DataViewEditorProps) => {
const {
services: { dataViews, notifications },
} = useKibana<DataViewEditorContext>();

const onSaveClick = async (dataViewSpec: DataViewSpec) => {
const onSaveClick = async (dataViewSpec: DataViewSpec, persist: boolean = true) => {
try {
let saveResponse;
if (editData) {
Expand All @@ -34,7 +35,9 @@ const IndexPatternFlyoutContentContainer = ({
editData.timeFieldName = timeFieldName;
saveResponse = await dataViews.updateSavedObject(editData);
} else {
saveResponse = await dataViews.createAndSave(dataViewSpec);
saveResponse = persist
? await dataViews.createAndSave(dataViewSpec)
: await dataViews.create(dataViewSpec);
}

if (saveResponse && !(saveResponse instanceof Error)) {
Expand All @@ -61,6 +64,7 @@ const IndexPatternFlyoutContentContainer = ({
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
editData={editData}
allowAdHoc={allowAdHocDataView || false}
/>
);
};
Expand Down
56 changes: 44 additions & 12 deletions src/plugins/data_view_editor/public/components/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,36 @@ import {

interface FooterProps {
onCancel: () => void;
onSubmit: () => void;
onSubmit: (isAdHoc?: boolean) => void;
submitDisabled: boolean;
isEdit: boolean;
allowAdHoc: boolean;
}

const closeButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutCloseButtonLabel', {
defaultMessage: 'Close',
});

const saveButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutSaveButtonLabel', {
defaultMessage: 'Create data view',
defaultMessage: 'Save data view to Kibana',
});

const editButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutEditButtonLabel', {
defaultMessage: 'Save',
});

export const Footer = ({ onCancel, onSubmit, submitDisabled, isEdit }: FooterProps) => {
const exploreButtonLabel = i18n.translate('indexPatternEditor.editor.flyoutExploreButtonLabel', {
defaultMessage: 'Use without saving',
});

export const Footer = ({ onCancel, onSubmit, submitDisabled, isEdit, allowAdHoc }: FooterProps) => {
const submitPersisted = () => {
onSubmit(false);
};
const submitAdHoc = () => {
onSubmit(true);
};

return (
<EuiFlyoutFooter className="indexPatternEditor__footer">
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
Expand All @@ -52,15 +64,35 @@ export const Footer = ({ onCancel, onSubmit, submitDisabled, isEdit }: FooterPro
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiButton
color="primary"
onClick={onSubmit}
data-test-subj="saveIndexPatternButton"
fill
disabled={submitDisabled}
>
{isEdit ? editButtonLabel : saveButtonLabel}
</EuiButton>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
{allowAdHoc && (
<EuiFlexItem grow={false}>
<EuiButton
color="primary"
onClick={submitAdHoc}
data-test-subj="exploreIndexPatternButton"
disabled={submitDisabled}
title={i18n.translate('indexPatternEditor.editor.flyoutExploreButtonTitle', {
defaultMessage: 'Use this data view without creating a saved object',
})}
>
{exploreButtonLabel}
</EuiButton>
</EuiFlexItem>
)}

<EuiFlexItem grow={false}>
<EuiButton
color="primary"
onClick={submitPersisted}
data-test-subj="saveIndexPatternButton"
fill
disabled={submitDisabled}
>
{isEdit ? editButtonLabel : saveButtonLabel}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlyoutFooter>
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/data_view_editor/public/components/form_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ export const schema = {
}),
defaultValue: INDEX_PATTERN_TYPE.DEFAULT,
},
isAdHoc: {
label: i18n.translate('indexPatternEditor.editor.form.IsAdHocLabel', {
defaultMessage: 'Creeate AdHoc DataView',
}),
defaultValue: false,
type: 'hidden',
},
};
2 changes: 2 additions & 0 deletions src/plugins/data_view_editor/public/open_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const getEditorOpener =
onCancel = () => {},
defaultTypeIsRollup = false,
requireTimestampField = false,
allowAdHocDataView = false,
}: DataViewEditorProps): CloseEditor => {
const closeEditor = () => {
if (overlayRef) {
Expand Down Expand Up @@ -73,6 +74,7 @@ export const getEditorOpener =
}}
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
allowAdHocDataView={allowAdHocDataView}
/>
</I18nProvider>
</KibanaReactContextProvider>,
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/data_view_editor/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export interface DataViewEditorProps {
* Pass the data view to be edited.
*/
editData?: DataView;
/**
* if set to true user is presented with an option to create ad-hoc dataview without a saved object.
*/
allowAdHocDataView?: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down Expand Up @@ -157,6 +161,7 @@ export interface IndexPatternConfig {
id?: string;
type: INDEX_PATTERN_TYPE;
name?: string;
isAdHoc: boolean;
}

export interface FormInternal extends Omit<IndexPatternConfig, 'timestampField'> {
Expand Down

0 comments on commit 6f9d771

Please sign in to comment.