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 experimental single question version #44

Merged
merged 5 commits into from
Aug 29, 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
24 changes: 18 additions & 6 deletions src/skills-builder/SkillsBuilder.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import React from 'react';
import React, { useRef } from 'react';
import { SkillsBuilderModal } from './skills-builder-modal';
import { SkillsBuilderProvider } from './skills-builder-context';
import { useVisibilityFlags } from './skills-builder-modal/view-results/data/hooks';
import SkillsBuilderProgressive from './skills-builder-modal/SkillsBuilderProgressive';

const SkillsBuilder = () => (
<SkillsBuilderProvider>
<SkillsBuilderModal />
</SkillsBuilderProvider>
);
const SkillsBuilder = () => {
const visibilityFlags = useRef(useVisibilityFlags());
const { isProgressive } = visibilityFlags.current;

return (
<SkillsBuilderProvider>
{ isProgressive ? (
<SkillsBuilderProgressive />
) : (
<SkillsBuilderModal />
)}

</SkillsBuilderProvider>
);
};

export default SkillsBuilder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { useContext } from 'react';
import {
Button, Container, ModalDialog, Form, Hyperlink, useMediaQuery, breakpoints,
} from '@edx/paragon';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import messages from './messages';

import { SkillsBuilderContext } from '../skills-builder-context';
import { SkillsBuilderHeader } from '../skills-builder-header';
import { SelectPreferences } from './select-preferences';
import ViewResults from './view-results/ViewResults';

import headerImage from '../images/headerImage.png';

const SkillsBuilderProgressive = () => {
const { formatMessage } = useIntl();
const isMedium = useMediaQuery({ maxWidth: breakpoints.medium.maxWidth });
const { state } = useContext(SkillsBuilderContext);
const { currentGoal, currentJobTitle, careerInterests } = state;

const sendActionButtonEvent = (eventSuffix) => {
sendTrackEvent(
`edx.skills_builder.${eventSuffix}`,
{
app_name: 'skills_builder',
category: 'skills_builder',
learner_data: {
current_goal: currentGoal,
current_job_title: currentJobTitle,
career_interests: careerInterests,
},
},
);
};

const exitButtonHandle = () => {
sendActionButtonEvent('exit');
};
const closeButtonHandle = () => {
sendActionButtonEvent('close');
window.location.href = getConfig().MARKETING_SITE_SEARCH_URL;
};

return (
<ModalDialog
title="Skills Builder"
size="fullscreen"
className="skills-builder-modal bg-light-200"
isOpen
onClose={closeButtonHandle}
>
<ModalDialog.Hero className="med-min-height">
<ModalDialog.Hero.Background className="bg-primary-500">
{ !isMedium && <img src={headerImage} alt="" className="h-100" /> }
</ModalDialog.Hero.Background>
<ModalDialog.Hero.Content>
<SkillsBuilderHeader isMedium={isMedium} />
</ModalDialog.Hero.Content>
</ModalDialog.Hero>

<ModalDialog.Body>
<Container size="md" className="p-4.5">
<Form>

<SelectPreferences />

{ careerInterests.length > 0 && (
<ViewResults />
)}

</Form>
</Container>
</ModalDialog.Body>

<ModalDialog.Footer>
<Hyperlink destination={getConfig().MARKETING_SITE_SEARCH_URL}>
<Button onClick={exitButtonHandle}>
{formatMessage(messages.exitButton)}
</Button>
</Hyperlink>
</ModalDialog.Footer>
</ModalDialog>
);
};

export default SkillsBuilderProgressive;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { useContext, useRef } from 'react';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
Expand All @@ -10,13 +10,16 @@ import JobTitleInstantSearch from './JobTitleInstantSearch';
import CareerInterestCard from './CareerInterestCard';
import { addCareerInterest } from '../../data/actions';
import { SkillsBuilderContext } from '../../skills-builder-context';
import { useVisibilityFlags } from '../view-results/data/hooks';
import messages from './messages';

