From b71e489868c3904c3f3e5c13d7b344db705d4700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=E2=95=AF=C2=B0=E2=96=A1=C2=B0=EF=BC=89=E2=95=AF?= =?UTF-8?q?=EF=B8=B5=20u=E1=B4=89=C7=9DssnH=20=C9=90=C9=9F=C9=90=CA=87soW?= Date: Tue, 17 Aug 2021 18:05:11 +0400 Subject: [PATCH] feat: Add the ability to copy k8s object name (#3575) Signed-off-by: Mostafa Hussein --- src/renderer/components/drawer/drawer.scss | 11 ++++++++ src/renderer/components/drawer/drawer.tsx | 29 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/drawer/drawer.scss b/src/renderer/components/drawer/drawer.scss index 47168df569..6598e156e4 100644 --- a/src/renderer/components/drawer/drawer.scss +++ b/src/renderer/components/drawer/drawer.scss @@ -80,6 +80,17 @@ padding-right: $padding; } + .drawer-title-text .Icon { + opacity: 0; + font-weight: normal; + margin-left: 8px; + } + + .drawer-title-text:hover .Icon { + opacity: 1; + transition: opacity 250ms; + } + .MenuActions.toolbar .Icon { color: $drawerTitleText; } diff --git a/src/renderer/components/drawer/drawer.tsx b/src/renderer/components/drawer/drawer.tsx index 5c3e648893..45591e65be 100644 --- a/src/renderer/components/drawer/drawer.tsx +++ b/src/renderer/components/drawer/drawer.tsx @@ -22,6 +22,7 @@ import "./drawer.scss"; import React from "react"; +import { clipboard } from "electron"; import { createPortal } from "react-dom"; import { cssNames, noop } from "../../utils"; import { Icon } from "../icon"; @@ -48,7 +49,12 @@ const defaultProps: Partial = { onClose: noop, }; +interface State { + isCopied: boolean; +} + export class Drawer extends React.Component { + static defaultProps = defaultProps as object; private mouseDownTarget: HTMLElement; @@ -60,6 +66,10 @@ export class Drawer extends React.Component { this.restoreScrollPos(); }); + public state: State = { + isCopied: false + }; + componentDidMount() { // Using window target for events to make sure they will be catched after other places (e.g. Dialog) window.addEventListener("mousedown", this.onMouseDown); @@ -125,9 +135,23 @@ export class Drawer extends React.Component { if (open) onClose(); }; + copyK8sObjName = () => { + const { title } = this.props; + const k8sObjName = title.toString().split(": ")[1]; + + clipboard.writeText(k8sObjName); + this.setState({isCopied: true}); + setTimeout(() => { + this.setState({isCopied: false}); + }, 3000); + }; + render() { const { open, position, title, animation, children, toolbar, size, usePortal } = this.props; let { className, contentClass } = this.props; + const { isCopied } = this.state; + const copyTooltip = isCopied? "Copied!" : "Copy"; + const copyIcon = isCopied? "done" : "content_copy"; className = cssNames("Drawer", className, position); contentClass = cssNames("drawer-content flex column box grow", contentClass); @@ -137,7 +161,10 @@ export class Drawer extends React.Component {
this.contentElem = e}>
-
{title}
+
+ {title} + +
{toolbar}