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

Crash details: make change log collapsible #1655

Open
wants to merge 3 commits into
base: nextjs
Choose a base branch
from

Conversation

roseeichelmann
Copy link
Contributor

Associated issues

Closes cityofaustin/atd-data-tech#19968

Testing

URL to test:
Local or netlify

Steps to test:

  1. Go to a crash details page, scroll down to the change log. It should be collapsed on default first load.
  2. Now expand it and refresh the page. The new state should have saved in local storage so on refresh it should still be expand it.
  3. Collapse it and refresh again, making sure your state is saved. Go to other crashes and make sure the saved state is persisting.

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

Copy link

netlify bot commented Jan 10, 2025

Deploy Preview for vision-zero-nextjs ready!

Name Link
🔨 Latest commit 9ba19e6
🔍 Latest deploy log https://app.netlify.com/sites/vision-zero-nextjs/deploys/678596800f9cf80008e03346
😎 Deploy Preview https://deploy-preview-1655--vision-zero-nextjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

defaultActiveKey={expandedItem}
// on accordion click save new expanded item state to local storage
onSelect={(e) => {
const localStorageValue = e !== null ? "0" : JSON.stringify(null); // local storage value must be a string type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was getting a typescript linting error when just setting to null "Type 'null' is not assignable to type 'string'." and this is just never something i would have been super aware before programming in a strongly typed language. its weird but interesting having to take into account the parameter typing of external methods that we dont control, like setItem,

Copy link
Contributor

@mddilley mddilley Jan 10, 2025

Choose a reason for hiding this comment

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

i'm glad you shared about this in dev sync because it is a TIL for me too! Purely in opinion zone here but I think it would be okay to use the String constructor to make null into a string to work around this too. 🤷

I do think the e could be change to eventKey after I found myself wondering how these Bootstrap accordions work. The docs show that the first parameter in the callback is a string and the second is an event object which I expected this e to be when I read the code.

Copy link
Member

@johnclary johnclary Jan 13, 2025

Choose a reason for hiding this comment

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

I think it would be okay to use the String constructor to make null into a string to work around this to

i like this suggestion a lot. my inclination would be to restrict expandedItem to being a string only, and deal with conversion to a string with the String constructor. And that way we can always store whatever String(e) is into local storage without caring about it's value beyond that.

also, for what it's worth we don't have to use "0" as the key value. we could use something that's more obviously a string, like "recordHistory". and it might to be good to stash that value as const var 🤷

One other detail @roseeichelmann—I think that instead of the defaultActiveKey prop, the activeKey prop is a better choice to use instead. i see this kind of like using the value prop instead of defaultValue prop on a controlled form input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are all great comments, thanks yall! just pushed these changes

@roseeichelmann roseeichelmann changed the title Crash details: make change log collapsable Crash details: make change log collapsible Jan 10, 2025
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 and I'm happy to see this feature carrying over into the new app. I left one suggestion for the code, but this works just as expected! 💯

defaultActiveKey={expandedItem}
// on accordion click save new expanded item state to local storage
onSelect={(e) => {
const localStorageValue = e !== null ? "0" : JSON.stringify(null); // local storage value must be a string type
Copy link
Contributor

@mddilley mddilley Jan 10, 2025

Choose a reason for hiding this comment

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

i'm glad you shared about this in dev sync because it is a TIL for me too! Purely in opinion zone here but I think it would be okay to use the String constructor to make null into a string to work around this too. 🤷

I do think the e could be change to eventKey after I found myself wondering how these Bootstrap accordions work. The docs show that the first parameter in the callback is a string and the second is an event object which I expected this e to be when I read the code.

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—this is looking really good. I requested to changes to tighten up some typing and naming.

I also want to remark that I'd like to nix the blue background on the accordion header when it's expanded. but i am happy to stash that in a follow-up issue. as part of that follow-up work it would be nice toto make the header look the same as the bootstrap Card header for consistency with the other cards on the page, i think?

Screenshot 2025-01-13 at 10 28 11 AM

import Table from "react-bootstrap/Table";
import Accordion from "react-bootstrap/Accordion";
import { formatDateTime } from "@/utils/formatters";
import ChangeLogDetails from "./ChangeLogDetails";
Copy link
Member

Choose a reason for hiding this comment

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

could convert to an absolute import 😇

defaultActiveKey={expandedItem}
// on accordion click save new expanded item state to local storage
onSelect={(e) => {
const localStorageValue = e !== null ? "0" : JSON.stringify(null); // local storage value must be a string type
Copy link
Member

@johnclary johnclary Jan 13, 2025

Choose a reason for hiding this comment

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

I think it would be okay to use the String constructor to make null into a string to work around this to

i like this suggestion a lot. my inclination would be to restrict expandedItem to being a string only, and deal with conversion to a string with the String constructor. And that way we can always store whatever String(e) is into local storage without caring about it's value beyond that.

also, for what it's worth we don't have to use "0" as the key value. we could use something that's more obviously a string, like "recordHistory". and it might to be good to stash that value as const var 🤷

One other detail @roseeichelmann—I think that instead of the defaultActiveKey prop, the activeKey prop is a better choice to use instead. i see this kind of like using the value prop instead of defaultValue prop on a controlled form input.

@@ -9,6 +9,9 @@ import {
ChangeLogEntryEnriched,
} from "@/types/changeLog";

// used to track the accordion expanded state of the change log
const localStorageKey = "expandedItem";
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 mind making this a little more descriptive and specific instead of "expandedItem", like "crashHistoryCardExpandedItem"?

Copy link
Member

Choose a reason for hiding this comment

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

btw, i created cityofaustin/atd-data-tech#20575 to add in support for version local storage across the app 👍

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 looks super Rose. Really well done. I think the comments from other reviewers all make sense and get support from me, and I added one little thing concerning a color choice, but that's hardly enough to stop this from shipping. Send it out to sea!

🚢🚢🚢🚢🚢

}}
>
<Accordion.Item eventKey="0">
<Accordion.Header>Record history</Accordion.Header>
Copy link
Member

Choose a reason for hiding this comment

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

This header gets a baby blue color when it's expanded, and it's the only header row in on the page to get that color. Can it be rgba(33, 37, 41, 0.03) like the rest of of the card headers?

Copy link
Member

Choose a reason for hiding this comment

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

agreed—and i created cityofaustin/atd-data-tech#20606 to follow-up on this 🙏

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.

Looks great + works great!

const localStorageValue = e !== null ? "0" : JSON.stringify(null); // local storage value must be a string type
onSelect={(eventKey) => {
const localStorageValue =
eventKey !== null ? recordHistoryItemName : String(null); // local storage value must be a string type
Copy link
Member

Choose a reason for hiding this comment

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

nbd, but you can do away with the ternary and use String(eventKey) as the localStorageValue since it will always be null or the recordHistoryItemName.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 - i think that removing this ternary would make more readable 💯

}}
>
<Accordion.Item eventKey="0">
<Accordion.Header>Record history</Accordion.Header>
Copy link
Member

Choose a reason for hiding this comment

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

agreed—and i created cityofaustin/atd-data-tech#20606 to follow-up on 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.

Thanks for making these adjustments! I retested, and I can still save my preferred layout. 🙌 🚀 🚢

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