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

fix: module boards can trigger mousedown events #402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/shell/boards/board-container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ describe('Board container', () => {
jest.advanceTimersToNextTimer();
});
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
const boardInitialSizeAndPos = buildBoardSizeAndPosition();
const boardNewPosition = {
top: 0,
Expand All @@ -702,7 +703,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 0, clientY: 0 },
boardNewPosition
boardNewPosition,
elementForMove
);
expect(board).toHaveStyle({
height: '70vh',
Expand All @@ -719,6 +721,7 @@ describe('Board container', () => {
jest.advanceTimersToNextTimer();
});
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
let boardInitialSizeAndPos = buildBoardSizeAndPosition();
let boardNewPosition = {
top: 10,
Expand All @@ -729,7 +732,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 10, clientY: 10 },
boardNewPosition
boardNewPosition,
elementForMove
);
boardInitialSizeAndPos = buildBoardSizeAndPosition({
...boardInitialSizeAndPos,
Expand All @@ -744,7 +748,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 80, clientY: 50 },
boardNewPosition
boardNewPosition,
elementForMove
);
expect(board).toHaveStyle({
height: '70vh',
Expand All @@ -762,6 +767,7 @@ describe('Board container', () => {
});
const border: Border = 'n';
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
const boardInitialSizeAndPos = buildBoardSizeAndPosition();
const mouseInitialPos = buildMousePosition(border, boardInitialSizeAndPos);
const deltaY = -50;
Expand Down Expand Up @@ -793,7 +799,8 @@ describe('Board container', () => {
clientY: boardNewInitialSizeAndPos.clientTop
},
{ clientX: 0, clientY: 0 },
boardNewSizeAndPos
boardNewSizeAndPos,
elementForMove
);
expect(board).toHaveStyle({
height: `${boardNewSizeAndPos.height}px`,
Expand All @@ -811,6 +818,7 @@ describe('Board container', () => {
});
const border: Border = 'n';
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
const boardInitialSizeAndPos = buildBoardSizeAndPosition();
const mouseInitialPos = buildMousePosition(border, boardInitialSizeAndPos);
const deltaY = -50;
Expand Down Expand Up @@ -844,7 +852,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 0, clientY: 0 },
boardNewPos
boardNewPos,
elementForMove
);
expect(board).toHaveStyle({
height: '70vh',
Expand All @@ -869,6 +878,7 @@ describe('Board container', () => {
jest.advanceTimersToNextTimer();
});
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
const actionElement = getAllByRoleWithIcon('button', { icon })[0];
let boardInitialSizeAndPos = buildBoardSizeAndPosition();
let boardNewPosition = {
Expand All @@ -880,7 +890,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 0, clientY: 0 },
boardNewPosition
boardNewPosition,
elementForMove
);
boardInitialSizeAndPos = buildBoardSizeAndPosition({
...boardInitialSizeAndPos,
Expand Down Expand Up @@ -986,6 +997,7 @@ describe('Board container', () => {
jest.advanceTimersToNextTimer();
});
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
const boardInitialSizeAndPos = buildBoardSizeAndPosition();
const boardNewPosition = {
top: 0,
Expand All @@ -996,7 +1008,8 @@ describe('Board container', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 0, clientY: 0 },
boardNewPosition
boardNewPosition,
elementForMove
);
await user.click(getByRoleWithIcon('button', { icon: ICONS.closeBoard }));
act(() => {
Expand Down
7 changes: 5 additions & 2 deletions src/shell/boards/board-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
return lastSavedPosition;
}

export const BoardContainer = (): React.JSX.Element | null => {

Check failure on line 192 in src/shell/boards/board-container.tsx

View check run for this annotation

Sonarqube Zextras / carbonio-shell-ui Sonarqube Results

src/shell/boards/board-container.tsx#L192

Refactor this function to reduce its Cognitive Complexity from 44 to the 15 allowed.
const t = getT();
const { boards, minimized, expanded, current, orderedBoards } = useBoardStore();

Expand Down Expand Up @@ -354,15 +354,18 @@
ref={boardRef}
width={currentBoardSizeAndPosition.width}
height={currentBoardSizeAndPosition.height}
onMouseDown={(!expanded && moveElementHandler) || undefined}
>
<ResizableContainer
crossAlignment={'unset'}
elementToResize={boardRef}
localStorageKey={LOCAL_STORAGE_BOARD_SIZE}
disabled={expanded}
>
<BoardHeader background={'gray5'}>
<BoardHeader
data-testid="BoardHeader"
background={'gray5'}
onMouseDown={(!expanded && moveElementHandler) || undefined}
>
<Padding all="extrasmall">
<Tooltip label={t('board.hide', 'Hide board')} placement="top" disabled={isMoving}>
<BackButton icon="BoardCollapseOutline" onClick={clickHandler(minimizeBoards)} />
Expand Down
3 changes: 1 addition & 2 deletions src/shell/boards/board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Board } from '../../../types';
import AppContextProvider from '../../boot/app/app-context-provider';
import { useAppStore } from '../../store/app';
import { BoardProvider, updateBoard, useBoardStore } from '../../store/boards';
import { stopPropagation } from '../../utils/utils';

const BoardContainer = styled.div<{ show: boolean }>`
display: ${(props): string => (props.show ? 'block' : 'none')};
Expand Down Expand Up @@ -75,7 +74,7 @@ export const AppBoard: FC<{ board: Board }> = ({ board }) => {
}, [board.url, history]);

return (
<BoardContainer show={current === board.id} onMouseDown={stopPropagation}>
<BoardContainer show={current === board.id}>
<Router history={history}>{route}</Router>
</BoardContainer>
);
Expand Down
12 changes: 9 additions & 3 deletions src/shell/shell-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('Shell view', () => {
});
const border: Border = 'n';
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
let boardInitialSizeAndPos = buildBoardSizeAndPosition();
const mouseInitialPos = buildMousePosition(border, boardInitialSizeAndPos);
const deltaY = -50;
Expand Down Expand Up @@ -111,7 +112,8 @@ describe('Shell view', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 500, clientY: 500 },
boardNewSizeAndPos
boardNewSizeAndPos,
elementForMove
);
await user.click(getByRoleWithIcon('button', { icon: ICONS.collapseBoard }));
await user.click(getByRoleWithIcon('button', { icon: ICONS.unCollapseBoard }));
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('Shell view', () => {
});
const border: Border = 'n';
const board = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove = screen.getByTestId(TESTID_SELECTORS.boardHeader);
let boardInitialSizeAndPos = buildBoardSizeAndPosition();
const mouseInitialPos = buildMousePosition(border, boardInitialSizeAndPos);
const deltaY = -50;
Expand All @@ -214,7 +217,8 @@ describe('Shell view', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 0, clientY: 0 },
boardNewSizeAndPos
boardNewSizeAndPos,
elementForMove
);
await user.click(getAllByRoleWithIcon('button', { icon: ICONS.close })[0]);
// update state to open a new board
Expand All @@ -236,6 +240,7 @@ describe('Shell view', () => {
jest.advanceTimersToNextTimer();
});
const board2Element = screen.getByTestId(TESTID_SELECTORS.board);
const elementForMove2 = screen.getByTestId(TESTID_SELECTORS.boardHeader);
boardInitialSizeAndPos = buildBoardSizeAndPosition({
...INITIAL_SIZE_AND_POS,
width: boardNewSizeAndPos.width,
Expand All @@ -247,7 +252,8 @@ describe('Shell view', () => {
boardInitialSizeAndPos,
{ clientX: boardInitialSizeAndPos.clientLeft, clientY: boardInitialSizeAndPos.clientTop },
{ clientX: 80, clientY: 55 },
boardNewSizeAndPos
boardNewSizeAndPos,
elementForMove2
);
expect(board2Element).toHaveStyle({
height: `${boardNewSizeAndPos.height}px`,
Expand Down
1 change: 1 addition & 0 deletions src/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const ICONS = {

export const TESTID_SELECTORS = {
board: 'NewItemContainer',
boardHeader: 'BoardHeader',
checkbox: 'checkbox',
dropdown: 'dropdown-popper-list',
resizableBorder(border: Border): string {
Expand Down