Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n';
import {
showSaveModal,
OnSaveProps,
SavedObjectSaveModal,
SavedObjectSaveModalWithSaveResult,
SaveResult,
} from '@kbn/saved-objects-plugin/public';
import { CONTENT_ID } from '../../common';
Expand Down Expand Up @@ -83,7 +83,7 @@ export const runSaveToLibrary = async (
};

const saveModal = (
<SavedObjectSaveModal
<SavedObjectSaveModalWithSaveResult
onSave={onSave}
onClose={() => resolve(undefined)}
title={newState.title ?? ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { BehaviorSubject } from 'rxjs';
jest.mock('@kbn/saved-objects-plugin/public', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { render } = require('@testing-library/react');
const MockSavedObjectSaveModal = ({ onSave }: { onSave: (props: OnSaveProps) => void }) => {
const MockSavedObjectSaveModal = ({
onSave,
}: {
onSave: (props: OnSaveProps) => Promise<unknown> | unknown;
}) => {
// invoke onSave synchronously to simulate the user confirming the save
onSave({
newTitle: 'Library panel one',
newCopyOnSave: true,
Expand All @@ -26,7 +31,7 @@ jest.mock('@kbn/saved-objects-plugin/public', () => {
return null;
};
return {
SavedObjectSaveModal: MockSavedObjectSaveModal,
SavedObjectSaveModalWithSaveResult: MockSavedObjectSaveModal,
showSaveModal: (saveModal: React.ReactElement) => {
render(saveModal);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import {
OnSaveProps,
SaveResult,
SavedObjectSaveModal,
SavedObjectSaveModalWithSaveResult,
showSaveModal,
} from '@kbn/saved-objects-plugin/public';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
Expand Down Expand Up @@ -113,7 +113,7 @@ export class AddToLibraryAction implements Action<EmbeddableApiContext> {
}
};
showSaveModal(
<SavedObjectSaveModal
<SavedObjectSaveModalWithSaveResult
onSave={onSave}
onClose={() => {}}
title={lastTitle ?? ''}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ jest.mock('@kbn/saved-objects-plugin/public', () => ({

import { DashboardSaveModal } from './save_modal';

const mockSave = jest.fn();
const mockClose = jest.fn();

test('renders DashboardSaveModal', () => {
const component = shallowWithI18nProvider(
<DashboardSaveModal
onSave={() => {}}
onClose={() => {}}
onSave={mockSave}
onClose={mockClose}
title="dash title"
description="dash description"
timeRestore={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import React, { Fragment, useCallback } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiIconTip, EuiSwitch } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { SavedObjectSaveModal } from '@kbn/saved-objects-plugin/public';
import type { SaveResult } from '@kbn/saved-objects-plugin/public';
import { SavedObjectSaveModalWithSaveResult } from '@kbn/saved-objects-plugin/public';
import { savedObjectsTaggingService } from '../../services/kibana_services';
import type { DashboardSaveOptions } from './types';

Expand All @@ -25,7 +26,7 @@ interface DashboardSaveModalProps {
newTimeRestore,
isTitleDuplicateConfirmed,
onTitleDuplicate,
}: DashboardSaveOptions) => void;
}: DashboardSaveOptions) => Promise<SaveResult>;
onClose: () => void;
title: string;
description: string;
Expand Down Expand Up @@ -130,7 +131,7 @@ export const DashboardSaveModal: React.FC<DashboardSaveModalProps> = ({
}, [persistSelectedTimeInterval, selectedTags, showStoreTimeOnSave]);

return (
<SavedObjectSaveModal
<SavedObjectSaveModalWithSaveResult
onSave={saveDashboard}
onClose={onClose}
title={title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiSwitch } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import type { OnSaveProps } from '@kbn/saved-objects-plugin/public';
import { SavedObjectSaveModal, showSaveModal } from '@kbn/saved-objects-plugin/public';
import type {
OnSaveProps,
SaveResult,
ShowSaveModalMinimalSaveModalProps,
} from '@kbn/saved-objects-plugin/public';
import {
SavedObjectSaveModalWithSaveResult,
showSaveModal,
} from '@kbn/saved-objects-plugin/public';
import type { SavedSearch, SaveSavedSearchOptions } from '@kbn/saved-search-plugin/public';
import { isLegacyTableEnabled } from '@kbn/discover-utils';
import type { DiscoverServices } from '../../../../build_services';
Expand Down Expand Up @@ -116,7 +123,7 @@ export async function onSaveSearch({
newTags: string[];
isTitleDuplicateConfirmed: boolean;
onTitleDuplicate: () => void;
}) => {
}): Promise<SaveResult> => {
const appState = state.appState.getState();
const currentTitle = savedSearch.title;
const currentTimeRestore = savedSearch.timeRestore;
Expand Down Expand Up @@ -189,10 +196,10 @@ export async function onSaveSearch({

onSaveCb?.();

return response;
return response ?? {};
};

const saveModal = (
const saveModal: React.ReactElement<ShowSaveModalMinimalSaveModalProps> = (
<SaveSearchObjectModal
isTimeBased={dataView?.isTimeBased() ?? false}
services={services}
Expand Down Expand Up @@ -220,7 +227,9 @@ const SaveSearchObjectModal: React.FC<{
description?: string;
timeRestore?: boolean;
tags: string[];
onSave: (props: OnSaveProps & { newTimeRestore: boolean; newTags: string[] }) => void;
onSave: (
props: OnSaveProps & { newTimeRestore: boolean; newTags: string[] }
) => Promise<SaveResult>;
onClose: () => void;
managed: boolean;
}> = ({
Expand All @@ -242,8 +251,8 @@ const SaveSearchObjectModal: React.FC<{
);
const [currentTags, setCurrentTags] = useState(tags);

const onModalSave = (params: OnSaveProps) => {
onSave({
const onModalSave = async (params: OnSaveProps): Promise<SaveResult> => {
return onSave({
...params,
newTimeRestore: timeRestore,
newTags: currentTags,
Expand Down Expand Up @@ -292,7 +301,7 @@ const SaveSearchObjectModal: React.FC<{
);

return (
<SavedObjectSaveModal
<SavedObjectSaveModalWithSaveResult
title={title}
showCopyOnSave={showCopyOnSave}
initialCopyOnSave={initialCopyOnSave}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export const LazySavedObjectSaveModalDashboard = React.lazy(
() => import('./saved_object_save_modal_dashboard')
);

/**
* Used with `showSaveModal` to pass `SaveResult` back from `onSave`
*/
export const LazySavedObjectSaveModalDashboardWithSaveResult = React.lazy(
() => import('./saved_object_save_modal_dashboard_with_save_result')
);

export const LazyDataViewPicker = React.lazy(() => import('./data_view_picker/data_view_picker'));

export const LazyFieldPicker = React.lazy(() => import('./field_picker/field_picker'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SaveModalDashboardProps } from './types';
import { SaveModalDashboardSelector } from './saved_object_save_modal_dashboard_selector';
import { getPresentationCapabilities } from '../utils/get_presentation_capabilities';

function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
function SavedObjectSaveModalDashboard<T = void>(props: SaveModalDashboardProps<T>) {
const { documentInfo, tagOptions, objectType, onClose, canSaveByReference } = props;
const { id: documentId } = documentInfo;
const initialCopyOnSave = !Boolean(documentId);
Expand Down Expand Up @@ -75,7 +75,7 @@ function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
setCopyOnSave(newCopyOnSave);
};

const onModalSave = (onSaveProps: OnSaveProps) => {
const onModalSave = async (onSaveProps: OnSaveProps): Promise<void> => {
let dashboardId = null;

// Don't save with a dashboard ID if we're
Expand All @@ -88,7 +88,7 @@ function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
}
}

props.onSave({ ...onSaveProps, dashboardId, addToLibrary: isAddToLibrarySelected });
await props.onSave({ ...onSaveProps, dashboardId, addToLibrary: isAddToLibrarySelected });
};

const saveLibraryLabel =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { SaveResult } from '@kbn/saved-objects-plugin/public';

import SavedObjectSaveModalDashboard from './saved_object_save_modal_dashboard';

/**
* Used with `showSaveModal` to pass `SaveResult` back from `onSave`
*/
const SavedObjectSaveModalDashboardWithSaveResult = SavedObjectSaveModalDashboard<SaveResult>;

// required for dynamic import using React.lazy()
// eslint-disable-next-line import/no-default-export
export default SavedObjectSaveModalDashboardWithSaveResult;
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ interface SaveModalDocumentInfo {
description?: string;
}

export interface SaveModalDashboardProps {
export interface SaveModalDashboardProps<T = void> {
documentInfo: SaveModalDocumentInfo;
canSaveByReference: boolean;
objectType: string;
onClose: () => void;
onSave: (props: OnSaveProps & { dashboardId: string | null; addToLibrary: boolean }) => void;
onSave: (
props: OnSaveProps & { dashboardId: string | null; addToLibrary: boolean }
) => Promise<T>;
tagOptions?: React.ReactNode | ((state: SaveModalState) => React.ReactNode);
// include a message if the user has to copy on save
mustCopyOnSaveMessage?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
LazyLabsFlyout,
LazyDashboardPicker,
LazySavedObjectSaveModalDashboard,
LazySavedObjectSaveModalDashboardWithSaveResult,
withSuspense,
LazyDataViewPicker,
LazyFieldPicker,
Expand Down
8 changes: 7 additions & 1 deletion src/platform/plugins/shared/saved_objects/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
import { SavedObjectsPublicPlugin } from './plugin';

export type { OnSaveProps, OriginSaveModalProps, SaveModalState, SaveResult } from './save_modal';
export { SavedObjectSaveModal, SavedObjectSaveModalOrigin, showSaveModal } from './save_modal';
export {
SavedObjectSaveModal,
SavedObjectSaveModalWithSaveResult,
SavedObjectSaveModalOrigin,
showSaveModal,
type ShowSaveModalMinimalSaveModalProps,
} from './save_modal';
export { isErrorNonFatal } from './saved_object';
export type { SavedObjectSaveOpts, SavedObject, SavedObjectConfig } from './types';

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
*/

export type { OnSaveProps, SaveModalState } from './saved_object_save_modal';
export { SavedObjectSaveModal } from './saved_object_save_modal';
export {
SavedObjectSaveModal,
SavedObjectSaveModalWithSaveResult,
} from './saved_object_save_modal';
export type { OriginSaveModalProps } from './saved_object_save_modal_origin';
export { SavedObjectSaveModalOrigin } from './saved_object_save_modal_origin';
export type { SaveResult } from './show_saved_object_save_modal';
export { showSaveModal } from './show_saved_object_save_modal';
export {
showSaveModal,
type ShowSaveModalMinimalSaveModalProps,
} from './show_saved_object_save_modal';
Loading