Skip to content

Add custom-response support for JSON-backed React response widgets#1158

Open
JackWilb wants to merge 10 commits intodevfrom
custom-response
Open

Add custom-response support for JSON-backed React response widgets#1158
JackWilb wants to merge 10 commits intodevfrom
custom-response

Conversation

@JackWilb
Copy link
Copy Markdown
Contributor

@JackWilb JackWilb commented Mar 19, 2026

Does this PR close any open issues?

Closes #1156

Give a longer description of what this PR addresses and why it's needed

This PR adds a new custom response type that lets study configs render a React component from src/public as a first-class response input while still participating in ReVISit’s standard answer, validation, provenance, correctness, and analysis flows.

It includes:

  • Parser and schema support for custom, including path, parameters, and JSON-serializable default values.
  • Runtime support for loading public response modules, rendering them in questionnaire blocks, and invoking an optional module-level validate export.
  • Form-state updates to support structured JSON answers, initialize defaults correctly, and validate custom responses alongside existing response types.
  • Analysis and export updates so custom response values can be displayed and included in tidy data.
  • A demo custom response card in demo-form-elements, plus parser/unit/e2e coverage for the new flow.

It also includes a few related robustness improvements:

  • Reuses shared public-module loading for React stimulus components.
  • Fixes custom-response validation so broken optional modules still surface as errors.
  • Preserves array order for custom-response correctness checks while keeping checkbox/dropdown grading order-insensitive.
  • Hardens a couple of existing components against missing data (VideoController typings and the adaptive VLAT feedback score lookup).

Provide pictures/videos of the behavior before and after these changes (optional)

Are there any additional TODOs before this PR is ready to go?

TODOs:

  • Update relevant documentation
  • ...

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

A preview of b705ef7 is uploaded and can be seen here:

https://revisit.dev/study/PR1158

Changes may take a few minutes to propagate.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new custom-response response type to let study configs render React-based response widgets from src/public while still integrating with the existing answer storage, validation, provenance, and analysis/export flows.

Changes:

  • Introduces custom-response to parser types + JSON schemas, including path, parameters, and JSON-serializable defaults.
  • Adds runtime loading/rendering of custom response modules (and optional module-level validate) and updates form/validation utilities to support JSON-valued answers.
  • Updates demos + tests (unit + e2e) and analysis visualization/export display behavior for structured JSON answers; includes a couple of small robustness fixes.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/demo-form-elements.spec.ts Extends e2e coverage to exercise the new custom response demo page and validation gating.
