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

ERA-7995: Migrate existing report form body into new report UI #805

Merged
merged 14 commits into from
Dec 12, 2022

Conversation

luixlive
Copy link
Contributor

@luixlive luixlive commented Nov 24, 2022

Ticket: https://allenai.atlassian.net/browse/ERA-7995
Env: https://era-7995.pamdas.org/
Figma: https://www.figma.com/file/1u3VbK9kbOEuUg9Wi8AHRW/Patrol-%26-Report-UI-Refresh-FINAL?node-id=1039%3A8672

Evidence
Desktop:
image

Mobile:
image

Notes
As a good boy scout, I took the time not to simply copy and paste our existing React JSON schema form implementation, but to update it to the latest version (I left the existing form in the modals as it was so we will be able to remove the old version of the library once we remove that). Now, as part of this new implementation, I followed the migration process, got rid of unnecessary old props and updated the styles. However, there are some form fields I don't know how to test that I see have some custom styles. @JoshuaVulcan could you help me explaining how to create a custom schema with all those advanced fields to see what styles do they need?

@luixlive luixlive marked this pull request as draft November 24, 2022 21:30
Base automatically changed from ERA-7994 to develop November 29, 2022 00:34
@luixlive luixlive marked this pull request as ready for review November 29, 2022 22:42
@luixlive
Copy link
Contributor Author

I added a couple event types with custom field types for testing purposes:
MEP arrest
image

Wildlife checkboxes
image

@tiffanynwong
Copy link
Collaborator

Looking so good!! The checkboxes look great! A few comments that may need to be separated out to other tickets but all related:

  1. Can we make all fields 40px in height? It seems like depending on if it's a dropdown, text field, location, or date field the height of the field changes. Screen Shot 2022-11-30 at 10 52 37 AM

  2. I'm a little worried about the legibility of text especially the field labels. (Sorry this is after seeing ER in ops rooms). Working on a typography guide which we could use to make text through out the app more consistent.

  3. Sorry didn't provide a design for arrays but now that I'm seeing it with all the other improvements it would be good to clean it up to be consistent with other components we have. Here's a figma link https://www.figma.com/file/1u3VbK9kbOEuUg9Wi8AHRW/Patrol-%26-Report-UI-Refresh-FINAL?node-id=2776%3A25500
    Some things to note in the design:

  • changed the "new" button to match the report, attachments, note button so that only the save button is blue. Also aligned left so that it's not floating
  • added back the arrows and used a trash icon we use elsewhere instead of the minus
  • made the arrows and delete button part of the array so that it's clear that those buttons are for that array
  • adjusted the padding between array titles and fields

Totally open to discussing the changes we want to make and when @JoshuaVulcan @luixlive

@luixlive
Copy link
Contributor Author

I think it makes sense to work those things in this same ticket. I'd just like to mention that the form is rendered by an external library we use: https://react-jsonschema-form.readthedocs.io/en/latest/ But what we do is to overwrite their styles to give it the ER touch. However, I've faced a couple things that are really tricky to do because of the way they render the DOM nodes and the classes they use. If I find myself in a scenario like that while doing these changes I'll let you know @tiffanynwong 😬

Copy link
Collaborator

@JoshuaVulcan JoshuaVulcan left a comment

Choose a reason for hiding this comment

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

Arrays need a little love, checkboxes look AMAZING, lots of surface area touched here and it seems to work quite well. I appreciate the error handling for failed schemas, where the form is rendered sans-body instead of leaving you in loading spinner hell.

I have a few questions about code style and test approach, but it's looking really good. V close to shippable.

@@ -7,6 +7,10 @@
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.26",
"@fortawesome/free-solid-svg-icons": "^5.12.0",
"@rjsf/bootstrap-4": "^5.0.0-beta.13",
"@rjsf/core": "^5.0.0-beta.13",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean we can remove react-jsonschema-form-bs4? I'd love to ditch that old stinky fork

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh, after we ditch the modals. Cool.

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's removed now. Doesnt' make sense to keep our users waiting if we can deliver upgraded / better-looking forms now 😄

@@ -231,6 +233,21 @@ const ReportDetailView = ({
reportTracker.track('Change Report Location');
}, [reportForm, reportTracker]);

