-
Notifications
You must be signed in to change notification settings - Fork 34
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
Update docs for definitions #236
Conversation
``` | ||
|
||
Then, call it to add all the `uiSchema` definitions. In this example, the definition is a function that takes the title for that field, which is used to populate the 'ui:title' property in uiSchema: | ||
Then, call it to add the `schema` and `uiSchema` functions. The definition is a function that takes the title for that field, which is used to populate the 'ui:title' property in uiSchema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I can't remember making this change... it might have been a half implementation of another thought. Let me know if it needs changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good first pass! A few comments for edits.
|
||
### Using definitions | ||
|
||
To use a definition, import it near the top of the file you want to reference it in: | ||
|
||
```js | ||
import currencyUI from 'us-forms-system/lib/js/definitions/currency'; | ||
import currencyConfig from 'us-forms-system/lib/js/definitions/currency'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be imported using curly brackets now: import { currencyConfig } from ...
. The reason is because before we were using default exports in the definitions file, and now we're not (basically changing how we export/import things).
``` | ||
|
||
Then, call it to add all the `uiSchema` definitions. In this example, the definition is a function that takes the title for that field, which is used to populate the 'ui:title' property in uiSchema: | ||
Then, call it to add the `schema` and `uiSchema` functions. The definition is a function that takes the title for that field, which is used to populate the 'ui:title' property in uiSchema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to change this language a little bit. It's still pretty specific to uiSchema
. Here's my recommended edit:
Then, use the definition by calling the schema
and uiSchema
functions on it where needed. Sometimes the functions take arguments to configure how the definitions are used. In this particular case, the uiSchema
for currency takes an optional argument for the title of the field. In this example we want to set the title to "Currency", so we pass that as a string to the uiSchema
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@@ -45,22 +47,25 @@ Available definitions are: | |||
### Autosuggest | |||
|
|||
A common type-ahead widget that lets a user type in values and narrow down a longer list of options. It is most commonly used with an `enum` of the available options as shown here. Define the uiSchema by calling the function that you import. You can pass an object with additional uiSchema properties. | |||
|
|||
```js | |||
import { uiSchema as autosuggestUI } from 'us-forms-system/lib/js/definitions/autosuggest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import statement needs to change to import { autosuggestConfig } from 'us-forms-system/lib/js/definitions/autosuggest';
.
'New York', | ||
'Chicago' | ||
] | ||
function schema() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what these code samples are trying to show is what this would look like in the form config, not what the definition code is. So I think this would actually remain the way it was before, where the schema
is an object in the form config. You can just revert this change for the schema
.
This particular definition is a little confusing because here we're not actually using the schema
from the definition, but instead writing our own schema into the form config, so I think we should clean that up as a separate issue. I'll create a ticket for that.
'New York', | ||
'Chicago' | ||
] | ||
} | ||
} | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage for the uiSchema
below also needs to change, where instead it would look like this:
uiSchema: {
officeLocation: autosuggestConfig.uiSchema(
...
)
}
(what is contained in the ...
is exactly as it is now (lines 74-81), it's just where the uiSchema function is called that needs to change)
@@ -81,63 +86,105 @@ Source: [/src/js/definitions/autosuggest.js](../../src/js/definitions/autosugges | |||
|
|||
### Currency | |||
|
|||
Formats and validates a US currency field. The display includes a leading `$` character. Call this exported function and pass it the label to be used on the field. | |||
Formats and validates a US currency field that includes a leading `$` character. You can pass this function a label to be used on the field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the language in the second sentence to be: "You can pass the uiSchema
function a label to be used on the field".
} | ||
``` | ||
Source: [/src/js/definitions/currency.js](../../src/js/definitions/currency.js) | ||
|
||
### Current or past dates | ||
|
||
The common date field with current or past validation set (i.e., dates in the future are not valid). Call this exported function and pass it the label to be used on the field. | ||
The common date field with validation warning that dates in the past or future are not valid. You can pass this function a label to be used on the field. Dates must be on or before January 1, 1900. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anywhere where it says "You can pass this function a label", I would specify to be "You can pass the uiSchema
function a label" because there are now 2 functions that are exported by a definition: the schema()
and the uiSchema()
. It's important to specify which of the two takes the additional argument.
|
||
uiSchema: { | ||
birthdate: currentOrPastDate('Date of Birth') | ||
currentOrPastDate: currentOrPastDateConfig.uiSchema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to show how this takes an additional argument for the label like we used to? So:
currentOrPastDate: currentOrPastDateConfig.uiSchema('Date of Birth')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep the birthdate
as well since it's a good example of when you might want a date not in the future (assuming the person filling out the form is giving their own birthdate 🤔).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, good point @dmethvin-gov!
|
||
uiSchema: { | ||
lastContact: currentOrPastMonthYear('Last Contact') | ||
currentOrPastMonthYear: currentOrPastMonthYearConfig.uiSchema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing about showing the label that can be passed to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lastContact
was similarly trying to give an example of when you might want this type of validated date.
|
||
uiSchema: { | ||
birthdate: currentOrPastDate('Date of Birth') | ||
currentOrPastDate: currentOrPastDateConfig.uiSchema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep the birthdate
as well since it's a good example of when you might want a date not in the future (assuming the person filling out the form is giving their own birthdate 🤔).
|
||
uiSchema: { | ||
lastContact: currentOrPastMonthYear('Last Contact') | ||
currentOrPastMonthYear: currentOrPastMonthYearConfig.uiSchema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lastContact
was similarly trying to give an example of when you might want this type of validated date.
I added some example labels in the `uiSchemas` - let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small nits to clean up! Thanks for taking this on, I know this was probably hard to do because it's so technical and nit-picky!
@@ -61,83 +66,119 @@ schema: { | |||
'New York', | |||
'Chicago' | |||
] | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one last } should be deleted!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't look right but I couldn't figure out how to check it. Thanks!
} | ||
} | ||
officeLocation: autosuggestConfig.uiSchema( | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry! I think my previous feedback was confusing. This is what the code should look like here:
uiSchema: {
officeLocation: autosuggestConfig.uiSchema(
'Preferred Office Location', // field title
null, // Promise to get options (optional)
{ // Additional uiSchema options
'ui:options': {
// When labels are not provided, it uses enumNames
labels: { }
}
}
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks!
schema: { | ||
type: 'object' | ||
properties: { | ||
currentOrPastDate: currentOrPastDateConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key also needs to be birthdate
, so:
birthdate: currentOrPastDateConfig.schema()
schema: { | ||
type: 'object', | ||
properties: { | ||
currentOrPastMonthYear: currentOrPastMonthYearConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key also needs to be lastContact
, the same as above.
schema: { | ||
type: 'object', | ||
properties: { | ||
date: dateConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startDate
here instead of date
schema: { | ||
type: 'object', | ||
properties: { | ||
dateRange: dateRangeConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
servicePeriod
instead of dateRange
schema: { | ||
type: 'object', | ||
properties: { | ||
monthYear: monthYearConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceStart
instead of monthYear
schema: { | ||
type: 'object', | ||
properties: { | ||
monthYearRange: monthYearRangeConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceRange
instead of monthYearRange
schema: { | ||
type: 'object', | ||
properties: { | ||
year: yearConfig.schema() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taxYear
instead of year
Updates since the last review
Thanks for the reviews, @annekainicUSDS and @dmethvin-gov! This is ready for a final check. |
Not sure why this failed in CircleCI the first time but I re-ran it and it's okay. |
Closes #231, which is related to #225.
This PR:
form.js
in https://github.com/usds/us-forms-system-starter-app/blob/test-new-schema-additions-to-usfs/js/config/form.jsThis needs a thorough review of the code samples, as well as the descriptions of the definitions.