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

Add buttons for copying canonical package URIs #1990

Merged
merged 1 commit into from
Dec 17, 2020
Merged
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
39 changes: 38 additions & 1 deletion catalog/app/containers/Bucket/PackageTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Lab from '@material-ui/lab'
import { Crumb, copyWithoutSpaces, render as renderCrumbs } from 'components/BreadCrumbs'
import * as Intercom from 'components/Intercom'
import * as Preview from 'components/Preview'
import * as Notifications from 'containers/Notifications'
import AsyncResult from 'utils/AsyncResult'
import * as AWS from 'utils/AWS'
import * as BucketConfig from 'utils/BucketConfig'
Expand All @@ -19,6 +20,7 @@ import * as LinkedData from 'utils/LinkedData'
import * as NamedRoutes from 'utils/NamedRoutes'
import * as PackageUri from 'utils/PackageUri'
import Link, { linkStyle } from 'utils/StyledLink'
import copyToClipboard from 'utils/clipboard'
import parseSearch from 'utils/parseSearch'
import * as s3paths from 'utils/s3paths'
import usePrevious from 'utils/usePrevious'
Expand Down Expand Up @@ -65,8 +67,10 @@ const useRevisionInfoStyles = M.makeStyles((t) => ({

function RevisionInfo({ revisionData, revision, bucket, name, path }) {
const { urls } = NamedRoutes.use()
const { push } = Notifications.use()
const classes = useRevisionInfoStyles()

const listRef = React.useRef()
const [anchor, setAnchor] = React.useState()
const [opened, setOpened] = React.useState(false)
const open = React.useCallback(() => setOpened(true), [])
Expand All @@ -84,6 +88,15 @@ function RevisionInfo({ revisionData, revision, bucket, name, path }) {
_: R.identity,
})

const getHttpsUri = (r) =>
`${window.origin}${urls.bucketPackageTree(bucket, name, r.hash, path)}`
Copy link
Member

Choose a reason for hiding this comment

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

Hm... I expected quilt+s3:// url here

Copy link
Member

Choose a reason for hiding this comment

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

Now it's the same URL as if you copy it by right click and select "Copy link location"

Screenshot from 2020-12-17 11-34-40


const copyHttpsUri = (r, containerRef) => (e) => {
e.preventDefault()
copyToClipboard(getHttpsUri(r), { container: containerRef && containerRef.current })
push('Canonical URI copied to clipboard')
}

return (
<>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
Expand All @@ -96,14 +109,29 @@ function RevisionInfo({ revisionData, revision, bucket, name, path }) {
{R.take(10, revision)} <M.Icon>expand_more</M.Icon>
</span>

{revisionData.case({
Ok: (r) => (
<M.IconButton
size="small"
title="Copy package revision's canonical catalog URI to the clipboard"
href={getHttpsUri(r)}
onClick={copyHttpsUri(r)}
style={{ marginTop: -4, marginBottom: -4 }}
>
<M.Icon>link</M.Icon>
</M.IconButton>
),
_: () => null,
})}

<M.Popover
open={opened && !!anchor}
anchorEl={anchor}
onClose={close}
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
transformOrigin={{ vertical: 'top', horizontal: 'center' }}
>
<M.List className={classes.list}>
<M.List className={classes.list} ref={listRef}>
{AsyncResult.case(
{
Ok: R.map((r) => (
Expand All @@ -127,6 +155,15 @@ function RevisionInfo({ revisionData, revision, bucket, name, path }) {
</span>
}
/>
<M.ListItemSecondaryAction>
<M.IconButton
title="Copy package revision's canonical catalog URI to the clipboard"
href={getHttpsUri(r)}
onClick={copyHttpsUri(r, listRef)}
>
<M.Icon>link</M.Icon>
</M.IconButton>
</M.ListItemSecondaryAction>
</M.ListItem>
)),
Err: () => (
Expand Down