src/utils/publicModules.ts Adds a shared helper for loading eager-globbed modules from src/public.
src/utils/correctAnswer.spec.ts Adds a correctness test ensuring deep-equality works for structured JSON answers.
src/store/types.ts Broadens stored answer typing to JSON values and introduces custom-response component/validator param types.
src/public/example-VLAT-adaptive/assets/Feedback.tsx Hardens adaptive feedback score lookup against missing data.
src/public/demo-form-elements/assets/CustomResponseCard.tsx Adds a demo custom response widget with structured JSON state + custom validation export.
src/parser/types.ts Adds JsonValue typing and introduces CustomResponse into the Response union.
src/parser/customResponse.spec.ts Adds parser tests for custom-response schema acceptance/rejection.
src/parser/StudyConfigSchema.json Adds CustomResponse + JSON value definitions to the StudyConfig schema and response union.
src/parser/LibraryConfigSchema.json Mirrors CustomResponse + JSON value definitions in the LibraryConfig schema.
src/controllers/VideoController.tsx Adjusts plyr-react typings usage and adds a CSS import resolution suppression comment.
src/controllers/ReactComponentController.tsx Reuses the shared public-module loader for React stimulus components.
src/components/response/utils.ts Updates defaults/init + validation generation to support JSON answers and custom-response validation hooks.
src/components/response/utils.spec.ts Adds unit coverage for custom-response defaults and validation integration.
src/components/response/customResponseModules.ts Adds a small loader wrapper for custom-response modules (default component + validate).
src/components/response/ResponseSwitcher.tsx Adds rendering path for custom-response via CustomResponseInput.
src/components/response/ResponseBlock.tsx Wires custom-response module validation into the response block form lifecycle.
src/components/response/CustomResponseInput.tsx Implements the runtime host that renders the loaded custom response component.
src/analysis/individualStudy/stats/ResponseVisualization.tsx Adds icon + display handling for custom-response answers (stringifies structured JSON).
public/demo-form-elements/config.json Adds a demo “Custom Response” page to the demo study config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@JackWilb JackWilb requested a review from Copilot March 26, 2026 05:43
@JackWilb JackWilb marked this pull request as ready for review March 26, 2026 05:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new custom response type so study configs can render JSON-backed React response widgets from src/public while integrating with existing answer storage, validation, correctness checks, and analysis/replay flows (closes #1156).

Changes:

  • Introduces custom response definitions (path, parameters, JSON-serializable default) across TS types and JSON schemas, plus parser coverage.
  • Adds runtime support for loading/rendering public custom response modules and running optional module-level validation.
  • Updates form state, correctness evaluation (order-sensitive arrays for custom; order-insensitive for checkbox/dropdown), and analysis views to handle structured JSON answers.

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/demo-form-elements.spec.ts Extends e2e coverage to exercise the new custom response demo page.
src/utils/publicModules.ts Adds shared eager public-module loader used by stimulus and custom response widgets.
src/utils/correctAnswer.ts Adds configurable array-order handling and passes response definitions into component-level correctness checks.
src/utils/correctAnswer.spec.ts Adds unit tests for order-preserving array comparisons and JSON object equality.
src/store/types.ts Expands stored answer typing to JsonValue and introduces custom response param/validation types.
src/store/hooks/useNextStep.ts Fixes skip-logic correctness counting by resolving inherited components and using correct component config per candidate.
src/store/hooks/useNextStep.spec.ts Adds regression test for block skip correctness counting across mixed component configs.
src/public/example-VLAT-adaptive/assets/Feedback.tsx Hardens adaptive VLAT feedback score lookup against missing data.
src/public/demo-form-elements/assets/CustomResponseCard.tsx Adds demo custom response widget with structured JSON value + module validation.
src/parser/types.ts Adds JsonValue types and new CustomResponse response type.
src/parser/customResponse.spec.ts Adds parser tests for valid/invalid custom response definitions.
src/parser/StudyConfigSchema.json Adds CustomResponse + JsonValue schema definitions and includes them in Response union.
src/parser/LibraryConfigSchema.json Mirrors CustomResponse + JsonValue schema additions for libraries.
src/controllers/VideoController.tsx Adjusts Plyr typing for sources and adds a CSS import lint suppression comment.
src/controllers/ReactComponentController.tsx Reuses shared public-module loader instead of duplicating import.meta.glob.
src/components/response/utils.ts Updates default initialization/validation to support JSON answers and custom validators/load errors.
src/components/response/utils.spec.ts Adds tests for custom defaults, falsy stored answers, and custom validation behavior.
src/components/response/customResponseModules.ts Adds helper to load custom response module exports (default component + optional validate).
src/components/response/ResponseSwitcher.tsx Wires new CustomResponseInput rendering path.
src/components/response/ResponseBlock.tsx Loads custom response modules, registers validators/load errors into form validation, and threads a field API to widgets.
src/components/response/CustomResponseInput.tsx Renders the loaded custom response component under an error boundary.
src/components/interface/StepsPanel.tsx Resolves inherited components for correctness display and response JSON preview.
src/analysis/individualStudy/table/TableView.tsx Computes correctness with response definitions to preserve intended array-order semantics.
src/analysis/individualStudy/summary/utils.tsx Threads studyConfig into correctness aggregation so custom array grading is consistent.
src/analysis/individualStudy/summary/SummaryView.tsx Passes studyConfig into overview stats computation.
src/analysis/individualStudy/stats/StatsView.tsx Passes studyConfig into per-trial overview stats computation.
src/analysis/individualStudy/stats/ResponseVisualization.tsx Uses new correctness options for checkbox/dropdown and renders JSON answers safely.
src/analysis/individualStudy/replay/AllTasksTimeline.tsx Resolves inherited component configs for correctness and correct-answer display.
public/demo-form-elements/config.json Adds a demo “Custom Response” page to the demo study config sequence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a new response type, custom-response, that allows a user to make their own react responses

2 participants