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

[MM-59253]: Remove plugin code from focalboard repo #5027

Merged
merged 11 commits into from
Aug 28, 2024
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"linux/dist/**": true,
},
"editor.codeActionsOnSave": {
// "source.organizeImports": true,
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved
"source.fixAll.eslint": true,
"source.fixAll.eslint": "explicit"
},
"[typescriptreact]": {
"editor.codeActionsOnSave": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {Provider as ReduxProvider} from 'react-redux'
import {MemoryRouter, Router} from 'react-router-dom'

import Mutator from '../../mutator'
import {Utils} from '../../utils'
import {Team} from '../../store/teams'
import {createBoard, Board} from '../../blocks/board'
import {IUser} from '../../user'
Expand Down Expand Up @@ -48,7 +47,6 @@ jest.mock('../../telemetry/telemetryClient')
const mockedTelemetry = mocked(TelemetryClient, true)

describe('components/boardTemplateSelector/boardTemplateSelector', () => {
const mockedUtils = mocked(Utils, true)
const mockedMutator = mocked(Mutator, true)
const mockedOctoClient = mocked(client, true)
const team1: Team = {
Expand Down Expand Up @@ -160,9 +158,6 @@ describe('components/boardTemplateSelector/boardTemplateSelector', () => {
jest.useRealTimers()
})
describe('not a focalboard Plugin', () => {
beforeAll(() => {
mockedUtils.isFocalboardPlugin.mockReturnValue(false)
})
test('should match snapshot', () => {
const {container} = render(wrapDNDIntl(
<ReduxProvider store={store}>
Expand All @@ -174,9 +169,6 @@ describe('components/boardTemplateSelector/boardTemplateSelector', () => {
})
})
describe('a focalboard Plugin', () => {
beforeAll(() => {
mockedUtils.isFocalboardPlugin.mockReturnValue(true)
})
test('should match snapshot', () => {
const {container} = render(wrapDNDIntl(
<ReduxProvider store={store}>
Expand Down
48 changes: 1 addition & 47 deletions webapp/src/components/boardsSwitcher/boardsSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import React, {useEffect, useState} from 'react'

import {FormattedMessage, useIntl} from 'react-intl'

import MenuWrapper from '../../widgets/menuWrapper'
import CompassIcon from '../../widgets/icons/compassIcon'
import Menu from '../../widgets/menu'
import Search from '../../widgets/icons/search'
import CreateCategory from '../createCategory/createCategory'
import {useAppSelector} from '../../store/hooks'
Expand All @@ -18,21 +15,14 @@ import {
import {getCurrentCard} from '../../store/cards'

import './boardsSwitcher.scss'
import AddIcon from '../../widgets/icons/add'
import BoardSwitcherDialog from '../boardsSwitcherDialog/boardSwitcherDialog'
import {Utils} from '../../utils'
import {Constants} from '../../constants'
import {TOUR_SIDEBAR, SidebarTourSteps} from '../../components/onboardingTour'

import IconButton from '../../widgets/buttons/iconButton'
import SearchForBoardsTourStep from '../../components/onboardingTour/searchForBoards/searchForBoards'

type Props = {
onBoardTemplateSelectorOpen: () => void
userIsGuest?: boolean
}

const BoardsSwitcher = (props: Props): JSX.Element => {
const BoardsSwitcher = (): JSX.Element => {
const intl = useIntl()

const [showSwitcher, setShowSwitcher] = useState<boolean>(false)
Expand Down Expand Up @@ -70,10 +60,6 @@ const BoardsSwitcher = (props: Props): JSX.Element => {
}
}

const handleCreateNewCategory = () => {
setShowCreateCategoryModal(true)
}

marianunez marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
document.addEventListener('keydown', handleQuickSwitchKeyPress)
document.addEventListener('keydown', handleEscKeyPress)
Expand All @@ -99,38 +85,6 @@ const BoardsSwitcher = (props: Props): JSX.Element => {
</div>
</div>
{shouldViewSearchForBoardsTour && <div><SearchForBoardsTourStep/></div>}
{
Utils.isFocalboardPlugin() && !props.userIsGuest &&
<MenuWrapper>
<IconButton
size='small'
inverted={true}
className='add-board-icon'
icon={<AddIcon/>}
title={'Add Board Dropdown'}
/>
<Menu>
<Menu.Text
id='create-new-board-option'
icon={<CompassIcon icon='plus'/>}
onClick={props.onBoardTemplateSelectorOpen}
name='Create new board'
/>
<Menu.Text
id='createNewCategory'
name={intl.formatMessage({id: 'SidebarCategories.CategoryMenu.CreateNew', defaultMessage: 'Create New Category'})}
icon={
<CompassIcon
icon='folder-plus-outline'
className='CreateNewFolderIcon'
/>
}
onClick={handleCreateNewCategory}
/>
</Menu>
</MenuWrapper>
}

{
showSwitcher &&
<BoardSwitcherDialog onClose={() => setShowSwitcher(false)}/>
Expand Down
1 change: 0 additions & 1 deletion webapp/src/components/cardDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const mockedUtils = mocked(Utils, true)
const mockedMutator = mocked(mutator, true)
const mockedOctoClient = mocked(octoClient, true)
mockedUtils.createGuid.mockReturnValue('test-id')
mockedUtils.isFocalboardPlugin.mockReturnValue(true)

beforeAll(() => {
mockDOM()
Expand Down
95 changes: 26 additions & 69 deletions webapp/src/components/cardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import ConfirmationDialogBox, {ConfirmationDialogBoxProps} from '../components/c

import Button from '../widgets/buttons/button'

import {getUserBlockSubscriptionList} from '../store/initialLoad'
import {getClientConfig} from '../store/clientConfig'

import {IUser} from '../user'
import {getMe} from '../store/users'
import {Permission} from '../constants'
import {Block, createBlock} from '../blocks/block'
import {AttachmentBlock, createAttachmentBlock} from '../blocks/attachmentBlock'
Expand Down Expand Up @@ -57,10 +52,8 @@ const CardDialog = (props: Props): JSX.Element => {
const contents = useAppSelector(getCardContents(props.cardId))
const comments = useAppSelector(getCardComments(props.cardId))
const attachments = useAppSelector(getCardAttachments(props.cardId))
const clientConfig = useAppSelector(getClientConfig)
const intl = useIntl()
const dispatch = useAppDispatch()
const me = useAppSelector<IUser|null>(getMe)
const isTemplate = card && card.fields.isTemplate

const [showConfirmationDialogBox, setShowConfirmationDialogBox] = useState<boolean>(false)
Expand Down Expand Up @@ -159,36 +152,31 @@ const CardDialog = (props: Props): JSX.Element => {
const attachmentBlock = createAttachmentBlock(uploadingBlock)
attachmentBlock.isUploading = true
dispatch(updateAttachments([attachmentBlock]))
if (attachment.size > clientConfig.maxFileSize && Utils.isFocalboardPlugin()) {
removeUploadingAttachment(uploadingBlock)
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.failed', defaultMessage: 'Unable to upload the file. Attachment size limit reached.'}), severity: 'normal'})
} else {
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.upload', defaultMessage: 'Attachment uploading.'}), severity: 'normal'})
const xhr = await octoClient.uploadAttachment(boardId, attachment)
if (xhr) {
xhr.upload.onprogress = (event) => {
const percent = Math.floor((event.loaded / event.total) * 100)
dispatch(updateUploadPrecent({
blockId: attachmentBlock.id,
uploadPercent: percent,
}))
}
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.upload', defaultMessage: 'Attachment uploading.'}), severity: 'normal'})
const xhr = await octoClient.uploadAttachment(boardId, attachment)
if (xhr) {
xhr.upload.onprogress = (event) => {
const percent = Math.floor((event.loaded / event.total) * 100)
dispatch(updateUploadPrecent({
blockId: attachmentBlock.id,
uploadPercent: percent,
}))
}

xhr.onload = () => {
if (xhr.status === 200 && xhr.readyState === 4) {
const json = JSON.parse(xhr.response)
const fileId = json.fileId
if (fileId) {
removeUploadingAttachment(uploadingBlock)
const block = createAttachmentBlock()
block.fields.fileId = fileId || ''
block.title = attachment.name
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.uploadSuccess', defaultMessage: 'Attachment uploaded successfull.'}), severity: 'normal'})
resolve(block)
} else {
removeUploadingAttachment(uploadingBlock)
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.failed', defaultMessage: 'Unable to upload the file. Attachment size limit reached.'}), severity: 'normal'})
}
xhr.onload = () => {
if (xhr.status === 200 && xhr.readyState === 4) {
const json = JSON.parse(xhr.response)
const fileId = json.fileId
if (fileId) {
removeUploadingAttachment(uploadingBlock)
const block = createAttachmentBlock()
block.fields.fileId = fileId || ''
block.title = attachment.name
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.uploadSuccess', defaultMessage: 'Attachment uploaded successfull.'}), severity: 'normal'})
resolve(block)
} else {
removeUploadingAttachment(uploadingBlock)
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.failed', defaultMessage: 'Unable to upload the file. Attachment size limit reached.'}), severity: 'normal'})
}
}
}
Expand Down Expand Up @@ -236,42 +224,11 @@ const CardDialog = (props: Props): JSX.Element => {
)
}

const followActionButton = (following: boolean): React.ReactNode => {
const followBtn = (
<>
<Button
className='cardFollowBtn follow'
emphasis='gray'
size='medium'
onClick={() => mutator.followBlock(props.cardId, 'card', me!.id)}
>
{intl.formatMessage({id: 'CardDetail.Follow', defaultMessage: 'Follow'})}
</Button>
</>
)

const unfollowBtn = (
<>
<Button
className='cardFollowBtn unfollow'
emphasis='tertiary'
size='medium'
onClick={() => mutator.unfollowBlock(props.cardId, 'card', me!.id)}
>
{intl.formatMessage({id: 'CardDetail.Following', defaultMessage: 'Following'})}
</Button>
</>
)

if (!isTemplate && Utils.isFocalboardPlugin() && !card?.limited) {
return (<>{attachBtn()}{following ? unfollowBtn : followBtn}</>)
}
const followActionButton = (): React.ReactNode => {
return (<>{attachBtn()}</>)
}

const followingCards = useAppSelector(getUserBlockSubscriptionList)
const isFollowingCard = Boolean(followingCards.find((following) => following.blockId === props.cardId))
const toolbar = followActionButton(isFollowingCard)
const toolbar = followActionButton()
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
Expand Down
13 changes: 2 additions & 11 deletions webapp/src/components/kanban/kanbanCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useState, useCallback, useMemo} from 'react'
import {useRouteMatch} from 'react-router-dom'
import {useIntl} from 'react-intl'

import {Board, IPropertyTemplate} from '../../blocks/board'
Expand All @@ -16,8 +15,6 @@ import PropertyValueElement from '../propertyValueElement'
import ConfirmationDialogBox, {ConfirmationDialogBoxProps} from '../confirmationDialogBox'
import './kanbanCard.scss'
import CardBadges from '../cardBadges'
import OpenCardTourStep from '../onboardingTour/openCard/open_card'
import CopyLinkTourStep from '../onboardingTour/copyLink/copy_link'
import CardActionsMenu from '../cardActionsMenu/cardActionsMenu'
import CardActionsMenuIcon from '../cardActionsMenu/cardActionsMenuIcon'

Expand All @@ -41,7 +38,6 @@ const KanbanCard = (props: Props) => {
const intl = useIntl()
const [isDragging, isOver, cardRef] = useSortable('card', card, !props.readonly, props.onDrop)
const visiblePropertyTemplates = props.visiblePropertyTemplates || []
const match = useRouteMatch<{boardId: string, viewId: string, cardId?: string}>()
let className = props.isSelected ? 'KanbanCard selected' : 'KanbanCard'
if (props.isManualSort && isOver) {
className += ' dragover'
Expand Down Expand Up @@ -85,21 +81,18 @@ const KanbanCard = (props: Props) => {
}
}, [props.onClick, card])

const isOnboardingCard = card.title === 'Create a new card'
const showOnboarding = isOnboardingCard && !match.params.cardId && !board.isTemplate && Utils.isFocalboardPlugin()

return (
<>
<div
ref={props.readonly ? () => null : cardRef}
className={`${className} ${showOnboarding && OnboardingCardClassName}`}
className={`${className}`}
draggable={!props.readonly}
style={{opacity: isDragging ? 0.5 : 1}}
onClick={handleOnClick}
>
{!props.readonly &&
<MenuWrapper
className={`optionsMenu ${showOnboarding ? 'show' : ''}`}
className={'optionsMenu'}
stopPropagationOnToggle={true}
>
<CardActionsMenuIcon/>
Expand Down Expand Up @@ -152,8 +145,6 @@ const KanbanCard = (props: Props) => {
</Tooltip>
))}
{props.visibleBadges && <CardBadges card={card}/>}
{showOnboarding && !match.params.cardId && <OpenCardTourStep/>}
{showOnboarding && !match.params.cardId && <CopyLinkTourStep/>}
</div>

{showConfirmationDialogBox && <ConfirmationDialogBox dialogBox={confirmDialogProps}/>}
Expand Down
Loading
Loading