Skip to content
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

Controls: Rework conditional controls with globals, queries #17883

Merged
merged 1 commit into from
Apr 5, 2022

Conversation

shilman
Copy link
Member

@shilman shilman commented Apr 5, 2022

Issue: #11984

What I did

Redid #17536 to include globals, query objects based on community feedback in #11984

Here's the new version:

argTypes: {
  field1: { if: { arg: 'foo' } }, // truthy: true
  field1: { if: { arg: 'foo', truthy: true } },
  field1: { if: { arg: 'foo', truthy: false } },
  field3: { if: { arg: 'foo', exists: true } },
  field3: { if: { arg: 'foo', exists: false } },
  field4: { if: { arg: 'foo', eq: 'bar' } },
  field5: { if: { arg: 'foo', neq: 'bar' } },
  field6: { if: { global: 'theme', eq: 'dark' } },
  field7: { if: { arg: 'foo', global: 'foo' } }, // => ERROR
  field8: { if: { } }, // => ERROR
  field8: { if: { arg: 'foo', eq: 'foo', exists: true } }, // => ERROR
}

The query object must contain either an arg or global target:

field type meaning
arg string The ID of the arg to test.
global string The ID of the global to test.

It may also contain at most one of the following operators:

operator type meaning
truthy boolean Is the target value truthy?
exists boolean Is the target value defined?
eq any Is the target value equal to the provided value?
neq any Is the target value NOT equal to the provided value?

If no operator is provided, that is equivalent to { truthy: true }.

How to test

See updated stories. Most of the tests are in the CSF PR ComponentDriven/csf#36

@nx-cloud
Copy link

nx-cloud bot commented Apr 5, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5dee035. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

LGTM

@shilman shilman merged commit d1edd8d into next Apr 5, 2022
@shilman shilman deleted the tech/condintial-args-rework branch April 5, 2022 10:06
@localjo
Copy link

localjo commented Jun 2, 2022

Is there any support for operators like gte or lte? I need to conditionally include/exclude controls based on whether a number is greater than or equal to a certain value.

@shilman
Copy link
Member Author

shilman commented Jun 2, 2022

@localjo Not yet! Wanted to keep it simple to start out. Want to create an issue?

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

Successfully merging this pull request may close these issues.

3 participants