Skip to content

Add enable_when attribute to the input#758

Open
projkov wants to merge 23 commits into
inferno-framework:mainfrom
projkov:conditional-rendering-of-modal-inputs
Open

Add enable_when attribute to the input#758
projkov wants to merge 23 commits into
inferno-framework:mainfrom
projkov:conditional-rendering-of-modal-inputs

Conversation

@projkov
Copy link
Copy Markdown

@projkov projkov commented Feb 2, 2026

Short description

Branch adds conditional visibility for inputs in the inputs modal: inputs can be shown or hidden based on another input’s value via a enable_when condition.

Change overview

  1. Enhance input visibility logic and add new helper functions
    1.1 showInput and conditionalShowInput in the client
    1.2 TestInput extended with enable_when
    1.3 Value normalization/comparison helpers
    1.4 InputFields switched from !input.hidden to showInput(input, inputsMap)
  2. Refactor input handling and enhance test coverage
    2.1 Refactors and tests for conditional visibility and hidden state
  3. Enhance input serializer and entity to support conditional display
    3.1 Backend: enable_when on input entity and API serializer
    3.2 enable_when treated as uninheritable (like locked / hidden)
  4. Add conditional input group to demo suite
    4.1 New optional demo group “Conditional Inputs Group” using enable_when (e.g. “How to get Bundle” → paste JSON / URL / $summary with different inputs)
  5. Initialize Bundler in inferno script
    5.1 bin/inferno: added require 'bundler/setup'
    5.2Gemfile.lock: added arm64-darwin-25 platform

References:

  1. Decouple bundle content tests from ways of retrieving bundle hl7au/au-ps-inferno#24
  2. Streamline modal interface hl7au/au-ps-inferno#26
  3. #inferno > Question: Adding conditional inputs to the modal window UI

Usage example:

group do
  id 'conditional_group'
  title 'Conditional Inputs Group'
  optional

  test 'Conditional, optional, empty input test' do
    input :get_type, title: 'How to get Bundle', type: 'radio', options: {
      list_options: [
        { value: 'copy_paste', label: 'Paste JSON' },
        { value: 'url', label: 'URL to FHIR Bundle' },
        { value: 'summary_op', label: '$summary Operation' }
      ]
    }
    input :bundle_copy_paste, title: 'Paste JSON', type: 'textarea', optional: true,
                              enable_when: { input_name: 'get_type', value: 'copy_paste' }
    input :bundle_url, title: 'URL to FHIR Bundle', type: 'text', optional: true,
                       enable_when: { input_name: 'get_type', value: 'url' }
    input :fhir_server_url, title: 'FHIR Server URL', type: 'text', optional: true,
                            enable_when: { input_name: 'get_type', value: 'summary_op' }
    input :patient_id, title: 'Patient ID', type: 'text', optional: true,
                       enable_when: { input_name: 'get_type', value: 'summary_op' }

    run { pass }
  end
end

Demo:

inferno-conditional-inputs

- Introduced `showInput` and `conditionalShowInput` functions to manage input field visibility based on conditions defined in `show_if`.
- Updated `InputFields` component to utilize the new visibility logic.
- Added new utility functions in `InputHelpers` for value normalization and comparison.
- Extended `TestInput` model to include `show_if` property for conditional rendering.
- Added tests to ensure correct rendering behavior based on input conditions.
- Simplified `sortAndNormalizeArray` function to directly handle arrays.
- Improved input construction and visibility assertion logic in tests.
- Added new tests for input visibility based on conditional rendering and hidden states.
- Ensured consistent naming conventions in test helper functions.
- Added `show_if` field to the input serializer for conditional rendering.
- Updated documentation to include `show_if` in input options.
- Included `show_if` in the list of uninheritables for input attributes to ensure proper handling during input definition merging.
- Introduced a new group for conditional inputs in the demo suite.
- Added tests for various input types that display based on the selected option.
- Enhanced the input structure to support conditional visibility using the `show_if` attribute.
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 92.15686% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.82%. Comparing base (c616e2a) to head (e7fba3c).

Files with missing lines Patch % Lines
client/src/components/TestSuite/TestSession.tsx 25.00% 3 Missing ⚠️
...tails/TestGroupListItem/NestedDescriptionPanel.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #758      +/-   ##
==========================================
+ Coverage   84.78%   84.82%   +0.04%     
==========================================
  Files         297      297              
  Lines       13969    14008      +39     
  Branches     1955     1975      +20     
==========================================
+ Hits        11843    11882      +39     
  Misses       2118     2118              
  Partials        8        8              
Flag Coverage Δ
frontend 79.49% <92.15%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@karlnaden karlnaden left a comment

Choose a reason for hiding this comment

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

Note additionally the missing test coverage.

