Skip to content

Commit

Permalink
feat: use ClipboardJS for copying shareable link
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjibansg committed Jul 5, 2023
1 parent 9a7951a commit 1ed47ff
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
67 changes: 67 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@rollup/plugin-inject": "^5.0.3",
"axios": "^1.2.5",
"bootstrap": "^5.2.3",
"clipboard": "^2.0.11",
"d3": "^7.8.2",
"jquery": "^3.6.3",
"monaco-editor": "^0.34.1",
Expand Down
15 changes: 9 additions & 6 deletions client/src/components/SubstraitGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<div id="svgContainer">
<div style="margin-right: 10vh; text-align: right">
<button
id="copy-button"
type="button"
class="btn btn-outline-primary btn-sm"
v-show="download"
style="margin-right: 1vh"
@click="generateLink"
ref="copyButton"
>
Copy Link
</button>
Expand Down Expand Up @@ -39,12 +41,14 @@
<script>
import { store } from "../components/store";
import axios from "axios";
import Clipboard from "clipboard";
export default {
name: "SubstraitGraph",
data: function () {
return {
download: false,
shareable_link: "",
};
},
mounted() {
Expand All @@ -57,6 +61,9 @@ export default {
this.observer.observe(this.$refs.d3Plot, {
childList: true,
});
this.clipboard = new Clipboard("#copy-button", {
text: () => this.shareable_link,
});
},
beforeDestroy() {
this.observer.disconnect();
Expand Down Expand Up @@ -105,12 +112,8 @@ export default {
validator_overrides: store.validation_override_levels,
});
const textField = document.createElement("textarea");
textField.innerText = this.currentUrl + "/plan/" + resp.data;
document.body.appendChild(textField);
textField.select();
document.execCommand("copy");
textField.remove();
this.shareable_link = this.currentUrl + "/plan/" + resp.data;
this.clipboard.onClick({ currentTarget: this.$refs.copyButton });
alert("Link copied to clipboard!");
} catch (error) {
console.log(error.response.data["detail"]);
Expand Down

0 comments on commit 1ed47ff

Please sign in to comment.