diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx index 60202d4903be..9ba53a1c6ac0 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx @@ -147,6 +147,20 @@ export class SavedObjectsDuplicateModal extends React.Component { return savedObjectTypeInfo && savedObjectTypeInfo[1]; }; + getIncludeAndNotDuplicateObjects = (targetWorkspaceId: string | undefined) => { + let selectedObjects = this.state.allSelectedObjects; + if (this.props.duplicateMode === DuplicateMode.All) { + selectedObjects = selectedObjects.filter((item) => this.isSavedObjectTypeIncluded(item.type)); + } + // If the target workspace is not selected, all saved objects will be retained. + // If the target workspace has been selected, filter out the saved objects that belongs to the workspace. + const includedSelectedObjects = selectedObjects.filter((item) => + !!targetWorkspaceId && !!item.workspaces ? !item.workspaces.includes(targetWorkspaceId) : true + ); + const ignoredSelectedObjectsLength = selectedObjects.length - includedSelectedObjects.length; + return { includedSelectedObjects, ignoredSelectedObjectsLength }; + }; + render() { const { workspaceOptions, @@ -156,17 +170,11 @@ export class SavedObjectsDuplicateModal extends React.Component { } = this.state; const { duplicateMode, onClose } = this.props; const targetWorkspaceId = targetWorkspaceOption?.at(0)?.key; - let selectedObjects = allSelectedObjects; - if (duplicateMode === DuplicateMode.All) { - selectedObjects = selectedObjects.filter((item) => this.isSavedObjectTypeIncluded(item.type)); - } - // If the target workspace is not selected, all saved objects will be retained. - // If the target workspace has been selected, filter out the saved objects that belongs to the workspace. - const includedSelectedObjects = selectedObjects.filter((item) => - !!targetWorkspaceId && !!item.workspaces ? !item.workspaces.includes(targetWorkspaceId) : true - ); - const ignoredSelectedObjectsLength = selectedObjects.length - includedSelectedObjects.length; + const { + includedSelectedObjects, + ignoredSelectedObjectsLength, + } = this.getIncludeAndNotDuplicateObjects(targetWorkspaceId); let confirmDuplicateButtonEnabled = false; if (!!targetWorkspaceId && includedSelectedObjects.length > 0) { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.test.tsx index f96ee5ee4aa3..da6f241f382c 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.test.tsx @@ -39,7 +39,6 @@ describe('Header', () => { onImport: () => {}, onRefresh: () => {}, onDuplicate: () => {}, - title: 'Saved Objects', objectCount: 4, filteredCount: 2, showDuplicateAll: false, @@ -56,7 +55,6 @@ describe('Header', () => { onImport: () => {}, onRefresh: () => {}, onDuplicate: () => {}, - title: 'Saved Objects', objectCount: 4, filteredCount: 2, showDuplicateAll: undefined, @@ -75,7 +73,6 @@ describe('Header - workspace enabled', () => { onImport: () => {}, onRefresh: () => {}, onDuplicate: () => {}, - title: 'Saved Objects', objectCount: 4, filteredCount: 2, showDuplicateAll: true,