const onJsonFormChange = useCallback((event) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to surface jsonForm instead of just form here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Answering all those comments here: It's simply me being over-descriptive. I'll remove the json prefix.

const onJsonFormChange = useCallback((event) => {
setReportForm({ ...reportForm, event_details: { ...reportForm.event_details, ...event.formData } });

reportTracker.track('Change Report Json Form Data');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to ^above, why would our analytics care that the form is json? Wouldn't "Change report form data" be more human-friendly and meaningful?

reportTracker.track('Change Report Json Form Data');
}, [reportForm, reportTracker]);

const onJsonFormError = (errors) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

onFormError....

jsonFormUISchema,
onJsonFormChange,
onJsonFormError,
onJsonFormSubmit,
Copy link
Collaborator

Choose a reason for hiding this comment

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

onFormSubmit

const DetailsSection = ({
jsonFormSchema,
jsonFormUISchema,
onJsonFormChange,
Copy link
Collaborator

Choose a reason for hiding this comment

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

onFormChange

jsonFormSchema,
jsonFormUISchema,
onJsonFormChange,
onJsonFormError,
Copy link
Collaborator

Choose a reason for hiding this comment

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

onFormError


beforeEach(() => {
AddReportMock = jest.fn(() => null);
AddReport.mockImplementation(AddReportMock);
fetchEventTypeSchemaMock = jest.fn(() => () => {});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Didn't we agree to start using msw for API interactions, instead of stubbing the fetch functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, it's the habit


const uiOptions = getUiOptions(uiSchema);
const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, uiOptions);
const DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, uiOptions);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting new pattern on rsjf's part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your comment reminds me that I simply removed the old code and that probably broke the modals forms 😅 I'll have to add the feature flag check in here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed, I removed the old version of the library. Now even the modals are using these new forms 👍

@luixlive luixlive requested a review from JoshuaVulcan December 5, 2022 19:42
@luixlive
Copy link
Contributor Author

luixlive commented Dec 5, 2022

@JoshuaVulcan @gaboDev @Alcoto95 this is ready for a review 👍

Copy link
Collaborator

@JoshuaVulcan JoshuaVulcan left a comment

Choose a reason for hiding this comment

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

We need a loading indicator for the new report body component. Look what happens for a small schema when I throttle my connectivity down a bit:

new-report-body-needs-loading-indicator

@luixlive
Copy link
Contributor Author

luixlive commented Dec 6, 2022

@JoshuaVulcan Totally, I like that idea. However, should we use our current spinner? I don't think it matches the beauty of our new form 😂 Maybe @tiffanynwong could help with a new icon / design for the "form loader"?

Copy link
Contributor

@Alcoto95 Alcoto95 left a comment

Choose a reason for hiding this comment

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

LGTM now

@tiffanynwong
Copy link
Collaborator

We need a loading indicator for the new report body component. Look what happens for a small schema when I throttle my connectivity down a bit:

new-report-body-needs-loading-indicator

We have a this spinner that is displayed when the report list takes time to load. Spoke to Ludwig and agree it could use fixing but we should keep our spinners consistent so if we change it here it should change in the report list as well.

If we're going to tidy up the spinner. Can we use a circular indeterminate spinner like this? https://mui.com/material-ui/react-progress/ And also change the color to bright blue #0056C7. Here's an example https://www.figma.com/file/1u3VbK9kbOEuUg9Wi8AHRW/Patrol-%26-Report-UI-Refresh-FINAL?node-id=2964%3A25128&t=JWUQGpSKERPdwnVm-1

Using a skeleton would be really cool but probably not worth the effort for the impact. https://mui.com/material-ui/react-skeleton/

@JoshuaVulcan
Copy link
Collaborator

Screen Shot 2022-12-07 at 7 11 12 AM

"Arrest with array" event type layout has some button/input overlap funk going on btw

@luixlive
Copy link
Contributor Author

luixlive commented Dec 7, 2022

@tiffanynwong actually updating the current loader would take way more time than I expected. I did the change in the form loader:
image

But doing it in every other spinner in the app would require a lot of effort. Should I keep the new design in the report's form?

@luixlive
Copy link
Contributor Author

luixlive commented Dec 7, 2022

Screen Shot 2022-12-07 at 7 11 12 AM

"Arrest with array" event type layout has some button/input overlap funk going on btw

Hmm could you tell me exactly where? I see the MEP arrest report with lots of arrays and all of them render nicely.

@JoshuaVulcan
Copy link
Collaborator

I pulled the "Arrest with array" event type from develop and put it in your feature environment, you can repro there.

@JoshuaVulcan
Copy link
Collaborator

JoshuaVulcan commented Dec 7, 2022

@tiffanynwong actually updating the current loader would take way more time than I expected. I did the change in the form loader: image

But doing it in every other spinner in the app would require a lot of effort. Should I keep the new design in the report's form?

Yes, please do keep the new spinner in the report form, it looks much better

@tiffanynwong
Copy link
Collaborator

@tiffanynwong actually updating the current loader would take way more time than I expected. I did the change in the form loader: image
But doing it in every other spinner in the app would require a lot of effort. Should I keep the new design in the report's form?

Yes, please do keep the new spinner in the report form, it looks much better

Can you check to make sure the blue is the same blue as the save button please :D

@luixlive
Copy link
Contributor Author

luixlive commented Dec 7, 2022

I pulled the "Arrest with array" event type from develop and put it in your feature environment, you can repro there.

I fixed the margin at the top, but the button is still a bit out of phase in the horizontal axis. This is because the only way to add a space between the form fields when there is more than one column per row was by adding a padding at the both sides of each column. That's how they do it and that's the only way I could, because of the way their grid system works. The button is not wrapped by a column, so it doesn't get that horizontal padding:
image

If this is important I'm open to any suggestions to fix it 😅

Copy link
Contributor

@Alcoto95 Alcoto95 left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 😄

@JoshuaVulcan
Copy link
Collaborator

JoshuaVulcan commented Dec 8, 2022

  1. The spinner seems to show indefinitely for schema requests which error out (such as "Test Hugo" in develop right now), instead of cancelling/showing a meaningful error message. If an error message is outside the scope of this task, maybe at least hiding the spinner once the request is done, regardless of success/failure.

  2. Datetime fields have extra top margins:
    Screen Shot 2022-12-08 at 1 27 40 PM

  3. Some new console errors and warnings are showing up. Some seem minor, like an HTML structural validity issue and a couple propTypes tweaks. See below:

Warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button>.
Warning: Failed prop type: The prop `formSchema` is marked as required in `DetailsSection`, but its value is `undefined`.
Warning: Failed prop type: The prop `formUISchema` is marked as required in `DetailsSection`, but its value is `undefined`.
uiSchema.classNames' is deprecated and may be removed in a major release; Use 'ui:classNames' instead.
Warning: Received `true` for a non-boolean attribute `custom`.

If you want to write it to the DOM, pass a string instead: custom="true" or custom={value.toString()}.
Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
  1. Can we tighten up the line-spacing property on the labels? It seems excessively "tall" right now when the label wraps:
    Screen Shot 2022-12-08 at 1 30 33 PM

Copy link
Collaborator

@JoshuaVulcan JoshuaVulcan left a comment

Choose a reason for hiding this comment

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

see above comment. This is getting suuuper close to being ready!

@luixlive
Copy link
Contributor Author

@JoshuaVulcan thanks! I didn't notice the warnings. I'll work on these things. I could add the error message if it's trivial. But if we require designs again, maybe I agree that we already loaded this task with a lot of stuff. We would require a third QA pass.

@luixlive
Copy link
Contributor Author

@JoshuaVulcan about the warnings:

1- The first one you mention, a button being inside a button, was not injected in this PR and seems like a rendering issue in the ReportMenu component. I didn't debug properly, but looks like the Toggle receives a prop as="button" and it wraps the KebabMenuIcon which is a button too. We could refactor that, but I don't think it should be part of this task.

2- You didn't mention one about enumNames being deprecated. But I think that will require a complete different ticket, where we also will need to notify the support team since looks like most of our reports use that property which is not standard and will probably be deprecated from react-jsonschema-form in favor of oneOf as is mentioned here: rjsf-team/react-jsonschema-form#532

@JoshuaVulcan JoshuaVulcan merged commit b835143 into develop Dec 12, 2022
@JoshuaVulcan JoshuaVulcan deleted the ERA-7995 branch December 12, 2022 22:05
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.

4 participants