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

Change: Adds copy functionality to breadcrumbs #312

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cypress/e2e/general/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Navigation tests', () => {

navigation.getLinkElement('account').click();

const redirect = `${Cypress.env('keycloak')}/realms/lagoon/account/`;
const redirect = `${Cypress.env('keycloak')}/realms/lagoon/account`;
cy.origin(redirect, { args: { redirect } }, ({ redirect }) => {
cy.location().should(loc => {
expect(loc.toString()).to.eq(redirect);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"@types/core-js": "^2.5.5",
"@types/git-url-parse": "^9.0.1",
"@types/react": "^18.0.37",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-dom": "^18.0.11",
"@types/react-highlight-words": "^0.16.4",
"@types/recompose": "^0.30.10",
Expand Down
61 changes: 42 additions & 19 deletions src/components/Breadcrumbs/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import Skeleton from 'react-loading-skeleton';

import Router from 'next/router';

import { BreadCrumbLink, StyledBreadCrumb } from './StyledBreadCrumb';
import { BreadCrumbLink, StyledBreadCrumb, StyledCopyWrapper } from './StyledBreadCrumb';

interface BreadcrumbProps {
header: string;
Expand All @@ -17,24 +18,46 @@ interface BreadcrumbProps {
asPath: string;
loading?: boolean;
}
const Breadcrumb: FC<BreadcrumbProps> = ({ header, title, urlObject, asPath, loading }) => {
const [copied, setCopied] = useState(false);

const Breadcrumb: FC<BreadcrumbProps> = ({ header, title, urlObject, asPath, loading }) => (
<>
<BreadCrumbLink
href={asPath}
onClick={e => {
e.preventDefault();
void Router.push(urlObject, asPath);
}}
>
<StyledBreadCrumb className="breadcrumb">
<div>
<label>{header}</label>
{title ? <h2>{title}</h2> : loading && <Skeleton width={150} />}
return (
<>
<BreadCrumbLink
href={asPath}
onClick={e => {
e.preventDefault();
void Router.push(urlObject, asPath);
}}
>
<StyledBreadCrumb className="breadcrumb">
<div>
<label>{header}</label>
{title ? <h2>{title}</h2> : loading && <Skeleton width={150} />}
</div>
</StyledBreadCrumb>
</BreadCrumbLink>
<StyledCopyWrapper>
<div className="copy-field">
<span className="copied" style={copied ? { top: '-20px', opacity: '0' } : {}}>
Copied
</span>
<CopyToClipboard
data-cy="copyButtonBreadcrumb"
text={title}
onCopy={() => {
setCopied(true);
setTimeout(function () {
setCopied(false);
}, 750);
}}
>
<span className="copy" />
</CopyToClipboard>
</div>
</StyledBreadCrumb>
</BreadCrumbLink>
</>
);
</StyledCopyWrapper>
</>
);
};

export default Breadcrumb;
44 changes: 43 additions & 1 deletion src/components/Breadcrumbs/StyledBreadCrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bp, color } from 'lib/variables';
import { bp, color, fontSize } from 'lib/variables';
import styled from 'styled-components';

export const StyledBreadCrumb = styled.div`
Expand Down Expand Up @@ -62,3 +62,45 @@ export const StyledBreadcrumbsWrapper = styled.div`
margin: 0 calc((100vw / 16) * 1);
}
`;

export const StyledCopyWrapper = styled.div`
margin-right: 8px;

.copy-field {
display: flex;
width: 100%;
overflow: visible;
transform: translateX(-13px);
}

.copy {
background: url('/static/images/copy.svg') center center no-repeat ${props => props.theme.backgrounds.breadCrumbs};
background-size: 16px;
bottom: 0;
height: 34px;
position: absolute;
right: 20px;
width: 40px;
top: 10px;
transition: all 0.5s;

&:hover {
background-color: ${props => props.theme.backgrounds.sidebar};
cursor: pointer;
}
}

.copied {
background-color: ${props => props.theme.backgrounds.breadCrumbs};
${fontSize(9, 16)};
border-radius: 3px;
padding: 0 2px;
position: absolute;
right: 20px;
text-transform: uppercase;
top: 10px;
transition:
top 0.5s,
opacity 0.75s ease-in;
}
`;
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4015,6 +4015,13 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb"
integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==

"@types/react-copy-to-clipboard@^5.0.7":
version "5.0.7"
resolved "https://registry.yarnpkg.com/@types/react-copy-to-clipboard/-/react-copy-to-clipboard-5.0.7.tgz#0cb724d4228f1c2f8f5675671b3971c8801d5f45"
integrity sha512-Gft19D+as4M+9Whq1oglhmK49vqPhcLzk8WfvfLvaYMIPYanyfLy0+CwFucMJfdKoSFyySPmkkWn8/E6voQXjQ==
dependencies:
"@types/react" "*"

"@types/react-dom@^18.0.11":
version "18.3.0"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.3.0.tgz#0cbc818755d87066ab6ca74fbedb2547d74a82b0"
Expand Down
Loading