Skip to content

Conversation

@yjose
Copy link
Member

@yjose yjose commented Nov 25, 2025

Summary

Implements conditional visibility system for survey questions and sections based on previous answers, reducing survey length and improving response rates.

Changes

  • Conditional Visibility System (src/lib/conditions.ts)

    • showIf conditions for questions/sections with operators: equals, notEquals, in, notIn
    • Question ID format validation and evaluation engine
    • Helper functions for visible question/section navigation
  • Survey Machine Refactoring

    • Track visible section indices dynamically
    • Navigate only through visible questions (skip hidden)
    • Auto-submit when all remaining questions hidden
    • Normalize answers before submission
  • Component Updates

    • Extract SurveyActions component from survey-form
    • Refactor Steps to use machine context and show only visible sections
    • Preserve auto-empty-array for unanswered multiple choice
  • Schema & Validation

    • Add ShowIfConditionSchema with operator validation
    • Support showIf field on questions and sections (optional)
    • Type exports for conditional logic
  • Tests & Documentation

    • 35+ new tests for conditional logic (364 total in machine tests)
    • RFC document with examples and operator reference
    • Sample conditional questions in YAML files

Test Coverage

  • ✅ All 133 tests passing
  • ✅ Build passes (pnpm check)
  • ✅ Handles question/section visibility
  • ✅ Skips hidden questions during navigation
  • ✅ Auto-submits when remaining questions hidden

Examples

questions:
  - label: Where are you working?
    choices: ["Morocco", "Outside Morocco"]
    required: true

  - label: Plans to return to Morocco?
    showIf:
      question: profile-q-0
      equals: 1  # Outside Morocco
    choices: ["Yes, within 12 months", "Yes, within 24 months", "No"]

Files Changed

17 files: +1291/-161 lines

  • Core: conditions.ts, survey-machine.ts, survey-schema.ts
  • Components: survey-controls.tsx, steps.tsx, survey-form.tsx
  • Tests: survey-machine.test.ts (+350 lines)
  • Docs: RFC-conditional-survey-logic.md

- Add conditional visibility system for questions/sections
- Refactor survey machine to handle visible question navigation
- Extract SurveyActions component from survey-form
- Refactor Steps to use machine context and visible sections
- Add comprehensive tests for conditional logic
- Update type definitions and disable inspector in test mode
- Fix: restore auto-empty-array for unanswered multiple choice
@netlify
Copy link

netlify bot commented Nov 25, 2025

Deploy Preview for stateofdev ready!

Name Link
🔨 Latest commit 572f2d5
🔍 Latest deploy log https://app.netlify.com/projects/stateofdev/deploys/6926e3f8b31fa700089f25f5
😎 Deploy Preview https://deploy-preview-147--stateofdev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link

