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

Migrate Files table to data grid #1438

Merged
merged 26 commits into from
Oct 10, 2024
Merged

Migrate Files table to data grid #1438

merged 26 commits into from
Oct 10, 2024

Conversation

chiaberry
Copy link
Member

@chiaberry chiaberry commented Oct 1, 2024

Associated issues

cityofaustin/atd-data-tech#18176
and a bonus cityofaustin/atd-data-tech#17597

I copied the patterns laid out in the Funding Table refactor, using DataGrid instead of Material Table, memoizing the columns, implementing the row mode model that data grid needs etc.

  • Files table had some data validation, the DataGrid column definition has a property preProcessEditCellProps that checks the input and will sets the error parameter update The file_url field also depends on the file_key field, I added a function to validate against the different variations in data.
  • the Files table also had some helperText in the text input fields
  • I added the Delete Confirmation Modal to the Files Table delete action
  • I wrote about this in a comment but I ran into the nuances between the valueGetter vs valueFormatter functions, the valueGetter function changes the value, it will then be used the sort comparator. valueFormatter does not change the value, but formats it for rendering and the sort comparator uses the original value. Our file types table has values 1, 2, 3, 4, that correspond to ["", "Funding", "Plans", "Estimates", "Other"].

Testing

URL to test:
There arent too many projects with files in staging, but here is one:
https://deploy-preview-1438--atd-moped-main.netlify.app/moped/projects/1695?tab=files

or if you run locally with prod data, this is a good project with files
https://localhost:3000/moped/projects/437?tab=files

Steps to test:

Test creating a file (use a url or fake file name to avoid issues with the file upload process in staging/local)
Test editing a record. You can do this by clicking the pencil, or double clicking in an editable field (name, file, type, description)
Cancel your edits. Or save your edits!!
Try deleting a record. A confirmation modal pops up.

Test sorting on file type. it sorts ascending, descending and then unsorts.

Do you like the widths of the columns as they are defined now? You can resize now, but wondering if anything should be defined differently.


Ship list

@chiaberry chiaberry added the WIP Work in progress label Oct 1, 2024
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.

Thank you for knocking out another Material Table instance. I'm running into some bugginess that I'm sure will be a quick fix 🙏 🙌

@@ -56,33 +51,225 @@ const useStyles = makeStyles((theme) => ({
},
downloadLink: {
cursor: "pointer",
overflow: "hidden",
display: "block",
textOverflow: "ellipsis",
Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure if this is working quite right—here's a long file link in project 437
Screenshot 2024-10-04 at 11 48 33 AM

Copy link
Member Author

Choose a reason for hiding this comment

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

ah because this isnt a link, this is just text. If it's truncated or overflow hidden, then users wouldn't be able to read the entire path

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm seeing a different issue when I entered a really long fake G drive location.

Screenshot 2024-10-07 at 4 57 06 PM

Here is an example of the behavior that I see in staging with the same length network location - https://moped.austinmobility.io/moped/projects/1695?tab=files.

Edit: I also realized that it is the codeStyle styles below that handle non-links and needs to be updated. I requested a change there instead of here.

preProcessEditCellProps: (params) => {
const hasError = params.props.value.trim().length < 1;
return { ...params.props, error: hasError };
},
Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure if this is source of the bug, but i'm hitting this error when i edit any column 💥
Screenshot 2024-10-04 at 11 47 27 AM

Copy link
Member Author

Choose a reason for hiding this comment

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

it is the source, thanks for catching it -- the weird thing is that I see the bug locally, but I am not seeing it on the netlify deploy link, which is confusing the heck out of me

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of the cause for this error message was my own lazy code, but the other part is that in cases where someone uploaded a file, the file_url was always going to be null, which was always returning an error and preventing the record from being updated.

width: 150,
valueGetter: (value) => fileTypes[value],
renderEditCell: (props) => <ProjectFilesTypeSelect {...props} />,
},
Copy link
Member

Choose a reason for hiding this comment

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

This input is a little squished (like half the width of the column) in edit mode. Maybe there are some tweaks needed in the Select component?
Screenshot 2024-10-04 at 11 47 44 AM

I am also getting the dreaded autocomplete warning when i switch into edit mode

Screenshot 2024-10-04 at 11 49 01 AM

Copy link
Member Author

Choose a reason for hiding this comment

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

I broke this when I added the valueGetter to make sorting work ☹️ . I am going to see how to fix this but also maintain ability to sort by the words and not the numbers

Copy link
Member Author

Choose a reason for hiding this comment

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

I broke the select when I used valueGetter, valueFormatter changes the value only for rendering and doesn't affect the underlying value. which means you still cant sort. valueGetter affects the underlying value, which means we can sort alphabetically vs 1,2,3,4 but it was then passing the string to the select component instead of the file_type number.

So now its valueFormatter to render the file_type strings, and passing those strings into the data grid sort comparator, while keeping the original value so the select works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for fixing and explaining the difference 🙏 I tested the select and the sorting, and I see no warning and the sort is working. 🚀

Copy link
Member

Choose a reason for hiding this comment

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

ditto—great to have these details ironed out for the next MaterialTable that gets replaced ✅

handleCancelClick,
handleEditClick,
handleDeleteOpen,
]);
Copy link
Member

