2020-12-28 20:52:41 -06:00
|
|
|
import { graphql, useStaticQuery } from 'gatsby';
|
2021-01-13 07:09:45 -06:00
|
|
|
import i18next from 'i18next';
|
2021-08-02 15:39:40 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import envData from '../../../../config/env.json';
|
|
|
|
import { isAuditedCert } from '../../../../utils/is-audited';
|
2021-01-26 02:55:07 +09:00
|
|
|
import { generateIconComponent } from '../../assets/icons';
|
2019-09-21 19:09:48 +05:30
|
|
|
|
2021-06-25 20:11:27 +05:30
|
|
|
import LinkButton from '../../assets/icons/link-button';
|
2021-08-02 15:39:40 +02:00
|
|
|
import { Link, Spacer } from '../helpers';
|
2020-12-28 20:52:41 -06:00
|
|
|
import './map.css';
|
2021-03-26 00:43:43 +05:30
|
|
|
|
|
|
|
const { curriculumLocale } = envData;
|
2019-09-21 19:09:48 +05:30
|
|
|
|
|
|
|
const propTypes = {
|
2021-01-13 07:09:45 -06:00
|
|
|
currentSuperBlock: PropTypes.string,
|
2020-12-28 20:52:41 -06:00
|
|
|
forLanding: PropTypes.bool
|
2019-09-21 19:09:48 +05:30
|
|
|
};
|
|
|
|
|
2021-02-13 06:06:04 +01:00
|
|
|
function createSuperBlockTitle(superBlock) {
|
|
|
|
const superBlockTitle = i18next.t(`intro:${superBlock}.title`);
|
|
|
|
return superBlock === 'coding-interview-prep'
|
2021-02-12 01:16:11 -08:00
|
|
|
? i18next.t('learn.cert-map-estimates.coding-prep', {
|
|
|
|
title: superBlockTitle
|
|
|
|
})
|
|
|
|
: i18next.t('learn.cert-map-estimates.certs', { title: superBlockTitle });
|
2019-09-21 19:09:48 +05:30
|
|
|
}
|
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
const linkSpacingStyle = {
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center'
|
|
|
|
};
|
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
function renderLandingMap(nodes) {
|
2021-02-13 06:06:04 +01:00
|
|
|
nodes = nodes.filter(node => node.superBlock !== 'coding-interview-prep');
|
2020-12-28 20:52:41 -06:00
|
|
|
return (
|
|
|
|
<ul data-test-label='certifications'>
|
|
|
|
{nodes.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
2021-02-13 06:06:04 +01:00
|
|
|
to={`/learn/${node.superBlock}/`}
|
2020-12-28 20:52:41 -06:00
|
|
|
>
|
2021-01-13 07:09:45 -06:00
|
|
|
<div style={linkSpacingStyle}>
|
2021-01-26 02:55:07 +09:00
|
|
|
{generateIconComponent(node.superBlock, 'map-icon')}
|
2021-02-13 06:06:04 +01:00
|
|
|
{i18next.t(`intro:${node.superBlock}.title`)}
|
2021-01-13 07:09:45 -06:00
|
|
|
</div>
|
2020-12-28 20:52:41 -06:00
|
|
|
<LinkButton />
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
function renderLearnMap(nodes, currentSuperBlock = '') {
|
|
|
|
nodes = nodes.filter(node => node.superBlock !== currentSuperBlock);
|
2021-02-11 13:40:32 +01:00
|
|
|
return curriculumLocale === 'english' ? (
|
2021-01-26 02:55:07 +09:00
|
|
|
<ul data-test-label='learn-curriculum-map'>
|
|
|
|
{nodes.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
2021-02-13 06:06:04 +01:00
|
|
|
to={`/learn/${node.superBlock}/`}
|
2021-01-26 02:55:07 +09:00
|
|
|
>
|
|
|
|
<div style={linkSpacingStyle}>
|
|
|
|
{generateIconComponent(node.superBlock, 'map-icon')}
|
|
|
|
{createSuperBlockTitle(node.superBlock)}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
2021-02-11 13:40:32 +01:00
|
|
|
) : (
|
|
|
|
<ul data-test-label='learn-curriculum-map'>
|
|
|
|
{nodes
|
2021-02-13 06:06:04 +01:00
|
|
|
.filter(node => isAuditedCert(curriculumLocale, node.superBlock))
|
2021-02-11 13:40:32 +01:00
|
|
|
.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
2021-02-13 06:06:04 +01:00
|
|
|
to={`/learn/${node.superBlock}/`}
|
2021-02-11 13:40:32 +01:00
|
|
|
>
|
|
|
|
<div style={linkSpacingStyle}>
|
|
|
|
{generateIconComponent(node.superBlock, 'map-icon')}
|
|
|
|
{createSuperBlockTitle(node.superBlock)}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
<hr />
|
|
|
|
<div style={{ textAlign: 'center' }}>
|
|
|
|
<p style={{ marginBottom: 0 }}>{i18next.t('learn.help-translate')} </p>
|
|
|
|
<Link
|
|
|
|
external={true}
|
|
|
|
sameTab={false}
|
2021-03-12 16:14:54 -08:00
|
|
|
to={i18next.t('links:help-translate-link-url')}
|
2021-02-11 13:40:32 +01:00
|
|
|
>
|
|
|
|
{i18next.t('learn.help-translate-link')}
|
|
|
|
</Link>
|
|
|
|
<Spacer />
|
|
|
|
</div>
|
|
|
|
{nodes
|
2021-02-13 06:06:04 +01:00
|
|
|
.filter(node => !isAuditedCert(curriculumLocale, node.superBlock))
|
2021-02-11 13:40:32 +01:00
|
|
|
.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
2021-02-13 06:06:04 +01:00
|
|
|
to={`/learn/${node.superBlock}/`}
|
2021-02-11 13:40:32 +01:00
|
|
|
>
|
|
|
|
<div style={linkSpacingStyle}>
|
|
|
|
{generateIconComponent(node.superBlock, 'map-icon')}
|
|
|
|
{createSuperBlockTitle(node.superBlock)}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
2020-12-28 20:52:41 -06:00
|
|
|
);
|
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
export function Map({ forLanding = false, currentSuperBlock = '' }) {
|
2020-12-28 20:52:41 -06:00
|
|
|
/*
|
|
|
|
* this query gets the first challenge from each block and the second block
|
|
|
|
* from each superblock, leaving you with one challenge from each
|
|
|
|
* superblock
|
|
|
|
*/
|
|
|
|
const data = useStaticQuery(graphql`
|
|
|
|
query SuperBlockNodes {
|
|
|
|
allChallengeNode(
|
|
|
|
sort: { fields: [superOrder] }
|
|
|
|
filter: { order: { eq: 2 }, challengeOrder: { eq: 1 } }
|
|
|
|
) {
|
|
|
|
nodes {
|
|
|
|
superBlock
|
|
|
|
dashedName
|
|
|
|
}
|
2019-10-22 13:38:19 +03:00
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
}
|
2020-12-28 20:52:41 -06:00
|
|
|
`);
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
let nodes = data.allChallengeNode.nodes;
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
return (
|
|
|
|
<div className='map-ui' data-test-label='learn-curriculum-map'>
|
2021-01-13 07:09:45 -06:00
|
|
|
{forLanding
|
|
|
|
? renderLandingMap(nodes)
|
|
|
|
: renderLearnMap(nodes, currentSuperBlock)}
|
2020-12-28 20:52:41 -06:00
|
|
|
</div>
|
|
|
|
);
|
2019-09-21 19:09:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Map.displayName = 'Map';
|
|
|
|
Map.propTypes = propTypes;
|
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
export default Map;
|