From d3f59e6d5de17250746938c02c052b89e5cf90b0 Mon Sep 17 00:00:00 2001
From: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>
Date: Fri, 23 Apr 2021 20:29:17 +0100
Subject: [PATCH] fix(dev): rename superBlock with v7 to certSlug (#41738)
* fix(dev): rename superBlock with v7 to slug
* improve name slug -> certSlug
* superBlockTitle -> superBlock
* correct teeny, tiny mistake
* fix: correct slug to certSlug in certLocation
* refactor currentCerts
* rename showCert cert -> certSlug and various
---
api-server/src/server/boot/certificate.js | 22 +-
client/gatsby-node.js | 1 +
.../client-only-routes/ShowCertification.js | 46 ++--
.../client-only-routes/ShowProjectLinks.js | 4 +-
.../profile/components/Certifications.js | 15 +-
.../src/components/settings/Certification.js | 48 ++---
client/src/pages/certification.js | 2 +-
client/src/redux/index.js | 30 +--
client/src/redux/propTypes.js | 8 +
client/src/redux/show-cert-saga.js | 4 +-
client/src/resources/certAndProjectMap.js | 200 +++++++++---------
.../templates/Introduction/SuperBlockIntro.js | 26 ++-
.../Introduction/components/Block.js | 12 +-
.../Introduction/components/CertChallenge.js | 55 ++---
client/src/utils/ajax.js | 8 +-
config/certification-settings.js | 24 ++-
16 files changed, 251 insertions(+), 254 deletions(-)
diff --git a/api-server/src/server/boot/certificate.js b/api-server/src/server/boot/certificate.js
index 48e5bac58c..1557ea923c 100644
--- a/api-server/src/server/boot/certificate.js
+++ b/api-server/src/server/boot/certificate.js
@@ -15,7 +15,7 @@ import { getChallenges } from '../utils/get-curriculum';
import {
completionHours,
certTypes,
- superBlockCertTypeMap,
+ certSlugTypeMap,
certTypeTitleMap,
certTypeIdMap,
certIds,
@@ -51,7 +51,7 @@ export default function bootCertificate(app) {
const verifyCert = createVerifyCert(certTypeIds, app);
api.put('/certificate/verify', ifNoUser401, ifNoSuperBlock404, verifyCert);
- api.get('/certificate/showCert/:username/:cert', showCert);
+ api.get('/certificate/showCert/:username/:certSlug', showCert);
app.use(api);
}
@@ -66,9 +66,11 @@ export function getFallbackFrontEndDate(completedChallenges, completedDate) {
return latestCertDate ? latestCertDate : completedDate;
}
+const certSlugs = Object.keys(certSlugTypeMap);
+
function ifNoSuperBlock404(req, res, next) {
- const { superBlock } = req.body;
- if (superBlock && superBlocks.includes(superBlock)) {
+ const { certSlug } = req.body;
+ if (certSlug && certSlugs.includes(certSlug)) {
return next();
}
return res.status(404).end();
@@ -130,8 +132,6 @@ function getCertById(anId, allChallenges) {
}))[0];
}
-const superBlocks = Object.keys(superBlockCertTypeMap);
-
function sendCertifiedEmail(
{
email = '',
@@ -223,11 +223,11 @@ function createVerifyCert(certTypeIds, app) {
const { Email } = app.models;
return function verifyCert(req, res, next) {
const {
- body: { superBlock },
+ body: { certSlug },
user
} = req;
- log(superBlock);
- let certType = superBlockCertTypeMap[superBlock];
+ log(certSlug);
+ let certType = certSlugTypeMap[certSlug];
log(certType);
return Observable.of(certTypeIds[certType])
.flatMap(challenge => {
@@ -335,9 +335,9 @@ function createShowCert(app) {
}
return function showCert(req, res, next) {
- let { username, cert } = req.params;
+ let { username, certSlug } = req.params;
username = username.toLowerCase();
- const certType = superBlockCertTypeMap[cert];
+ const certType = certSlugTypeMap[certSlug];
const certId = certTypeIdMap[certType];
const certTitle = certTypeTitleMap[certType];
const completionTime = completionHours[certType] || 300;
diff --git a/client/gatsby-node.js b/client/gatsby-node.js
index f6cf66bf89..133a2a1b1f 100644
--- a/client/gatsby-node.js
+++ b/client/gatsby-node.js
@@ -132,6 +132,7 @@ exports.createPages = function createPages({ graphql, actions, reporter }) {
);
// Create intro pages
+ // TODO: Remove allMarkdownRemark (populate from elsewhere)
result.data.allMarkdownRemark.edges.forEach(edge => {
const {
node: { frontmatter, fields }
diff --git a/client/src/client-only-routes/ShowCertification.js b/client/src/client-only-routes/ShowCertification.js
index 56de02be4f..54342fa76f 100644
--- a/client/src/client-only-routes/ShowCertification.js
+++ b/client/src/client-only-routes/ShowCertification.js
@@ -33,6 +33,7 @@ import envData from '../../../config/env.json';
import RedirectHome from '../components/RedirectHome';
import { Loader, Spacer } from '../components/helpers';
import { isEmpty } from 'lodash';
+import { User } from '../redux/propTypes';
const { clientLocale } = envData;
@@ -48,7 +49,7 @@ const propTypes = {
date: PropTypes.number
}),
certDashedName: PropTypes.string,
- certName: PropTypes.string,
+ certSlug: PropTypes.string,
createFlashMessage: PropTypes.func.isRequired,
executeGA: PropTypes.func,
fetchProfileForUser: PropTypes.func,
@@ -58,48 +59,27 @@ const propTypes = {
errored: PropTypes.bool
}),
isDonating: PropTypes.bool,
+ isValidCert: PropTypes.bool,
location: PropTypes.shape({
pathname: PropTypes.string
}),
showCert: PropTypes.func.isRequired,
signedInUserName: PropTypes.string,
- user: PropTypes.shape({
- completedChallenges: PropTypes.arrayOf(
- PropTypes.shape({
- id: PropTypes.string,
- solution: PropTypes.string,
- githubLink: PropTypes.string,
- files: PropTypes.arrayOf(
- PropTypes.shape({
- contents: PropTypes.string,
- ext: PropTypes.string,
- key: PropTypes.string,
- name: PropTypes.string,
- path: PropTypes.string
- })
- )
- })
- ),
- profileUI: PropTypes.shape({
- showName: PropTypes.bool
- }),
- username: PropTypes.string
- }),
+ user: User,
userFetchState: PropTypes.shape({
complete: PropTypes.bool
}),
userFullName: PropTypes.string,
- username: PropTypes.string,
- validCertName: PropTypes.bool
+ username: PropTypes.string
};
const requestedUserSelector = (state, { username = '' }) =>
userByNameSelector(username.toLowerCase())(state);
-const validCertNames = certMap.map(cert => cert.slug);
+const validCertSlugs = certMap.map(cert => cert.certSlug);
const mapStateToProps = (state, props) => {
- const validCertName = validCertNames.some(name => name === props.certName);
+ const isValidCert = validCertSlugs.some(slug => slug === props.certSlug);
return createSelector(
showCertSelector,
showCertFetchStateSelector,
@@ -110,7 +90,7 @@ const mapStateToProps = (state, props) => {
(cert, fetchState, signedInUserName, userFetchState, isDonating, user) => ({
cert,
fetchState,
- validCertName,
+ isValidCert,
signedInUserName,
userFetchState,
isDonating,
@@ -132,9 +112,9 @@ const ShowCertification = props => {
const [isDonationClosed, setIsDonationClosed] = useState(false);
useEffect(() => {
- const { username, certName, validCertName, showCert } = props;
- if (validCertName) {
- showCert({ username, certName });
+ const { username, certSlug, isValidCert, showCert } = props;
+ if (isValidCert) {
+ showCert({ username, certSlug });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -208,13 +188,13 @@ const ShowCertification = props => {
const {
cert,
fetchState,
- validCertName,
+ isValidCert,
createFlashMessage,
signedInUserName,
location: { pathname }
} = props;
- if (!validCertName) {
+ if (!isValidCert) {
createFlashMessage(standardErrorMessage);
return