From 27831136c9fcb7aff28045c69aca39ea401bd239 Mon Sep 17 00:00:00 2001 From: Paul Esch-Laurent Date: Mon, 11 Apr 2022 14:00:52 -0500 Subject: [PATCH] fix: hide 'Copy link' for `single-user` installs --- webapp/src/components/cardDialog.tsx | 28 ++++++++-------- .../src/components/gallery/gallery.test.tsx | 6 ++++ .../components/gallery/galleryCard.test.tsx | 30 +++++++++++++++++ webapp/src/components/gallery/galleryCard.tsx | 31 ++++++++++-------- webapp/src/components/kanban/kanbanCard.tsx | 32 +++++++++++-------- 5 files changed, 88 insertions(+), 39 deletions(-) diff --git a/webapp/src/components/cardDialog.tsx b/webapp/src/components/cardDialog.tsx index 1ba9a02ff..33fb7e4f1 100644 --- a/webapp/src/components/cardDialog.tsx +++ b/webapp/src/components/cardDialog.tsx @@ -119,21 +119,23 @@ const CardDialog = (props: Props): JSX.Element => { onClick={handleDeleteButtonOnClick} /> - } - id='copy' - name={intl.formatMessage({id: 'CardDialog.copyLink', defaultMessage: 'Copy link'})} - onClick={() => { - let cardLink = window.location.href + {me?.id !== "single-user" && + } + id='copy' + name={intl.formatMessage({id: 'CardDialog.copyLink', defaultMessage: 'Copy link'})} + onClick={() => { + let cardLink = window.location.href - if (!cardLink.includes(props.cardId)) { - cardLink += `/${props.cardId}` - } + if (!cardLink.includes(props.cardId)) { + cardLink += `/${props.cardId}` + } - Utils.copyTextToClipboard(cardLink) - sendFlashMessage({content: intl.formatMessage({id: 'CardDialog.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) - }} - /> + Utils.copyTextToClipboard(cardLink) + sendFlashMessage({content: intl.formatMessage({id: 'CardDialog.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) + }} + /> + } {!isTemplate && { comments: { comments: {}, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + } } const store = mockStateStore([], state) beforeEach(() => { diff --git a/webapp/src/components/gallery/galleryCard.test.tsx b/webapp/src/components/gallery/galleryCard.test.tsx index 6c895cb5f..5183765e9 100644 --- a/webapp/src/components/gallery/galleryCard.test.tsx +++ b/webapp/src/components/gallery/galleryCard.test.tsx @@ -85,6 +85,12 @@ describe('src/components/gallery/GalleryCard', () => { comments: {}, commentsByCard: {}, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + }, } store = mockStateStore([], state) }) @@ -264,6 +270,12 @@ describe('src/components/gallery/GalleryCard', () => { [board.id]: {userId: 'user_id_1', schemeAdmin: true}, }, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + }, } store = mockStateStore([], state) }) @@ -330,6 +342,12 @@ describe('src/components/gallery/GalleryCard', () => { [board.id]: {userId: 'user_id_1', schemeAdmin: true}, }, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + }, } store = mockStateStore([], state) }) @@ -391,6 +409,12 @@ describe('src/components/gallery/GalleryCard', () => { [board.id]: {userId: 'user_id_1', schemeAdmin: true}, }, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + }, } store = mockStateStore([], state) }) @@ -471,6 +495,12 @@ describe('src/components/gallery/GalleryCard', () => { [board.id]: {userId: 'user_id_1', schemeAdmin: true}, }, }, + users: { + me: { + id: 'user_id_1', + props: {}, + }, + }, } store = mockStateStore([], state) }) diff --git a/webapp/src/components/gallery/galleryCard.tsx b/webapp/src/components/gallery/galleryCard.tsx index c35d8ead1..9c60b5683 100644 --- a/webapp/src/components/gallery/galleryCard.tsx +++ b/webapp/src/components/gallery/galleryCard.tsx @@ -8,6 +8,8 @@ import {Card} from '../../blocks/card' import {ContentBlock} from '../../blocks/contentBlock' import {useSortable} from '../../hooks/sortable' import mutator from '../../mutator' +import {IUser} from '../../user' +import {getMe} from '../../store/users' import {getCardContents} from '../../store/contents' import {useAppSelector} from '../../store/hooks' import TelemetryClient, {TelemetryActions, TelemetryCategory} from '../../telemetry/telemetryClient' @@ -49,6 +51,7 @@ const GalleryCard = (props: Props) => { const intl = useIntl() const [isDragging, isOver, cardRef] = useSortable('card', card, props.isManualSort && !props.readonly, props.onDrop) const contents = useAppSelector(getCardContents(card.id)) + const me = useAppSelector(getMe) const visiblePropertyTemplates = props.visiblePropertyTemplates || [] @@ -99,21 +102,23 @@ const GalleryCard = (props: Props) => { }} /> - } - id='copy' - name={intl.formatMessage({id: 'GalleryCard.copyLink', defaultMessage: 'Copy link'})} - onClick={() => { - let cardLink = window.location.href + {me?.id !== "single-user" && + } + id='copy' + name={intl.formatMessage({id: 'GalleryCard.copyLink', defaultMessage: 'Copy link'})} + onClick={() => { + let cardLink = window.location.href - if (!cardLink.includes(card.id)) { - cardLink += `/${card.id}` - } + if (!cardLink.includes(card.id)) { + cardLink += `/${card.id}` + } - Utils.copyTextToClipboard(cardLink) - sendFlashMessage({content: intl.formatMessage({id: 'GalleryCard.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) - }} - /> + Utils.copyTextToClipboard(cardLink) + sendFlashMessage({content: intl.formatMessage({id: 'GalleryCard.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) + }} + /> + } } diff --git a/webapp/src/components/kanban/kanbanCard.tsx b/webapp/src/components/kanban/kanbanCard.tsx index b526e8ea8..327398ad9 100644 --- a/webapp/src/components/kanban/kanbanCard.tsx +++ b/webapp/src/components/kanban/kanbanCard.tsx @@ -21,6 +21,9 @@ import Tooltip from '../../widgets/tooltip' import {Permission} from '../../constants' import {sendFlashMessage} from '../flashMessages' import PropertyValueElement from '../propertyValueElement' +import {IUser} from '../../user' +import {getMe} from '../../store/users' +import {useAppSelector} from '../../store/hooks' import BoardPermissionGate from '../permissions/boardPermissionGate' @@ -51,6 +54,7 @@ const KanbanCard = (props: Props) => { const [isDragging, isOver, cardRef] = useSortable('card', card, !props.readonly, props.onDrop) const visiblePropertyTemplates = props.visiblePropertyTemplates || [] const match = useRouteMatch<{boardId: string, viewId: string, cardId?: string}>() + const me = useAppSelector(getMe) let className = props.isSelected ? 'KanbanCard selected' : 'KanbanCard' if (props.isManualSort && isOver) { className += ' dragover' @@ -142,21 +146,23 @@ const KanbanCard = (props: Props) => { }} /> - } - id='copy' - name={intl.formatMessage({id: 'KanbanCard.copyLink', defaultMessage: 'Copy link'})} - onClick={() => { - let cardLink = window.location.href + {me?.id !== "single-user" && + } + id='copy' + name={intl.formatMessage({id: 'KanbanCard.copyLink', defaultMessage: 'Copy link'})} + onClick={() => { + let cardLink = window.location.href - if (!cardLink.includes(card.id)) { - cardLink += `/${card.id}` - } + if (!cardLink.includes(card.id)) { + cardLink += `/${card.id}` + } - Utils.copyTextToClipboard(cardLink) - sendFlashMessage({content: intl.formatMessage({id: 'KanbanCard.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) - }} - /> + Utils.copyTextToClipboard(cardLink) + sendFlashMessage({content: intl.formatMessage({id: 'KanbanCard.copiedLink', defaultMessage: 'Copied!'}), severity: 'high'}) + }} + /> + } }