fix(client): return an empty string for empty sections

This commit is contained in:
Valeriy S
2019-02-18 12:43:09 +03:00
committed by Stuart Taylor
parent cd501ee4c5
commit 6d5e3865e7
3 changed files with 15 additions and 10 deletions

View File

@ -9,17 +9,11 @@ const propTypes = {
section: PropTypes.string section: PropTypes.string
}; };
function emptyInstruction(instructions) {
return /^<section\s+id\s*=\s*("|')instructions\1\s*>\s*<\/section>$/.test(
instructions
);
}
function ChallengeDescription({ description, instructions, section }) { function ChallengeDescription({ description, instructions, section }) {
return ( return (
<div className={`challenge-instructions ${section}`}> <div className={`challenge-instructions ${section}`}>
<div dangerouslySetInnerHTML={{ __html: description }} /> <div dangerouslySetInnerHTML={{ __html: description }} />
{!emptyInstruction(instructions) && ( {instructions && (
<Fragment> <Fragment>
<hr /> <hr />
<div dangerouslySetInnerHTML={{ __html: instructions }} /> <div dangerouslySetInnerHTML={{ __html: instructions }} />

View File

@ -1,6 +1,8 @@
const Joi = require('joi'); const Joi = require('joi');
Joi.objectId = require('joi-objectid')(Joi); Joi.objectId = require('joi-objectid')(Joi);
const { challengeTypes } = require('../../client/utils/challengeTypes');
function getSchemaForLang(lang) { function getSchemaForLang(lang) {
let schema = Joi.object().keys({ let schema = Joi.object().keys({
block: Joi.string(), block: Joi.string(),
@ -12,7 +14,11 @@ function getSchemaForLang(lang) {
.required(), .required(),
checksum: Joi.number(), checksum: Joi.number(),
dashedName: Joi.string(), dashedName: Joi.string(),
description: Joi.string().required(), description: Joi.when('challengeType', {
is: challengeTypes.step,
then: Joi.string().allow(''),
otherwise: Joi.string().required()
}),
fileName: Joi.string(), fileName: Joi.string(),
files: Joi.array().items( files: Joi.array().items(
Joi.object().keys({ Joi.object().keys({
@ -37,7 +43,7 @@ function getSchemaForLang(lang) {
videoUrl: Joi.string().allow(''), videoUrl: Joi.string().allow(''),
helpRoom: Joi.string(), helpRoom: Joi.string(),
id: Joi.objectId().required(), id: Joi.objectId().required(),
instructions: Joi.string().required(), instructions: Joi.string().allow(''),
isBeta: Joi.bool(), isBeta: Joi.bool(),
isComingSoon: Joi.bool(), isComingSoon: Joi.bool(),
isLocked: Joi.bool(), isLocked: Joi.bool(),

View File

@ -62,7 +62,12 @@ function textToData(sectionIds) {
} }
} }
}); });
const textArray = toHTML({ ...node, children: newChildren }); const hasData = newChildren.some(
node => node.type !== 'text' || !/^\s*$/.test(node.value)
);
const textArray = hasData
? toHTML({ ...node, children: newChildren })
: '';
file.data = { file.data = {
...file.data, ...file.data,
[sectionId]: textArray [sectionId]: textArray