Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 2 additions & 26 deletions src/library-authoring/containers/ContainerInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<ContainerInfo /> with containerType: ${containerType}`, () => {
beforeEach(() => {
Expand Down Expand Up @@ -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`, // <srong>draft</strong>
'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' });
Expand Down Expand Up @@ -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);

Expand All @@ -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`, // <strong>draft</strong>
'i',
),
)).toBeInTheDocument();
}
});

it(`omits child count before publishing an empty ${containerType}`, async () => {
Expand Down
14 changes: 9 additions & 5 deletions src/library-authoring/hierarchy/ItemHierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -155,7 +159,7 @@ export const ItemHierarchy = ({
showArrow={showSubsections}
selected={selectedSections}
willPublish={selectedSections}
publishMessage={publishMessage(sections)}
publishMessage={publishMessage(sections, selectedSubsections || selectedUnits || selectedComponents)}
/>
)}
{showSubsections && (
Expand All @@ -171,7 +175,7 @@ export const ItemHierarchy = ({
showArrow={showUnits}
selected={selectedSubsections}
willPublish={selectedSubsections || selectedSections}
publishMessage={publishMessage(subsections)}
publishMessage={publishMessage(subsections, selectedUnits || selectedComponents)}
/>
)}
{showUnits && (
Expand All @@ -187,7 +191,7 @@ export const ItemHierarchy = ({
showArrow={showComponents}
selected={selectedUnits}
willPublish={selectedUnits || selectedSubsections || selectedSections}
publishMessage={publishMessage(units)}
publishMessage={publishMessage(units, selectedComponents)}
/>
)}
{showComponents && (
Expand Down
25 changes: 1 addition & 24 deletions src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container className="p-3 status-box draft-status">
<h4>{intl.formatMessage(messages.publishConfirmHeading)}</h4>
<p>{childWarningMessage()} {parentWarningMessage()}</p>
<p>{childWarningMessage()}</p>
<ItemHierarchy showPublishStatus />
<ActionRow>
<Button
Expand Down