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

added most recent history item to status #268

Merged
merged 3 commits into from
Mar 8, 2022

Conversation

0lafe
Copy link
Collaborator

@0lafe 0lafe commented Mar 4, 2022

Fixes #261

Screen.Recording.2022-03-03.at.10.57.40.PM.mov

I made some mistakes when trying to resolve the merge conflicts on the last PR. Hopefully this one will work instead

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

Visit the preview URL for this PR (updated for commit 0lafe/advocacy-maps@1f1b000):

https://digital-testimony-dev--pr268-add-recent-history-t-vboxh12a.web.app

(expires Tue, 15 Mar 2022 23:06:02 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bc0858669d4997df2a9165c2144bd1e2dbba0242

@0lafe
Copy link
Collaborator Author

0lafe commented Mar 4, 2022

I took Alex's advice and abstracted the history table to its own reusable component. The only issue I found was how to format the props being passed to it. In history it is an array of history, however in the status it is a single element from an array. I opted to make the table component require an array, even of length 1, however I don't know what the best practice here would be.

Copy link
Member

@alexjball alexjball left a comment

Choose a reason for hiding this comment

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

Thanks Ben! always requiring an array sgtm as it simplifies the component's interface

const BillHistoryTable = (props) => {
const { documentHistoryActions } = props

const DocumentHistoryActionRows = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Components should always be defined at the top level -- as it is this component is redefined each render. We should move this outside the BillHistoryTable, so it's defined at the module level, and then pass the props to it and have it access the documentHistoryActions from the props.

@0lafe
Copy link
Collaborator Author

0lafe commented Mar 8, 2022

Hey @alexjball I believe I accomplished what you intended, but I'm not exactly sure. If this is what you were asking for, do you mind letting me know what this does better? It seems more readable, but I assumed your comment was more related to repeating the mapping logic with additional rerenders, which I assume this would still do.

import React from "react";
import { Table } from 'react-bootstrap'

const DocumentHistoryActionRows = (documentHistoryActions) => {
Copy link
Member

Choose a reason for hiding this comment

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

Need to wrap the documentHistoryActions in curly braces to extract it from the props object:

const DocumentHistoryActionRows = ({documentHistoryActions}) => {

@alexjball
Copy link
Member

Hey @0lafe this article goes into some detail: https://levelup.gitconnected.com/code-review-avoid-declaring-react-component-inside-parent-component-1768a645f523

When you define DocumentHistoryActionRows inside another component, you create a new function each render, so react sees <DocumentHistoryActionRows .../> as a new component each render, which causes additional unmounting and remounting. It would work fine in this case but can cause bugs in general (as in the article)

Will approve and merge once the curly braces are fixed (currently causes an error when I click status)

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.

add last item of history to status modal
2 participants