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

refactor: change event schema #28

Merged
merged 1 commit into from
Aug 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ const ProductCardGrid = ({
handleCourseCardClick={handleCourseCardClick}
rec={rec}
productType={productTypeName}
indexInList={index}
position={index}
/>
))
) : (
productTypeRecommendations?.slice(0, 4).map(rec => (
productTypeRecommendations?.slice(0, 4).map((rec, index) => (
<RecommendationCard
key={rec.uuid}
handleCourseCardClick={handleCourseCardClick}
rec={rec}
productType={productTypeName}
position={index}
/>
))
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
import cardImageCapFallbackSrc from '../../images/card-imagecap-fallback.png';

const RecommendationCard = ({
rec, productType, handleCourseCardClick, indexInList,
rec, productType, handleCourseCardClick, position,
}) => {
const {
card_image_url: cardImageUrl,
Expand All @@ -17,6 +17,7 @@ const RecommendationCard = ({
organization_logo_override: organizationLogoOverride,
partner,
title,
uuid,
} = rec;

const schoolName = organizationShortCodeOverride
Expand All @@ -25,14 +26,17 @@ const RecommendationCard = ({
const schoolLogoUrl = organizationLogoOverride
|| owners[0].logoImageUrl;

// If this label changes, make sure to duplicate the change in extractProductKeys.js
const productLabel = courseKey || `${title} [${uuid}]`;

return (
<Card
as={Hyperlink}
target="_blank"
showLaunchIcon={false}
destination={marketingUrl}
className="product-card"
onClick={() => handleCourseCardClick(courseKey, productType, indexInList)}
onClick={() => handleCourseCardClick(productLabel, productType, position)}
>
<Card.ImageCap
src={cardImageUrl}
Expand Down Expand Up @@ -65,14 +69,11 @@ RecommendationCard.propTypes = {
active_run_key: PropTypes.string,
organization_short_code_override: PropTypes.string,
organization_logo_override: PropTypes.string,
uuid: PropTypes.string.isRequired,
}).isRequired,
productType: PropTypes.string.isRequired,
handleCourseCardClick: PropTypes.func.isRequired,
indexInList: PropTypes.number,
};

RecommendationCard.defaultProps = {
indexInList: 0,
position: PropTypes.number.isRequired,
};

export default RecommendationCard;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const RecommendationStack = ({ selectedRecommendations, productTypeNames }) => {
const { expandedList } = state;
const { id: jobId, name: jobName, recommendations } = selectedRecommendations;

const handleCourseCardClick = (courseKey, productTypeName, index) => {
const handleCourseCardClick = (productLabel, productTypeName, index) => {
// check to see if the grid of recommendations for this product line has been expanded
if (expandedList.includes(productTypeName)) {
// fire expanded click event
Expand All @@ -22,9 +22,9 @@ const RecommendationStack = ({ selectedRecommendations, productTypeNames }) => {
app_name: 'skills_builder',
category: 'skills_builder',
page: 'skills_builder',
courserun_key: courseKey,
label: productLabel,
product_line: productTypeName,
index_in_list: index,
position: index,
selected_recommendations: {
job_id: jobId,
job_name: jobName,
Expand All @@ -41,8 +41,9 @@ const RecommendationStack = ({ selectedRecommendations, productTypeNames }) => {
app_name: 'skills_builder',
category: 'skills_builder',
page: 'skills_builder',
courserun_key: courseKey,
label: productLabel,
product_line: productTypeName,
position: index,
selected_recommendations: {
job_id: jobId,
job_name: jobName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ViewResults = () => {
selected_recommendations: {
job_id: results[0].id,
job_name: results[0].name,
/* We extract the title and course key into an array of objects */
/* Extract a product label, title, and position for each recommendation */
product_keys: extractProductKeys(results[0].recommendations),
},
is_default: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ describe('view-results', () => {
app_name: 'skills_builder',
category: 'skills_builder',
page: 'skills_builder',
courserun_key: 'MONS101',
label: 'MONS101',
position: 0,
product_line: '2U_degree',
selected_recommendations: {
job_id: 0,
Expand Down
20 changes: 10 additions & 10 deletions src/skills-builder/test/__mocks__/jobSkills.mockData.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ export const mockData = {
useAlgoliaSearch: [{}, {}, {}],
productKeys: {
course: [
{ title: 'Mining with the Mons', courserun_key: 'MONS101' },
{ title: 'The Art of Warren Upkeep', courserun_key: 'WAR101' },
{ title: 'Mining with the Mons', label: 'MONS101', position: 0 },
{ title: 'The Art of Warren Upkeep', label: 'WAR101', position: 1 },
],
'2U_degree': [
{ title: 'Mining with the Mons', courserun_key: 'MONS101' },
{ title: 'The Art of Warren Upkeep', courserun_key: 'WAR101' },
{ title: 'Mining with the Mons', label: 'MONS101', position: 0 },
{ title: 'The Art of Warren Upkeep', label: 'WAR101', position: 1 },
],
program: [
{ title: 'Mining with the Mons', courserun_key: 'MONS101' },
{ title: 'The Art of Warren Upkeep', courserun_key: 'WAR101' },
{ title: 'Mining with the Mons', label: 'MONS101', position: 0 },
{ title: 'The Art of Warren Upkeep', label: 'WAR101', position: 1 },
],
boot_camp: [
{ title: 'Mining with the Mons', courserun_key: 'MONS101' },
{ title: 'The Art of Warren Upkeep', courserun_key: 'WAR101' },
{ title: 'Mining with the Mons', label: 'MONS101', position: 0 },
{ title: 'The Art of Warren Upkeep', label: 'WAR101', position: 1 },
],
executive_education: [
{ title: 'Mining with the Mons', courserun_key: 'MONS101' },
{ title: 'The Art of Warren Upkeep', courserun_key: 'WAR101' },
{ title: 'Mining with the Mons', label: 'MONS101', position: 0 },
{ title: 'The Art of Warren Upkeep', label: 'WAR101', position: 1 },
],
},
};
Expand Down
10 changes: 6 additions & 4 deletions src/skills-builder/utils/extractProductKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { productTypeNames } from '../skills-builder-modal/view-results/data/cons
* @return
* @typedef productKeys - an object with a key for each product line
* @type {object}
* @property {array[object]} product_line - each object contains a title and product key
* @property {array[object]} product_line - each object contains a title, product label, and its position in the list
*/
export const extractProductKeys = (recommendations, expandedList = []) => (
Object.fromEntries(
Expand All @@ -30,10 +30,12 @@ export const extractProductKeys = (recommendations, expandedList = []) => (
return [
type,
// create an array of objects for each product line
// each object contains a title and product key, rather than the entire response from Algolia (rec)
recommendationsRefinedList?.map(rec => ({
// each object contains a title, product label, and position - rather than the entire response from Algolia
recommendationsRefinedList?.map((rec, index) => ({
title: rec.title,
courserun_key: rec.active_run_key,
// If this label changes, make sure to duplicate the change in RecommendationCard.jsx
label: rec.active_run_key || `${rec.title} [${rec.uuid}]`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This little bit of naming logic is duplicated and also important. Should we add a comment that if the label is changed that we should also update productLabel in RecommendationCard.jsx (and vice-versa)?

Not sure if it would ever change... but seems like it would cause a weird mismatch and may be hard to track down?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out! I'll add a comment in both places. The schema is bound to be modified again so it'll be nice to have the reminder

position: index,
})),
];
}),
Expand Down
8 changes: 5 additions & 3 deletions src/skills-builder/utils/tests/extractProductKeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ const mockRecommendations = Object.fromEntries(
)),
);

// When the values are extracted, each course should only have two values: title and courserun_key
// When the values are extracted, each course should only have: title, label, and position
const expectedCourseData = [
{
title: 'Mining with the Mons',
courserun_key: 'MONS101',
label: 'MONS101',
position: 0,
},
{
title: 'The Art of Warren Upkeep',
courserun_key: 'WAR101',
label: 'WAR101',
position: 1,
},
];

Expand Down