feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev
2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions
+114 -1
View File
@@ -1,7 +1,14 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import { createSelector } from 'redux-orm';
import orm from '../orm';
import { selectPath } from './router';
import { isLocalId } from '../utils/local-id';
import { BoardContexts, ListTypes } from '../constants/Enums';
export const makeSelectListById = () =>
createSelector(
@@ -34,15 +41,121 @@ export const makeSelectCardIdsByListId = () =>
return listModel;
}
return listModel.getFilteredOrderedCardsModelArray().map((cardModel) => cardModel.id);
return listModel.getCardsModelArray().map((cardModel) => cardModel.id);
},
);
export const selectCardIdsByListId = makeSelectCardIdsByListId();
export const makeSelectFilteredCardIdsByListId = () =>
createSelector(
orm,
(_, id) => id,
({ List }, id) => {
const listModel = List.withId(id);
if (!listModel) {
return listModel;
}
return listModel.getFilteredCardsModelArray().map((cardModel) => cardModel.id);
},
);
export const selectFilteredCardIdsByListId = makeSelectFilteredCardIdsByListId();
export const selectCurrentListId = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
if (boardModel.context === BoardContexts.BOARD) {
return null;
}
const listModel = boardModel.lists
.filter({
type: boardModel.context || ListTypes.ACTIVE, // TODO: hack?
})
.first();
return listModel && listModel.id;
},
);
export const selectCurrentList = createSelector(
orm,
(state) => selectCurrentListId(state),
({ List }, id) => {
if (!id) {
return id;
}
const listModel = List.withId(id);
if (!listModel) {
return listModel;
}
return listModel.ref;
},
);
export const selectFirstFiniteListId = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
const listModel = boardModel.getFiniteListsQuerySet().first();
return listModel && listModel.id;
},
);
export const selectFilteredCardIdsForCurrentList = createSelector(
orm,
(state) => selectCurrentListId(state),
({ List }, id) => {
if (!id) {
return id;
}
const listModel = List.withId(id);
if (!listModel) {
return listModel;
}
return listModel.getFilteredCardsModelArray().map((cardModel) => cardModel.id);
},
);
export default {
makeSelectListById,
selectListById,
makeSelectCardIdsByListId,
selectCardIdsByListId,
makeSelectFilteredCardIdsByListId,
selectFilteredCardIdsByListId,
selectCurrentListId,
selectCurrentList,
selectFirstFiniteListId,
selectFilteredCardIdsForCurrentList,
};