Skip to content

Commit

Permalink
MM-62104 Fix board disappearing or move to default category when swit…
Browse files Browse the repository at this point in the history
…ching teams (#44)

* MM-62104 Fix board disappearing or move to default category when switching teams

* fix tests
  • Loading branch information
Rajat-Dabade authored Dec 12, 2024
1 parent 709f339 commit 5dbf729
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions webapp/src/components/sidebar/sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {createMemoryHistory} from 'history'
import {Provider as ReduxProvider} from 'react-redux'
import {Router} from 'react-router-dom'

import {render} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import {render, waitFor} from '@testing-library/react'

import thunk from 'redux-thunk'

import {mocked} from 'jest-mock'

import userEvent from '@testing-library/user-event'

import {mockMatchMedia, wrapIntl} from '../../testUtils'

import {TestBlockFactory} from '../../test/testBlockFactory'
Expand Down Expand Up @@ -306,7 +307,7 @@ describe('components/sidebarSidebar', () => {
expect(sidebarCollapsedCategory.length).toBe(1)
})

test('should assign default category if current board doesnt have a category', () => {
test('should assign default category if current board doesnt have a category', async () => {
const board2 = TestBlockFactory.createBoard()
board2.id = 'board2'

Expand Down Expand Up @@ -362,7 +363,9 @@ describe('components/sidebarSidebar', () => {
const {container} = render(component)
expect(container).toMatchSnapshot()

expect(mockedOctoClient.moveBoardToCategory).toBeCalledWith('team-id', 'board2', 'default_category', '')
await waitFor(() =>
expect(mockedOctoClient.moveBoardToCategory).toBeCalledWith('team-id', 'board2', 'default_category', '')
)
})

test('shouldnt do any category assignment is board is in a category', () => {
Expand Down
12 changes: 8 additions & 4 deletions webapp/src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const Sidebar = (props: Props) => {
const me = useAppSelector<IUser|null>(getMe)
const activeViewID = useAppSelector(getCurrentViewId)
const currentBoard = useAppSelector(getCurrentBoard)
const [initialized, setInitialized] = useState(false)

useEffect(() => {
const categoryOnChangeHandler = (_: WSClient, categories: Category[]) => {
Expand All @@ -98,11 +99,14 @@ const Sidebar = (props: Props) => {
const team = useAppSelector(getCurrentTeam)

useEffect(() => {
setInitialized(false)
if (team) {
dispatch(fetchSidebarCategories(team!.id))
dispatch(fetchSidebarCategories(team!.id)).then(() => {
setInitialized(true)
})
}
loadTheme()
}, [team?.id])
}, [team?.id, dispatch])

useEffect(() => {
function handleResize() {
Expand All @@ -125,7 +129,7 @@ const Sidebar = (props: Props) => {
// because there is no good, explicit API call to add this logic to when opening
// a board that you have implicit access to.
useEffect(() => {
if (!sidebarCategories || sidebarCategories.length === 0 || !currentBoard || !team || currentBoard.isTemplate) {
if (!initialized || !sidebarCategories || sidebarCategories.length === 0 || !currentBoard || !team || currentBoard.isTemplate) {
return
}

Expand All @@ -147,7 +151,7 @@ const Sidebar = (props: Props) => {
}

octoClient.moveBoardToCategory(team.id, currentBoard.id, boardsCategory.id, '')
}, [sidebarCategories, currentBoard, team])
}, [sidebarCategories, currentBoard, team, initialized])

useWebsockets(teamId, (websocketClient: WSClient) => {
const onCategoryReorderHandler = (_: WSClient, newCategoryOrder: string[]): void => {
Expand Down

0 comments on commit 5dbf729

Please sign in to comment.