-
Notifications
You must be signed in to change notification settings - Fork 128
Fixes #5043 - Add download button to non-owner shot page #5048
Fixes #5043 - Add download button to non-owner shot page #5048
Conversation
@punamdahiya Could you add a description of what this PR is supposed to do? |
@6a68 PR is bringing back download button on !owned shot page as shown here #5043 (comment) |
<img src={this.props.staticLink("/static/img/icon-download.svg")} /> | ||
</button> | ||
</Localized></div>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved downloadButton outside of ownership check, as want to display it for both owned and !owned shots
@@ -107,7 +108,7 @@ exports.ShotPageHeader = class ShotPageHeader extends React.Component { | |||
hasFxa={this.props.isFxaAuthenticated}> | |||
{ myShotsText } | |||
{ shotInfo } | |||
<div className="shot-alt-actions"> | |||
<div className={classnames({"shot-alt-actions": this.props.isOwner})}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For !owned shots, we want download button to show on the same row as shot title and don't need shot-alt-actions class that renders alt action buttons in separate row on medium and small window widths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking the header into a second line at small widths seems kind of important, but here it's only encoded in a bit of conditional CSS. I think it'd be better to be explicit in the React component about which items are which. How about adding a shotActions
prop to the ShotPageHeader
that takes any buttons we want to show in the owner-only palette? Then the children
will always be rendered on the top line.
@6a68 I am confused by suggested shotActions prop on ShotPageHeader, is it a boolean that sets if we want shotactions button (favorite, edit, copy, delete, settings) shown or not. |
@6a68 Taken a stab at keeping logic of owner only buttons and its styles together in view.js. My understanding to bring logic of owner only palette inside ShotPageHeader component, we need to bring in defining all buttons and its related methods inside the component. Let me know if I am missing a better approach here. Thanks |
Sorry, missed your question. We can keep the logic in view.js, and just have two different ways to pass rendered buttons into the ShotPageHeader: the |
@punamdahiya Here's a second attempt at an explanation: Instead of passing all the elements into the ShotPageHeader using the special Elaborating a little bit in code:
const shotActions = this.props.isOwner ?
[favoriteShotButton, editButton, copyButton, downloadButton, trashOrFlagButton] : null
render() {
return (
<ShotPageHeader ... shotActions={shotActions}>
{this.props.isOwner ? downloadButton : signInButton}
</ShotPageHeader>
);
// inside ShotPageHeader.js
renderShotActions() {
return (
this.props.shotActions ?
<div class="shot-alt-actions">{this.props.shotActions}</div> : null
)
}
// inside the ShotPageHeader render method:
const shotActions = this.renderShotActions();
return (
<Header shouldGetFirefox={this.props.shouldGetFirefox} isOwner={this.props.isOwner}
hasFxa={this.props.isFxaAuthenticated}>
{ myShotsText }
{ shotInfo }
{ shotActions }
{ this.props.children }
</Header> This will give us a clear separation between elements that are rendered as a separate menu of buttons (the I hope this clarifies what I was asking for earlier, but if it's still unclear, let me know :-) |
c5c156f
to
3aafec2
Compare
{ this.props.children } | ||
</div> | ||
{ signin } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping signin here as signin button is defined in shot page header component
<img src={this.props.staticLink("/static/img/icon-download.svg")} /> | ||
</button> | ||
</Localized></div>; | ||
|
||
if (this.props.isOwner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check isn't elegant but keeping it in favor of executing a block of code that's not needed for !owned shots
@6a68 Updated PR with the suggested approach, thanks for detailed feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React has some complaints:
Looks like the PropTypes
need to be updated, and you'll need to set a key
attribute on the buttons. Probably the simplest thing is just to set the key to the button-specific class when the buttons are created, like <div className="favorite-shot-button" key="favorite-shot-button">
. They keys just need to be unique among siblings in a list, but globally-unique identifiers work, too.
See the keys doc and the more in-depth keys doc if you want to learn more about the details. I think keys
as a hint to the virtual DOM algorithm matters a lot more when you're, say, trying to minimize DOM operations when updating a Facebook home feed. In our case, it's more of an annoyance / curiosity, but we might as well follow the framework's advice.
3aafec2
to
ebcd4b1
Compare
Thanks for catching console warnings! Updated PropTypes and key attributes in PR. |
ebcd4b1
to
33929f5
Compare
keys docs shared above is informative. Good to know that key don't need to be unique globally. Updating with more meaningful key values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice work
No description provided.