From 9e507fc2099140779c84cd51292af67c1b56a9d2 Mon Sep 17 00:00:00 2001 From: Harshil Sharma Date: Thu, 31 Mar 2022 17:55:29 +0530 Subject: [PATCH] Adde missing board menu options in sidebar --- .../boardTemplateSelector.test.tsx | 1 - .../boardTemplateSelector.tsx | 6 +++-- .../boardTemplateSelectorItem.tsx | 7 +++--- webapp/src/components/sidebar/sidebar.tsx | 4 ++- webapp/src/constants.ts | 2 ++ webapp/src/mutator.ts | 2 +- webapp/src/octoClient.ts | 5 ++-- webapp/src/pages/boardPage/boardPage.tsx | 6 +++-- .../boardPage/teamToBoardAndViewRedirect.tsx | 3 ++- .../pages/boardPage/websocketConnection.tsx | 11 ++++---- webapp/src/store/globalTemplates.ts | 4 ++- webapp/src/utils.test.ts | 25 +++++++++++++++++++ 12 files changed, 57 insertions(+), 19 deletions(-) diff --git a/webapp/src/components/boardTemplateSelector/boardTemplateSelector.test.tsx b/webapp/src/components/boardTemplateSelector/boardTemplateSelector.test.tsx index fea3ddf8a..b683903db 100644 --- a/webapp/src/components/boardTemplateSelector/boardTemplateSelector.test.tsx +++ b/webapp/src/components/boardTemplateSelector/boardTemplateSelector.test.tsx @@ -231,7 +231,6 @@ describe('components/boardTemplateSelector/boardTemplateSelector', () => { const editIcon = screen.getByText(template1Title).parentElement?.querySelector('.EditIcon') expect(editIcon).not.toBeNull() userEvent.click(editIcon!) - expect(history.push).toBeCalledTimes(1) }) test('return BoardTemplateSelector and click to add board from template', async () => { render(wrapDNDIntl( diff --git a/webapp/src/components/boardTemplateSelector/boardTemplateSelector.tsx b/webapp/src/components/boardTemplateSelector/boardTemplateSelector.tsx index a39d0bd5b..92354d906 100644 --- a/webapp/src/components/boardTemplateSelector/boardTemplateSelector.tsx +++ b/webapp/src/components/boardTemplateSelector/boardTemplateSelector.tsx @@ -25,6 +25,8 @@ import {BaseTourSteps, TOUR_BASE} from '../onboardingTour' import {Utils} from "../../utils" +import {Constants} from "../../constants" + import BoardTemplateSelectorPreview from './boardTemplateSelectorPreview' import BoardTemplateSelectorItem from './boardTemplateSelectorItem' @@ -53,7 +55,7 @@ const BoardTemplateSelector = (props: Props) => { }, [match, history, onClose]) useEffect(() => { - if (octoClient.teamId !== '0' && globalTemplates.length === 0) { + if (octoClient.teamId !== Constants.globalTeamId && globalTemplates.length === 0) { dispatch(fetchGlobalTemplates()) } }, [octoClient.teamId]) @@ -95,7 +97,7 @@ const BoardTemplateSelector = (props: Props) => { } const handleUseTemplate = async () => { - await mutator.addBoardFromTemplate(currentTeam?.id || '0', intl, showBoard, () => showBoard(currentBoardId), activeTemplate.id, currentTeam?.id) + await mutator.addBoardFromTemplate(currentTeam?.id || Constants.globalTeamId, intl, showBoard, () => showBoard(currentBoardId), activeTemplate.id, currentTeam?.id) if (activeTemplate.title === OnboardingBoardTitle) { resetTour() } diff --git a/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.tsx b/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.tsx index 4a056899c..f1aa5a0df 100644 --- a/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.tsx +++ b/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.tsx @@ -10,6 +10,7 @@ import EditIcon from '../../widgets/icons/edit' import DeleteBoardDialog from '../sidebar/deleteBoardDialog' import './boardTemplateSelectorItem.scss' +import {Constants} from "../../constants" type Props = { isActive: boolean @@ -31,8 +32,6 @@ const BoardTemplateSelectorItem = (props: Props) => { onEdit(template.id) }, [onEdit, template]) - console.log(`Template Metadata: name: ${template.title} template version: ${template.templateVersion}`) - return (
{ > {template.icon} {template.title} - {!template.templateVersion && + + {/* don't show template menu options for default templates */} + {template.teamId !== Constants.globalTeamId &&
} diff --git a/webapp/src/components/sidebar/sidebar.tsx b/webapp/src/components/sidebar/sidebar.tsx index 596a96561..ba7efb4b2 100644 --- a/webapp/src/components/sidebar/sidebar.tsx +++ b/webapp/src/components/sidebar/sidebar.tsx @@ -29,6 +29,8 @@ import wsClient, {WSClient} from '../../wsclient' import {getCurrentTeam} from '../../store/teams' +import {Constants} from "../../constants" + import SidebarCategory from './sidebarCategory' import SidebarSettingsMenu from './sidebarSettingsMenu' import SidebarUserMenu from './sidebarUserMenu' @@ -152,7 +154,7 @@ const Sidebar = (props: Props) => {
} - {team && team.id !== '0' && + {team && team.id !== Constants.globalTeamId &&
{Utils.isFocalboardPlugin() && <> diff --git a/webapp/src/constants.ts b/webapp/src/constants.ts index 4159c1310..fe55d024a 100644 --- a/webapp/src/constants.ts +++ b/webapp/src/constants.ts @@ -186,6 +186,8 @@ class Constants { Y: ['y', 89], Z: ['z', 90], } + + static readonly globalTeamId = '0' } export {Constants, Permission} diff --git a/webapp/src/mutator.ts b/webapp/src/mutator.ts index c8e617b17..a7f49d321 100644 --- a/webapp/src/mutator.ts +++ b/webapp/src/mutator.ts @@ -1047,7 +1047,7 @@ class Mutator { beforeUndo: () => Promise, boardTemplateId: string, toTeam?: string, - ): Promise<[Block[], string]> { + ): Promise { const asTemplate = false const actionDescription = intl.formatMessage({id: 'Mutator.new-board-from-template', defaultMessage: 'new board from template'}) diff --git a/webapp/src/octoClient.ts b/webapp/src/octoClient.ts index 36f5a0e13..619d509c5 100644 --- a/webapp/src/octoClient.ts +++ b/webapp/src/octoClient.ts @@ -12,6 +12,7 @@ import {Category, CategoryBlocks} from './store/sidebar' import {Team} from './store/teams' import {Subscription} from './wsclient' import {PrepareOnboardingResponse} from './onboardingTour' +import {Constants} from "./constants" // // OctoClient is the client interface to the server APIs @@ -45,7 +46,7 @@ class OctoClient { localStorage.setItem('focalboardSessionId', value) } - constructor(serverUrl?: string, public teamId = '0') { + constructor(serverUrl?: string, public teamId = Constants.globalTeamId) { this.serverUrl = serverUrl } @@ -144,7 +145,7 @@ class OctoClient { private teamPath(teamId?: string): string { let teamIdToUse = teamId if (!teamId) { - teamIdToUse = this.teamId === '0' ? UserSettings.lastTeamId || this.teamId : this.teamId + teamIdToUse = this.teamId === Constants.globalTeamId ? UserSettings.lastTeamId || this.teamId : this.teamId } return `/api/v1/teams/${teamIdToUse}` diff --git a/webapp/src/pages/boardPage/boardPage.tsx b/webapp/src/pages/boardPage/boardPage.tsx index 523441904..3fa138d1b 100644 --- a/webapp/src/pages/boardPage/boardPage.tsx +++ b/webapp/src/pages/boardPage/boardPage.tsx @@ -22,6 +22,8 @@ import TelemetryClient, {TelemetryActions, TelemetryCategory} from '../../teleme import {fetchUserBlockSubscriptions, getMe} from '../../store/users' import {IUser} from '../../user' +import {Constants} from "../../constants" + import SetWindowTitleAndIcon from './setWindowTitleAndIcon' import TeamToBoardAndViewRedirect from './teamToBoardAndViewRedirect' import UndoRedoHotKeys from './undoRedoHotKeys' @@ -41,7 +43,7 @@ const BoardPage = (props: Props): JSX.Element => { const dispatch = useAppDispatch() const match = useRouteMatch<{boardId: string, viewId: string, cardId?: string, teamId?: string}>() const [mobileWarningClosed, setMobileWarningClosed] = useState(UserSettings.mobileWarningClosed) - const teamId = match.params.teamId || UserSettings.lastTeamId || '0' + const teamId = match.params.teamId || UserSettings.lastTeamId || Constants.globalTeamId const me = useAppSelector(getMe) // if we're in a legacy route and not showing a shared board, @@ -110,7 +112,7 @@ const BoardPage = (props: Props): JSX.Element => { // and set it as most recently viewed board UserSettings.setLastBoardID(teamId, match.params.boardId) - if (match.params.viewId && match.params.viewId !== '0') { + if (match.params.viewId && match.params.viewId !== Constants.globalTeamId) { dispatch(setCurrentView(match.params.viewId)) UserSettings.setLastViewId(match.params.boardId, match.params.viewId) } diff --git a/webapp/src/pages/boardPage/teamToBoardAndViewRedirect.tsx b/webapp/src/pages/boardPage/teamToBoardAndViewRedirect.tsx index ac890256c..e52744d56 100644 --- a/webapp/src/pages/boardPage/teamToBoardAndViewRedirect.tsx +++ b/webapp/src/pages/boardPage/teamToBoardAndViewRedirect.tsx @@ -8,6 +8,7 @@ import {setCurrent as setCurrentView, getCurrentBoardViews} from '../../store/vi import {useAppSelector, useAppDispatch} from '../../store/hooks' import {UserSettings} from '../../userSettings' import {getSidebarCategories} from '../../store/sidebar' +import {Constants} from "../../constants" const TeamToBoardAndViewRedirect = (): null => { const boardId = useAppSelector(getCurrentBoardId) @@ -16,7 +17,7 @@ const TeamToBoardAndViewRedirect = (): null => { const history = useHistory() const match = useRouteMatch<{boardId: string, viewId: string, cardId?: string, teamId?: string}>() const categories = useAppSelector(getSidebarCategories) - const teamId = match.params.teamId || UserSettings.lastTeamId || '0' + const teamId = match.params.teamId || UserSettings.lastTeamId || Constants.globalTeamId useEffect(() => { let boardID = match.params.boardId diff --git a/webapp/src/pages/boardPage/websocketConnection.tsx b/webapp/src/pages/boardPage/websocketConnection.tsx index 960c99077..09b75cad5 100644 --- a/webapp/src/pages/boardPage/websocketConnection.tsx +++ b/webapp/src/pages/boardPage/websocketConnection.tsx @@ -22,6 +22,7 @@ import {useAppSelector, useAppDispatch} from '../../store/hooks' import {followBlock, getMe, unfollowBlock} from '../../store/users' import {IUser} from '../../user' +import {Constants} from "../../constants" const websocketTimeoutForBanner = 5000 @@ -49,8 +50,8 @@ const WebsocketConnection = (props: Props) => { useEffect(() => { let subscribedToTeam = false if (wsClient.state === 'open') { - wsClient.authenticate(props.teamId || '0', token) - wsClient.subscribeToTeam(props.teamId || '0') + wsClient.authenticate(props.teamId || Constants.globalTeamId, token) + wsClient.subscribeToTeam(props.teamId || Constants.globalTeamId) subscribedToTeam = true } @@ -71,7 +72,7 @@ const WebsocketConnection = (props: Props) => { const incrementalBoardUpdate = (_: WSClient, boards: Board[]) => { // only takes into account the entities that belong to the team or the user boards - const teamBoards = boards.filter((b: Board) => b.teamId === '0' || b.teamId === props.teamId) + const teamBoards = boards.filter((b: Board) => b.teamId === Constants.globalTeamId || b.teamId === props.teamId) dispatch(updateBoards(teamBoards)) } @@ -83,8 +84,8 @@ const WebsocketConnection = (props: Props) => { const updateWebsocketState = (_: WSClient, newState: 'init'|'open'|'close'): void => { if (newState === 'open') { const newToken = localStorage.getItem('focalboardSessionId') || '' - wsClient.authenticate(props.teamId || '0', newToken) - wsClient.subscribeToTeam(props.teamId || '0') + wsClient.authenticate(props.teamId || Constants.globalTeamId, newToken) + wsClient.subscribeToTeam(props.teamId || Constants.globalTeamId) subscribedToTeam = true } diff --git a/webapp/src/store/globalTemplates.ts b/webapp/src/store/globalTemplates.ts index b7b0ae2ec..9352aa2e5 100644 --- a/webapp/src/store/globalTemplates.ts +++ b/webapp/src/store/globalTemplates.ts @@ -6,6 +6,8 @@ import {createSlice, createAsyncThunk} from '@reduxjs/toolkit' import {default as client} from '../octoClient' import {Board} from '../blocks/board' +import {Constants} from "../constants" + import {RootState} from './index' // ToDo: move this to team templates or simply templates @@ -13,7 +15,7 @@ import {RootState} from './index' export const fetchGlobalTemplates = createAsyncThunk( 'globalTemplates/fetch', async () => { - const templates = await client.getTeamTemplates('0') + const templates = await client.getTeamTemplates(Constants.globalTeamId) return templates.sort((a, b) => a.title.localeCompare(b.title)) }, ) diff --git a/webapp/src/utils.test.ts b/webapp/src/utils.test.ts index 5e98b8d92..510ea8789 100644 --- a/webapp/src/utils.test.ts +++ b/webapp/src/utils.test.ts @@ -3,6 +3,10 @@ import {createIntl} from 'react-intl' +import {createMemoryHistory} from "history" + +import {match as routerMatch} from "react-router-dom" + import {Utils, IDType} from './utils' import {IAppWindow} from './types' @@ -161,4 +165,25 @@ describe('utils', () => { expect(Utils.compareVersions('10.9.4', '10.9.2')).toBe(-1) }) }) + + describe('showBoard test', () => { + it('should switch boards', () => { + const match = { + params: { + boardId: 'board_id_1', + viewId: 'view_id_1', + cardId: 'card_id_1', + teamId: 'team_id_1', + }, + path: '/team/:teamId/:boardId?/:viewId?/:cardId?', + } as unknown as routerMatch<{boardId: string, viewId?: string, cardId?: string, teamId?: string}> + + const history = createMemoryHistory() + history.push = jest.fn() + + Utils.showBoard('board_id_2', match, history) + + expect(history.push).toBeCalledWith('/team/team_id_1/board_id_2') + }) + }) })