1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-05 14:50:29 +02:00

Adde missing board menu options in sidebar

This commit is contained in:
Harshil Sharma 2022-03-31 17:55:29 +05:30
parent 9d6a26e230
commit 9e507fc209
12 changed files with 57 additions and 19 deletions

View File

@ -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(

View File

@ -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()
}

View File

@ -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 (
<div
className={isActive ? 'BoardTemplateSelectorItem active' : 'BoardTemplateSelectorItem'}
@ -40,7 +39,9 @@ const BoardTemplateSelectorItem = (props: Props) => {
>
<span className='template-icon'>{template.icon}</span>
<span className='template-name'>{template.title}</span>
{!template.templateVersion &&
{/* don't show template menu options for default templates */}
{template.teamId !== Constants.globalTeamId &&
<div className='actions'>
<IconButton
icon={<DeleteIcon/>}

View File

@ -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) => {
</div>
</div>}
{team && team.id !== '0' &&
{team && team.id !== Constants.globalTeamId &&
<div className='WorkspaceTitle'>
{Utils.isFocalboardPlugin() &&
<>

View File

@ -186,6 +186,8 @@ class Constants {
Y: ['y', 89],
Z: ['z', 90],
}
static readonly globalTeamId = '0'
}
export {Constants, Permission}

View File

@ -1047,7 +1047,7 @@ class Mutator {
beforeUndo: () => Promise<void>,
boardTemplateId: string,
toTeam?: string,
): Promise<[Block[], string]> {
): Promise<BoardsAndBlocks> {
const asTemplate = false
const actionDescription = intl.formatMessage({id: 'Mutator.new-board-from-template', defaultMessage: 'new board from template'})

View File

@ -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}`

View File

@ -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<IUser|null>(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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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))
},
)

View File

@ -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')
})
})
})