Choose a reason for hiding this comment

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

love the memoized columns—looks great!!

@chiaberry chiaberry added the WIP Work in progress label Oct 4, 2024
@chiaberry chiaberry removed the WIP Work in progress label Oct 7, 2024
Copy link
Collaborator

@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.

Yay - this is looking great! I tested locally, and I was able to create linked files and edit from within the table rows. I'm requesting one change based on what I was seeing with long network locations for files that are links.

@@ -682,7 +682,7 @@ export const PROJECT_FILE_ATTACHMENTS_UPDATE = gql`
$fileId: Int!
$fileName: String!
$fileType: Int!
$fileDescription: String!
Copy link
Collaborator

Choose a reason for hiding this comment

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

🐛 squashed! 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice to see this component growing up to handle validation! 🌱

@@ -56,33 +51,225 @@ const useStyles = makeStyles((theme) => ({
},
downloadLink: {
cursor: "pointer",
overflow: "hidden",
display: "block",
textOverflow: "ellipsis",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm seeing a different issue when I entered a really long fake G drive location.

Screenshot 2024-10-07 at 4 57 06 PM

Here is an example of the behavior that I see in staging with the same length network location - https://moped.austinmobility.io/moped/projects/1695?tab=files.

Edit: I also realized that it is the codeStyle styles below that handle non-links and needs to be updated. I requested a change there instead of here.

width: 150,
valueGetter: (value) => fileTypes[value],
renderEditCell: (props) => <ProjectFilesTypeSelect {...props} />,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for fixing and explaining the difference 🙏 I tested the select and the sorting, and I see no warning and the sort is working. 🚀

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.

Nice—it's working great! Two minor things that are not blocking my approval:

When I edit a row, sometimes the sort order changes after I save. That was tripping me up a bit because i thought my edits were not getting saved correctly. I'm not sure if this is a bug in prod, so I'll let y'all decide on it 👍

Also, I noticed the activity logs for my edits were missing a field or two—possibly audit fields? Anyway, it's probably not a new bug.

Screenshot 2024-10-08 at 9 24 59 AM

🚢

Copy link
Collaborator

@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 amazing! Thanks for updating the sort and handling the network locations wrapping too. So excited to have another table converted to DataGrid, and there are nice improvements in here too! It is going to make the next one even more straightforward. 🙌 🚢

@mddilley
Copy link
Collaborator

mddilley commented Oct 8, 2024

fyi - i created this spin off issue to capture another small bug that is in production too. sorting the "File" column doesn't work quite as expected on uploaded files since they all have a common S3 path. Plenty of improvements in this PR so let's save for another day! Thank you again @chiaberry! 🎉

Copy link
Contributor

@tillyw tillyw left a comment

Choose a reason for hiding this comment

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

tested locally and looks and functions great! thank you for upgrading this table with DataGrid and adding the increased functionality, validation and modal! being able to inline edit is so nice ✨ long file paths and urls render as expected:

Screenshot 2024-10-09 at 2 46 43 PM

a couple minor things we could maybe address in the future:

  • is it possible to disable editing on the 'file' field when it is an actual file (as opposed to a url or file path) since you can't actually edit that field in that case?
  • i know we've come across this before, but when i double click on the 'file' field when it is a url it tries to open the url rather than allowing me to edit the field

as far as default column widths, i think we could shrink the 'file size' field by at least half and give that extra space to the 'file' field, since file size will probably only ever be around 5-6 characters

@mateoclarke mateoclarke mentioned this pull request Oct 9, 2024
4 tasks
Copy link
Contributor

@mateoclarke mateoclarke left a comment

Choose a reason for hiding this comment

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

👍

@chiaberry
Copy link
Member Author

@tillyw thank you for pointing out the file size column width could be smaller!
and thanks everyone for the reviews

@chiaberry chiaberry merged commit a50f7da into main Oct 10, 2024
4 checks passed
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.

5 participants