From 04366add16b2742c3a7476d8890f2fa1f7b88bd5 Mon Sep 17 00:00:00 2001 From: Michael Uray Date: Sun, 18 Oct 2026 01:53:39 +0000 Subject: [PATCH 1/2] feat(tracker): optional estimation sum in issue list group headers Issue list group headers only showed the reported/estimated time when the list was grouped by milestone or assignee, so e.g. a Backlog status group gave no idea how much work it holds. Add a "Show estimation sum in groups" display option to the issue, milestone and component list views (off by default). When enabled, IssueStatistics is shown for every grouping. The list header now passes the projected documents of the whole group and the view options to header extras. With the option enabled, IssueStatistics fetches the time fields of the not yet loaded group issues once per set of group issue ids (no extra live subscriptions, no refetch on live updates of loaded rows or when another page is loaded); loaded rows stay live. Milestone/assignee summaries without the option keep using the loaded rows as before. The summing is extracted into the pure helper calcIssueTimeStats with unit tests. Sub-issues with an ancestor in the same group are counted through that ancestor's childInfo, and only childInfo entries of sub-issues of the same group are used, so a sub-issue listed in another group is counted there and not twice (all entries are used when sub-issues are hidden). Closed issues are capped by reported time and unstarted issues are excluded only for milestone/assignee planning groups, as before. Fixes #7034 Signed-off-by: Michael Uray --- models/tracker/src/viewlets.ts | 14 ++- plugins/tracker-assets/lang/cs.json | 1 + plugins/tracker-assets/lang/de.json | 1 + plugins/tracker-assets/lang/en.json | 1 + plugins/tracker-assets/lang/es.json | 1 + plugins/tracker-assets/lang/fr.json | 1 + plugins/tracker-assets/lang/it.json | 1 + plugins/tracker-assets/lang/ja.json | 1 + plugins/tracker-assets/lang/ko.json | 1 + plugins/tracker-assets/lang/pl.json | 1 + plugins/tracker-assets/lang/pt-br.json | 1 + plugins/tracker-assets/lang/pt.json | 1 + plugins/tracker-assets/lang/ru.json | 1 + plugins/tracker-assets/lang/tr.json | 1 + plugins/tracker-assets/lang/zh.json | 1 + .../src/__tests__/issueTimeStats.test.ts | 117 +++++++++++++++++ .../milestones/IssueStatistics.svelte | 119 ++++++++++-------- .../tracker-resources/src/issueTimeStats.ts | 81 ++++++++++++ plugins/tracker-resources/src/plugin.ts | 1 + .../src/components/list/ListHeader.svelte | 5 +- 20 files changed, 296 insertions(+), 55 deletions(-) create mode 100644 plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts create mode 100644 plugins/tracker-resources/src/issueTimeStats.ts diff --git a/models/tracker/src/viewlets.ts b/models/tracker/src/viewlets.ts index 30282c7ae08..0137fa912b7 100644 --- a/models/tracker/src/viewlets.ts +++ b/models/tracker/src/viewlets.ts @@ -27,6 +27,14 @@ import tracker from './plugin' // (List + Kanban) and the Gantt viewlet block. Keep this list as the single // source of truth so a change in one place can never disagree with the // other half of the UI. +const showEstimationSumViewOption: ViewOptionModel = { + key: 'showEstimationSum', + type: 'toggle', + defaultValue: false, + actionTarget: 'display', + label: tracker.string.ShowEstimationSum +} + const SEARCH_VIEW_OPTIONS: ViewOptionModel[] = [ { key: 'showQuickModeSelector', @@ -107,7 +115,7 @@ export const issuesOptions = (kanban: boolean): ViewOptionsModel => ({ action: view.function.HideArchived, label: view.string.HideArchived }, - ...(!kanban ? [showColorsViewOption] : []), + ...(!kanban ? [showColorsViewOption, showEstimationSumViewOption] : []), ...SEARCH_VIEW_OPTIONS ] }) @@ -670,7 +678,7 @@ export function defineViewlets (builder: Builder): void { ['dueDate', SortingOrder.Ascending] ], groupDepth: 1, - other: [showColorsViewOption] + other: [showColorsViewOption, showEstimationSumViewOption] } builder.createDoc( @@ -712,7 +720,7 @@ export function defineViewlets (builder: Builder): void { ['dueDate', SortingOrder.Ascending] ], groupDepth: 1, - other: [showColorsViewOption] + other: [showColorsViewOption, showEstimationSumViewOption] } builder.createDoc( diff --git a/plugins/tracker-assets/lang/cs.json b/plugins/tracker-assets/lang/cs.json index a86d17ab3ca..0bcf9e4dcd4 100644 --- a/plugins/tracker-assets/lang/cs.json +++ b/plugins/tracker-assets/lang/cs.json @@ -231,6 +231,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Odhad podúkolů", + "ShowEstimationSum": "Zobrazit součet odhadů ve skupinách", "ChildReportedTime": "Čas podúkolů", "CapacityValue": "z {value}d", "NewRelatedIssue": "Nový související úkol", diff --git a/plugins/tracker-assets/lang/de.json b/plugins/tracker-assets/lang/de.json index 4ef15e6c56f..f33c78c61a4 100644 --- a/plugins/tracker-assets/lang/de.json +++ b/plugins/tracker-assets/lang/de.json @@ -272,6 +272,7 @@ "TimeSpendHours": "{value}Std", "TimeSpendMinutes": "{value}Min", "ChildEstimation": "Schätzung Unteraufgaben", + "ShowEstimationSum": "Summe der Schätzungen in Gruppen anzeigen", "ChildReportedTime": "Zeit Unteraufgaben", "CapacityValue": "von {value}T", "NewRelatedIssue": "Neue verwandte Aufgabe", diff --git a/plugins/tracker-assets/lang/en.json b/plugins/tracker-assets/lang/en.json index 01a260ee457..fddd39d4209 100644 --- a/plugins/tracker-assets/lang/en.json +++ b/plugins/tracker-assets/lang/en.json @@ -258,6 +258,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Sub-issues estimation", + "ShowEstimationSum": "Show estimation sum in groups", "ChildReportedTime": "Sub-issues time", "CapacityValue": "of {value}d", "NewRelatedIssue": "New related issue", diff --git a/plugins/tracker-assets/lang/es.json b/plugins/tracker-assets/lang/es.json index e64739a8677..1c819d8550e 100644 --- a/plugins/tracker-assets/lang/es.json +++ b/plugins/tracker-assets/lang/es.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Estimación de subtemas", + "ShowEstimationSum": "Mostrar la suma de estimaciones en los grupos", "ChildReportedTime": "Tiempo de subtemas", "CapacityValue": "de {value}d", "NewRelatedIssue": "Nuevo problema relacionado", diff --git a/plugins/tracker-assets/lang/fr.json b/plugins/tracker-assets/lang/fr.json index f50efabb503..adc7f452c1e 100644 --- a/plugins/tracker-assets/lang/fr.json +++ b/plugins/tracker-assets/lang/fr.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Estimation des sous-problèmes", + "ShowEstimationSum": "Afficher la somme des estimations dans les groupes", "ChildReportedTime": "Temps des sous-problèmes", "CapacityValue": "de {value}j", "NewRelatedIssue": "Nouvelle issue liée", diff --git a/plugins/tracker-assets/lang/it.json b/plugins/tracker-assets/lang/it.json index 6987099ebb9..c120f22faae 100644 --- a/plugins/tracker-assets/lang/it.json +++ b/plugins/tracker-assets/lang/it.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Stima delle subissue", + "ShowEstimationSum": "Mostra la somma delle stime nei gruppi", "ChildReportedTime": "Tempo delle subissue", "CapacityValue": "di {value}d", "NewRelatedIssue": "Nuova issue correlata", diff --git a/plugins/tracker-assets/lang/ja.json b/plugins/tracker-assets/lang/ja.json index 72af11ae93f..029612ba957 100644 --- a/plugins/tracker-assets/lang/ja.json +++ b/plugins/tracker-assets/lang/ja.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}時間", "TimeSpendMinutes": "{value}分", "ChildEstimation": "子イシューの見積もり", + "ShowEstimationSum": "グループに見積もりの合計を表示", "ChildReportedTime": "子イシューの時間", "CapacityValue": "うち {value}日", "NewRelatedIssue": "新しい関連イシュー", diff --git a/plugins/tracker-assets/lang/ko.json b/plugins/tracker-assets/lang/ko.json index 628aad44b3b..ea7795977ad 100644 --- a/plugins/tracker-assets/lang/ko.json +++ b/plugins/tracker-assets/lang/ko.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}시간", "TimeSpendMinutes": "{value}분", "ChildEstimation": "하위 이슈 예상치", + "ShowEstimationSum": "그룹에 예상치 합계 표시", "ChildReportedTime": "하위 이슈 시간", "CapacityValue": "{value}일 중", "NewRelatedIssue": "새 관련 이슈", diff --git a/plugins/tracker-assets/lang/pl.json b/plugins/tracker-assets/lang/pl.json index 9f2fe1c26da..9ffb266b640 100644 --- a/plugins/tracker-assets/lang/pl.json +++ b/plugins/tracker-assets/lang/pl.json @@ -238,6 +238,7 @@ "TimeSpendHours": "{value, plural, =1 {1 godzina} few {# godziny} many {# godzin} other {# godziny}}", "TimeSpendMinutes": "{value, plural, =1 {1 minuta} few {# minuty} many {# minut} other {# minuty}}", "ChildEstimation": "Wycena podzagadnień", + "ShowEstimationSum": "Pokaż sumę wycen w grupach", "ChildReportedTime": "Czas poświęcony na podzagadnienia", "CapacityValue": "z {value, plural, =1 {1 dnia} other {# dni}}", "NewRelatedIssue": "Nowe powiązane zadanie", diff --git a/plugins/tracker-assets/lang/pt-br.json b/plugins/tracker-assets/lang/pt-br.json index af8ed33bea5..cc9d7cd51f8 100644 --- a/plugins/tracker-assets/lang/pt-br.json +++ b/plugins/tracker-assets/lang/pt-br.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Estimativa de sub-tarefas", + "ShowEstimationSum": "Mostrar a soma das estimativas nos grupos", "ChildReportedTime": "Tempo de sub-tarefas", "CapacityValue": "de {value}d", "NewRelatedIssue": "Nova tarefa relacionada", diff --git a/plugins/tracker-assets/lang/pt.json b/plugins/tracker-assets/lang/pt.json index 7742053a95e..4887c26c9b8 100644 --- a/plugins/tracker-assets/lang/pt.json +++ b/plugins/tracker-assets/lang/pt.json @@ -228,6 +228,7 @@ "TimeSpendHours": "{value}h", "TimeSpendMinutes": "{value}m", "ChildEstimation": "Estimativa de sub-tarefas", + "ShowEstimationSum": "Mostrar a soma das estimativas nos grupos", "ChildReportedTime": "Tempo de sub-tarefas", "CapacityValue": "de {value}d", "NewRelatedIssue": "Nova tarefa relacionada", diff --git a/plugins/tracker-assets/lang/ru.json b/plugins/tracker-assets/lang/ru.json index b67cf1828c5..0d3c55aa034 100644 --- a/plugins/tracker-assets/lang/ru.json +++ b/plugins/tracker-assets/lang/ru.json @@ -258,6 +258,7 @@ "TimeSpendHours": "{value} ч", "TimeSpendMinutes": "{value} м", "ChildEstimation": "Оценка подзадач", + "ShowEstimationSum": "Показывать сумму оценок в группах", "ChildReportedTime": "Время подзадач", "CapacityValue": "из {value} д", "NewRelatedIssue": "Завести связанную задачу", diff --git a/plugins/tracker-assets/lang/tr.json b/plugins/tracker-assets/lang/tr.json index f465a56e61a..0bda336afff 100644 --- a/plugins/tracker-assets/lang/tr.json +++ b/plugins/tracker-assets/lang/tr.json @@ -245,6 +245,7 @@ "TimeSpendHours": "{value}s", "TimeSpendMinutes": "{value}dk", "ChildEstimation": "Alt sorunlar tahmini", + "ShowEstimationSum": "Gruplarda tahmin toplamını göster", "ChildReportedTime": "Alt sorunlar zamanı", "CapacityValue": "{value}g üzerinden", "NewRelatedIssue": "Yeni ilgili sorun", diff --git a/plugins/tracker-assets/lang/zh.json b/plugins/tracker-assets/lang/zh.json index 68634b0207a..028e96c544d 100644 --- a/plugins/tracker-assets/lang/zh.json +++ b/plugins/tracker-assets/lang/zh.json @@ -241,6 +241,7 @@ "TimeSpendHours": "{value} 小时", "TimeSpendMinutes": "{value} 分钟", "ChildEstimation": "子问题估算", + "ShowEstimationSum": "在分组中显示估算总和", "ChildReportedTime": "子问题时间", "CapacityValue": "共 {value} 天", "NewRelatedIssue": "新相关问题", diff --git a/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts b/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts new file mode 100644 index 00000000000..901a9a74cc9 --- /dev/null +++ b/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts @@ -0,0 +1,117 @@ +// +// Copyright © 2026 Hardcore Engineering Inc. +// SPDX-License-Identifier: EPL-2.0 +// + +import { calcIssueTimeStats, type IssueTimeInfo, type IssueTimeStatsOptions } from '../issueTimeStats' + +function issue ( + id: string, + status: string, + estimation: number, + reportedTime: number, + parents: string[] = [], + children: Array<{ childId: string, estimation: number, reportedTime: number }> = [] +): IssueTimeInfo { + return { + _id: id as any, + attachedTo: (parents[parents.length - 1] ?? 'no-parent') as any, + parents: parents.map((parentId) => ({ parentId }) as any), + status: status as any, + estimation, + reportedTime, + childInfo: children as any + } +} + +const options = (skipUnStarted: boolean, includeAllChildren = false): IssueTimeStatsOptions => ({ + isUnStarted: (it) => it.status === 'backlog', + isClosed: (it) => it.status === 'done' || it.status === 'canceled', + skipUnStarted, + includeAllChildren +}) + +describe('calcIssueTimeStats', () => { + it('returns zero for an empty group', () => { + expect(calcIssueTimeStats([], options(false))).toEqual({ estimation: 0, reportedTime: 0 }) + }) + + it('sums estimation and reported time of plain issues', () => { + const docs = [issue('a', 'todo', 2, 1), issue('b', 'todo', 3, 0.5)] + expect(calcIssueTimeStats(docs, options(false))).toEqual({ estimation: 5, reportedTime: 1.5 }) + }) + + it('counts backlog issues unless skipUnStarted is set', () => { + const docs = [issue('a', 'backlog', 4, 0), issue('b', 'todo', 1, 0)] + expect(calcIssueTimeStats(docs, options(false)).estimation).toBe(5) + expect(calcIssueTimeStats(docs, options(true)).estimation).toBe(1) + }) + + it('does not count a sub-issue twice when its parent is in the same group', () => { + const parent = issue('p', 'todo', 10, 1, [], [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 0 } + ]) + const c1 = issue('c1', 'todo', 2, 1, ['p']) + const c2 = issue('c2', 'todo', 3, 0, ['p']) + expect(calcIssueTimeStats([parent, c1, c2], options(false))).toEqual({ estimation: 5, reportedTime: 2 }) + }) + + it('leaves time of sub-issues listed in another group to that group', () => { + const parent = issue('p', 'todo', 10, 1, [], [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 4 } + ]) + const c1 = issue('c1', 'todo', 2, 1, ['p']) + const c2 = issue('c2', 'done', 3, 4, ['p']) + // Group A holds the parent and c1, group B holds c2 only. + const a = calcIssueTimeStats([parent, c1], options(false)) + const b = calcIssueTimeStats([c2], options(false)) + expect(a).toEqual({ estimation: 2, reportedTime: 2 }) + expect(b).toEqual({ estimation: 3, reportedTime: 4 }) + }) + + it('uses own time of a parent whose sub-issues are all in other groups', () => { + const parent = issue('p', 'todo', 10, 1, [], [{ childId: 'c1', estimation: 2, reportedTime: 1 }]) + expect(calcIssueTimeStats([parent], options(false))).toEqual({ estimation: 10, reportedTime: 1 }) + }) + + it('counts all sub-issues through the parent when sub-issues are not listed', () => { + const parent = issue('p', 'todo', 10, 1, [], [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 0 } + ]) + expect(calcIssueTimeStats([parent], options(false, true))).toEqual({ estimation: 5, reportedTime: 2 }) + }) + + it('skips a nested sub-issue whose ancestor is in the group', () => { + const root = issue('r', 'todo', 0, 0, [], [ + { childId: 'm', estimation: 0, reportedTime: 0 }, + { childId: 'g', estimation: 4, reportedTime: 1 } + ]) + // The intermediate parent 'm' is in another group. + const grandChild = issue('g', 'todo', 4, 1, ['r', 'm']) + expect(calcIssueTimeStats([root, grandChild], options(false))).toEqual({ estimation: 4, reportedTime: 1 }) + }) + + it('counts a sub-issue whose parent is in another group', () => { + const child = issue('c', 'todo', 2, 1, ['p']) + expect(calcIssueTimeStats([child], options(false))).toEqual({ estimation: 2, reportedTime: 1 }) + }) + + it('keeps parent estimation when sub-issues are not estimated', () => { + const parent = issue('p', 'todo', 8, 0, [], [{ childId: 'c', estimation: 0, reportedTime: 0 }]) + const child = issue('c', 'todo', 0, 0, ['p']) + expect(calcIssueTimeStats([parent, child], options(false)).estimation).toBe(8) + }) + + it('caps estimation of closed issues by reported time', () => { + const docs = [ + issue('a', 'done', 5, 2), + issue('b', 'canceled', 1, 3), + issue('p', 'done', 0, 0, [], [{ childId: 'c', estimation: 6, reportedTime: 4 }]), + issue('c', 'done', 6, 4, ['p']) + ] + expect(calcIssueTimeStats(docs, options(false))).toEqual({ estimation: 2 + 1 + 4, reportedTime: 2 + 3 + 4 }) + }) +}) diff --git a/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte b/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte index 0238b6ed119..249e870df15 100644 --- a/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte +++ b/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte @@ -13,75 +13,92 @@ // limitations under the License. --> -{#if docs && (category === 'milestone' || category === 'assignee')} +{#if show}
(capacity ?? 0)}> diff --git a/plugins/tracker-resources/src/issueTimeStats.ts b/plugins/tracker-resources/src/issueTimeStats.ts new file mode 100644 index 00000000000..17a6f47a3ad --- /dev/null +++ b/plugins/tracker-resources/src/issueTimeStats.ts @@ -0,0 +1,81 @@ +// +// Copyright © 2026 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import type { Issue } from '@hcengineering/tracker' + +export type IssueTimeInfo = Pick< +Issue, +'_id' | 'attachedTo' | 'parents' | 'status' | 'estimation' | 'reportedTime' | 'childInfo' +> + +export interface IssueTimeStatsOptions { + // Issue status belongs to the "unstarted" (backlog) category. + isUnStarted: (issue: T) => boolean + // Issue status belongs to a "won" or "lost" category. + isClosed: (issue: T) => boolean + // Do not count estimation of unstarted issues. + skipUnStarted: boolean + // Sub-issues are not listed on their own (e.g. sub-issues are hidden), so + // all of them are counted through their parent. + includeAllChildren: boolean +} + +export interface IssueTimeStats { + estimation: number + reportedTime: number +} + +/** + * Sum estimation and reported time of a group of issues. + * + * Sub-issues with a parent in the same group are counted through that parent's + * childInfo only. Sub-issues listed in another group are counted there, so only + * the childInfo entries of sub-issues from this group are used (all of them if + * includeAllChildren is set). Nothing is counted twice and time stays in the + * group of the issue it belongs to. For a parent with estimated sub-issues the + * sub-issue estimation replaces the parent one. For closed issues the + * estimation is capped by the reported time. + */ +export function calcIssueTimeStats ( + docs: T[], + options: IssueTimeStatsOptions +): IssueTimeStats { + const ids = new Set(docs.map((it) => it._id)) + const hasParentInGroup = (it: T): boolean => + ids.has(it.attachedTo) || (it.parents ?? []).some((p) => ids.has(p.parentId)) + const roots = docs.filter((it) => !hasParentInGroup(it)) + + let estimation = 0 + let reportedTime = 0 + for (const it of roots) { + const allChildren = it.childInfo ?? [] + const childInfo = options.includeAllChildren ? allChildren : allChildren.filter((ct) => ids.has(ct.childId)) + const cReported = childInfo.reduce((a, b) => a + b.reportedTime, 0) + reportedTime += cReported !== 0 ? cReported + it.reportedTime : it.reportedTime + + if (options.skipUnStarted && options.isUnStarted(it)) continue + + const closed = options.isClosed(it) + const cEstimation = childInfo.reduce((a, b) => a + b.estimation, 0) + if (childInfo.length > 0 && cEstimation !== 0) { + estimation += closed && cReported < cEstimation ? cReported : cEstimation + } else if (childInfo.length === 0 && closed && it.reportedTime < it.estimation) { + estimation += it.reportedTime + } else { + estimation += it.estimation + } + } + return { estimation, reportedTime } +} diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index b4e326877ae..7ca05dce973 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -276,6 +276,7 @@ export default mergeIds(trackerId, tracker, { TimeSpendMinutes: '' as IntlString, ChildEstimation: '' as IntlString, + ShowEstimationSum: '' as IntlString, ChildReportedTime: '' as IntlString, CapacityValue: '' as IntlString, AddedReference: '' as IntlString, diff --git a/plugins/view-resources/src/components/list/ListHeader.svelte b/plugins/view-resources/src/components/list/ListHeader.svelte index 2fac066863d..c737275b8e5 100644 --- a/plugins/view-resources/src/components/list/ListHeader.svelte +++ b/plugins/view-resources/src/components/list/ListHeader.svelte @@ -182,7 +182,10 @@ {/if}
{#each extraHeaders ?? [] as extra} - + {/each}
{/if} From ea7c7010f7ad68afd08ccc303fba65ff0c6ea533 Mon Sep 17 00:00:00 2001 From: Michael Uray Date: Mon, 2 Nov 2026 12:54:15 +0000 Subject: [PATCH 2/2] fix(tracker): keep milestone and assignee totals unchanged without the sum option Without "Show estimation sum in groups", milestone and assignee group headers again use the previous calculation: the loaded rows plus the full childInfo of each loaded parent. Sub-issues that are not loaded yet keep counting, so the totals are the same as before this feature. With the option enabled, all issues of the group are fetched and each issue's time is counted in the group the issue is listed in. A sub-issue assigned to Bob under a parent assigned to Alice then counts for Bob, not for Alice. This is a change from the previous behaviour, limited to the opt-in option. Signed-off-by: Michael Uray --- .../src/__tests__/issueTimeStats.test.ts | 106 +++++++++++++++--- .../milestones/IssueStatistics.svelte | 21 ++-- .../tracker-resources/src/issueTimeStats.ts | 35 ++++++ 3 files changed, 136 insertions(+), 26 deletions(-) diff --git a/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts b/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts index 901a9a74cc9..ef83fa3e009 100644 --- a/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts +++ b/plugins/tracker-resources/src/__tests__/issueTimeStats.test.ts @@ -3,7 +3,12 @@ // SPDX-License-Identifier: EPL-2.0 // -import { calcIssueTimeStats, type IssueTimeInfo, type IssueTimeStatsOptions } from '../issueTimeStats' +import { + calcIssueTimeStats, + calcPlanningIssueTimeStats, + type IssueTimeInfo, + type IssueTimeStatsOptions +} from '../issueTimeStats' function issue ( id: string, @@ -48,20 +53,34 @@ describe('calcIssueTimeStats', () => { }) it('does not count a sub-issue twice when its parent is in the same group', () => { - const parent = issue('p', 'todo', 10, 1, [], [ - { childId: 'c1', estimation: 2, reportedTime: 1 }, - { childId: 'c2', estimation: 3, reportedTime: 0 } - ]) + const parent = issue( + 'p', + 'todo', + 10, + 1, + [], + [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 0 } + ] + ) const c1 = issue('c1', 'todo', 2, 1, ['p']) const c2 = issue('c2', 'todo', 3, 0, ['p']) expect(calcIssueTimeStats([parent, c1, c2], options(false))).toEqual({ estimation: 5, reportedTime: 2 }) }) it('leaves time of sub-issues listed in another group to that group', () => { - const parent = issue('p', 'todo', 10, 1, [], [ - { childId: 'c1', estimation: 2, reportedTime: 1 }, - { childId: 'c2', estimation: 3, reportedTime: 4 } - ]) + const parent = issue( + 'p', + 'todo', + 10, + 1, + [], + [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 4 } + ] + ) const c1 = issue('c1', 'todo', 2, 1, ['p']) const c2 = issue('c2', 'done', 3, 4, ['p']) // Group A holds the parent and c1, group B holds c2 only. @@ -77,18 +96,32 @@ describe('calcIssueTimeStats', () => { }) it('counts all sub-issues through the parent when sub-issues are not listed', () => { - const parent = issue('p', 'todo', 10, 1, [], [ - { childId: 'c1', estimation: 2, reportedTime: 1 }, - { childId: 'c2', estimation: 3, reportedTime: 0 } - ]) + const parent = issue( + 'p', + 'todo', + 10, + 1, + [], + [ + { childId: 'c1', estimation: 2, reportedTime: 1 }, + { childId: 'c2', estimation: 3, reportedTime: 0 } + ] + ) expect(calcIssueTimeStats([parent], options(false, true))).toEqual({ estimation: 5, reportedTime: 2 }) }) it('skips a nested sub-issue whose ancestor is in the group', () => { - const root = issue('r', 'todo', 0, 0, [], [ - { childId: 'm', estimation: 0, reportedTime: 0 }, - { childId: 'g', estimation: 4, reportedTime: 1 } - ]) + const root = issue( + 'r', + 'todo', + 0, + 0, + [], + [ + { childId: 'm', estimation: 0, reportedTime: 0 }, + { childId: 'g', estimation: 4, reportedTime: 1 } + ] + ) // The intermediate parent 'm' is in another group. const grandChild = issue('g', 'todo', 4, 1, ['r', 'm']) expect(calcIssueTimeStats([root, grandChild], options(false))).toEqual({ estimation: 4, reportedTime: 1 }) @@ -115,3 +148,42 @@ describe('calcIssueTimeStats', () => { expect(calcIssueTimeStats(docs, options(false))).toEqual({ estimation: 2 + 1 + 4, reportedTime: 2 + 3 + 4 }) }) }) + +describe('calcPlanningIssueTimeStats', () => { + it('returns zero for an empty loaded page', () => { + expect(calcPlanningIssueTimeStats([], options(true))).toEqual({ estimation: 0, reportedTime: 0 }) + }) + + it('counts all children even outside the page and preserves a larger parent estimate only for zero child estimation', () => { + const parent = issue('p', 'todo', 10, 1, [], [{ childId: 'c', estimation: 2, reportedTime: 3 }]) + expect(calcPlanningIssueTimeStats([parent], options(true))).toEqual({ estimation: 2, reportedTime: 4 }) + const zeroChildren = issue('p', 'todo', 10, 1, [], [{ childId: 'c', estimation: 0, reportedTime: 3 }]) + expect(calcPlanningIssueTimeStats([zeroChildren], options(true))).toEqual({ estimation: 10, reportedTime: 4 }) + }) + + it('suppresses loaded direct children but preserves the historical missing-direct-parent case', () => { + const root = issue('r', 'todo', 10, 1, [], [{ childId: 'g', estimation: 4, reportedTime: 2 }]) + const grandchild = issue('g', 'todo', 4, 2, ['r', 'm']) + expect(calcPlanningIssueTimeStats([root, grandchild], options(true))).toEqual({ estimation: 8, reportedTime: 5 }) + expect(calcPlanningIssueTimeStats([root, issue('m', 'todo', 0, 0, ['r']), grandchild], options(true))).toEqual({ + estimation: 4, + reportedTime: 3 + }) + }) + + it('keeps own and child reported time for backlog roots', () => { + const parent = issue('p', 'backlog', 10, 1, [], [{ childId: 'c', estimation: 2, reportedTime: 3 }]) + expect(calcPlanningIssueTimeStats([parent], options(true))).toEqual({ estimation: 0, reportedTime: 4 }) + }) + + it.each(['done', 'canceled'])('preserves all historical %s cap branches', (status) => { + const docs = [ + issue('a', status, 5, 2), + issue('b', status, 1, 3), + issue('c', status, 10, 8, [], [{ childId: 'x', estimation: 6, reportedTime: 3 }]), + issue('d', status, 10, 1, [], [{ childId: 'y', estimation: 2, reportedTime: 4 }]), + issue('e', status, 8, 1, [], [{ childId: 'z', estimation: 0, reportedTime: 2 }]) + ] + expect(calcPlanningIssueTimeStats(docs, options(true))).toEqual({ estimation: 16, reportedTime: 24 }) + }) +}) diff --git a/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte b/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte index 249e870df15..853b6a4a9d2 100644 --- a/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte +++ b/plugins/tracker-resources/src/components/milestones/IssueStatistics.svelte @@ -20,7 +20,7 @@ import { floorFractionDigits, Label } from '@hcengineering/ui' import { ViewOptions } from '@hcengineering/view' import { FixedColumn, statusStore } from '@hcengineering/view-resources' - import { calcIssueTimeStats } from '../../issueTimeStats' + import { calcIssueTimeStats, calcPlanningIssueTimeStats } from '../../issueTimeStats' import tracker from '../../plugin' import EstimationProgressCircle from '../issues/timereport/EstimationProgressCircle.svelte' import TimePresenter from '../issues/timereport/TimePresenter.svelte' @@ -54,10 +54,9 @@ if (key === fetchedKey) return fetchedKey = key const seq = ++fetchSeq - if (ids === undefined) { - fetched = undefined - return - } + // Discard the previous group while the next group's request is pending. + fetched = undefined + if (ids === undefined) return const res = await client.findAll( tracker.class.Issue, { _id: { $in: ids } }, @@ -85,15 +84,19 @@ $: groupDocs = fetched !== undefined ? [...loaded.values(), ...fetched.filter((it) => !loaded.has(it._id))] : (docs ?? []) - $: stats = calcIssueTimeStats(groupDocs, { - isUnStarted: (it) => $statusStore.byId.get(it.status)?.category === task.statusCategory.UnStarted, - isClosed: (it) => { + $: statsOptions = { + isUnStarted: (it: Issue) => $statusStore.byId.get(it.status)?.category === task.statusCategory.UnStarted, + isClosed: (it: Issue) => { const cat = $statusStore.byId.get(it.status)?.category return cat === task.statusCategory.Won || cat === task.statusCategory.Lost }, skipUnStarted: planning, includeAllChildren: viewOptions?.shouldShowSubIssues === false - }) + } + $: stats = + planning && !showSum + ? calcPlanningIssueTimeStats(docs ?? [], statsOptions) + : calcIssueTimeStats(groupDocs, statsOptions) $: totalEstimation = floorFractionDigits(stats.estimation, 3) $: totalReported = floorFractionDigits(stats.reportedTime, 3) diff --git a/plugins/tracker-resources/src/issueTimeStats.ts b/plugins/tracker-resources/src/issueTimeStats.ts index 17a6f47a3ad..d6b90032bd1 100644 --- a/plugins/tracker-resources/src/issueTimeStats.ts +++ b/plugins/tracker-resources/src/issueTimeStats.ts @@ -79,3 +79,38 @@ export function calcIssueTimeStats ( } return { estimation, reportedTime } } + +/** + * Preserve the historical milestone/assignee totals when the sum option is off. + * Only a loaded direct parent suppresses a row; all childInfo entries count, + * including children outside the loaded page or group. + */ +export function calcPlanningIssueTimeStats ( + docs: T[], + options: Pick, 'isUnStarted' | 'isClosed'> +): IssueTimeStats { + const ids = new Set(docs.map((it) => it._id)) + const roots = docs.filter((it) => !ids.has(it.attachedTo)) + + let estimation = 0 + let reportedTime = 0 + for (const it of roots) { + const childInfo = it.childInfo ?? [] + const cReported = childInfo.reduce((a, b) => a + b.reportedTime, 0) + reportedTime += cReported !== 0 ? cReported + it.reportedTime : it.reportedTime + + if (options.isUnStarted(it)) continue + + const cEstimation = childInfo.reduce((a, b) => a + b.estimation, 0) + if (childInfo.length > 0 && cEstimation !== 0) { + estimation += options.isClosed(it) && cReported < cEstimation ? cReported : cEstimation + } else if (childInfo.length === 0 && options.isClosed(it) && it.reportedTime < it.estimation) { + estimation += it.reportedTime + } else { + // A nonempty child list with zero estimation historically keeps the + // parent's estimation even when the parent is closed. + estimation += it.estimation + } + } + return { estimation, reportedTime } +}