Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Connect embed section of settings page to API #1329

Merged
merged 3 commits into from May 13, 2021

Conversation

TaiWilkin
Copy link
Contributor

@TaiWilkin TaiWilkin commented May 6, 2021

Overview

Connects the Embed Configuration settings tab to the API, allowing
data fetching, creation, and update. Additionally, adds some UI error
handling, and updates the components to reflect API data structure.

A small, unrelated second commit fixes an error in the proptypes for Feature Flags.

Connects #1312

Demo

Screen Shot 2021-05-06 at 1 44 07 PM

Testing Instructions

  • Login as c1@example.com and navigate to settings. Select EMBED.
    • You should see an error message.
  • Login as a different user, with no nonstandard fields, and navigate to settings. Select EMBED.
    • The page should show no extra fields.
    • The other settings should be the defaults.
  • Update each of the values on the page.
    • The fields should update as before.
  • Refresh the page.
    • The updated values should be maintained.
  • Login as a user with nonstandard fields.
    • The fields should be listed.
  • Update some (not all) of the fields and refresh the page.
    • The updated fields should show the new values.
    • The untouched fields should still appear correctly.

Checklist

  • fixup! commits have been squashed
  • CI passes after rebase
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines

@jwalgran
Copy link
Contributor

Looking at this now.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

The persistence is working, but there are issues with the mechanics of how the updates happen and how errors are reported that I think we need to address.

src/app/src/components/EmbeddedMapConfig.jsx Show resolved Hide resolved
const handleError = e => {
setError(getErrorMessage(e));
setLoading(false);
setTimeout(() => setError(null), 5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are auto-dismissing this temporary error message, have we considered using a Material UI "toast" component that is designed for that purpose?

I am seeing some unexpected blinking and scroll behavior in Firefox when running the first test step.

2021-05-11 14 37 44

Copy link
Contributor Author

@TaiWilkin TaiWilkin May 12, 2021

Choose a reason for hiding this comment

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

We're currently using react-toastify elsewhere in the app, so I've switched to that here in 9d913b8 - it definitely is an improvement in terms of workflow and appearance.

/* eslint-disable react-hooks/exhaustive-deps */
// Disabled exhaustive dependencies warning because we don't want to rerun
// in response to the loading state changing
// When the embed cofig or fields are updated, wait for 500ms. If no
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: cofig → config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch - updated in 9d913b8

} else {
createConfig();
}
}, 500);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we choose 500ms for any specific reason?

I am seeing "polling" like behavior where a PUT requests are being made repeatedly. I was expecting that PUT requests would only be made in response to a field changing.

2021-05-11 14 41 23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The polling behavior was caused because the update and create functions are being recreated on each render. Removing them from the dependency array restored expected behavior. The 500ms delay is meant to prevent repeated calls to the database while the user is actively typing, but the actual duration of the debounce is fairly random.

@@ -517,3 +517,5 @@ export const PPE_FIELD_NAMES = Object.freeze([
'ppe_contact_email',
'ppe_website',
]);

export const OARFont = 'ff-tisa-sans-web-pro,sans-serif';
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few other components that reference this font string. Consider spreading the use of this constant to those component to ease the burden on a future maintainer that needs to change the font.

Screen Shot 2021-05-11 at 2 07 37 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 5726f0f.

Comment on lines 29 to 30
color: embedConfig.color.length ? embedConfig.color : '#3d2f8c',
font: embedConfig.font.length ? embedConfig.font : OARFont,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using .length on these fields rather than a basic check for a falsey value? Could we ever end up in an exceptional situation because color or length are null/undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 9d913b8 and also moved some values to constants for clarity/DRYness. I was thinking that 0s would come out as 'false' but since the numbers are strings, that isn't actually an issue.

column_name: f.columnName,
}));

const formatWidthForServer = ({ width, fullWidth }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

When I check the 100% box I am seeing the width field being set to 100.

2021-05-11 14 47 21

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to make the behavior a little bit more logical in 9d913b8, but I did want to note as well that full-width embed isn't set up for the preview or embed code yet (#1311 will add that), so the required/expected behavior here will likely undergo additional changes when that is implemented.

@TaiWilkin
Copy link
Contributor Author

Ready for another look.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

Changes look good. Thanks.

@jwalgran jwalgran removed their assignment May 13, 2021
@jwalgran jwalgran added the task 004 Enable contributors to embed a map displaying only the facilities with which they are associated in label May 13, 2021
Connects the Embed Configuration settings tab to the API, allowing
data fetching, creation, and update. Additionally, adds some UI error
handling, and updates the components to reflect API data structure.
@TaiWilkin TaiWilkin merged commit a281902 into develop May 13, 2021
@TaiWilkin TaiWilkin deleted the tw/connect-embed-config branch May 13, 2021 14:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
task 004 Enable contributors to embed a map displaying only the facilities with which they are associated in
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants