diff --git a/src/library-authoring/containers/ContainerInfo.test.tsx b/src/library-authoring/containers/ContainerInfo.test.tsx index 3273ccb1a5..44ff7ea9b3 100644 --- a/src/library-authoring/containers/ContainerInfo.test.tsx +++ b/src/library-authoring/containers/ContainerInfo.test.tsx @@ -139,32 +139,24 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a containerId: unitId, childType: 'component', willPublishCount: 2, - parentType: 'subsection', - parentCount: 3, }, { containerType: ContainerType.Subsection, containerId: subsectionId, childType: 'unit', willPublishCount: 3, - parentType: 'section', - parentCount: 2, }, { containerType: ContainerType.Section, containerId: sectionId, childType: 'subsection', willPublishCount: 4, - parentType: '', - parentCount: 0, }, ].forEach(({ containerId, containerType, childType, willPublishCount, - parentType, - parentCount, }) => { describe(` with containerType: ${containerType}`, () => { beforeEach(() => { @@ -250,16 +242,8 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a 'i', ), )).toBeInTheDocument(); - if (parentCount > 0) { - expect(screen.getByText( - new RegExp( - `Its parent ${parentType}s will be`, // draft - 'i', - ), - )).toBeInTheDocument(); - } expect(screen.queryAllByText('Will Publish').length).toBe(willPublishCount); - expect(screen.queryAllByText('Draft').length).toBe(4 - willPublishCount); + expect(screen.queryAllByText('Draft').length).toBe(0); // Click on the confirm Cancel button const publishCancel = await screen.findByRole('button', { name: 'Cancel' }); @@ -306,7 +290,7 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a expect(mockShowToast).toHaveBeenCalledWith('Failed to publish changes'); }); - it(`shows single child / parent message before publishing the ${containerType}`, async () => { + it(`shows single child message before publishing the ${containerType}`, async () => { const user = userEvent.setup(); render(singleChild(containerId), containerType); @@ -323,14 +307,6 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a 'i', ), )).toBeInTheDocument(); - if (parentCount) { - expect(screen.getByText( - new RegExp( - `Its parent ${parentType} will be`, // draft - 'i', - ), - )).toBeInTheDocument(); - } }); it(`omits child count before publishing an empty ${containerType}`, async () => { diff --git a/src/library-authoring/hierarchy/ItemHierarchy.tsx b/src/library-authoring/hierarchy/ItemHierarchy.tsx index 036f1be209..199a0eccdb 100644 --- a/src/library-authoring/hierarchy/ItemHierarchy.tsx +++ b/src/library-authoring/hierarchy/ItemHierarchy.tsx @@ -108,13 +108,17 @@ export const ItemHierarchy = ({ } = data; // Returns a message describing the publish status of the given hierarchy row. - const publishMessage = (contents: ItemHierarchyMember[]) => { + const publishMessage = ( + contents: ItemHierarchyMember[], + isParentOfSelectedRow = false, + ) => { // If we're not showing publish status, then we don't need a publish message - if (!showPublishStatus) { + if (!showPublishStatus || isParentOfSelectedRow) { return undefined; } // If any item has unpublished changes, mark this row as Draft. + // Skip Draft for parent rows of currently selected row. if (contents.some((item) => item.hasUnpublishedChanges)) { return messages.draftChipText; } @@ -155,7 +159,7 @@ export const ItemHierarchy = ({ showArrow={showSubsections} selected={selectedSections} willPublish={selectedSections} - publishMessage={publishMessage(sections)} + publishMessage={publishMessage(sections, selectedSubsections || selectedUnits || selectedComponents)} /> )} {showSubsections && ( @@ -171,7 +175,7 @@ export const ItemHierarchy = ({ showArrow={showUnits} selected={selectedSubsections} willPublish={selectedSubsections || selectedSections} - publishMessage={publishMessage(subsections)} + publishMessage={publishMessage(subsections, selectedUnits || selectedComponents)} /> )} {showUnits && ( @@ -187,7 +191,7 @@ export const ItemHierarchy = ({ showArrow={showComponents} selected={selectedUnits} willPublish={selectedUnits || selectedSubsections || selectedSections} - publishMessage={publishMessage(units)} + publishMessage={publishMessage(units, selectedComponents)} /> )} {showComponents && ( diff --git a/src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx b/src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx index aa39ba4228..d3a131a132 100644 --- a/src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx +++ b/src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx @@ -81,33 +81,10 @@ export const ItemHierarchyPublisher = ({ ); }; - const parentWarningMessage = () => { - let parentCount: number; - let parentMessage: MessageDescriptor; - - switch (itemType) { - case ContainerType.Section: - // Section has no parents - return undefined; - case ContainerType.Subsection: - parentMessage = messages.publishSubsectionWithParentWarning; - parentCount = hierarchy.sections.length; - break; - case ContainerType.Unit: - parentMessage = messages.publishUnitWithParentWarning; - parentCount = hierarchy.subsections.length; - break; - default: // The item is a component - parentMessage = messages.publishComponentsWithParentWarning; - parentCount = hierarchy.units.length; - } - return intl.formatMessage(parentMessage, { parentCount, highlight }); - }; - return ( {intl.formatMessage(messages.publishConfirmHeading)} - {childWarningMessage()} {parentWarningMessage()} + {childWarningMessage()}
{childWarningMessage()} {parentWarningMessage()}
{childWarningMessage()}