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

Fix various things in the crash recommendations form #1542

Merged
merged 13 commits into from
Sep 10, 2024

Conversation

roseeichelmann
Copy link
Contributor

@roseeichelmann roseeichelmann commented Sep 4, 2024

Associated issues

Closes cityofaustin/atd-data-tech#18468

Testing

URL to test:
Netlify

Steps to test:

  1. Go to our staging website to see the buggy behavior of this component. Click on a crash without a fatality, update an injury to fatality to show the recommendation form. Try to add recommendation text or update, see that the mutation fails. Add a status, see that an empty partner record is created. Go to another crash, make it a fatality, and this time start by adding partners and then recommendation text, this actually works as expected.
  2. Now test the netlify preview. See that the updates section isnt there until you create a recommendation. If you first create a recommendation text or status, a partner wont be created yet. Now add partners, status, etc.
  3. Go to a new crash and this time add partners first, a recommendation record will be created when you add a partner. The update section will then display. Add text to all fields, status, etc.

Ship list

  • Check migrations for any conflicts with latest migrations in master branch
  • Confirm Hasura role permissions for necessary access
  • Code reviewed
  • Product manager approved

@roseeichelmann roseeichelmann added the WIP Work in progress label Sep 4, 2024
recommendations_partners: { data: { partner_id: $partner_id } }
}
) {
insert_recommendations(objects: [$recommendationRecord]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously we had a bug where if you created a recommendation by just filling out the status, a recommendation record would be created along with a partner record that just had null as the partner id, so then you would end up with something that looks like this
image
we dont want to create a partner record until the user actually adds a partner. so im changing this mutation to use an object variable that may or may not contain partner data so we arent creating empty partners

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - thanks for tightening this up for less cruft in the DB.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this. Would you rename the Add button to Save? And can you disable the button until the input has been modified?

One other tiny detail—would you mind removing the colon (:) from the Coordination Parter and Status labels?

onAdd={onAdd}
onEdit={onEdit}
/>
{doesRecommendationRecordExist && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dont show the update section until a recommendation has been created

Copy link
Member

Choose a reason for hiding this comment

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

would you hide this field until rec_text is not null? otherwise this appears after you save a coordination parter or status.

@@ -15,23 +15,9 @@ export const GET_RECOMMENDATION_LOOKUPS = gql`

export const INSERT_RECOMMENDATION = gql`
mutation InsertRecommendation(
$text: String
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mutation was failing silently if you try to create a recommendation by first adding recommendation text because this mutation was expecting the variable text but we were feeding it rec_text

const valuesObject = {
recommendations_partners: {
// Mutation expects lookup IDs as integers
data: { [field]: parseInt(selectedItem.id) },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively i could have this valuesObject conditionally formatted based on whether doesRecommendationRecordExist, so it only gets this nested insert format if the rec record doesnt exist yet, and we wouldnt have to specify valuesObject.recommendations_partners.data in the onAddPartner function

@@ -74,7 +75,7 @@ const Recommendations = ({ crashPk, recommendation, refetch }) => {
const onAddPartner = valuesObject => {
const recommendationPartnerRecord = {
recommendationRecordId,
...valuesObject,
...valuesObject.recommendations_partners.data,
Copy link
Contributor Author

@roseeichelmann roseeichelmann Sep 4, 2024

Choose a reason for hiding this comment

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

dont want that nested insert format if the recommendation record already exists and we are only inserting a partner record. like i mentioned in the comment above, i could handle this logic in that component instead and format the valuesObject there based on whether the recommendation record exists yet

@roseeichelmann
Copy link
Contributor Author

roseeichelmann commented Sep 4, 2024

@johnclary the issue says to have visual feedback when the form is saving (does this mean a spinner?) so i guess you mean whenever the user clicks the add button or edits and saves, but none of our other components like notes or related records tables have any kind of feedback when you edit fields? could you expand maybe on what you would want to see? personally i think its fine as is

Copy link
Member

@frankhereford frankhereford left a comment

Choose a reason for hiding this comment

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

🚢🚢🚢 This is absolutely an improvement. Thank you @roseeichelmann!

I have been thinking about the possibilities you raised about using logic in the component to control the use of the nested record creation in the graphql. I am not sure, so don't give this too much weight, but I think I like it the way you have it. Simpler code, less deeply buried logic, and the application seems to be working as I would expect it. I like it!

recommendations_partners: { data: { partner_id: $partner_id } }
}
) {
insert_recommendations(objects: [$recommendationRecord]) {
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - thanks for tightening this up for less cruft in the DB.

@roseeichelmann roseeichelmann removed the WIP Work in progress label Sep 4, 2024
Copy link
Member

@chiaberry chiaberry left a comment

Choose a reason for hiding this comment

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

i think I am following the alternative way of doing this, but the way you have it here makes sense to me. Thank you for fixing the silent failure, I tried adding things in different order and it all checks out

Copy link
Member

@johnclary johnclary left a comment

Choose a reason for hiding this comment

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

Thanks @roseeichelmann!

I think that back when i created this issue i did not realize that editing the coordination partners or status input triggers an insert/update immediately—which was adding to my confusion about potential bugginess.

I requested feedback in order to tighten up the save behavior of the text and text updates.

I agree we can leaving the loading feedback out of scope. If we were going to do a bigger refactor of this form, it would be great to rework this so that it behaves like one big form—you edit any field then click "Save" to save changes. I'd also like to make the parters and status inputs look like normal bootstrap inputs (with outlines, focus effects, etc), but the i can see multiselect library doesn't make that easy. It'd be nice to replace it with react-select for a superior UX. I'll drop that in a backlog issue.

onAdd={onAdd}
onEdit={onEdit}
/>
{doesRecommendationRecordExist && (
Copy link
Member

Choose a reason for hiding this comment

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

would you hide this field until rec_text is not null? otherwise this appears after you save a coordination parter or status.

recommendations_partners: { data: { partner_id: $partner_id } }
}
) {
insert_recommendations(objects: [$recommendationRecord]) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this. Would you rename the Add button to Save? And can you disable the button until the input has been modified?

One other tiny detail—would you mind removing the colon (:) from the Coordination Parter and Status labels?

@@ -42,7 +44,7 @@ const RecommendationTextInput = ({
};

// Recommendation record does not exist yet, adding a value will create record
const isAddingRecommendation =
const isCreatingRecord =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make it more apparent that we are talking about this is going to create a recommendation record, not talking about just adding recommendation text

partner_id: {
label: "Coordination Partner:",
lookupOptions: "atd__coordination_partners_lkp",
key: "coord_partner_desc",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a duplication pretty much of the first object and its not actually doing anything?


const isEmptyString = !inputValue.trim();
// Save null to database if user entered empty string or only spaces/newlines
const valuesObject = { [field]: isEmptyString ? null : inputValue };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously we were allowing empty strings to be saved to the database.

@roseeichelmann
Copy link
Contributor Author

roseeichelmann commented Sep 6, 2024

@johnclary this is ready for re-review! i agree about making this one big form in the future. i disabled the save button until there is input and also made it so that users cant save empty strings to the database, including just spaces or newlines.

question though, what if someone has rec text and update text, then they delete whats in the rec text. do we want the update section to still disappear even though it has content or should it show? currently i have it so that the update section will always show up if there is update text

…on text, fix border showing up underneath recommendation when there is no update section
@chiaberry
Copy link
Member

I was re-testing this PR after the changes, and your comment made me want to try "deleting" the rec text, by updating it to be an empty string. It feels weird having the text flash again before the area turning into an input again.

But I dont know how often the recommendation text would be deleted vs being updated. So maybe its not worth trying to fix the UX right now

Copy link
Member

@johnclary johnclary left a comment

Choose a reason for hiding this comment

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

🚢 thanks @roseeichelmann !!

@roseeichelmann roseeichelmann merged commit e56e3c6 into master Sep 10, 2024
8 checks passed
@roseeichelmann roseeichelmann deleted the 18468_fix_recommendations branch September 10, 2024 17:50
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.

The crash recommendations form is busted in various ways
4 participants