const CareerInterestSelect = () => {
const { formatMessage } = useIntl();
const { state, dispatch, algolia } = useContext(SkillsBuilderContext);
const { careerInterests } = state;
const { searchClient } = algolia;
const visibilityFlags = useRef(useVisibilityFlags());
const { showCareerInterestCards } = visibilityFlags.current;

const handleCareerInterestSelect = (value) => {
if (!careerInterests.includes(value) && careerInterests.length < 3) {
Expand Down Expand Up @@ -50,14 +53,17 @@ const CareerInterestSelect = () => {
/>
</InstantSearch>
</Form.Label>
<Row>
{careerInterests.map((interest, index) => (
{ showCareerInterestCards && (
<Row>
{careerInterests.map((interest, index) => (
// eslint-disable-next-line react/no-array-index-key
<Col key={index} xs={12} sm={4} className="mb-4">
<CareerInterestCard interest={interest} />
</Col>
))}
</Row>
<Col key={index} xs={12} sm={4} className="mb-4">
<CareerInterestCard interest={interest} />
</Col>
))}
</Row>
)}

</Stack>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useContext } from 'react';
import React, { useContext, useRef } from 'react';
import {
Stack,
} from '@edx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import { SkillsBuilderContext } from '../../skills-builder-context';
import { useVisibilityFlags } from '../view-results/data/hooks';
import GoalSelect from './GoalSelect';
import JobTitleSelect from './JobTitleSelect';
import CareerInterestSelect from './CareerInterestSelect';
Expand All @@ -13,21 +14,24 @@ const SelectPreferences = () => {
const { formatMessage } = useIntl();
const { state } = useContext(SkillsBuilderContext);
const { currentGoal, currentJobTitle } = state;
const visibilityFlags = useRef(useVisibilityFlags());
const { showGoal, showCurrentJobTitle, alwaysShowCareerInterest } = visibilityFlags.current;

return (
<Stack gap={4}>
<p className="lead">
{formatMessage(messages.skillsBuilderDescription)}
</p>
<Stack gap={4}>
{ showGoal && (
<GoalSelect />
)}

<GoalSelect />

{currentGoal && (
{currentGoal && showCurrentJobTitle && (
<JobTitleSelect />
)}

{currentGoal && currentJobTitle && (
{(alwaysShowCareerInterest || (currentGoal && currentJobTitle)) && (
<CareerInterestSelect />
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import {
Card, CardDeck, Chip, Stack,
} from '@edx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { addCareerInterest } from '../../data/actions';
import { SkillsBuilderContext } from '../../skills-builder-context';
import messages from './messages';

/*
A variant on the RelatedSkillsSelectableBoxSet that allows for interactive content.
Instead of a radio select button in the top, there is a close button.
Since the contents can be interactive, this form will allow for selecting skills to
drill down for skill-specific recommendations.

This component needs to be like a CardDeck, but also behave like a radio group.
*/
const RelatedSkillsInteractiveBoxSet = ({
jobSkillsList, // selectedJobTitle, onChange, // we will need these
}) => {
const { formatMessage } = useIntl();
const { state, dispatch } = useContext(SkillsBuilderContext);
const { careerInterests } = state;

const renderTopFiveSkills = (skills) => {
const topFiveSkills = skills.sort((a, b) => b.significance - a.significance).slice(0, 5);
return (
topFiveSkills.map(skill => (
<Chip key={skill.external_id} className="chip-max-width">
{skill.name}
</Chip>
))
);
};

const handleCareerInterestSelect = (value) => {
if (!careerInterests.includes(value) && careerInterests.length < 3) {
dispatch(addCareerInterest(value));

sendTrackEvent(
'edx.skills_builder.career_interest.added',
{
app_name: 'skills_builder',
category: 'skills_builder',
learner_data: {
career_interest: value,
},
},
);
}
};

// eslint-disable-next-line react/prop-types
const CardComponent = ({ name, skills }) => (
<Card
isClickable
onClick={handleCareerInterestSelect}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't appear to be doing anything when I test in my local environment. This function handleCareerInterestSelect is used add to the careerInterests array which doesn't change the what the recommendations are in the UI.

I think we need to utilize the onChange function here which calls handleJobTitleChange from ViewResults. Unfortunately, this function is expecting the clicked item to be a control with a e.target.value but since it's a card, we'll have to find a different way to pass the value. This value should be the name of the job so that the rest of the function works properly.

Or perhaps we need an entirely new function for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. This part doesn't actually work. I would love to get your input on how to implement this correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need an entirely new function for this.

key={name}
xs={12}
sm={4}
className="mb-4"
>
<Card.Header
title={name}
size="sm"
/>
<Card.Section>
<Stack gap={2} className="align-items-start">
<p className="heading-label x-small">{formatMessage(messages.relatedSkillsHeading)}</p>
{ renderTopFiveSkills(skills) }
</Stack>
</Card.Section>
</Card>
);

const interactiveBox = (() => (
<CardDeck
hasInteractiveChildren
hasEqualColumnHeights
columnSizes={4}
>
{jobSkillsList.map(job => (
<CardComponent
name={job.name}
skills={job.skills}
key={job.name}
/>
))}
</CardDeck>
));

return (
interactiveBox()
);
};

RelatedSkillsInteractiveBoxSet.propTypes = {
jobSkillsList: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
selectedJobTitle: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};

export default RelatedSkillsInteractiveBoxSet;
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { CheckCircle, ErrorOutline } from '@edx/paragon/icons';
import { SkillsBuilderContext } from '../../skills-builder-context';
import RelatedSkillsSelectableBoxSet from './RelatedSkillsSelectableBoxSet';
import RelatedSkillsInteractiveBoxSet from './RelatedSkillsInteractiveBoxSet';
import messages from './messages';
import RecommendationStack from './RecommendationStack';

import { getRecommendations } from './data/service';
import { useProductTypes } from './data/hooks';
import { useProductTypes, useVisibilityFlags } from './data/hooks';
import { extractProductKeys } from '../../utils/extractProductKeys';
import { setExpandedList } from '../../data/actions';

Expand All @@ -23,7 +24,6 @@ const ViewResults = () => {
const { algolia, state, dispatch } = useContext(SkillsBuilderContext);
const { jobSearchIndex, productSearchIndex } = algolia;
const { careerInterests } = state;

const [selectedJobTitle, setSelectedJobTitle] = useState('');
const [jobSkillsList, setJobSkillsList] = useState([]);
const [productRecommendations, setProductRecommendations] = useState([]);
Expand All @@ -32,6 +32,8 @@ const ViewResults = () => {
const [fetchError, setFetchError] = useState(false);

const productTypes = useRef(useProductTypes());
const visibilityFlags = useRef(useVisibilityFlags());
const { showMatchesFoundAlert, isInteractiveBoxSet } = visibilityFlags.current;

useEffect(() => {
const getAllRecommendations = async () => {
Expand Down Expand Up @@ -138,25 +140,39 @@ const ViewResults = () => {
</Row>
) : (
<Stack gap={4.5} className="pb-4.5">
<Alert
variant="success"
icon={CheckCircle}
>
<Alert.Heading>
{formatMessage(messages.matchesFoundSuccessAlert)}
</Alert.Heading>
</Alert>

<RelatedSkillsSelectableBoxSet
jobSkillsList={jobSkillsList}
selectedJobTitle={selectedJobTitle}
onChange={handleJobTitleChange}
/>
{ showMatchesFoundAlert && (
<Alert
variant="success"
icon={CheckCircle}
>
<Alert.Heading>
{formatMessage(messages.matchesFoundSuccessAlert)}
</Alert.Heading>
</Alert>
)}
{ /* This should just pass the isInteractiveBoxSet flag to the component */ }
{ isInteractiveBoxSet ? (
<RelatedSkillsInteractiveBoxSet
jobSkillsList={jobSkillsList}
selectedJobTitle={selectedJobTitle}
onChange={handleJobTitleChange}
isInteractiveBoxSet={isInteractiveBoxSet}
/>
) : (
<RelatedSkillsSelectableBoxSet
jobSkillsList={jobSkillsList}
selectedJobTitle={selectedJobTitle}
onChange={handleJobTitleChange}
/>
)}

{selectedRecommendations
&& (
<RecommendationStack
selectedRecommendations={selectedRecommendations}
productTypeNames={productTypes.current}
/>
)}
</Stack>
)
);
Expand Down
Loading