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

BC-7008 - Implement element socket actions #3245

Merged
merged 69 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1b81539
add initial pinia implementation
muratmerdoglu-dp May 14, 2024
99bf893
fix move card by keyboard for rest api, improve coverage
NFriedo May 14, 2024
f8bc8da
refactor createElement in cardStore
hoeppner-dataport May 15, 2024
5c1d59d
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 15, 2024
d455ee7
refactor deleteElement in cardStore
hoeppner-dataport May 15, 2024
a3678ed
fix: type issue
hoeppner-dataport May 15, 2024
7ec736f
chore: fix type issue
hoeppner-dataport May 15, 2024
077e85a
chore: fix type issue
hoeppner-dataport May 15, 2024
bc20cd4
add tests for createElement and deleteElement in cardSocketApi
NFriedo May 15, 2024
1bd954f
fix add element dialog tests
NFriedo May 15, 2024
89cd3aa
refactor: moveElement in cardStore
hoeppner-dataport May 15, 2024
f6924b6
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 15, 2024
d8edcd3
add cardRestApi tests for create and delete Element
NFriedo May 15, 2024
ab73e12
refactor updateElement in cardStore
hoeppner-dataport May 15, 2024
92090ad
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 15, 2024
4062f27
add control to switch to edit mode after creating a card
muratmerdoglu-dp May 16, 2024
0fd5aba
add cardRestApi test for updateElement, adjust fetchBoardRequest test
NFriedo May 16, 2024
fa937d5
add cardRestApi test for moveElement
NFriedo May 16, 2024
cfcd4fc
add carddSocketApi test for moveElement und updateElement
NFriedo May 16, 2024
23df460
fix ContentElementState unit test
muratmerdoglu-dp May 16, 2024
16a4942
fix CardHost unit test
muratmerdoglu-dp May 16, 2024
482cdf5
fix Board.store unit test failing
muratmerdoglu-dp May 16, 2024
bcfe6a1
Merge branch 'main' into BC-7008-element-socket-actions
muratmerdoglu-dp May 17, 2024
0874803
fix: some tests in card.store.unit.ts
hoeppner-dataport May 17, 2024
a31fc72
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 17, 2024
9a3572b
fix: resizing of boardTitle
hoeppner-dataport May 17, 2024
c462d14
Merge branch 'main' into BC-7008-element-socket-actions
NFriedo May 17, 2024
f80142b
fix Card store unit tests
muratmerdoglu-dp May 17, 2024
b5e7c97
Merge branch 'BC-7008-element-socket-actions' of https://github.com/h…
muratmerdoglu-dp May 17, 2024
dd44439
fix test
NFriedo May 17, 2024
6fd77c4
fix: card movements
hoeppner-dataport May 17, 2024
ab1bc76
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 17, 2024
7591e8e
fix: some tests
hoeppner-dataport May 17, 2024
5fdce42
fix board store unit tests
NFriedo May 17, 2024
d07658b
fix setup for board column unit ts
NFriedo May 17, 2024
6719f08
fix: some tests
hoeppner-dataport May 17, 2024
9c94e4b
fix moveCard related unit tests
muratmerdoglu-dp May 19, 2024
b85c983
chore: remove unnecessary import
muratmerdoglu-dp May 19, 2024
2f5ce59
chore: fix tests
hoeppner-dataport May 21, 2024
917d43e
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 21, 2024
e9aea00
add tests for board store, improve test coverage
NFriedo May 21, 2024
6d9f671
fix sonarcloud issues in board store
NFriedo May 21, 2024
2117a18
chore: fixing some tests of CardStore
hoeppner-dataport May 21, 2024
b3bdfb2
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 21, 2024
92733f0
fix: problem with not automatically opening file upload dialog
hoeppner-dataport May 21, 2024
e10a960
fix card store unit tests, improve test coverage
NFriedo May 21, 2024
aab6d17
fix updateElement tests, improve coverage
NFriedo May 22, 2024
d10b8f0
improve coverage
NFriedo May 22, 2024
aa747a7
adjust card store unit tests
NFriedo May 22, 2024
232f2b0
adjust boardRestApi moveCard tests
NFriedo May 22, 2024
9f12080
fix: hidden addCard-button
hoeppner-dataport May 22, 2024
a6a39f2
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 22, 2024
6a84692
fix: file element is not shown for other clients
hoeppner-dataport May 22, 2024
2e7eb85
Merge branch 'main' of github.com:hpi-schul-cloud/nuxt-client into BC…
hoeppner-dataport May 23, 2024
3b29a25
fix: problem with moving card by keyboard into new column
hoeppner-dataport May 23, 2024
f8c390e
chore: fix boardRestApi unit test
muratmerdoglu-dp May 23, 2024
97dda51
fix focus column header
NFriedo May 23, 2024
baf11e1
add isOwnAction-property to success-actions
hoeppner-dataport May 23, 2024
0826ed4
add debounces for text inputs in FileElement
hoeppner-dataport May 23, 2024
e0f375f
improved focus handling for originator and listeners
hoeppner-dataport May 23, 2024
ff6e00c
fix card store tests
NFriedo May 23, 2024
62217c5
improve test coverage card store test
NFriedo May 23, 2024
7e8e192
fix boardSocketApi tests
NFriedo May 23, 2024
52c45a5
fix cardSocketApi test
hoeppner-dataport May 23, 2024
11c9e52
fix cardRestApi unit tests
muratmerdoglu-dp May 23, 2024
5f5c183
fix: FileContent unit test
hoeppner-dataport May 23, 2024
4056741
fix boardRestApi unit tests
muratmerdoglu-dp May 23, 2024
3d579fe
fix: BoardStore unit-tests
hoeppner-dataport May 23, 2024
d4f43e1
Merge branch 'BC-7008-element-socket-actions' of github.com:hpi-schul…
hoeppner-dataport May 23, 2024
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
123 changes: 54 additions & 69 deletions src/modules/data/board/Board.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useBoardRestApi } from "./boardActions/boardRestApi.composable";
import { useBoardSocketApi } from "./boardActions/boardSocketApi.composable";
import { useBoardFocusHandler } from "./BoardFocusHandler.composable";
import { useSharedEditMode } from "./EditMode.composable";
import { CardMove } from "@/types/board/DragAndDrop";
import { ColumnResponse } from "@/serverApi/v3";
import { envConfigModule } from "@/store";
import {
CreateCardRequestPayload,
Expand All @@ -18,7 +16,6 @@ import {
DisconnectSocketRequestPayload,
FetchBoardRequestPayload,
FetchBoardSuccessPayload,
MoveCardRequestPayload,
MoveCardSuccessPayload,
MoveColumnRequestPayload,
MoveColumnSuccessPayload,
Expand All @@ -43,6 +40,8 @@ export const useBoardStore = defineStore("boardStore", () => {

const { setEditModeId } = useSharedEditMode();

const getLastColumnIndex = () => board.value!.columns.length - 1;

const getColumnIndex = (columnId: string | undefined): number => {
if (columnId === undefined) return -1;
if (board.value === undefined) return -1;
Expand All @@ -52,8 +51,8 @@ export const useBoardStore = defineStore("boardStore", () => {
};

const getColumnId = (columnIndex: number): string | undefined => {
if (board.value === undefined) return;
if (columnIndex === undefined) return;
if (board.value === undefined) return; // shouldn't happen because board presence is checked by callers
if (columnIndex === undefined) return; // shouldn't happen because columnIndex is always set by type definition
if (columnIndex < 0) return;
if (columnIndex > board.value.columns.length - 1) return;

Expand All @@ -62,6 +61,20 @@ export const useBoardStore = defineStore("boardStore", () => {
return board.value.columns[columnIndex].id;
};

const getCardLocation = (cardId: string) => {
if (!board.value) return;

const columnIndex = board.value.columns.findIndex(
(column) => column.cards.find((c) => c.cardId === cardId) !== undefined
);
if (columnIndex === -1) return undefined;

const column = board.value.columns[columnIndex];
const columnId = column.id;
const cardIndex = column.cards.findIndex((c) => c.cardId === cardId);
return { columnIndex, columnId, cardIndex };
};

const setBoard = (newBoard: Board | undefined) => {
board.value = newBoard;
};
Expand All @@ -70,7 +83,10 @@ export const useBoardStore = defineStore("boardStore", () => {
isLoading.value = loading;
};

let allowToSwitchEditMode = false;

const createCardRequest = (payload: CreateCardRequestPayload) => {
allowToSwitchEditMode = true;
socketOrRest.createCardRequest(payload);
};

Expand All @@ -88,7 +104,9 @@ export const useBoardStore = defineStore("boardStore", () => {
cardId: newCard.id,
height: 120,
});
if (allowToSwitchEditMode === false) return;
setEditModeId(newCard.id);
allowToSwitchEditMode = false;
};

const createColumnRequest = async (payload: CreateColumnRequestPayload) => {
Expand Down Expand Up @@ -122,10 +140,9 @@ export const useBoardStore = defineStore("boardStore", () => {
if (!board.value) return;
const columnId = payload.columnId;
const columnIndex = getColumnIndex(columnId);
if (columnIndex < 0) {
return;
if (columnIndex !== -1) {
board.value.columns.splice(columnIndex, 1);
}
board.value.columns.splice(columnIndex, 1);
};

const updateBoardTitleRequest = async (
Expand All @@ -152,7 +169,7 @@ export const useBoardStore = defineStore("boardStore", () => {
if (!board.value) return;
const { columnId, newTitle } = payload;
const columnIndex = getColumnIndex(columnId);
if (columnIndex > -1) {
if (columnIndex !== -1) {
board.value.columns[columnIndex].title = newTitle;
}
};
Expand Down Expand Up @@ -196,77 +213,38 @@ export const useBoardStore = defineStore("boardStore", () => {
board.value.columns.splice(addedIndex, 0, column);
};

const getColumnIndices = (
fromColumnId: string | undefined,
toColumnId: string | undefined,
columnDelta: number | undefined
) => {
const fromColumnIndex = getColumnIndex(fromColumnId);
const newColumnId: string | undefined =
columnDelta === undefined
? toColumnId
: getColumnId(fromColumnIndex + columnDelta);

return { fromColumnIndex, toColumnIndex: getColumnIndex(newColumnId) };
};
const moveCardToNewColumn = async (cardId: string) => {
const cardLocation = getCardLocation(cardId);
if (cardLocation === undefined) return;

const isMoveValid = (
payload: CardMove,
columns: Array<ColumnResponse>,
targetColumnIndex: number,
fromColumnIndex: number
) => {
const { cardId, newIndex, oldIndex } = payload;
if (cardId === undefined || targetColumnIndex === undefined) return false; // ensure values are set

const movedInsideColumn = fromColumnIndex === targetColumnIndex;
if (movedInsideColumn) {
if (
(newIndex === oldIndex && fromColumnIndex === targetColumnIndex) || // same position
newIndex < 0 || // first card - can't move up
newIndex > columns[fromColumnIndex].cards.length - 1 // last card - can't move down
)
return false;
}
const {
columnIndex: fromColumnIndex,
columnId: fromColumnId,
cardIndex: oldIndex,
} = cardLocation;

return true;
await socketOrRest.moveCardRequest({
cardId,
fromColumnId,
fromColumnIndex,
oldIndex,
newIndex: 0,
});
};

const moveCardRequest = async (payload: MoveCardRequestPayload) => {
await socketOrRest.moveCardRequest(payload);
};
const moveCardRequest = socketOrRest.moveCardRequest;

const moveCardSuccess = async (payload: MoveCardSuccessPayload) => {
if (!board.value) return;

const {
newIndex,
oldIndex,
toColumnId,
fromColumnId,
columnDelta,
forceNextTick,
fromColumnIndex,
toColumnIndex,
} = payload;

const { fromColumnIndex, toColumnIndex } = getColumnIndices(
fromColumnId,
toColumnId,
columnDelta
);

const targetColumnIndex = toColumnIndex ?? board.value.columns.length - 1;

if (
!isMoveValid(
payload,
board.value.columns,
targetColumnIndex,
fromColumnIndex
)
) {
return;
}

const item = board.value.columns[fromColumnIndex].cards.splice(
oldIndex,
1
Expand All @@ -280,9 +258,12 @@ export const useBoardStore = defineStore("boardStore", () => {
await nextTick();
}

board.value.columns[targetColumnIndex].cards =
board.value.columns[targetColumnIndex].cards ?? [];
board.value.columns[targetColumnIndex].cards.splice(newIndex, 0, item);
const toColumn = board.value.columns[toColumnIndex];
if (!toColumn.cards) {
toColumn.cards = [];
}

toColumn.cards.splice(newIndex, 0, item);
};

const disconnectSocketRequest = (payload: DisconnectSocketRequestPayload) => {
Expand All @@ -306,6 +287,9 @@ export const useBoardStore = defineStore("boardStore", () => {
return {
board,
isLoading,
getColumnIndex,
getColumnId,
getLastColumnIndex,
setBoard,
setLoading,
createCardRequest,
Expand All @@ -316,6 +300,7 @@ export const useBoardStore = defineStore("boardStore", () => {
deleteColumnRequest,
deleteColumnSuccess,
disconnectSocketRequest,
moveCardToNewColumn,
moveCardRequest,
moveCardSuccess,
moveColumnRequest,
Expand Down
Loading
Loading