fix(client): provide return types for get-completion-percentage (#49458)

fix: provide return types

I also moved the undefined check closer to the source, so it's clearer
what is missing
This commit is contained in:
Oliver Eyton-Williams
2023-02-21 07:40:01 -08:00
committed by GitHub
parent 9f1562291c
commit 424711fcad
2 changed files with 12 additions and 16 deletions
@@ -94,30 +94,25 @@ export const challengeDataSelector = state => {
export const currentBlockIdsSelector = state => {
const { block, certification, challengeType } = challengeMetaSelector(state);
const allChallengesInfo = allChallengesInfoSelector(state);
const currentBlockIds = getCurrentBlockIds(
return getCurrentBlockIds(
allChallengesInfo,
block,
certification,
challengeType
);
if (!currentBlockIds) {
return [];
}
return currentBlockIds;
};
export const completedChallengesInBlockSelector = state => {
const completedChallengesIds = completedChallengesIdsSelector(state);
const currentBlockIds = currentBlockIdsSelector(state);
const { id } = challengeMetaSelector(state);
const completedChallengesInBlock = getCompletedChallengesInBlock(
return getCompletedChallengesInBlock(
completedChallengesIds,
currentBlockIds,
id
);
return completedChallengesInBlock;
};
export const completedPercentageSelector = state => {
@@ -23,7 +23,7 @@ export function getCompletedChallengesInBlock(
completedChallengesIds: string[],
currentBlockIds: string[],
currentChallengeId: string
) {
): number {
const oldCompletionCount = completedChallengesIds.filter(challengeId =>
currentBlockIds.includes(challengeId)
).length;
@@ -39,13 +39,14 @@ export const getCurrentBlockIds = (
block: string,
certification: string,
challengeType: number
) => {
): string[] => {
const { challengeEdges, certificateNodes } = allChallengesInfo;
const currentCertificateIds = certificateNodes
.filter(
node => dasherize(node.challenge.certification) === certification
)[0]
?.challenge.tests.map(test => test.id);
const currentCertificateIds =
certificateNodes
.filter(
node => dasherize(node.challenge.certification) === certification
)[0]
?.challenge.tests.map(test => test.id) ?? [];
const currentBlockIds = challengeEdges
.filter(edge => edge.node.challenge.block === block)
.map(edge => edge.node.challenge.id);