mirror of
https://github.com/mattermost/focalboard.git
synced 2025-02-07 19:30:18 +02:00
[GH-3947]: Added confirmation dialog when deleting a card in calendar/galley view (#3996)
Co-authored-by: Paul Esch-Laurent <paul.esch-laurent@mattermost.com> Co-authored-by: Rajat Dabade <rajat.dabade@mattermost.com>
This commit is contained in:
parent
3479e02657
commit
ed3197ca62
@ -396,7 +396,7 @@
|
|||||||
"rhs-boards.no-boards-linked-to-channel": "No boards are linked to {channelName} yet",
|
"rhs-boards.no-boards-linked-to-channel": "No boards are linked to {channelName} yet",
|
||||||
"rhs-boards.no-boards-linked-to-channel-description": "Boards is a project management tool that helps define, organize, track and manage work across teams, using a familiar kanban board view.",
|
"rhs-boards.no-boards-linked-to-channel-description": "Boards is a project management tool that helps define, organize, track and manage work across teams, using a familiar kanban board view.",
|
||||||
"rhs-boards.unlink-board": "Unlink board",
|
"rhs-boards.unlink-board": "Unlink board",
|
||||||
"rhs-boards.unlink-board1": "Unlink board Hello",
|
"rhs-boards.unlink-board1": "Unlink board",
|
||||||
"rhs-channel-boards-header.title": "Boards",
|
"rhs-channel-boards-header.title": "Boards",
|
||||||
"share-board.publish": "Publish",
|
"share-board.publish": "Publish",
|
||||||
"share-board.share": "Share",
|
"share-board.share": "Share",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React, {useCallback, useMemo} from 'react'
|
import React, {useCallback, useMemo, useState} from 'react'
|
||||||
import {useIntl} from 'react-intl'
|
import {useIntl} from 'react-intl'
|
||||||
|
|
||||||
import FullCalendar, {EventChangeArg, EventInput, EventContentArg, DayCellContentArg} from '@fullcalendar/react'
|
import FullCalendar, {EventChangeArg, EventInput, EventContentArg, DayCellContentArg} from '@fullcalendar/react'
|
||||||
@ -21,6 +21,7 @@ import PropertyValueElement from '../propertyValueElement'
|
|||||||
import {Constants, Permission} from '../../constants'
|
import {Constants, Permission} from '../../constants'
|
||||||
import {useHasCurrentBoardPermissions} from '../../hooks/permissions'
|
import {useHasCurrentBoardPermissions} from '../../hooks/permissions'
|
||||||
import CardBadges from '../cardBadges'
|
import CardBadges from '../cardBadges'
|
||||||
|
import ConfirmationDialogBox, {ConfirmationDialogBoxProps} from '../confirmationDialogBox'
|
||||||
|
|
||||||
import './fullcalendar.scss'
|
import './fullcalendar.scss'
|
||||||
import MenuWrapper from '../../widgets/menuWrapper'
|
import MenuWrapper from '../../widgets/menuWrapper'
|
||||||
@ -74,6 +75,8 @@ const CalendarFullView = (props: Props): JSX.Element|null => {
|
|||||||
const {board, cards, activeView, dateDisplayProperty, readonly} = props
|
const {board, cards, activeView, dateDisplayProperty, readonly} = props
|
||||||
const isSelectable = !readonly
|
const isSelectable = !readonly
|
||||||
const canAddCards = useHasCurrentBoardPermissions([Permission.ManageBoardCards])
|
const canAddCards = useHasCurrentBoardPermissions([Permission.ManageBoardCards])
|
||||||
|
const [showConfirmationDialogBox, setShowConfirmationDialogBox] = useState<boolean>(false)
|
||||||
|
const [cardItem, setCardItem] = useState<Card>()
|
||||||
|
|
||||||
const visiblePropertyTemplates = useMemo(() => (
|
const visiblePropertyTemplates = useMemo(() => (
|
||||||
board.cardProperties.filter((template: IPropertyTemplate) => activeView.fields.visiblePropertyIds.includes(template.id))
|
board.cardProperties.filter((template: IPropertyTemplate) => activeView.fields.visiblePropertyIds.includes(template.id))
|
||||||
@ -114,10 +117,35 @@ const CalendarFullView = (props: Props): JSX.Element|null => {
|
|||||||
|
|
||||||
const visibleBadges = activeView.fields.visiblePropertyIds.includes(Constants.badgesColumnId)
|
const visibleBadges = activeView.fields.visiblePropertyIds.includes(Constants.badgesColumnId)
|
||||||
|
|
||||||
|
const openConfirmationDialogBox = (card: Card) => {
|
||||||
|
setShowConfirmationDialogBox(true)
|
||||||
|
setCardItem(card)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDeleteCard = useCallback(() => {
|
||||||
|
if (!cardItem) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mutator.deleteBlock(cardItem, 'delete card')
|
||||||
|
}, [cardItem, board.id])
|
||||||
|
|
||||||
|
const confirmDialogProps: ConfirmationDialogBoxProps = useMemo(() => {
|
||||||
|
return {
|
||||||
|
heading: intl.formatMessage({id: 'CardDialog.delete-confirmation-dialog-heading', defaultMessage: 'Confirm card delete!'}),
|
||||||
|
confirmButtonText: intl.formatMessage({id: 'CardDialog.delete-confirmation-dialog-button-text', defaultMessage: 'Delete'}),
|
||||||
|
onConfirm: handleDeleteCard,
|
||||||
|
onClose: () => {
|
||||||
|
setShowConfirmationDialogBox(false)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}, [handleDeleteCard])
|
||||||
|
|
||||||
const renderEventContent = (eventProps: EventContentArg): JSX.Element|null => {
|
const renderEventContent = (eventProps: EventContentArg): JSX.Element|null => {
|
||||||
const {event} = eventProps
|
const {event} = eventProps
|
||||||
const card = cards.find((o) => o.id === event.id) || cards[0]
|
const card = cards.find((o) => o.id === event.id) || cards[0]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div
|
<div
|
||||||
className='EventContent'
|
className='EventContent'
|
||||||
onClick={() => props.showCard(event.id)}
|
onClick={() => props.showCard(event.id)}
|
||||||
@ -130,7 +158,7 @@ const CalendarFullView = (props: Props): JSX.Element|null => {
|
|||||||
<IconButton icon={<OptionsIcon/>}/>
|
<IconButton icon={<OptionsIcon/>}/>
|
||||||
<CardActionsMenu
|
<CardActionsMenu
|
||||||
cardId={card.id}
|
cardId={card.id}
|
||||||
onClickDelete={() => mutator.deleteBlock(card, 'delete card')}
|
onClickDelete={() => openConfirmationDialogBox(card)}
|
||||||
onClickDuplicate={() => {
|
onClickDuplicate={() => {
|
||||||
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.DuplicateCard, {board: board.id, card: card.id})
|
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.DuplicateCard, {board: board.id, card: card.id})
|
||||||
mutator.duplicateCard(card.id, board.id)
|
mutator.duplicateCard(card.id, board.id)
|
||||||
@ -161,6 +189,7 @@ const CalendarFullView = (props: Props): JSX.Element|null => {
|
|||||||
{visibleBadges &&
|
{visibleBadges &&
|
||||||
<CardBadges card={card}/> }
|
<CardBadges card={card}/> }
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,6 +280,7 @@ const CalendarFullView = (props: Props): JSX.Element|null => {
|
|||||||
selectMirror={true}
|
selectMirror={true}
|
||||||
select={onNewEvent}
|
select={onNewEvent}
|
||||||
/>
|
/>
|
||||||
|
{showConfirmationDialogBox && <ConfirmationDialogBox dialogBox={confirmDialogProps}/>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -904,6 +904,77 @@ exports[`src/components/gallery/GalleryCard without block content return Gallery
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
class="Dialog dialog-back confirmation-dialog-box"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="backdrop"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="wrapper"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="dialog"
|
||||||
|
role="dialog"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="toolbar"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1
|
||||||
|
class="dialog-title"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="toolbar--right"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-label="Close dialog"
|
||||||
|
title="Close dialog"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
class="CompassIcon icon-close CloseIcon"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="box-area"
|
||||||
|
title="Confirmation Dialog Box"
|
||||||
|
>
|
||||||
|
<h3
|
||||||
|
class="text-heading5"
|
||||||
|
>
|
||||||
|
Confirm card delete!
|
||||||
|
</h3>
|
||||||
|
<div
|
||||||
|
class="sub-text"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="action-buttons"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
title="Cancel"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
Cancel
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
title="Delete"
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
Delete
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -159,8 +159,6 @@ describe('src/components/gallery/GalleryCard', () => {
|
|||||||
const buttonDelete = screen.getByRole('button', {name: 'Delete'})
|
const buttonDelete = screen.getByRole('button', {name: 'Delete'})
|
||||||
userEvent.click(buttonDelete)
|
userEvent.click(buttonDelete)
|
||||||
expect(container).toMatchSnapshot()
|
expect(container).toMatchSnapshot()
|
||||||
expect(mockedMutator.deleteBlock).toBeCalledTimes(1)
|
|
||||||
expect(mockedMutator.deleteBlock).toBeCalledWith(card, 'delete card')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('return GalleryCard and duplicate card', () => {
|
test('return GalleryCard and duplicate card', () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import React, {useMemo} from 'react'
|
import React, {useMemo, useState, useCallback} from 'react'
|
||||||
import {FormattedMessage} from 'react-intl'
|
import {useIntl, FormattedMessage} from 'react-intl'
|
||||||
|
|
||||||
import {Board, IPropertyTemplate} from '../../blocks/board'
|
import {Board, IPropertyTemplate} from '../../blocks/board'
|
||||||
import {Card} from '../../blocks/card'
|
import {Card} from '../../blocks/card'
|
||||||
@ -22,6 +22,7 @@ import PropertyValueElement from '../propertyValueElement'
|
|||||||
import './galleryCard.scss'
|
import './galleryCard.scss'
|
||||||
import CardBadges from '../cardBadges'
|
import CardBadges from '../cardBadges'
|
||||||
import CardActionsMenu from '../cardActionsMenu/cardActionsMenu'
|
import CardActionsMenu from '../cardActionsMenu/cardActionsMenu'
|
||||||
|
import ConfirmationDialogBox, {ConfirmationDialogBoxProps} from '../confirmationDialogBox'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
board: Board
|
board: Board
|
||||||
@ -37,12 +38,29 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const GalleryCard = (props: Props) => {
|
const GalleryCard = (props: Props) => {
|
||||||
|
const intl = useIntl()
|
||||||
const {card, board} = props
|
const {card, board} = props
|
||||||
const [isDragging, isOver, cardRef] = useSortable('card', card, props.isManualSort && !props.readonly, props.onDrop)
|
const [isDragging, isOver, cardRef] = useSortable('card', card, props.isManualSort && !props.readonly, props.onDrop)
|
||||||
const contents = useAppSelector(getCardContents(card.id))
|
const contents = useAppSelector(getCardContents(card.id))
|
||||||
|
const [showConfirmationDialogBox, setShowConfirmationDialogBox] = useState<boolean>(false)
|
||||||
|
|
||||||
const visiblePropertyTemplates = props.visiblePropertyTemplates || []
|
const visiblePropertyTemplates = props.visiblePropertyTemplates || []
|
||||||
|
|
||||||
|
const handleDeleteCard = useCallback(() => {
|
||||||
|
mutator.deleteBlock(card, 'delete card')
|
||||||
|
}, [card, board.id])
|
||||||
|
|
||||||
|
const confirmDialogProps: ConfirmationDialogBoxProps = useMemo(() => {
|
||||||
|
return {
|
||||||
|
heading: intl.formatMessage({id: 'CardDialog.delete-confirmation-dialog-heading', defaultMessage: 'Confirm card delete!'}),
|
||||||
|
confirmButtonText: intl.formatMessage({id: 'CardDialog.delete-confirmation-dialog-button-text', defaultMessage: 'Delete'}),
|
||||||
|
onConfirm: handleDeleteCard,
|
||||||
|
onClose: () => {
|
||||||
|
setShowConfirmationDialogBox(false)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}, [handleDeleteCard])
|
||||||
|
|
||||||
const image: ContentBlock|undefined = useMemo(() => {
|
const image: ContentBlock|undefined = useMemo(() => {
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
if (Array.isArray(contents[i])) {
|
if (Array.isArray(contents[i])) {
|
||||||
@ -60,6 +78,7 @@ const GalleryCard = (props: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div
|
<div
|
||||||
className={className}
|
className={className}
|
||||||
onClick={(e: React.MouseEvent) => props.onClick(e, card)}
|
onClick={(e: React.MouseEvent) => props.onClick(e, card)}
|
||||||
@ -74,7 +93,7 @@ const GalleryCard = (props: Props) => {
|
|||||||
<IconButton icon={<OptionsIcon/>}/>
|
<IconButton icon={<OptionsIcon/>}/>
|
||||||
<CardActionsMenu
|
<CardActionsMenu
|
||||||
cardId={card!.id}
|
cardId={card!.id}
|
||||||
onClickDelete={() => mutator.deleteBlock(card, 'delete card')}
|
onClickDelete={() => setShowConfirmationDialogBox(true)}
|
||||||
onClickDuplicate={() => {
|
onClickDuplicate={() => {
|
||||||
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.DuplicateCard, {board: board.id, card: card.id})
|
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.DuplicateCard, {board: board.id, card: card.id})
|
||||||
mutator.duplicateCard(card.id, board.id)
|
mutator.duplicateCard(card.id, board.id)
|
||||||
@ -151,6 +170,8 @@ const GalleryCard = (props: Props) => {
|
|||||||
className='gallery-badges'
|
className='gallery-badges'
|
||||||
/>}
|
/>}
|
||||||
</div>
|
</div>
|
||||||
|
{showConfirmationDialogBox && <ConfirmationDialogBox dialogBox={confirmDialogProps}/>}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user