From 73cce61a1e1f7ebce06efeed2ab716d873a3878e Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Thu, 1 Sep 2022 07:49:56 +0200 Subject: [PATCH] SO management: Use diplay name for type in overwrite modal (#139711) --- .../objects_table/components/flyout.tsx | 4 ++-- .../components/overwrite_modal.test.tsx | 22 +++++++++++++++++++ .../components/overwrite_modal.tsx | 9 ++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx index dd46606a60316..8e376fe7c7e6a 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx @@ -618,7 +618,7 @@ export class Flyout extends Component { } 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 { const { conflict } = conflictingRecord; const onFinish = (overwrite: boolean, destinationId?: string) => conflictingRecord.done([overwrite, destinationId]); - confirmOverwriteModal = ; + confirmOverwriteModal = ; } return ( diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.test.tsx index c07ab70079ccf..37da868d04248 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.test.tsx @@ -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 }>(); + + expect(wrapper.props()).toEqual( + expect.objectContaining({ + title: 'Overwrite fooDisplayName?', + }) + ); + }); + }); }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.tsx index 4458ed02f4f4c..2b84c1bea2820 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/overwrite_modal.tsx @@ -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 (