Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/lint_build.yaml
Comment thread
JackWilb marked this conversation as resolved.
Comment thread
JackWilb marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ on:

jobs:
lint:
uses: revisit-studies/.github/.github/workflows/lint.yaml@main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn'

- name: Install yarn packages (from cache if available)
run: yarn install --frozen-lockfile

- name: Run linter
run: yarn lint

- name: Build application
run: yarn build
61 changes: 36 additions & 25 deletions src/components/response/ResponseBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ function findMatchingStrings(arr1: string[], arr2: string[]): string[] {
return matches;
}

function collectResponseValuesFromTrialValidation(
validationForStep?: Partial<Record<ResponseBlockLocation, ValidationStatus>>,
): StoredAnswer['answer'] {
if (!validationForStep) {
return {};
}

return Object.values(validationForStep).reduce((acc, curr) => {
if (curr && Object.hasOwn(curr, 'values')) {
return { ...acc, ...curr.values };
}
return acc;
}, {} as StoredAnswer['answer']);
}

function collectResponseValuesFromAnalysisState(
analysisProvState: Partial<Record<ResponseBlockLocation, FormElementProvenance>>,
status?: StoredAnswer,
): StoredAnswer['answer'] {
return (['aboveStimulus', 'belowStimulus', 'sidebar'] as ResponseBlockLocation[]).reduce((acc, responseLocation) => {
const locationProv = analysisProvState[responseLocation];
return {
...acc,
...(locationProv?.form || {}),
};
}, { ...(status?.answer || {}) } as StoredAnswer['answer']);
}

export function ResponseBlock({
config,
location,
Expand Down Expand Up @@ -231,26 +259,14 @@ export function ResponseBlock({
[customResponseModules],
);
const combinedLiveValues = useMemo(() => {
const validationForStep = trialValidation[identifier];
if (!validationForStep) {
return {};
}

return Object.values(validationForStep).reduce((acc, curr) => {
if (Object.hasOwn(curr, 'values')) {
return { ...acc, ...(curr as ValidationStatus).values };
}
return acc;
}, {}) as StoredAnswer['answer'];
const validationForStep = trialValidation[identifier] as Partial<Record<ResponseBlockLocation, ValidationStatus>> | undefined;
return collectResponseValuesFromTrialValidation(validationForStep);
}, [identifier, trialValidation]);
const combinedAnalysisValues = useMemo(
() => ['aboveStimulus', 'belowStimulus', 'sidebar'].reduce((acc, responseLocation) => {
const locationProv = analysisProvState[responseLocation as ResponseBlockLocation] as FormElementProvenance | undefined;
return {
...acc,
...(locationProv?.form || {}),
};
}, { ...(status?.answer || {}) } as StoredAnswer['answer']),
() => collectResponseValuesFromAnalysisState(
analysisProvState as Partial<Record<ResponseBlockLocation, FormElementProvenance>>,
status,
),
[analysisProvState, status],
);
const combinedValues = useMemo(
Expand Down Expand Up @@ -498,13 +514,8 @@ export function ResponseBlock({
const newAttemptsUsed = attemptsUsed + 1;
setAttemptsUsed(newAttemptsUsed);

const trialValidationCopy = structuredClone(trialValidation[identifier]);
const allAnswers = (trialValidationCopy ? Object.values(trialValidationCopy).reduce((acc, curr) => {
if (Object.hasOwn(curr, 'values')) {
return { ...acc, ...(curr as ValidationStatus).values };
}
return acc;
}, {}) : {}) as StoredAnswer['answer'];
const trialValidationCopy = structuredClone(trialValidation[identifier]) as Partial<Record<ResponseBlockLocation, ValidationStatus>> | undefined;
const allAnswers = collectResponseValuesFromTrialValidation(trialValidationCopy);

const correctAnswers = Object.fromEntries(
(config?.correctAnswer ?? []).map((configCorrectAnswer) => {
Expand Down
Loading
Loading