mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
SO management: Use diplay name for type in overwrite modal (#139711)
This commit is contained in:
parent
07aa6d9586
commit
73cce61a1e
3 changed files with 31 additions and 4 deletions
|
@ -618,7 +618,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { close } = this.props;
|
||||
const { close, allowedTypes } = this.props;
|
||||
|
||||
let confirmOverwriteModal: ReactNode;
|
||||
const { conflictingRecord } = this.state;
|
||||
|
@ -626,7 +626,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
|
|||
const { conflict } = conflictingRecord;
|
||||
const onFinish = (overwrite: boolean, destinationId?: string) =>
|
||||
conflictingRecord.done([overwrite, destinationId]);
|
||||
confirmOverwriteModal = <OverwriteModal {...{ conflict, onFinish }} />;
|
||||
confirmOverwriteModal = <OverwriteModal {...{ conflict, onFinish, allowedTypes }} />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -23,6 +23,7 @@ describe('OverwriteModal', () => {
|
|||
const props: OverwriteModalProps = {
|
||||
conflict: { obj, error: { type: 'conflict', destinationId: 'qux' } },
|
||||
onFinish,
|
||||
allowedTypes: [],
|
||||
};
|
||||
|
||||
it('should render as expected', async () => {
|
||||
|
@ -65,6 +66,7 @@ describe('OverwriteModal', () => {
|
|||
},
|
||||
},
|
||||
onFinish,
|
||||
allowedTypes: [],
|
||||
};
|
||||
|
||||
it('should render as expected', async () => {
|
||||
|
@ -93,4 +95,24 @@ describe('OverwriteModal', () => {
|
|||
expect(onFinish).toHaveBeenCalledWith(true, 'qux');
|
||||
});
|
||||
});
|
||||
|
||||
describe('displaying a type with a displayName', () => {
|
||||
const props: OverwriteModalProps = {
|
||||
conflict: { obj, error: { type: 'conflict', destinationId: 'qux' } },
|
||||
onFinish,
|
||||
allowedTypes: [
|
||||
{ name: 'foo', hidden: false, namespaceType: 'multiple', displayName: 'fooDisplayName' },
|
||||
],
|
||||
};
|
||||
|
||||
it('should use the displayName for the title of the modal', async () => {
|
||||
const wrapper = shallowWithI18nProvider<{ title: string }>(<OverwriteModal {...props} />);
|
||||
|
||||
expect(wrapper.props()).toEqual(
|
||||
expect.objectContaining({
|
||||
title: 'Overwrite fooDisplayName?',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,15 +10,17 @@ import React, { useState, Fragment, ReactNode } from 'react';
|
|||
import { EuiConfirmModal, EUI_MODAL_CONFIRM_BUTTON, EuiText, EuiSuperSelect } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import moment from 'moment';
|
||||
import type { SavedObjectManagementTypeInfo } from '../../../../common/types';
|
||||
import { FailedImportConflict } from '../../../lib/resolve_import_errors';
|
||||
import { getDefaultTitle } from '../../../lib';
|
||||
|
||||
export interface OverwriteModalProps {
|
||||
conflict: FailedImportConflict;
|
||||
onFinish: (overwrite: boolean, destinationId?: string) => void;
|
||||
allowedTypes: SavedObjectManagementTypeInfo[];
|
||||
}
|
||||
|
||||
export const OverwriteModal = ({ conflict, onFinish }: OverwriteModalProps) => {
|
||||
export const OverwriteModal = ({ conflict, onFinish, allowedTypes }: OverwriteModalProps) => {
|
||||
const { obj, error } = conflict;
|
||||
let initialDestinationId: string | undefined;
|
||||
let selectControl: ReactNode = null;
|
||||
|
@ -78,6 +80,8 @@ export const OverwriteModal = ({ conflict, onFinish }: OverwriteModalProps) => {
|
|||
|
||||
const { type, meta } = obj;
|
||||
const title = meta.title || getDefaultTitle(obj);
|
||||
const typeMeta = allowedTypes.find((t) => t.name === type);
|
||||
const typeDisplayName = typeMeta?.displayName ?? type;
|
||||
const bodyText =
|
||||
error.type === 'conflict'
|
||||
? i18n.translate('savedObjectsManagement.objectsTable.overwriteModal.body.conflict', {
|
||||
|
@ -91,11 +95,12 @@ export const OverwriteModal = ({ conflict, onFinish }: OverwriteModalProps) => {
|
|||
values: { title },
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<EuiConfirmModal
|
||||
title={i18n.translate('savedObjectsManagement.objectsTable.overwriteModal.title', {
|
||||
defaultMessage: 'Overwrite {type}?',
|
||||
values: { type },
|
||||
values: { type: typeDisplayName },
|
||||
})}
|
||||
cancelButtonText={i18n.translate(
|
||||
'savedObjectsManagement.objectsTable.overwriteModal.cancelButtonText',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue