Add custom-response support for JSON-backed React response widgets#1158
Add custom-response support for JSON-backed React response widgets#1158
Conversation
|
A preview of b705ef7 is uploaded and can be seen here: ✨ https://revisit.dev/study/PR1158 ✨ Changes may take a few minutes to propagate. |
There was a problem hiding this comment.
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-responseto parser types + JSON schemas, includingpath,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.
# Conflicts: # src/controllers/VideoController.tsx
There was a problem hiding this comment.
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
customresponse definitions (path,parameters, JSON-serializabledefault) 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.
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
customresponse type that lets study configs render a React component fromsrc/publicas a first-class response input while still participating in ReVISit’s standard answer, validation, provenance, correctness, and analysis flows.It includes:
custom, includingpath,parameters, and JSON-serializable default values.validateexport.demo-form-elements, plus parser/unit/e2e coverage for the new flow.It also includes a few related robustness improvements:
VideoControllertypings 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: