Skip to content

Commit 5b7efc6

Browse files
authored
feat: add library reuse indicators to all components in course outline [FC-0097] (#2295)
Add library reuse indicator to units, subsections and sections in course outline.
1 parent f9cd15e commit 5b7efc6

File tree

7 files changed

+47
-21
lines changed

7 files changed

+47
-21
lines changed

src/course-outline/card-header/TitleButton.jsx renamed to src/course-outline/card-header/TitleButton.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import PropTypes from 'prop-types';
21
import { useIntl } from '@edx/frontend-platform/i18n';
32
import {
43
Button,
@@ -12,12 +11,21 @@ import {
1211
} from '@openedx/paragon/icons';
1312
import messages from './messages';
1413

14+
interface TitleButtonProps {
15+
title: string;
16+
prefixIcon?: React.ReactNode;
17+
isExpanded: boolean;
18+
onTitleClick: () => void;
19+
namePrefix: string;
20+
}
21+
1522
const TitleButton = ({
1623
title,
24+
prefixIcon,
1725
isExpanded,
1826
onTitleClick,
1927
namePrefix,
20-
}) => {
28+
}: TitleButtonProps) => {
2129
const intl = useIntl();
2230
const titleTooltipMessage = intl.formatMessage(messages.expandTooltip);
2331

@@ -39,17 +47,11 @@ const TitleButton = ({
3947
className="item-card-header__title-btn"
4048
onClick={onTitleClick}
4149
>
50+
{prefixIcon}
4251
<Truncate.Deprecated lines={1} className={`${namePrefix}-card-title mb-0`}>{title}</Truncate.Deprecated>
4352
</Button>
4453
</OverlayTrigger>
4554
);
4655
};
4756

48-
TitleButton.propTypes = {
49-
title: PropTypes.string.isRequired,
50-
isExpanded: PropTypes.bool.isRequired,
51-
onTitleClick: PropTypes.func.isRequired,
52-
namePrefix: PropTypes.string.isRequired,
53-
};
54-
5557
export default TitleButton;
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import PropTypes from 'prop-types';
21
import { Link } from 'react-router-dom';
32
import { Button, Truncate } from '@openedx/paragon';
43

4+
interface TitleLinkProps {
5+
title: string;
6+
titleLink: string;
7+
namePrefix: string;
8+
prefixIcon?: React.ReactNode;
9+
}
10+
511
const TitleLink = ({
612
title,
713
titleLink,
814
namePrefix,
9-
}) => (
15+
prefixIcon,
16+
}: TitleLinkProps) => (
1017
<Button
1118
as={Link}
1219
variant="tertiary"
1320
data-testid={`${namePrefix}-card-header__title-link`}
14-
className="item-card-header__title-btn"
21+
className="item-card-header__title-btn align-items-end"
1522
to={titleLink}
1623
>
24+
{prefixIcon}
1725
<Truncate.Deprecated lines={1} className={`${namePrefix}-card-title mb-0`}>{title}</Truncate.Deprecated>
1826
</Button>
1927
);
2028

21-
TitleLink.propTypes = {
22-
title: PropTypes.string.isRequired,
23-
titleLink: PropTypes.string.isRequired,
24-
namePrefix: PropTypes.string.isRequired,
25-
};
26-
2729
export default TitleLink;

src/course-outline/section-card/SectionCard.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ const section = {
6464
},
6565
}],
6666
},
67+
upstreamInfo: {
68+
readyToSync: true,
69+
upstreamRef: 'lct:org1:lib1:section:1',
70+
versionSynced: 1,
71+
},
6772
} as XBlock;
6873

6974
const onEditSectionSubmit = jest.fn();

src/course-outline/section-card/SectionCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {
44
import { useDispatch } from 'react-redux';
55
import { useIntl } from '@edx/frontend-platform/i18n';
66
import {
7-
Bubble, Button, StandardModal, useToggle,
7+
Bubble, Button, Icon, StandardModal, useToggle,
88
} from '@openedx/paragon';
9+
import { Newsstand } from '@openedx/paragon/icons';
910
import { useSearchParams } from 'react-router-dom';
1011
import classNames from 'classnames';
1112

@@ -224,6 +225,9 @@ const SectionCard = ({
224225
isExpanded={isExpanded}
225226
onTitleClick={handleExpandContent}
226227
namePrefix={namePrefix}
228+
prefixIcon={!!section.upstreamInfo?.upstreamRef && (
229+
<Icon src={Newsstand} className="mr-1" />
230+
)}
227231
/>
228232
);
229233

src/course-outline/subsection-card/SubsectionCard.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ const subsection: XBlock = {
6767
id: unit.id,
6868
}],
6969
},
70+
upstreamInfo: {
71+
readyToSync: true,
72+
upstreamRef: 'lct:org1:lib1:subsection:1',
73+
versionSynced: 1,
74+
},
7075
} as XBlock;
7176

7277
const section: XBlock = {

src/course-outline/subsection-card/SubsectionCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import React, {
44
import { useDispatch } from 'react-redux';
55
import { useSearchParams } from 'react-router-dom';
66
import { useIntl } from '@edx/frontend-platform/i18n';
7-
import { StandardModal, useToggle } from '@openedx/paragon';
7+
import { Icon, StandardModal, useToggle } from '@openedx/paragon';
8+
import { Newsstand } from '@openedx/paragon/icons';
89
import classNames from 'classnames';
910
import { isEmpty } from 'lodash';
1011

@@ -170,6 +171,9 @@ const SubsectionCard = ({
170171
isExpanded={isExpanded}
171172
onTitleClick={handleExpandContent}
172173
namePrefix={namePrefix}
174+
prefixIcon={!!subsection.upstreamInfo?.upstreamRef && (
175+
<Icon src={Newsstand} className="mr-1" />
176+
)}
173177
/>
174178
);
175179

src/course-outline/unit-card/UnitCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
useRef,
66
} from 'react';
77
import { useDispatch } from 'react-redux';
8-
import { useToggle } from '@openedx/paragon';
8+
import { Icon, useToggle } from '@openedx/paragon';
9+
import { Newsstand } from '@openedx/paragon/icons';
910
import { isEmpty } from 'lodash';
1011
import { useSearchParams } from 'react-router-dom';
1112

@@ -159,6 +160,9 @@ const UnitCard = ({
159160
title={displayName}
160161
titleLink={getTitleLink(id)}
161162
namePrefix={namePrefix}
163+
prefixIcon={!!unit.upstreamInfo?.upstreamRef && (
164+
<Icon src={Newsstand} size="sm" className="mr-1" />
165+
)}
162166
/>
163167
);
164168

0 commit comments

Comments
 (0)