Skip to content

unify banner state in application to pay down some tech debt - #6884

Merged
shiftkey merged 4 commits into
developmentfrom
standardize-banner-state
Feb 21, 2019
Merged

shiftkey merged 4 commits into
developmentfrom
standardize-banner-state

Conversation

@shiftkey

@shiftkey shiftkey commented Feb 19, 2019 •

Copy link
Copy Markdown
Member

Overview

This PR demonstrates how a unified banner API might work in the application. I need to implement some banners as part of the rebase flow in #6698, so I wanted to open this cleanup PR early and get feedback.

Shout out to @outofambit for brain dumping her thoughts earlier today to help me get started.

Description

This work came from our learnings about managing popups, with a slight improvement that I don't think we've done elsewhere.

First, we defined a unified Banner type to represent all the possible states of a banner:

https://github.com/desktop/desktop/blob/0eea8253dc44554cd6b649332e08b97192665d02/app/src/models/banner.ts#L1-L22

Then, we defined a single currentBanner state inside app-state, replacing successfulMergeBannerState and mergeConflictsBannerState.

Lastly, AppStore and Dispatcher now define a single setBanner/clearBanner functions to manage this state, rather than two pairs of functions to update each state.

This PR differs from our current Popup infrastructure by moving the render function out to it's own module, rather than inlining it inside App:

https://github.com/desktop/desktop/blob/0eea8253dc44554cd6b649332e08b97192665d02/app/src/ui/app.tsx#L1888-L1896

This means App doesn't need to be aware of the components it can render as banners (fewer imports, better separation of concerns), and we can use assertNever to ensure renderBanner handles all of the states it should:

https://github.com/desktop/desktop/blob/0eea8253dc44554cd6b649332e08b97192665d02/app/src/ui/banners/render-banner.tsx#L12-L41

You might note that the UpdateAvailable banner is technically a banner, but for the sake of this PR I'm not touching that logic or it's representation. I think it could live in there at some point, but I haven't thought about it.

Release notes

Notes: no-notes

@shiftkey shiftkey added tech-debt Issues and pull requests related to addressing technical debt or improving the codebase ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Feb 19, 2019
@shiftkey
shiftkey requested a review from outofambit February 19, 2019 22:10
@shiftkey

Copy link
Copy Markdown
Member Author

I've tentatively rebased #6698 on top of this branch to help me test the API. It's not a hard dependency on shipping, but given how much this better organizes things I'd like to gather feedback on this while I'm testing #6698

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cowboy on horse in a basketball court celebrating

@outofambit

Copy link
Copy Markdown
Contributor

Glad to see the addition of a render-banner to this pattern! Thats a worthwhile improvement. 🎉

@shiftkey

Copy link
Copy Markdown
Member Author

FYI @desktop/engineering I plan to merge this in tomorrow morning my time so #6698 will be ready to review, so let me know if there's any other feedback about this change.

@shiftkey
shiftkey merged commit ea85ed0 into development Feb 21, 2019
@shiftkey
shiftkey deleted the standardize-banner-state branch February 21, 2019 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers tech-debt Issues and pull requests related to addressing technical debt or improving the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants