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

Enable address editing #1564

Merged
merged 19 commits into from
Oct 3, 2024
Merged

Enable address editing #1564

merged 19 commits into from
Oct 3, 2024

Conversation

roseeichelmann
Copy link
Contributor

@roseeichelmann roseeichelmann commented Sep 20, 2024

Associated issues

Closes cityofaustin/atd-data-tech#19014

Testing

URL to test:
Netlify

Steps to test:

  1. Go to a crash
  2. Test editing the primary address/secondary address fields
  3. When you type into an input your input should be auto capitalized
  4. If you are editing and click on the swap address button before saving/canceling, you will be taken out of edit mode on that field
  5. Test swapping the addresses

Ship list

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

@roseeichelmann roseeichelmann added the WIP Work in progress label Sep 20, 2024
@roseeichelmann roseeichelmann changed the base branch from main to 19016_swap_addresses September 20, 2024 17:40
@@ -160,8 +173,10 @@ const DataTable = ({
autoFocus
name={field}
id={field}
onChange={e => handleInputChange(e)}
defaultValue={fieldValue}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

im updating all of these inputs to be controlled components instead of uncontrolled

onChange={e => handleInputChange(e)}
value={editValue
.toString()
.toUpperCase()}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updating these to be controlled components allows me to auto capitalize user input as they type

const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false);

const crash = data?.crash;

const toggleModal = () => {
// make sure we are not in edit mode on a field
setEditField("");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so that if we are in edit mode on a field and click the swap address button, we get out of edit mode

value={editValue}
onChange={e =>
setEditValue(
e.target.value.toUpperCase()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

auto capitalize user input

@roseeichelmann roseeichelmann changed the base branch from 19016_swap_addresses to main September 24, 2024 17:23
@roseeichelmann roseeichelmann changed the base branch from main to 19016_swap_addresses September 24, 2024 17:30
@roseeichelmann roseeichelmann removed the WIP Work in progress label Sep 24, 2024
@@ -1,12 +1,12 @@
{
"name": "atd-vz-data",
"version": "1.47.0",
"version": "2.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

from running npm install for the first time in awhile

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 tried editing fields, quitting editing halfway through, opening them again, swapping addresses mid edit, and it all works as you described it should.

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.

yay, address editing! 🙌

and thanks for switching these over to controlled components. i'm seeing a few warnings that should be a quick fix.

also, one result of this change is that the previous value flashes on the screen while the save + refetch happens. can you see if there's a fix for this maybe in the handleFieldUpdate callback?

🙏

editor/src/Components/DataTable.js Show resolved Hide resolved
@@ -33,13 +34,22 @@ const DataTable = ({
const roles = getRoles();
const isReadOnlyUser = isReadOnly(roles);

// Sets the state of the value for the current field being edited
const [editValue, setEditValue] = useState();
Copy link
Member

Choose a reason for hiding this comment

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

eslint is barking because null/undefined is not a valid value to pass to input elements. we need an empty string as the default value and whenever you reset the value.

Copy link
Member

@johnclary johnclary Sep 25, 2024

Choose a reason for hiding this comment

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

i'm also getting this warning when i start editing a blank field:

Warning: A component is changing an uncontrolled input of type text to be controlled.

i think this might resolve itself if you make default input type a string.

// Import Lookup tables and aggregate an object of uiType= "select" options
const { data: lookupSelectOptions } = useQuery(GET_LOOKUPS);

const handleEditClick = (field, fieldValue) => {
setEditField(field);
setEditValue(fieldValue);
Copy link
Member

Choose a reason for hiding this comment

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

here to you need to set the edit value to "" if it is null

Base automatically changed from 19016_swap_addresses to main October 1, 2024 18:00
@roseeichelmann
Copy link
Contributor Author

@johnclary this is ready for re-review!

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.

Rose, I just noticed a little bug when editing a yes/no field. The dropdown defaults to "Yes", even when the current value is "No".

E.g., here's the non-edit state:
Screenshot 2024-10-02 at 1 46 32 PM

And here's what is rendered after toggling the edit:
Screenshot 2024-10-02 at 1 46 35 PM

Can you check this?

Copy link
Contributor

@mddilley mddilley left a comment

Choose a reason for hiding this comment

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

Looks great! I replicated the bug that John caught too, and, after that, this is good to go! I was able to edit every address field and all other select (non-boolean) and text type fields too.

@roseeichelmann
Copy link
Contributor Author

@johnclary @mddilley thanks for catching that guys! it had to do with the way i was checking for falsey values in general instead of explicitly checking if the edit value was null to set it to an empty string in the handleEditClick

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.

🚢 🚢 🚢 🚢

Copy link
Contributor

@mddilley mddilley left a comment

Choose a reason for hiding this comment

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

Awesome! I tested again with the updated handling and it is ✨

@roseeichelmann roseeichelmann merged commit acab040 into main Oct 3, 2024
8 checks passed
@roseeichelmann roseeichelmann deleted the 19014_enable_address_editing branch October 3, 2024 16:02
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.

[Enhancement] Enable address editing
4 participants