8000 inputs: let the checkbox and multiselect parse arrays by tahini · Pull Request #1039 · chairemobilite/evolution · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

inputs: let the checkbox and multiselect parse arrays #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

tahini
Copy link
Contributor
@tahini tahini commented Jun 17, 2025

fixes #1036

Add a asArray parameter to the parseValue function, which allows to specify if the expected value should be an array, but still convert to the correct datatype the values in the array.

Add a isInputTypeWithArrayValue function to determine if the input type should give an array value. checkboxes and multiselects are inputs with array values.

@tahini tahini requested review from kaligrafy and Copilot June 17, 2025 13:24
Copy link
@Copilot 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

This PR enhances the value parsing logic to natively support array inputs (e.g., checkboxes and multiselects) by introducing an asArray flag and a helper to detect array-based input types.

  • Adds isInputTypeWithArrayValue to identify inputs that should parse arrays.
  • Extends parseValue in helpers to handle single vs. array values based on asArray.
  • Updates all calls to parseValue in the frontend to pass the new flag and revises tests accordingly.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/evolution-frontend/src/components/survey/Question.tsx Passes asArray to parseValue for checkbox/multiselect types
packages/evolution-frontend/src/actions/utils/WidgetOperation.ts Same update as above in widget operation utility
packages/evolution-common/src/utils/helpers.ts Refactors and overloads parseValue to support array parsing
packages/evolution-common/src/utils/tests/helpers.test.ts Expands tests to cover both asArray=false and asArray=true
packages/evolution-common/src/services/questionnaire/types/WidgetConfig.ts Adds isInputTypeWithArrayValue helper
packages/evolution-common/src/services/questionnaire/types/tests/WidgetConfig.test.ts Adds tests for the new array‐detection helper
Comments suppressed due to low confidence (2)

packages/evolution-common/src/services/questionnaire/types/tests/WidgetConfig.test.ts:84

  • [nitpick] The describe block name 'isQuestionAnswerAnArray' does not match the function under test 'isInputTypeWithArrayValue'; updating it to reflect the actual function name would improve clarity.
describe('isQuestionAnswerAnArray', () => {

packages/evolution-common/src/utils/tests/helpers.test.ts:118

  • Add test cases for parsing boolean and geojson types with asArray=true to ensure array parsing works correctly for these data types.
each([

Comment on lines 320 to 321
export const isInputTypeWithArrayValue = (inputType: QuestionWidgetConfig['inputType']): boolean =>
inputType === 'checkbox' || inputType === 'multiselect';
Copy link
Preview
Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using a Set or array include check (e.g., ['checkbox', 'multiselect'].includes(inputType)) instead of hardcoded OR conditions to make this easier to extend in the future.

Suggested change
export const isInputTypeWithArrayValue = (inputType: QuestionWidgetConfig['inputType']): boolean =>
inputType === 'checkbox' || inputType === 'multiselect';
const inputTypesWithArrayValues = ['checkbox', 'multiselect'];
export const isInputTypeWithArrayValue = (inputType: QuestionWidgetConfig['inputType']): boolean =>
inputTypesWithArrayValues.includes(inputType);

Copilot uses AI. Check for mistakes.

fixes chairemobilite#1036

Add a `asArray` parameter to the `parseValue` function, which allows to
specify if the expected value should be an array, but still convert to
the correct datatype the values in the array.

Add a `isInputTypeWithArrayValue` function to determine if the input
type should give an array value. checkboxes and multiselects are inputs
with array values.
@tahini tahini merged commit 9cc1816 into chairemobilite:main Jun 17, 2025
6 checks passed
@tahini tahini deleted the fixCheckbox branch June 17, 2025 14:35
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.

Bug: Checkbox widget checked is not showing
2 participants
0