Skip to content

Commit 0db79f3

Browse files
fix: clean up invalid breadcrumb usages in library updates (#2811)
1 parent 82e2419 commit 0db79f3

5 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/container-comparison/CompareContainersWidget.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ describe('CompareContainersWidget', () => {
6868
let block = await screen.findByText('subsection block 00');
6969
await user.click(block);
7070
// Breadcrumbs - shows old and new name
71-
expect(await screen.findByRole('button', { name: 'subsection block 00' })).toBeInTheDocument();
72-
expect(await screen.findByRole('button', { name: 'subsection block 0' })).toBeInTheDocument();
71+
expect(await screen.findByRole('heading', { name: 'subsection block 00' })).toBeInTheDocument();
72+
expect(await screen.findByRole('heading', { name: 'subsection block 0' })).toBeInTheDocument();
7373

7474
// Back breadcrumb
7575
const backbtns = await screen.findAllByRole('button', { name: 'Back' });
@@ -83,8 +83,8 @@ describe('CompareContainersWidget', () => {
8383

8484
// After side click also works
8585
await user.click(block);
86-
expect(await screen.findByRole('button', { name: 'subsection block 00' })).toBeInTheDocument();
87-
expect(await screen.findByRole('button', { name: 'subsection block 0' })).toBeInTheDocument();
86+
expect(await screen.findByRole('heading', { name: 'subsection block 00' })).toBeInTheDocument();
87+
expect(await screen.findByRole('heading', { name: 'subsection block 0' })).toBeInTheDocument();
8888
});
8989

9090
test('should show removed container diff state', async () => {

src/container-comparison/CompareContainersWidget.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { useCallback, useMemo, useState } from 'react';
2-
32
import {
43
Alert,
5-
Breadcrumb, Button, Card, Icon, Stack,
4+
Button,
5+
Card,
6+
Icon,
7+
Stack,
68
} from '@openedx/paragon';
7-
import { ArrowBack, Add, Delete } from '@openedx/paragon/icons';
9+
import {
10+
Add,
11+
ArrowBack,
12+
ChevronRight,
13+
Delete,
14+
} from '@openedx/paragon/icons';
815
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
916

1017
import { ContainerType, getBlockType } from '@src/generic/key-utils';
@@ -148,25 +155,15 @@ const CompareContainersWidgetInner = ({
148155
return title;
149156
}
150157
return (
151-
<Breadcrumb
152-
ariaLabel={intl.formatMessage(messages.breadcrumbAriaLabel)}
153-
links={[
154-
{
155-
// This raises failed prop-type error as label expects a string but it works without any issues
156-
label: <Stack direction="horizontal" gap={1}><Icon size="xs" src={ArrowBack} />Back</Stack>,
157-
onClick: onBackBtnClick,
158-
variant: 'link',
159-
className: 'px-0 text-gray-900',
160-
},
161-
{
162-
label: title,
163-
variant: 'link',
164-
className: 'px-0 text-gray-900',
165-
disabled: true,
166-
},
167-
]}
168-
linkAs={Button}
169-
/>
158+
<Stack direction="horizontal" gap={1}>
159+
<Button variant="link" className="px-0 text-gray-900" onClick={onBackBtnClick}>
160+
{/* We could also use iconBefore={ArrowBack} on the <Button> above but it's a bit too big that way. */}
161+
<Icon size="xs" src={ArrowBack} className="mr-1" />
162+
{intl.formatMessage(messages.breadcrumbBackLabel)}
163+
</Button>
164+
<Icon size="md" src={ChevronRight} />
165+
<span role="heading" aria-level={3}>{title}</span>
166+
</Stack>
170167
);
171168
}, [parent]);
172169

src/container-comparison/messages.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ const messages = defineMessages({
6868
},
6969
breadcrumbAriaLabel: {
7070
id: 'course-authoring.container-comparison.diff.breadcrumb.ariaLabel',
71-
defaultMessage: 'Title breadcrumb',
72-
description: 'Aria label text for breadcrumb in diff preview',
71+
defaultMessage: 'Location',
72+
description: 'Accessible label for the breadcrumbs which display the location of the unit, e.g. Section 1 > Unit 4',
73+
},
74+
breadcrumbBackLabel: {
75+
id: 'course-authoring.container-comparison.diff.breadcrumb.backLabel',
76+
defaultMessage: 'Back',
77+
description: 'Link to go back to the parent section/subsection',
7378
},
7479
diffBeforeTitle: {
7580
id: 'course-authoring.container-comparison.diff.before.title',

src/course-unit/move-modal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const MoveModal: FC<IUseMoveModalParams> = ({
5050
{ label: breadcrumb, 'data-parent-index': index }
5151
))}
5252
activeLabel={breadcrumbs[breadcrumbs.length - 1]}
53-
clickHandler={({ target }) => handleBreadcrumbsClick(target.dataset.parentIndex)}
53+
clickHandler={({ currentTarget }) => handleBreadcrumbsClick(currentTarget.dataset.parentIndex!)}
5454
/>
5555
), [isExtraSmall, breadcrumbs, handleBreadcrumbsClick]);
5656

src/library-authoring/generic/parent-breadcrumbs/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const ParentBreadcrumbs = ({ libraryData, parents, containerType }: Paren
105105
// Add all parents as a single object containing list of links
106106
// This is converted to overflow menu by OverflowLinks component
107107
links.push({
108-
label: parents.displayName || [],
108+
label: parents.displayName || '',
109109
to: parents.key?.map((parentKey) => `/library/${libraryId}/${parentType}/${parentKey}`) || [],
110110
containerType,
111111
});
@@ -114,6 +114,8 @@ export const ParentBreadcrumbs = ({ libraryData, parents, containerType }: Paren
114114
return (
115115
<Breadcrumb
116116
ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)}
117+
// @ts-ignore FIXME: <Breadcrumb> uses `label` as a key, so it shouldn't be an array (string[]),
118+
// even if our custom <OverflowLinks> is handling arrays properly.
117119
links={links}
118120
linkAs={OverflowLinks}
119121
/>

0 commit comments

Comments
 (0)