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

Typescript #47

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Typescript #47

wants to merge 27 commits into from

Conversation

pjm17971
Copy link
Contributor

@pjm17971 pjm17971 commented Mar 10, 2020

DO NOT MERGE

TODO Checklist

  • Chooser
    • Reimplement with react-select 2.0
    • Add react-window to chooser for performance improvements
    • Add async loading functionality to chooser
    • Storybook stories for chooser
      • Basic non-search chooser
      • Basic searchable chooser
      • Edit mode test
      • Disabled test
      • Required test with clearable chooser
      • Custom view example
      • Async loading for chooser
      • Async loading for chooser (form)
      • Chooser in full form example
  • TextEdit
    • Storybook stories for TextEdit
      • Basic TextEdit
      • Hidden TextEdit
      • Disabled
      • Selected
      • Required
      • View mode
      • Custom view mode
      • Example in full form
  • TextArea
    • Storybook stories for TextArea
  • Help for fields
    • Tooltip help
    • Schema help text could also be fn
  • Switch control
    • Basic switch
    • Disabled switch
    • Default options switch
    • Switch view mode
    • Switch custom view mode
  • Date edit control
    • Basic date control
    • Required date control
    • Disabled date control
    • Basic date edit control view only
    • Time picker basic
    • Time picker view mode
    • Month picker basic
    • Month picker view mode
    • Constraints (min and max dates)
  • View control
    • Basic view control

Transition Guide

  • Views can either be a function which takes the current FieldValue and returns a React Element (like before) or a string. The prop name for these are displayView rather than view. For Choosers with async loading it is necessary to implement displayView to return the current item label because the Chooser will not know the item label until the list of items is loaded.
  • Chooser is implemented on react-select 2.x. Some props have been aligned to this API: isDisabled replaces disabled, isSearchable replaces disableSearch and isClearable replaces allowSingleDeselect.

Async Chooser

This PR adds Async Chooser functionality, allowing the Chooser to request data when it is displayed. The most likely use for this would be for inline editing. The Chooser would display a text value for the selected item until the user opted to edit it. At that point the user would see a spinner within the Chooser and the component would request data. When the data is loaded the user can then select from the list as usual.

Here is a Chooser that would be nested inside a Form:

<Chooser
    field="color"
    width={280}
    choiceLoader={loadOptions}
    displayView={value => (
        <span style={{ color: "steelblue" }}>
            <b>
            { availableColors.find(item => item.get("id") === value)?.get("label") }
             </b>
         </span>
    )}
/>

Note two special things here: the use of choiceLoader and the use of displayView.

The choiceLoader is a function:

const loadOptions = (filter: string, callback: any) => {
    if (cachedAvailableColors) {
        callback(filteredColors(cachedAvailableColors, filter));
    } else {
        setTimeout(() => {
            callback(filteredColors(availableColors, filter));
            cachedAvailableColors = availableColors;
        }, 5000);
    }
};

Here we're using a setTimeout to simulate an async fetch operation. Note that this function will be called whenever the filter (search string) is changed, so this means you can either fetch based on that filter if the backend supports that, or cache the full list so you can return just the filtered set derived from the cache rather than repeatedly fetching.

The other things to keep in mind with async chooser fetching is that the Chooser will not know what label to display for an item in the list that isn't loaded yet. Therefore you need to use displayView to provide that. In this case we grab it from the original list, but ideally you'd load that as part of the form initial state.

Help facility

You can now specify a help string in the Schema that will be displayed along side each field. An icon indicates the presence of help. Hovering over the icon will display the help text. Help text can be markdown.

Screen Shot 2020-03-20 at 7 48 39 AM

Switch control

For boolean values (on/off) you can use the new Switch control. The value passed to the switch control will be 0 or 1. The control will show a label next to both states that defaults to On and Off. You can customize that by passing options to the switch, which is a two element array ["deactivated", "activated"] and these labels will be shown instead. When the control is in view only mode these labels will also be used for the display text. As with other controls you can pass in a displayView prop to customize this, either with alternative text or with a function.

Screen Shot 2020-03-20 at 12 13 25 PM

Date edit control

The DateEdit control has been updated to the latest version of react-datepicker, which is considerably more robust than previous versions. As part of that change you can now specify minDate and maxDate props to constrain the picker. You can also select both a Date and Time using the timePicker bool prop. Finally you can select just a month with the monthPicker prop.

Screen Shot 2020-03-25 at 2 19 15 PM

Peter Murphy added 27 commits February 3, 2020 07:22
Still lots to do as this only includes and has storybook stuff for the textedit control. But the main code base (Form, List, etc) now builds in Typescript. Uses rollup for the build. Updates everything to latest versions.
Note that I had to fix the storybook version because the next patch version is currently broken.

"@storybook/react": "5.3.10"
…he user

For example, the user would add a TextEdit control to a form, but when that is rendered it has a set of props added to it. At that point it becomes a TextEditControl (wrapped in a formGroup). This lets us be clearer about types.

Also added a ChooserControl etc. Still some work to do on that, it's just the most basic implementation with the new react-select api.
Adds displayView prop which can either be a string or a function that returns a React Element. Like the previous view prop, this is used to show specialized rendering for the chooser when data is not loaded yet.

Added an example of the chooser async loading data when the inline editing is triggered and then selecting by search from a large list.
DateEditControl can now constain choice to specific date ranges. It can also select a time along side the date. Finally there's an option to select just a month.
Also start filling out form examples
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.

1 participant