Skip to content

Commit f1c3578

Browse files
authored
fix(hierarchy): hide parent draft text in publish confirmation [FC-0123] (#3029)
Fix publish confirmation hierarchy messaging for Library Authoring sidebar. When selected row has descendants/ancestors in hierarchy, parent rows no longer show Draft chip and parent warning text removed from confirmation copy. This avoids confusing message that parent rows "will be draft" while publishing selected item.
1 parent 919b0f4 commit f1c3578

3 files changed

Lines changed: 12 additions & 55 deletions

File tree

src/library-authoring/containers/ContainerInfo.test.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,24 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a
139139
containerId: unitId,
140140
childType: 'component',
141141
willPublishCount: 2,
142-
parentType: 'subsection',
143-
parentCount: 3,
144142
},
145143
{
146144
containerType: ContainerType.Subsection,
147145
containerId: subsectionId,
148146
childType: 'unit',
149147
willPublishCount: 3,
150-
parentType: 'section',
151-
parentCount: 2,
152148
},
153149
{
154150
containerType: ContainerType.Section,
155151
containerId: sectionId,
156152
childType: 'subsection',
157153
willPublishCount: 4,
158-
parentType: '',
159-
parentCount: 0,
160154
},
161155
].forEach(({
162156
containerId,
163157
containerType,
164158
childType,
165159
willPublishCount,
166-
parentType,
167-
parentCount,
168160
}) => {
169161
describe(`<ContainerInfo /> with containerType: ${containerType}`, () => {
170162
beforeEach(() => {
@@ -250,16 +242,8 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a
250242
'i',
251243
),
252244
)).toBeInTheDocument();
253-
if (parentCount > 0) {
254-
expect(screen.getByText(
255-
new RegExp(
256-
`Its parent ${parentType}s will be`, // <srong>draft</strong>
257-
'i',
258-
),
259-
)).toBeInTheDocument();
260-
}
261245
expect(screen.queryAllByText('Will Publish').length).toBe(willPublishCount);
262-
expect(screen.queryAllByText('Draft').length).toBe(4 - willPublishCount);
246+
expect(screen.queryAllByText('Draft').length).toBe(0);
263247

264248
// Click on the confirm Cancel button
265249
const publishCancel = await screen.findByRole('button', { name: 'Cancel' });
@@ -306,7 +290,7 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a
306290
expect(mockShowToast).toHaveBeenCalledWith('Failed to publish changes');
307291
});
308292

309-
it(`shows single child / parent message before publishing the ${containerType}`, async () => {
293+
it(`shows single child message before publishing the ${containerType}`, async () => {
310294
const user = userEvent.setup();
311295
render(singleChild(containerId), containerType);
312296

@@ -323,14 +307,6 @@ let mockShowToast: { (message: string, action?: ToastActionData): void; mock?: a
323307
'i',
324308
),
325309
)).toBeInTheDocument();
326-
if (parentCount) {
327-
expect(screen.getByText(
328-
new RegExp(
329-
`Its parent ${parentType} will be`, // <strong>draft</strong>
330-
'i',
331-
),
332-
)).toBeInTheDocument();
333-
}
334310
});
335311

336312
it(`omits child count before publishing an empty ${containerType}`, async () => {

src/library-authoring/hierarchy/ItemHierarchy.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ export const ItemHierarchy = ({
108108
} = data;
109109

110110
// Returns a message describing the publish status of the given hierarchy row.
111-
const publishMessage = (contents: ItemHierarchyMember[]) => {
111+
const publishMessage = (
112+
contents: ItemHierarchyMember[],
113+
isParentOfSelectedRow = false,
114+
) => {
112115
// If we're not showing publish status, then we don't need a publish message
113-
if (!showPublishStatus) {
116+
if (!showPublishStatus || isParentOfSelectedRow) {
114117
return undefined;
115118
}
116119

117120
// If any item has unpublished changes, mark this row as Draft.
121+
// Skip Draft for parent rows of currently selected row.
118122
if (contents.some((item) => item.hasUnpublishedChanges)) {
119123
return messages.draftChipText;
120124
}
@@ -155,7 +159,7 @@ export const ItemHierarchy = ({
155159
showArrow={showSubsections}
156160
selected={selectedSections}
157161
willPublish={selectedSections}
158-
publishMessage={publishMessage(sections)}
162+
publishMessage={publishMessage(sections, selectedSubsections || selectedUnits || selectedComponents)}
159163
/>
160164
)}
161165
{showSubsections && (
@@ -171,7 +175,7 @@ export const ItemHierarchy = ({
171175
showArrow={showUnits}
172176
selected={selectedSubsections}
173177
willPublish={selectedSubsections || selectedSections}
174-
publishMessage={publishMessage(subsections)}
178+
publishMessage={publishMessage(subsections, selectedUnits || selectedComponents)}
175179
/>
176180
)}
177181
{showUnits && (
@@ -187,7 +191,7 @@ export const ItemHierarchy = ({
187191
showArrow={showComponents}
188192
selected={selectedUnits}
189193
willPublish={selectedUnits || selectedSubsections || selectedSections}
190-
publishMessage={publishMessage(units)}
194+
publishMessage={publishMessage(units, selectedComponents)}
191195
/>
192196
)}
193197
{showComponents && (

src/library-authoring/hierarchy/ItemHierarchyPublisher.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,10 @@ export const ItemHierarchyPublisher = ({
8181
);
8282
};
8383

84-
const parentWarningMessage = () => {
85-
let parentCount: number;
86-
let parentMessage: MessageDescriptor;
87-
88-
switch (itemType) {
89-
case ContainerType.Section:
90-
// Section has no parents
91-
return undefined;
92-
case ContainerType.Subsection:
93-
parentMessage = messages.publishSubsectionWithParentWarning;
94-
parentCount = hierarchy.sections.length;
95-
break;
96-
case ContainerType.Unit:
97-
parentMessage = messages.publishUnitWithParentWarning;
98-
parentCount = hierarchy.subsections.length;
99-
break;
100-
default: // The item is a component
101-
parentMessage = messages.publishComponentsWithParentWarning;
102-
parentCount = hierarchy.units.length;
103-
}
104-
return intl.formatMessage(parentMessage, { parentCount, highlight });
105-
};
106-
10784
return (
10885
<Container className="p-3 status-box draft-status">
10986
<h4>{intl.formatMessage(messages.publishConfirmHeading)}</h4>
110-
<p>{childWarningMessage()} {parentWarningMessage()}</p>
87+
<p>{childWarningMessage()}</p>
11188
<ItemHierarchy showPublishStatus />
11289
<ActionRow>
11390
<Button

0 commit comments

Comments
 (0)