Skip to content

final fixes for recommender POC. #5327

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

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 @@ -184,6 +184,7 @@ exports[`Matches shallow shapshot 2`] = `
</div>
</div>
</div>
<hr />
<div
className="src-shared-components-challenge-listing-Filters-FiltersPanel-___style__buttons___2r3xW"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PT from 'prop-types';
import React from 'react';

import './style.scss';

export default function MatchScore({ score }) {
return (
<span styleName="match-score">
{score}% match
</span>
);
}

MatchScore.defaultProps = {
score: 0,
};

MatchScore.propTypes = {
score: PT.number,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import "~styles/mixins";

.match-score {
background-color: $tc-light-blue-30;
color: $tc-dark-blue-100;
font-size: 10px;
line-height: 12px;
padding: 3px;
border-radius: 2px;
margin-left: 5px;
margin-top: 1px;
}
22 changes: 15 additions & 7 deletions src/shared/components/challenge-listing/ChallengeCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Tags from '../Tags';

import ChallengeStatus from './Status';
import TrackAbbreviationTooltip from '../Tooltips/TrackAbbreviationTooltip';
import MatchScore from './MatchScore';
import { calculateScore } from '../../../utils/challenge-listing/helper';
import './style.scss';

/* TODO: Note that this component uses a dirty trick to cheat linter and to be
Expand Down Expand Up @@ -67,13 +69,19 @@ function ChallengeCard({
</div>

<div styleName={isRegistrationOpen ? 'challenge-details with-register-button' : 'challenge-details'}>
<Link
onClick={() => selectChallengeDetailsTab(DETAIL_TABS.DETAILS)}
to={challengeDetailLink}
styleName="challenge-title"
openNewTab={openChallengesInNewTabs}
><p>{challenge.name}</p>
</Link>
<div styleName="challenge-detail-header">
<Link
onClick={() => selectChallengeDetailsTab(DETAIL_TABS.DETAILS)}
to={challengeDetailLink}
styleName="challenge-title"
openNewTab={openChallengesInNewTabs}
><p>{challenge.name}</p>
</Link>
{
challenge.matchScore
&& <MatchScore score={calculateScore(challenge.matchScore)} />
}
</div>
<div styleName="details-footer">
<span styleName="date">
{challenge.status === 'Active' ? 'Ends ' : 'Ended '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ $challenge-radius-4: $corner-radius * 2;
display: inline-block;
}
}

.challenge-detail-header {
display: flex;
}
}
// date and technologies
.details-footer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* eslint-disable jsx-a11y/label-has-for */

import _ from 'lodash';
import React from 'react';
import React, { useState, useEffect } from 'react';
import PT from 'prop-types';
import Select from 'components/Select';
import DateRangePicker from 'components/DateRangePicker';
Expand Down Expand Up @@ -250,8 +250,30 @@ export default function FiltersPanel({
const past = isPastBucket(activeBucket);
const disableClearFilterButtons = isFilterEmpty(filterState, past ? 'past' : '', activeBucket);

const availableTypes = activeBucket === 'openForRegistration'
? validTypes : validTypes.filter(item => item.abbreviation !== 'REC');
const availableTypes = validTypes.filter(item => item.abbreviation !== 'REC');
const isRecommendedChallengesVisible = activeBucket === 'openForRegistration';
const [recommendedToggle, setRecommendedToggle] = useState(false);

useEffect(() => {
if (recommendedToggle) {
const types = _.union(filterState.types, ['REC']);
setFilterState({ ..._.clone(filterState), types });
}
}, []);

const onSwitchRecommendedChallenge = (on) => {
const { types } = filterState;
types.push('REC');
setRecommendedToggle(on);

if (on) {
setSort('openForRegistration', 'updatedBy');
setFilterState({ ..._.clone(filterState), types });
} else {
setFilterState({ ..._.clone(filterState), types: ['TSK', 'CH', 'F2F'] });
setSort('openForRegistration', 'startDate');
}
};

const handleTypeChange = (option, e) => {
let { types } = filterState;
Expand All @@ -261,20 +283,14 @@ export default function FiltersPanel({
types = types.filter(type => type !== option.value);
}

if (option.label === 'Recommended') {
types = types.filter(type => type === 'REC');
if (!e.target.checked) {
setFilterState({ ..._.clone(filterState), types: ['TSK', 'CH', 'F2F'] });
setSort('openForRegistration', 'startDate');
} else {
setSort('openForRegistration', 'updatedBy');
setFilterState({ ..._.clone(filterState), types });
}
if (recommendedToggle) {
types = [...types, 'REC'];
} else {
types = types.filter(type => type !== 'REC');
setFilterState({ ..._.clone(filterState), types });
setSort('openForRegistration', 'startDate');
}

setFilterState({ ..._.clone(filterState), types });
setSort('openForRegistration', 'startDate');
};

const recommendedCheckboxTip = (
Expand Down Expand Up @@ -462,24 +478,7 @@ export default function FiltersPanel({
checked={filterState.types.includes(option.value)}
onChange={e => handleTypeChange(option, e)}
/>
{
option.label === 'Recommended'
? (
<label styleName="checkbox-label" htmlFor={option.label}>
<Tooltip
id="recommended-tip"
content={recommendedCheckboxTip}
className={style['tooltip-overlay']}
trigger={['hover', 'focus']}
>
{option.label}
</Tooltip>

</label>
)

: <label styleName="checkbox-label" htmlFor={option.label}>{option.label}</label>
}
<label styleName="checkbox-label" htmlFor={option.label}>{option.label}</label>
</span>
))
}
Expand Down Expand Up @@ -579,8 +578,41 @@ export default function FiltersPanel({
</div>
)
}

{
isRecommendedChallengesVisible
&& (
<div styleName="filter-row recommended-challenges-filter">
<span
styleName="filter-switch-with-label"
aria-label={`Recommended challenge toggle button pressed ${recommendedToggle ? 'On' : 'Off'}`}
role="switch"
aria-checked={recommendedToggle}
>
<SwitchWithLabel
enabled={recommendedToggle}
labelAfter="Recommended Challenges"
onSwitch={onSwitchRecommendedChallenge}
/>
</span>

<div styleName="recommended-challenge-tooltip">
<Tooltip
id="recommended-tip"
content={recommendedCheckboxTip}
className={style['tooltip-overlay']}
trigger={['hover', 'focus']}
>
<i className="fa fa-info-cirle" aria-hidden="true" />
</Tooltip>
</div>
</div>
)
}
</div>

<hr />

<div styleName="buttons">
<Button
composeContextTheme={COMPOSE.SOFT}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "../../../../../styles/awesome.css";
@import '~styles/mixins';

.uppercase {
Expand Down Expand Up @@ -285,7 +286,7 @@
display: inline-block;
line-height: 30px;
flex: 1 0 auto;
min-width: calc(11% - 10px);
min-width: calc(33% - 10px);

&:not(:last-child) {
padding-right: 10px;
Expand Down Expand Up @@ -422,6 +423,15 @@
}
}
}

.recommended-challenges-filter {
display: flex;
margin-bottom: 25px;

.recommended-challenge-tooltip {
margin: 3px 0 0 3px;
}
}
}

.tctooltiptext {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ function onGetRecommendedChallengesDone(state, { error, payload }) {
allRecommendedChallengesLoaded: challenges.length >= payload.meta.allRecommendedChallengesCount,
meta: {
...state.meta,
allRecommendedChallengesCount: payload.meta.allRecommendedChallengesCount,
openChallengesCount: payload.meta.allRecommendedChallengesCount,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/challenge-listing/buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function isPastBucket(bucket) {
* @param {Object} filterState current filter state
*/
export function isRecommendedChallengeType(bucket, filterState) {
return bucket === 'openForRegistration' && filterState.types.length === 1 && filterState.types[0] === 'REC';
return bucket === 'openForRegistration' && filterState.types.includes('REC');
}

export default undefined;
8 changes: 8 additions & 0 deletions src/shared/utils/challenge-listing/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ export function phaseStartDate(phase) {
// For all other cases, take the `actualStartDate` as phase is already started
return new Date(phase.actualStartDate);
}

/**
* Calculate match percentage.
* @param {Float} score
*/
export function calculateScore(score) {
return Math.trunc(Math.abs(score + 1.0) * 100.0 / 2.0);
}
4 changes: 4 additions & 0 deletions src/styles/awesome.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
content: "\f110";
}

.fa-info-cirle::before {
content: "\0024D8";
}

@keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
Expand Down