Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add highlight content card to stepper and individual sets #912

Merged
merged 20 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ee6e285
feat: Add highlight content card to stepper and individual sets
brobro10000 Dec 5, 2022
d1e2ec0
feat: Add highlight content card to stepper and individual sets
brobro10000 Dec 7, 2022
8c09af9
feat: Added delete to individual cards
brobro10000 Dec 9, 2022
5de4ae0
Merge branch 'master' into hu/ent-6562
brobro10000 Dec 9, 2022
f699452
chore: Unit testing
brobro10000 Dec 9, 2022
cd6cdae
Merge branch 'hu/ent-6562' of https://github.com/openedx/frontend-app…
brobro10000 Dec 9, 2022
97876cc
Merge branch 'hu/ent-6562' of https://github.com/openedx/frontend-app…
brobro10000 Dec 9, 2022
db03859
Merge branch 'hu/ent-6562' of https://github.com/openedx/frontend-app…
brobro10000 Dec 9, 2022
58e5861
Merge branch 'master' of https://github.com/openedx/frontend-app-admi…
brobro10000 Dec 9, 2022
e7bafe7
Merge branch 'master' of https://github.com/openedx/frontend-app-admi…
brobro10000 Dec 9, 2022
1e9f486
Merge branch 'hu/ent-6562' of https://github.com/openedx/frontend-app…
brobro10000 Dec 13, 2022
edce596
feat: Add hyperlinks on card titles
brobro10000 Dec 13, 2022
d77cd5e
chore: Update test for mapToStore enterpriseSlug
brobro10000 Dec 14, 2022
dc1d591
feat: PR fixes
brobro10000 Dec 16, 2022
60587a7
Merge branch 'master' into hu/ent-6562
brobro10000 Dec 16, 2022
7bc6c4f
chore: tests
brobro10000 Dec 19, 2022
cd1782c
chore:test part 2
brobro10000 Dec 19, 2022
722df03
chore: update tests
adamstankiewicz Dec 19, 2022
17b8baa
chore: update tests... again
adamstankiewicz Dec 19, 2022
d1d51b0
chore: PR feedback
brobro10000 Dec 19, 2022
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
65 changes: 65 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"enzyme-adapter-react-16": "1.15.6",
"husky": "0.14.3",
"identity-obj-proxy": "3.0.0",
"jest-canvas-mock": "^2.4.0",
"jest-localstorage-mock": "^2.4.22",
"postcss": "8.1.0",
"react-dev-utils": "11.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import HighlightSetSection from './HighlightSetSection';
const ContentHighlightCardContainer = () => {
const { enterpriseCuration: { enterpriseCuration } } = useContext(EnterpriseAppContext);
const highlightSets = useHighlightSetsForCuration(enterpriseCuration);

return (
<Stack gap={4}>
<HighlightSetSection
Expand Down
46 changes: 33 additions & 13 deletions src/components/ContentHighlights/ContentHighlightCardItem.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
import React from 'react';
import { Card } from '@edx/paragon';
import { Card, Hyperlink } from '@edx/paragon';
import Truncate from 'react-truncate';
import PropTypes from 'prop-types';
import { FOOTER_TEXT_BY_CONTENT_TYPE } from './data/constants';
import { getContentHighlightCardFooter } from './data/utils';

const ContentHighlightCardItem = ({
isLoading,
title,
href,
contentType,
partners,
cardImageUrl,
price,
}) => {
const cardLogoSrc = partners?.length === 1 ? partners[0].logoImageUrl : undefined;
const cardLogoAlt = partners?.length === 1 ? `${partners[0].name}'s logo` : undefined;
const cardSubtitle = partners?.map(p => p.name).join(', ');

const cardInfo = {
cardImgSrc: cardImageUrl,
cardLogoSrc: partners.length === 1 ? partners[0].logoImageUrl : undefined,
cardLogoAlt: partners.length === 1 ? `${partners[0].name}'s logo` : undefined,
cardTitle: <Truncate lines={3} title={title}>{title}</Truncate>,
cardSubtitle: partners.map(p => p.name).join(', '),
cardFooter: getContentHighlightCardFooter({ price, contentType }),
};
if (href) {
cardInfo.cardTitle = (
<Hyperlink destination={href} target="_blank">
<Truncate lines={3} title={title}>{title}</Truncate>
</Hyperlink>
);
}
return (
<Card>
<Card isLoading={isLoading}>
<Card.ImageCap
src={cardImageUrl}
src={cardInfo.cardImgSrc}
srcAlt=""
logoSrc={cardLogoSrc}
logoAlt={cardLogoAlt}
logoSrc={cardInfo.cardLogoSrc}
logoAlt={cardInfo.cardLogoAlt}
/>
<Card.Header
title={<Truncate lines={3} title={title}>{title}</Truncate>}
subtitle={<Truncate lines={2} title={cardSubtitle}>{cardSubtitle}</Truncate>}
title={cardInfo.cardTitle}
subtitle={<Truncate lines={2} title={cardInfo.cardSubtitle}>{cardInfo.cardSubtitle}</Truncate>}
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved
/>
{contentType && (
<>
<Card.Section />
<Card.Footer
textElement={FOOTER_TEXT_BY_CONTENT_TYPE[contentType.toLowerCase()]}
textElement={cardInfo.cardFooter}
/>
</>
)}
Expand All @@ -39,18 +53,24 @@ const ContentHighlightCardItem = ({
};

ContentHighlightCardItem.propTypes = {
isLoading: PropTypes.bool,
cardImageUrl: PropTypes.string,
title: PropTypes.string.isRequired,
href: PropTypes.string,
contentType: PropTypes.oneOf(['course', 'program', 'learnerpathway']).isRequired,
partners: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
uuid: PropTypes.string,
logoImageUrl: PropTypes.string,
})).isRequired,
price: PropTypes.number,
};

ContentHighlightCardItem.defaultProps = {
isLoading: false,
href: undefined,
cardImageUrl: undefined,
price: undefined,
};

export default ContentHighlightCardItem;
19 changes: 13 additions & 6 deletions src/components/ContentHighlights/ContentHighlightSet.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Container } from '@edx/paragon';
import { useParams } from 'react-router-dom';
import React from 'react';
import ContentHighlightsCardItemContainer from './ContentHighlightsCardItemsContainer';
import CurrentContentHighlightItemsHeader from './CurrentContentHighlightItemsHeader';
import { useHighlightSet } from './data/hooks';

const ContentHighlightSet = () => (
<Container fluid className="mt-5">
<CurrentContentHighlightItemsHeader />
<ContentHighlightsCardItemContainer />
</Container>
);
const ContentHighlightSet = () => {
const { highlightSetUUID } = useParams();
const { highlightSet, isLoading } = useHighlightSet(highlightSetUUID);
return (
<Container className="mt-5">
<CurrentContentHighlightItemsHeader isLoading={isLoading} highlightTitle={highlightSet?.title} />
<ContentHighlightsCardItemContainer isLoading={isLoading} highlightedContent={highlightSet?.highlightedContent} />
</Container>
);
};

export default ContentHighlightSet;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
import React, { useState } from 'react';
import { CardGrid } from '@edx/paragon';
import { camelCaseObject } from '@edx/frontend-platform';
import React from 'react';
import { CardGrid, Alert } from '@edx/paragon';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import ContentHighlightCardItem from './ContentHighlightCardItem';
import { TEST_COURSE_HIGHLIGHTS_DATA } from './data/constants';
import {
DEFAULT_ERROR_MESSAGE, HIGHLIGHTS_CARD_GRID_COLUMN_SIZES, MAX_CONTENT_ITEMS_PER_HIGHLIGHT_SET,
} from './data/constants';
import SkeletonContentCardContainer from './SkeletonContentCardContainer';
import { generateAboutPageUrl } from './data/utils';

const ContentHighlightsCardItemsContainer = () => {
const [highlightCourses] = useState(
camelCaseObject(TEST_COURSE_HIGHLIGHTS_DATA)[0]?.highlightedContent,
);

if (!highlightCourses) {
return null;
const ContentHighlightsCardItemsContainer = ({ enterpriseSlug, isLoading, highlightedContent }) => {
if (isLoading) {
return (
<SkeletonContentCardContainer length={MAX_CONTENT_ITEMS_PER_HIGHLIGHT_SET} />
);
}
if (!highlightedContent || highlightedContent?.length === 0) {
return (
<Alert data-testid="empty-highlighted-content" variant="warning">
{DEFAULT_ERROR_MESSAGE.EMPTY_HIGHLIGHT_SET}
</Alert>
);
}

return (
<CardGrid
columnSizes={{
xs: 12,
lg: 6,
xl: 4,
}}
>
{highlightCourses.map(({
uuid, title, contentType, authoringOrganizations,
<CardGrid columnSizes={HIGHLIGHTS_CARD_GRID_COLUMN_SIZES}>
{highlightedContent.map(({
uuid, title, contentType, authoringOrganizations, contentKey,
}) => (
<ContentHighlightCardItem
isLoading={isLoading}
key={uuid}
cardImageUrl="https://picsum.photos/200/300"
title={title}
contentType={contentType.toLowerCase()}
href={generateAboutPageUrl({
enterpriseSlug,
contentType: contentType?.toLowerCase(),
contentKey,
})}
contentType={contentType?.toLowerCase()}
partners={authoringOrganizations}
/>
))}
</CardGrid>
);
};

export default ContentHighlightsCardItemsContainer;
ContentHighlightsCardItemsContainer.propTypes = {
enterpriseSlug: PropTypes.string.isRequired,
isLoading: PropTypes.bool.isRequired,
highlightedContent: PropTypes.arrayOf(PropTypes.shape({
uuid: PropTypes.string,
contentType: PropTypes.oneOf(['course', 'program', 'learnerpathway']),
title: PropTypes.string,
cardImageUrl: PropTypes.string,
authoringOrganizations: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
logoImageUrl: PropTypes.string,
uuid: PropTypes.string,
})),
})).isRequired,
};

const mapStateToProps = state => ({
enterpriseSlug: state.portalConfiguration.enterpriseSlug,
});

export default connect(mapStateToProps)(ContentHighlightsCardItemsContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const ContentHighlightsContextProvider = ({ children }) => {
contentHighlights: [],
searchClient,
});

return (
<ContentHighlightsContext.Provider value={contextValue}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ContentHighlightsDashboardBase = ({ children }) => {
}, [history, location, locationState]);

return (
<Container fluid className="my-5">
<Container className="my-5">
<ContentHighlightHelmet title="Highlights" />
{children}
<Toast
Expand Down
Loading