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

Code Review Timeline #46132

Merged
merged 5 commits into from
May 6, 2022
Merged

Conversation

maureensturgeon
Copy link
Contributor

@maureensturgeon maureensturgeon commented May 3, 2022

Renders the timeline dynamically from the review and commit data in a new CodeReviewTimeline component.

Screen Shot 2022-05-03 at 11 05 26 AM

Links

Testing story

Tested locally and added unit tests

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@maureensturgeon maureensturgeon changed the base branch from staging to maureen/LP-2301-code-review-component May 3, 2022 00:53
@maureensturgeon maureensturgeon force-pushed the maureen/LP-2312-code-review-timeline branch from ca85aed to fcd4b42 Compare May 3, 2022 16:35
@maureensturgeon maureensturgeon marked this pull request as ready for review May 3, 2022 19:01
@maureensturgeon maureensturgeon requested a review from a team as a code owner May 3, 2022 19:01
@maureensturgeon maureensturgeon requested review from a team and moneppo May 3, 2022 19:02
Copy link
Contributor

@bencodeorg bencodeorg 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! Got some good modern React experience reading through this :)

refresh();
}, [refresh]);

const refresh = useCallback(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is like a modern react/js tutorial for me 👏

isVersionExpired: PropTypes.bool
});

const commentShape = PropTypes.shape({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe reviewCommentShape since commits also have comments?

Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

Take a look at my long comment about how the data-related code is structured and see what you think? If you decide that you like your current implementation better, that's fine with me too.

const [commitsData, setCommitsData] = useState([]);
const [hasOpenCodeReview, setHasOpenCodeReview] = useState(null);

const dataApi = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

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

This interaction between dataApi, refresh and the useEffect seems a bit complicated.

I think useMemo is intended as an optimization -- React is allowed to throw away the memoized value and recalculate if it wants to. Unfortunately, I think that would lead to a refresh here which seems undesirable. I think my suggestion here is to not have the data api be instanced. Just use it to organize some exports and pass all of the needed parameters to getCodeReviews and getCommits.

I'm not sure about this, but it might also be helpful to have the data api expose a single method (hook?) that gets both code reviews and commits and combines that data (the logic that's currently in CodeReviewTimeline). One way to think about this is that the fact this data is coming from two separate APIs is abstracted from all of the UX components. This might then simplify refresh enough that we don't need to define it separately and can call the data api directly from the useEffect.

Finally, just throwing it out there for the future, I wonder if useFetch would help further simplify some of the logic.

(Sorry, this ended up being a lot. Also happy to chat in person.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the benefits of having an instance is storing the csrf token, which could be stored on the component instead. I do see your point about having some of the combining logic extracted. I'll play around with it. Things actually change a bit in the next PR where I decide to store the open code review separately on the state so that I can more easily mutate it when changes are made: #46150

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, up to you whether you want to continue to iterate on this PR or if you want to merge this and come back to it later.

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'm looking at potential refactors on the next branch, so I'm going to merge this one and keep looking at it.

Comment on lines +27 to +29
useEffect(() => {
scrollToBottom();
}, [reviewData, commitsData]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this typically only happen once (after the data arrives)? (I could imagine this being disorienting if it happens more often.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the intent is that this just happens when the data loads. This will probably be easier to tweak when things are more wired up and I'm able to walk through the different flows

mergedData.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));

return (
<div style={styles.wrapper}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful, so clear!

commit: 'commit'
};

const CodeReviewTimeline = props => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the "primary" component, it'd be great to have a header comment that gives a short description of how it and its children components work together.

Base automatically changed from maureen/LP-2301-code-review-component to staging May 5, 2022 21:41
@maureensturgeon maureensturgeon merged commit 6cd4c4c into staging May 6, 2022
@maureensturgeon maureensturgeon deleted the maureen/LP-2312-code-review-timeline branch May 6, 2022 17:57
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.

None yet

3 participants