1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-02-07 19:30:18 +02:00

Fixing the sorting of cards taking into consideration the last comment date (#2663)

This commit is contained in:
Jesús Espino 2022-03-29 13:59:11 +02:00 committed by GitHub
parent 8212e5401e
commit c58eee4d85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import {Card} from '../blocks/card'
import {IUser} from '../user'
import {Board} from '../blocks/board'
import {BoardView} from '../blocks/boardView'
import {CommentBlock} from '../blocks/commentBlock'
import {Utils} from '../utils'
import {Constants} from '../constants'
import {CardFilter} from '../cardFilter'
@ -14,6 +15,7 @@ import {CardFilter} from '../cardFilter'
import {loadBoardData, initialReadOnlyLoad} from './initialLoad'
import {getCurrentBoard} from './boards'
import {getBoardUsers} from './users'
import {getLastCommentByCard} from './comments'
import {getCurrentView} from './views'
import {getSearchText} from './searchText'
@ -157,7 +159,7 @@ function manualOrder(activeView: BoardView, cardA: Card, cardB: Card) {
return indexA - indexB
}
function sortCards(cards: Card[], board: Board, activeView: BoardView, usersById: {[key: string]: IUser}): Card[] {
function sortCards(cards: Card[], lastCommentByCard: {[key: string]: CommentBlock}, board: Board, activeView: BoardView, usersById: {[key: string]: IUser}): Card[] {
if (!activeView) {
return cards
}
@ -217,7 +219,9 @@ function sortCards(cards: Card[], board: Board, activeView: BoardView, usersById
} else if (template.type === 'createdTime') {
result = a.createAt - b.createAt
} else if (template.type === 'updatedTime') {
result = a.updateAt - b.updateAt
const aUpdateAt = Math.max(a.updateAt, lastCommentByCard[a.id]?.updateAt || 0)
const bUpdateAt = Math.max(b.updateAt, lastCommentByCard[b.id]?.updateAt || 0)
result = aUpdateAt - bUpdateAt
} else {
// Text-based sort
@ -292,11 +296,12 @@ function searchFilterCards(cards: Card[], board: Board, searchTextRaw: string):
export const getCurrentViewCardsSortedFilteredAndGrouped = createSelector(
getCurrentBoardCards,
getLastCommentByCard,
getCurrentBoard,
getCurrentView,
getSearchText,
getBoardUsers,
(cards, board, view, searchText, users) => {
(cards, lastCommentByCard, board, view, searchText, users) => {
if (!view || !board || !users || !cards) {
return []
}
@ -308,7 +313,7 @@ export const getCurrentViewCardsSortedFilteredAndGrouped = createSelector(
if (searchText) {
result = searchFilterCards(result, board, searchText)
}
result = sortCards(result, board, view, users)
result = sortCards(result, lastCommentByCard, board, view, users)
return result
},
)

View File

@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
import {createSlice, PayloadAction, createSelector} from '@reduxjs/toolkit'
import {CommentBlock} from '../blocks/commentBlock'
@ -92,3 +92,17 @@ export function getLastCardComment(cardId: string): (state: RootState) => Commen
return comments?.[comments?.length - 1]
}
}
export const getLastCommentByCard = createSelector(
(state: RootState) => state.comments?.commentsByCard || null,
(commentsByCard: {[key: string]: CommentBlock[]}|null): {[key: string]: CommentBlock} => {
const lastCommentByCard: {[key: string]: CommentBlock} = {}
Object.keys(commentsByCard || {}).forEach((cardId) => {
if (commentsByCard && commentsByCard[cardId]) {
const comments = commentsByCard[cardId]
lastCommentByCard[cardId] = comments?.[comments?.length - 1]
}
})
return lastCommentByCard
},
)