github-actions bot commented Nov 25, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 31.29% 1300 / 4154
🔵 Statements 31.29% 1300 / 4154
🔵 Functions 61.7% 87 / 141
🔵 Branches 78.4% 276 / 352
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
scripts/export-results.ts 0% 0% 0% 0% 1-32
scripts/generate-questions.ts 0% 100% 100% 0% 8-93
scripts/validate-survey.ts 0% 100% 100% 0% 7-33
src/actions/init-session.ts 0% 100% 100% 0% 2-88
src/actions/submit-answers.ts 0% 100% 100% 0% 2-49
src/components/faq-item.astro 0% 0% 0% 0% 1-43
src/components/faq-list.astro 0% 0% 0% 0% 1-49
src/components/footer.astro 0% 0% 0% 0% 1-96
src/components/google-analytics.astro 0% 0% 0% 0% 1-12
src/components/header.astro 0% 0% 0% 0% 1-114
src/components/layout.astro 0% 0% 0% 0% 1-160
src/components/social-media-card.astro 0% 0% 0% 0% 1-112
src/components/theme-toggle.astro 0% 0% 0% 0% 1
src/components/chart/bar-chart.tsx 0% 100% 100% 0% 2-223
src/components/chart/chart-actions.tsx 0% 100% 100% 0% 3-63
src/components/chart/chart.astro 0% 0% 0% 0% 1-47
src/components/chart/chart.tsx 0% 100% 100% 0% 3-75
src/components/chart/data.ts 94.28% 100% 0% 94.28% 50-51
src/components/chart/pie-chart.tsx 0% 100% 100% 0% 2-140
src/components/chart/share-buttons.tsx 0% 0% 0% 0% 1-121
src/components/chart/utils.ts 95.08% 91.83% 83.33% 95.08% 93-94, 179-180, 187-188
src/components/home/hero.astro 0% 0% 0% 0% 1-106
src/components/home/past-repports.tsx 0% 0% 0% 0% 1-182
src/components/home/why.tsx 0% 0% 0% 0% 1-129
src/components/playground/chart-types.ts 0% 100% 100% 0% 3-6
src/components/playground/filters-options.tsx 0% 100% 100% 0% 6-175
src/components/playground/index.tsx 0% 100% 100% 0% 5-83
src/components/playground/playground-form.tsx 0% 100% 100% 0% 3-256
src/components/report/hero.astro 0% 0% 0% 0% 1-111
src/components/report/index.astro 0% 0% 0% 0% 1-73
src/components/report/toc.astro 0% 0% 0% 0% 1-67
src/components/survey/choice.tsx 100% 100% 100% 100%
src/components/survey/exit-popup.astro 0% 0% 0% 0% 1-36
src/components/survey/index.astro 0% 0% 0% 0% 1-43
src/components/survey/question.tsx 100% 87.17% 100% 100%
src/components/survey/steps.tsx 87.71% 96.42% 40% 87.71% 25-28, 31-35, 124-128
src/components/survey/survey-app.tsx 0% 100% 100% 0% 2-15
src/components/survey/survey-context.tsx 71.95% 71.42% 100% 71.95% 25-43, 56-58, 65-67, 90
src/components/survey/survey-controls.tsx 100% 100% 85.71% 100%
src/components/survey/survey-form.tsx 96.61% 80% 100% 96.61% 37-38
src/components/survey/survey-inspector.ts 3.22% 100% 0% 3.22% 5-44
src/components/survey/survey-machine.ts 93.37% 76.36% 91.66% 93.37% 62-63, 206, 211-216, 218-231
src/components/survey/utils.ts 28.57% 100% 0% 28.57% 3-5, 8-9
src/lib/captcha.ts 0% 0% 0% 0% 1-31
src/lib/conditions.ts 100% 100% 100% 100%
src/lib/utils.ts 0% 100% 100% 0% 2-7
src/lib/firebase/client.ts 0% 100% 100% 0% 3-16
src/lib/firebase/database.ts 0% 100% 100% 0% 2-39
src/lib/firebase/server.ts 0% 100% 100% 0% 2-50
src/lib/validators/survey-schema.ts 95.12% 75% 90% 95.12% 27-34
src/lib/validators/survey-validator.ts 0% 100% 100% 0% 3-579
src/pages/2022.astro 0% 0% 0% 0% 1-10
src/pages/before-start.astro 0% 0% 0% 0% 1-65
src/pages/home.astro 0% 0% 0% 0% 1-9
src/pages/playground.astro 0% 0% 0% 0% 1-18
src/pages/survey.astro 0% 0% 0% 0% 1-28
src/pages/thanks.astro 0% 0% 0% 0% 1-142
src/pages/api/init-session.ts 0% 100% 100% 0% 2-35
src/pages/api/remove-session.ts 0% 100% 100% 0% 3-10
Generated in workflow #1 for commit 572f2d5 by the Vitest Coverage Report Action

yjose and others added 6 commits November 25, 2025 15:36
…o Astro

- Add 51 unit tests for conditions.ts evaluation functions
- Add blocking cross-reference validation for showIf conditions
- Fix SectionList type to include questions property (remove any cast)
- Convert theme-toggle from React to Astro component with vanilla JS
- Add eslint-disable no-console to files using console.log
- Change console.warn to console.log for consistency
- Remove unused console.warn from init-session API

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Deleted the validate-survey-questions.sh script and its associated workflow.
- Introduced a new CI workflow (ci.yml) that includes linting, testing, and coverage reporting.
- Removed the old lint.yml and validate-survey-questions.yml workflows to streamline CI processes.
@yjose yjose merged commit 1d40024 into master Nov 26, 2025
1 check passed
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.

2 participants