From b456fe9f65ff311897f440d0c48532d2f5ef811b Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 30 Apr 2020 17:27:58 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20algorithme=20de=20d=C3=A9tection?= =?UTF-8?q?=20des=20tickets=20non=20collect=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voir #22 --- client/src/store/sagas/kanboards.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/client/src/store/sagas/kanboards.ts b/client/src/store/sagas/kanboards.ts index 83162cb..f3d8f78 100644 --- a/client/src/store/sagas/kanboards.ts +++ b/client/src/store/sagas/kanboards.ts @@ -75,13 +75,13 @@ function createCards(projects: Project[], issues: any, lane: BoardLane, rest: Se return projectIssues.reduce((projectCards: KanboardCard[], issue: any) => { const hasLabel = issue.labels.some((l: any) => l.name === lane.issueLabel); - const card = getMemoizedKanboardCard(issue.id, issue.title, p, issue); + const { card, memoized } = getMemoizedKanboardCard(issue.id, issue.title, p, issue); if (hasLabel) { projectCards.push(card); rest.delete(card); } else { - rest.add(card); + if (!memoized) rest.add(card); } return projectCards; @@ -95,11 +95,19 @@ function createCards(projects: Project[], issues: any, lane: BoardLane, rest: Se const kanboardCardMemo: {[key: string]: KanboardCard} = {}; -function getMemoizedKanboardCard(id: number, title: string, project: Project, issue: Issue): KanboardCard { - const key = `${project.id}-${issue.id}-${id}`; - if (kanboardCardMemo.hasOwnProperty(key)) return kanboardCardMemo[key]; +function getKanboardCardMemoizationKey(id: number, project: Project, issue: Issue) { + return `${project.id}-${issue.id}-${id}`; +} + +function isKanboardCardMemoized(key: string) { + return kanboardCardMemo.hasOwnProperty(key) +} + +function getMemoizedKanboardCard(id: number, title: string, project: Project, issue: Issue) { + const key = getKanboardCardMemoizationKey(id, project, issue); + if (isKanboardCardMemoized(key)) return { card: kanboardCardMemo[key], memoized: true }; kanboardCardMemo[key] = { id, title, project, issue }; - return kanboardCardMemo[key]; + return { card: kanboardCardMemo[key], memoized: false }; } function resetKandboarCardMemo() {