refactor: files{} -> challengeFiles[], and key -> fileKey (#43023)

* fix(client): fix client

* fix propType and add comment

* revert user.json prettification

* slight type refactor and payload correction

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* update ChallengeFile type imports

* add cypress test for code-storage

* update test and storage epic

* fix Shaun's tired brain's logic

* refactor with suggestions

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* update codeReset

* increate cypress timeout because firefox is slow

* remove unused import to make linter happy

* use focus on editor

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* use more specific seletor for cypress editor test

* account for silly null challengeFiles

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Shaun Hamilton
2021-08-12 19:48:28 +01:00
committed by GitHub
parent 1f62dfe2b3
commit 59f17f237b
41 changed files with 916 additions and 910 deletions

View File

@@ -14,16 +14,17 @@ import { actionTypes } from './action-types';
const { forumLocation } = envData;
function filesToMarkdown(files = {}) {
const moreThenOneFile = Object.keys(files).length > 1;
return Object.keys(files).reduce((fileString, key) => {
const file = files[key];
if (!file) {
function filesToMarkdown(challengeFiles = {}) {
const moreThanOneFile = challengeFiles?.length > 1;
return challengeFiles.reduce((fileString, challengeFile) => {
if (!challengeFile) {
return fileString;
}
const fileName = moreThenOneFile ? `\\ file: ${file.contents}` : '';
const fileType = file.ext;
return `${fileString}\`\`\`${fileType}\n${fileName}\n${file.contents}\n\`\`\`\n\n`;
const fileName = moreThanOneFile
? `\\ file: ${challengeFile.contents}`
: '';
const fileType = challengeFile.ext;
return `${fileString}\`\`\`${fileType}\n${fileName}\n${challengeFile.contents}\n\`\`\`\n\n`;
}, '\n');
}
@@ -32,7 +33,7 @@ function createQuestionEpic(action$, state$, { window }) {
ofType(actionTypes.createQuestion),
tap(() => {
const state = state$.value;
const files = challengeFilesSelector(state);
const challengeFiles = challengeFilesSelector(state);
const { title: challengeTitle, helpCategory } =
challengeMetaSelector(state);
const {
@@ -64,7 +65,7 @@ function createQuestionEpic(action$, state$, { window }) {
${
projectFormValues
?.map(([key, val]) => `${key}: ${transformEditorLink(val)}\n`)
?.join('') || filesToMarkdown(files)
?.join('') || filesToMarkdown(challengeFiles)
}\n\n
${endingText}`);