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

Copy URL button #327

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"data_explorer_service": "file:src/api",
"lodash.debounce": "^4.0.8",
"react": "^16.3.0",
"react-copy-to-clipboard": "5.0.1",
"react-dom": "^16.3.0",
"react-scripts": "^2.0.0",
"react-select": "^2.0.0",
Expand Down
43 changes: 43 additions & 0 deletions ui/src/components/CopyUrlButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { PrimaryButton, TerraTooltip } from "libs/common";
import "@clr/icons/clr-icons.css";

const style = {
copyUrlButton: {
marginRight: "16px"
Copy link
Contributor

Choose a reason for hiding this comment

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

React will automatically append a "px" suffix so by convention we do this, to be slightly cleaner:

marginRight: 16

}
};

export default class CopyUrlButton extends React.Component {
constructor(props) {
super(props);
this.state = {
buttonText: "Copy URL to clipboard"
};
this.handleButtonClick = this.handleButtonClick.bind(this);
}

handleButtonClick() {
// Just change the button text for a second
this.setState({ buttonText: "Copied!" });
setTimeout(
() => this.setState({ buttonText: "Copy URL to clipboard" }),
1000
);
}

render() {
const { className } = this.props;

return (
<div onClick={this.handleButtonClick} style={style.copyUrlButton}>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's recommended to use className rather than style.

In this repo we use the material-ui styling solution.

  • At the bottom of this file: export default withStyles(styles)(CopyUrlButton);
const { classes } = this.props;
... className={classes.copyUrlButton}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanks! In this case, since we wanted to move the copyUrl button to the left we don't even need the extra styling. So I just removed this altogether.

<TerraTooltip title={this.state.buttonText}>
<CopyToClipboard text={window.location.href}>
<clr-icon shape="copy-to-clipboard" size="20" />
</CopyToClipboard>
</TerraTooltip>
</div>
);
}
}
2 changes: 2 additions & 0 deletions ui/src/components/DeHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Toolbar from "@material-ui/core/Toolbar";
import { withStyles } from "@material-ui/core/styles";

import colors from "libs/colors";
import CopyUrlButton from "components/CopyUrlButton";
import SaveButton from "components/SaveButton";
import Search from "components/Search";

Expand Down Expand Up @@ -148,6 +149,7 @@ class DeHeader extends React.Component {
exportUrlApi={this.props.exportUrlApi}
selectedFacetValues={this.props.selectedFacetValues}
/>
<CopyUrlButton />
</Toolbar>
</AppBar>
);
Expand Down