list_options?: InputOption[];
mode?: string;
};
enable_when?: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please propose updated Inferno documentation in this section (rendered here) for this input feature.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Comment thread client/src/models/testSuiteModels.ts Outdated
};
enable_when?: {
input_name: string;
value: string | string[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a decent amount of added complexity to support string[] here for unclear benefit. Technically it allows you to use a multi-select checkbox field as a target for the enable-when, but in practice you would be enabling for a specific set of boxes checked and not able to enable based on a single checkbox. You don't have any examples or unit tests for this case, so I think my request is to take it out and explicitly document that enable_when is meant to target inputs with the radio type. That is the primary use case and I think better to keep this simple (as you've already done) than try to make it fully general.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have changed this attribute to a string type and also added an example with the select input.

Comment thread bin/inferno Outdated
- Removed the `isEqual` function in favor of direct normalization comparison for input visibility logic.
- Updated `TestInput` model to restrict `enable_when.value` to a single string instead of an array.
- Enhanced demo suite tests to include new radio and select input types with conditional visibility.
- Improved test specifications to reflect changes in input structure and visibility conditions.
@projkov projkov requested a review from karlnaden February 6, 2026 15:05
@projkov
Copy link
Copy Markdown
Author

projkov commented Feb 6, 2026

Hello Karl @karlnaden

All problems should now be resolved on my end.

Comment thread client/src/components/InputsModal/InputHelpers.ts Outdated
constructInput({
name: 'dependent',
title: 'Dependent',
enable_when: { input_name: 'trigger', value: ['a', 'b'] },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should the value be a string rep of the Array? Or is use with checkboxes disallowed?

@projkov
Copy link
Copy Markdown
Author

projkov commented Mar 6, 2026

Hello team,

I was busy this week, but I hope to continue work on the request next week.

@karlnaden
Copy link
Copy Markdown
Contributor

Hello team,

I was busy this week, but I hope to continue work on the request next week.

@projkov Are you able to get this PR finished in the next week or two? We'd like to include it in the Inferno May release.

@karlnaden
Copy link
Copy Markdown
Contributor

@projkov checking in again to get a sense for your timeline on this enhancement.

@projkov
Copy link
Copy Markdown
Author

projkov commented May 4, 2026

Hello Karl @karlnaden
Sorry for the late answer. I didn't see the notification.
Unfortunately, I'm going to finish this PR next week, somewhere between May 11th and 13th.

@karlnaden
Copy link
Copy Markdown
Contributor

Hello Karl @karlnaden Sorry for the late answer. I didn't see the notification. Unfortunately, I'm going to finish this PR next week, somewhere between May 11th and 13th.

No worries @projkov - this week would be great. We have some planned releases coming out in early June that would use this feature if it were available. Thanks for helping to improve Inferno.

@projkov
Copy link
Copy Markdown
Author

projkov commented May 15, 2026

Hello Karl. @karlnaden

Looks like if the conditional field is required, it could be a problem in cases where it is hidden and doesn't have a value.
What behavior do we expect in this case? It looks like in this case we need to show a log with at least a warning.

@karlnaden
Copy link
Copy Markdown
Contributor

Hello Karl. @karlnaden

Looks like if the conditional field is required, it could be a problem in cases where it is hidden and doesn't have a value. What behavior do we expect in this case? It looks like in this case we need to show a log with at least a warning.

Define what you mean by "problem" here. If it is a crash in the UI, then we'd need to do something about it. If it is just a "you can't successfully run this test because your design doesn't display an input that you need to populate", that already exists (see the existing demonstration suite, for example) and I don't think that we need to over engineer logic to detect it and surface it.

In summary, assuming this is just a situation where design decisions can make your tests unrunnable in the UI, I don't think you need to detect or log that.

@karlnaden
Copy link
Copy Markdown
Contributor

@projkov is this ready for review, or are you still working on it?

…d add checkbox options and default value methods in demo suite tests.
@projkov
Copy link
Copy Markdown
Author

projkov commented May 20, 2026

Hello Karl @karlnaden

I have doubt about how conditional rendering should work with checkbox field. Right now it works only when a single specific checkbox is selected.

It looks strange from my perspective. What do you think?

@karlnaden
Copy link
Copy Markdown
Contributor

I have doubt about how conditional rendering should work with checkbox field. Right now it works only when a single specific checkbox is selected.

It looks strange from my perspective. What do you think?

I agree that only working when one checkbox is populated does not meet the spirit of checkboxes. I wonder if for this initial pass at this functionality only radio-type inputs are supported (matches the single selection). I think that is useful even if it isn't fully general. Do you have a specific case that needs checkbox support? If so, then it would be better to re-think the design to support multi-selection cases.

@projkov
Copy link
Copy Markdown
Author

projkov commented May 20, 2026

I have doubt about how conditional rendering should work with checkbox field. Right now it works only when a single specific checkbox is selected.
It looks strange from my perspective. What do you think?

I agree that only working when one checkbox is populated does not meet the spirit of checkboxes. I wonder if for this initial pass at this functionality only radio-type inputs are supported (matches the single selection). I think that is useful even if it isn't fully general. Do you have a specific case that needs checkbox support? If so, then it would be better to re-think the design to support multi-selection cases.

Right now, I don’t have any cases where a checkbox field is suitable. Let’s keep it simple and not provide this functionality for checkboxes. If someone needs this feature, then we can think about it in the next iteration.

@projkov projkov requested a review from karlnaden May 20, 2026 15:24
Copy link
Copy Markdown
Contributor

@karlnaden karlnaden left a comment

Choose a reason for hiding this comment

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

Code coverage flags are related to lint, so fine to skip.

Please address my comments on the documentation PR and then I will merge them both in.

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