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

Update docs for definitions #236

Merged
merged 8 commits into from
Aug 28, 2018
Merged

Update docs for definitions #236

merged 8 commits into from
Aug 28, 2018

Conversation

bernars-usa
Copy link
Contributor

Closes #231, which is related to #225.

This PR:

This needs a thorough review of the code samples, as well as the descriptions of the definitions.

```

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:
Copy link
Contributor Author

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.

Copy link
Contributor

@annekainicUSDS annekainicUSDS left a 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';
Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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';
Copy link
Contributor

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() {
Copy link
Contributor

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'
]
}
}
}
},
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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()
Copy link
Contributor

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')

Copy link
Contributor

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 🤔).

Copy link
Contributor

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()
Copy link
Contributor

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

Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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.
Copy link
Contributor

@annekainicUSDS annekainicUSDS left a 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'
]
}
Copy link
Contributor

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!

Copy link
Contributor Author

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(
...
Copy link
Contributor

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: { }
      }
    }
  )
}

Copy link
Contributor Author

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()
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

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

taxYear instead of year

@bernars-usa bernars-usa dismissed dmethvin-gov’s stale review August 27, 2018 20:39

Updates since the last review

@bernars-usa
Copy link
Contributor Author

Thanks for the reviews, @annekainicUSDS and @dmethvin-gov! This is ready for a final check.

@dmethvin-gov
Copy link
Contributor

Not sure why this failed in CircleCI the first time but I re-ran it and it's okay.

@bernars-usa bernars-usa merged commit 44bf861 into master Aug 28, 2018
@bernars-usa bernars-usa deleted the definitions-functions branch August 28, 2018 15:01
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.

3 participants