From 6acdb0535c0fc1596fca2f2218435b96d2f58a1b Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:09:14 -0800 Subject: [PATCH] fix(github-project): use content values for built-in grouping and sorting (#38818) * fix(github-project): derive built-in field display and ordering from content * fix(i18n): register linked PR summary overflow fallback * fix: satisfy project projection static checks * test(github-project): cover normalized phone metadata and update field contracts * fix(github-project): narrow optional grouping values explicitly * test(github-project): place fixture safety rationale at assertion start * test(github-project): isolate Node and native regression boundaries --- mobile/src/i18n/locales/de.json | 3 +- mobile/src/i18n/locales/en.json | 3 +- mobile/src/i18n/locales/es.json | 3 +- mobile/src/i18n/locales/fr.json | 3 +- mobile/src/i18n/locales/ja.json | 3 +- mobile/src/i18n/locales/ko.json | 3 +- mobile/src/i18n/locales/pt.json | 3 +- mobile/src/i18n/locales/ru.json | 3 +- mobile/src/i18n/locales/tr.json | 3 +- mobile/src/i18n/locales/zh-Hant.json | 3 +- mobile/src/i18n/locales/zh.json | 3 +- .../mobile-tasks-github-project-list.tsx | 9 +- ...obile-tasks-project-content-fields.test.ts | 89 +++++++++++++++++ .../src/tasks/mobile-tasks-project-fields.ts | 32 +++++-- .../tasks/mobile-tasks-view-state-types.ts | 5 + .../components/github-project/ProjectCell.tsx | 21 ++-- .../ProjectViewList.fixture.tsx | 39 ++++++++ .../github-project/group-sort.test.ts | 95 +++++++++++++++++++ src/shared/github/project-content-field.ts | 68 +++++++++++++ src/shared/github/project-group-sort.ts | 44 +++++++-- ...thub-project-provider-columns.unit.test.ts | 58 ++++++++++- 21 files changed, 451 insertions(+), 42 deletions(-) create mode 100644 mobile/src/tasks/mobile-tasks-project-content-fields.test.ts create mode 100644 src/renderer/src/components/github-project/ProjectViewList.fixture.tsx create mode 100644 src/shared/github/project-content-field.ts diff --git a/mobile/src/i18n/locales/de.json b/mobile/src/i18n/locales/de.json index d573ffcd111..9865ff62358 100644 --- a/mobile/src/i18n/locales/de.json +++ b/mobile/src/i18n/locales/de.json @@ -3277,7 +3277,8 @@ "moreFields_one": "+{{count}} Feld", "moreFields_other": "+{{count}} Felder", "noItems": "Keine Projekteinträge", - "pullRequestSubtitle": "Pull Request · {{repository}}{{number}}" + "pullRequestSubtitle": "Pull Request · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}} weitere" }, "githubProjectPickers": { "add": "Hinzufügen", diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 0326524a590..74135d0b9d5 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -3895,7 +3895,8 @@ "moreFields_one": "+{{count}} field", "moreFields_other": "+{{count}} fields", "loading": "Loading project…", - "noMatches": "No project items match." + "noMatches": "No project items match.", + "linkedPullRequestsOverflow": "+{{count}} more" }, "githubProjectPickers": { "title": "GitHub Projects", diff --git a/mobile/src/i18n/locales/es.json b/mobile/src/i18n/locales/es.json index a2089955800..0f23daf9d47 100644 --- a/mobile/src/i18n/locales/es.json +++ b/mobile/src/i18n/locales/es.json @@ -3366,7 +3366,8 @@ "moreFields_one": "+{{count}} campo", "moreFields_other": "+{{count}} campos", "noItems": "No hay elementos en el proyecto", - "pullRequestSubtitle": "Pull request · {{repository}}{{number}}" + "pullRequestSubtitle": "Pull request · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}} más" }, "githubProjectPickers": { "add": "Agregar", diff --git a/mobile/src/i18n/locales/fr.json b/mobile/src/i18n/locales/fr.json index 7fe42c24865..76a4f97b624 100644 --- a/mobile/src/i18n/locales/fr.json +++ b/mobile/src/i18n/locales/fr.json @@ -3366,7 +3366,8 @@ "moreFields_one": "+{{count}} champ", "moreFields_other": "+{{count}} champs", "noItems": "Aucun élément de projet", - "pullRequestSubtitle": "Pull request · {{repository}}{{number}}" + "pullRequestSubtitle": "Pull request · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}} de plus" }, "githubProjectPickers": { "add": "Ajouter", diff --git a/mobile/src/i18n/locales/ja.json b/mobile/src/i18n/locales/ja.json index 5399945a881..58b432afe2e 100644 --- a/mobile/src/i18n/locales/ja.json +++ b/mobile/src/i18n/locales/ja.json @@ -3273,7 +3273,8 @@ "moreFields_one": "+{{count}} フィールド", "moreFields_other": "+{{count}} フィールド", "noItems": "プロジェクトのアイテムがありません。", - "pullRequestSubtitle": "PR · {{repository}}{{number}}" + "pullRequestSubtitle": "PR · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "他{{count}}件" }, "githubProjectPickers": { "add": "追加", diff --git a/mobile/src/i18n/locales/ko.json b/mobile/src/i18n/locales/ko.json index 9892360a871..d05dc9828a0 100644 --- a/mobile/src/i18n/locales/ko.json +++ b/mobile/src/i18n/locales/ko.json @@ -3273,7 +3273,8 @@ "moreFields_one": "필드 +{{count}}개", "moreFields_other": "필드 +{{count}}개", "noItems": "프로젝트 항목이 없습니다.", - "pullRequestSubtitle": "PR · {{repository}}{{number}}" + "pullRequestSubtitle": "PR · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}}개 더" }, "githubProjectPickers": { "add": "추가", diff --git a/mobile/src/i18n/locales/pt.json b/mobile/src/i18n/locales/pt.json index 69b65e4358c..9cf6e3c756a 100644 --- a/mobile/src/i18n/locales/pt.json +++ b/mobile/src/i18n/locales/pt.json @@ -3366,7 +3366,8 @@ "moreFields_one": "+{{count}} campo", "moreFields_other": "+{{count}} campos", "noItems": "Nenhum item no projeto", - "pullRequestSubtitle": "Pull request · {{repository}}{{number}}" + "pullRequestSubtitle": "Pull request · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}} mais" }, "githubProjectPickers": { "add": "Adicionar", diff --git a/mobile/src/i18n/locales/ru.json b/mobile/src/i18n/locales/ru.json index 5373153d86f..c73566a00d2 100644 --- a/mobile/src/i18n/locales/ru.json +++ b/mobile/src/i18n/locales/ru.json @@ -3455,7 +3455,8 @@ "moreFields_one": "+{{count}} поле", "moreFields_other": "+{{count}} поля", "noItems": "В проекте нет элементов", - "pullRequestSubtitle": "Пул-реквест · {{repository}}{{number}}" + "pullRequestSubtitle": "Пул-реквест · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "Ещё {{count}}" }, "githubProjectPickers": { "add": "Добавить", diff --git a/mobile/src/i18n/locales/tr.json b/mobile/src/i18n/locales/tr.json index e9bd579c8f8..23ffec9063f 100644 --- a/mobile/src/i18n/locales/tr.json +++ b/mobile/src/i18n/locales/tr.json @@ -3277,7 +3277,8 @@ "moreFields_one": "+{{count}} alan", "moreFields_other": "+{{count}} alan", "noItems": "Proje öğesi yok", - "pullRequestSubtitle": "Pull request · {{repository}}{{number}}" + "pullRequestSubtitle": "Pull request · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "+{{count}} tane daha" }, "githubProjectPickers": { "add": "Ekle", diff --git a/mobile/src/i18n/locales/zh-Hant.json b/mobile/src/i18n/locales/zh-Hant.json index 9ad470c120d..f31a875dba9 100644 --- a/mobile/src/i18n/locales/zh-Hant.json +++ b/mobile/src/i18n/locales/zh-Hant.json @@ -3273,7 +3273,8 @@ "moreFields_one": "+{{count}} 個欄位", "moreFields_other": "+{{count}} 個欄位", "noItems": "沒有專案項目", - "pullRequestSubtitle": "PR · {{repository}}{{number}}" + "pullRequestSubtitle": "PR · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "另有 {{count}} 個" }, "githubProjectPickers": { "add": "新增", diff --git a/mobile/src/i18n/locales/zh.json b/mobile/src/i18n/locales/zh.json index 3131aa20c9e..241f5cc269a 100644 --- a/mobile/src/i18n/locales/zh.json +++ b/mobile/src/i18n/locales/zh.json @@ -3273,7 +3273,8 @@ "moreFields_one": "+{{count}} 个字段", "moreFields_other": "+{{count}} 个字段", "noItems": "没有项目条目", - "pullRequestSubtitle": "PR · {{repository}}{{number}}" + "pullRequestSubtitle": "PR · {{repository}}{{number}}", + "linkedPullRequestsOverflow": "另有 {{count}} 个" }, "githubProjectPickers": { "add": "添加", diff --git a/mobile/src/tasks/mobile-tasks-github-project-list.tsx b/mobile/src/tasks/mobile-tasks-github-project-list.tsx index 363e792a4f7..c06a1336792 100644 --- a/mobile/src/tasks/mobile-tasks-github-project-list.tsx +++ b/mobile/src/tasks/mobile-tasks-github-project-list.tsx @@ -1,3 +1,4 @@ +import { projectContentField } from '../../../src/shared/github/project-content-field' import type { ConnectionPresentationModel } from './use-mobile-tasks-connection-presentation' import { translate } from '../i18n/mobile-i18n' import { @@ -30,15 +31,15 @@ import type { GitHubProjectField, GitHubProjectRow } from './mobile-tasks-view-s import { pressedStyle } from '../theme/mobile-theme' function isProjectFieldEmpty(row: GitHubProjectRow, field: GitHubProjectField): boolean { + const contentValue = projectContentField(row.content, field.dataType) + if (contentValue !== undefined) { + return contentValue === null + } switch (field.dataType) { case 'ASSIGNEES': return row.content.assignees.map((user) => user.login).join(', ') === '' case 'LABELS': return row.content.labels.map((label) => label.name).join(', ') === '' - case 'REPOSITORY': - return row.content.repository == null - case 'PARENT_ISSUE': - return !row.content.parentIssue case 'ISSUE_TYPE': return row.content.issueType?.name == null case 'TITLE': diff --git a/mobile/src/tasks/mobile-tasks-project-content-fields.test.ts b/mobile/src/tasks/mobile-tasks-project-content-fields.test.ts new file mode 100644 index 00000000000..59c2769ede7 --- /dev/null +++ b/mobile/src/tasks/mobile-tasks-project-content-fields.test.ts @@ -0,0 +1,89 @@ +import React from 'react' +import { renderToStaticMarkup } from 'react-dom/server' +import { describe, expect, it, vi } from 'vitest' +import type { GitHubProjectRow } from '../../../src/shared/github/project-types' +import { projectRelationsTableFixture } from '../../../src/shared/github/project-relations.test-fixture' +import { normalizeLinkedPullRequests } from '../../../src/main/github/project-view/project-view-field-normalization' + +vi.mock('./mobile-tasks-dependencies', () => ({ + View: ({ children }: React.PropsWithChildren) => React.createElement('div', null, children), + Text: ({ children }: React.PropsWithChildren) => React.createElement('span', null, children), + Pressable: ({ children }: React.PropsWithChildren) => React.createElement('div', null, children), + FlatList: ({ + data, + renderItem + }: { + data: { row: GitHubProjectRow }[] + renderItem: (args: { item: unknown }) => React.ReactNode + }) => + React.createElement( + 'div', + null, + data.map((item) => React.createElement('div', { key: item.row.id }, renderItem({ item }))) + ), + colors: {}, + spacing: {}, + ChevronDown: () => null, + TaskProviderLogo: () => null +})) +vi.mock('lucide-react-native', () => ({ Inbox: () => null })) +vi.mock('../components/MobileStateView', () => ({ + MobileLoadErrorState: () => null, + MobileNoMatchState: () => null, + MobileStateView: () => null +})) +vi.mock('./mobile-tasks-search-control', () => ({ + clearMobileTasksSearch: () => {} +})) +vi.mock('./mobile-tasks-legacy-styles', () => ({ styles: {} })) +vi.mock('../theme/mobile-theme', () => ({ pressedStyle: {} })) +vi.mock('./mobile-tasks-legacy-foundation', async () => { + const fields = await import('./mobile-tasks-project-fields') + return { + projectFieldDisplayLabel: fields.projectFieldDisplayLabel, + projectGroupMeta: () => '', + projectRowStatusLabel: () => '', + formatUpdatedAt: () => '', + getRepoBadgeColor: () => '' + } +}) +import { renderMobileTasksGitHubProjectList } from './mobile-tasks-github-project-list' +import type { ConnectionPresentationModel } from './use-mobile-tasks-connection-presentation' + +function phoneText(table: ReturnType): string { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Only the populated-list fields are read; inert controls never invoke omitted actions. + const model = { + activeGitHubProject: table.project, + githubProjectTable: table, + githubProjectSummaryFields: table.selectedView.fields.slice(1), + githubProjectRepoSlugReady: true, + visibleGitHubProjectRows: table.rows, + githubProjectListEntries: table.rows.map((row) => ({ type: 'row', row })), + insets: { bottom: 0 }, + findProjectRowRepo: () => null + } as unknown as ConnectionPresentationModel + return renderToStaticMarkup(renderMobileTasksGitHubProjectList(model, 'dark', 0)).replace( + /<[^>]*>/g, + '' + ) +} + +describe('content-backed project field surfaces', () => { + it('renders fetched phone summary data and overflow when no numeric PR is available', () => { + const table = projectRelationsTableFixture() + const populated = phoneText(table) + expect(populated).toContain('#12') + expect(populated).toContain('1/2 (50%)') + table.rows[0].content.linkedPullRequests = normalizeLinkedPullRequests({ + __typename: 'ProjectV2ItemFieldPullRequestValue', + pullRequests: { nodes: [null, {}], totalCount: 3 } + }) + expect(phoneText(table)).toContain('+3') + delete table.rows[0].content.subIssuesProgress + delete table.rows[0].content.linkedPullRequests + const absent = phoneText(table) + expect(absent).not.toContain('#12') + expect(absent).not.toContain('1/2 (50%)') + expect(absent).not.toContain('+3') + }) +}) diff --git a/mobile/src/tasks/mobile-tasks-project-fields.ts b/mobile/src/tasks/mobile-tasks-project-fields.ts index 4ac8d094187..102ea9c4b2b 100644 --- a/mobile/src/tasks/mobile-tasks-project-fields.ts +++ b/mobile/src/tasks/mobile-tasks-project-fields.ts @@ -1,3 +1,8 @@ +import { + projectContentField, + projectContentFieldLabel +} from '../../../src/shared/github/project-content-field' +import { translate } from '../i18n/mobile-i18n' import type { GitHubProjectTable as SharedGitHubProjectTable } from '../../../src/shared/github/project-types' import { isIterationCurrent } from '../../../src/shared/github/project-group-sort' import type { ProjectGroup } from '../../../src/shared/github/project-group-sort' @@ -48,18 +53,33 @@ export function projectFieldValueLabel(row: GitHubProjectRow, field: GitHubProje } export function projectFieldDisplayLabel(row: GitHubProjectRow, field: GitHubProjectField): string { + const contentValue = projectContentField(row.content, field.dataType) + if (contentValue !== undefined) { + if (!contentValue) { + return 'Empty' + } + const label = projectContentFieldLabel(contentValue) + if (contentValue.kind !== 'linked') { + return label + } + const overflow = contentValue.linked.totalCount - contentValue.linked.pullRequests.length + return [ + label, + overflow > 0 + ? translate('tasks.githubProjectList.linkedPullRequestsOverflow', '+{{count}} more', { + count: overflow + }) + : '' + ] + .filter(Boolean) + .join(' ') + } if (field.dataType === 'ASSIGNEES') { return row.content.assignees.map((user) => user.login).join(', ') || 'Empty' } if (field.dataType === 'LABELS') { return row.content.labels.map((label) => label.name).join(', ') || 'Empty' } - if (field.dataType === 'REPOSITORY') { - return row.content.repository ?? 'Empty' - } - if (field.dataType === 'PARENT_ISSUE') { - return row.content.parentIssue ? `#${row.content.parentIssue.number}` : 'Empty' - } if (field.dataType === 'ISSUE_TYPE') { return row.content.issueType?.name ?? 'Empty' } diff --git a/mobile/src/tasks/mobile-tasks-view-state-types.ts b/mobile/src/tasks/mobile-tasks-view-state-types.ts index 03fa7ec5bdf..3a04e0ad65b 100644 --- a/mobile/src/tasks/mobile-tasks-view-state-types.ts +++ b/mobile/src/tasks/mobile-tasks-view-state-types.ts @@ -155,6 +155,11 @@ export type GitHubProjectRow = { labels: Array<{ name: string; color: string }> assignees: Array<{ login: string; name: string | null }> parentIssue?: { number: number; title: string; url: string } | null + subIssuesProgress?: { completed: number; total: number; percentCompleted: number } | null + linkedPullRequests?: { + pullRequests: { number: number; title: string; url: string }[] + totalCount: number + } | null } fieldValuesByFieldId?: Record updatedAt: string diff --git a/src/renderer/src/components/github-project/ProjectCell.tsx b/src/renderer/src/components/github-project/ProjectCell.tsx index ade697abcf6..0b812f91f3b 100644 --- a/src/renderer/src/components/github-project/ProjectCell.tsx +++ b/src/renderer/src/components/github-project/ProjectCell.tsx @@ -1,5 +1,9 @@ import type { RuntimeClientTarget } from '../../../../shared/runtime-client-target' import React from 'react' +import { + projectContentField, + projectContentFieldLabel +} from '../../../../shared/github/project-content-field' import { TYPE_FIELD_DATA_TYPE } from './columns' import type { GitHubIssueType, @@ -43,6 +47,7 @@ export default function ProjectCell({ sourceHost, sourceTarget }: Props): React.JSX.Element { + const contentValue = projectContentField(row.content, field.dataType) const value = row.fieldValuesByFieldId[field.id] const editableValue = editable && row.itemType !== 'REDACTED' if (field.dataType === 'TITLE') { @@ -84,28 +89,29 @@ export default function ProjectCell({ if (field.dataType === 'REPOSITORY') { return ( - {row.content.repository ?? ''} + {contentValue ? projectContentFieldLabel(contentValue) : ''} ) } if (field.dataType === 'PARENT_ISSUE') { return ( - {row.content.parentIssue ? `#${row.content.parentIssue.number}` : ''} + {contentValue ? projectContentFieldLabel(contentValue) : ''} ) } if (field.dataType === 'LINKED_PULL_REQUESTS') { - const linked = row.content.linkedPullRequests + const linked = contentValue?.kind === 'linked' ? contentValue.linked : null if (!linked) { return } - const labels = linked.pullRequests.map((pr) => `#${pr.number}`) const overflow = linked.totalCount - linked.pullRequests.length // Only the numbers truncate, so "+N more" stays visible in narrow columns. return ( - {labels.join(', ')} + + {contentValue ? projectContentFieldLabel(contentValue) : ''} + {overflow > 0 ? ( <> {' '} @@ -122,13 +128,12 @@ export default function ProjectCell({ ) } if (field.dataType === 'SUB_ISSUES_PROGRESS') { - const progress = row.content.subIssuesProgress - if (!progress || progress.total === 0) { + if (!contentValue) { return } return ( - {progress.completed}/{progress.total} ({progress.percentCompleted}%) + {projectContentFieldLabel(contentValue)} ) } diff --git a/src/renderer/src/components/github-project/ProjectViewList.fixture.tsx b/src/renderer/src/components/github-project/ProjectViewList.fixture.tsx new file mode 100644 index 00000000000..25ee789b631 --- /dev/null +++ b/src/renderer/src/components/github-project/ProjectViewList.fixture.tsx @@ -0,0 +1,39 @@ +import { defineFixture } from '../../component-fixtures/component-fixture' +import { projectRelationsTableFixture } from '../../../../shared/github/project-relations.test-fixture' +import ProjectViewList from './ProjectViewList' + +const table = projectRelationsTableFixture() +const repository = { + kind: 'field', + id: 'repo', + name: 'Repository', + dataType: 'REPOSITORY' +} as const +const parent = { + kind: 'field', + id: 'parent', + name: 'Parent issue', + dataType: 'PARENT_ISSUE' +} as const +const title = { kind: 'field', id: 'title', name: 'Title', dataType: 'TITLE' } as const +const base = table.rows[0] +table.rows = [101, 9, 2].map((number, position) => ({ + ...base, + id: `child-${number}`, + position, + content: { + ...base.content, + title: `Deliver milestone ${number}`, + repository: position === 2 ? 'acme/tools' : 'acme/app', + parentIssue: { number, title: 'Milestone', url: `https://github.com/acme/app/issues/${number}` } + } +})) +table.selectedView.fields = [title, parent, repository, ...table.selectedView.fields.slice(1)] +table.selectedView.groupByFields = [repository] +table.selectedView.sortByFields = [{ field: parent, direction: 'ASC' }] +table.totalCount = table.rows.length + +export const contentFields = defineFixture({ + width: 1280, + render: () => +}) diff --git a/src/renderer/src/components/github-project/group-sort.test.ts b/src/renderer/src/components/github-project/group-sort.test.ts index 6f5ec06ecbb..6736ee3127a 100644 --- a/src/renderer/src/components/github-project/group-sort.test.ts +++ b/src/renderer/src/components/github-project/group-sort.test.ts @@ -251,3 +251,98 @@ it('uses the first iteration ordering and metadata when legacy field IDs repeat' completed: true }) }) + +it('sorts content-backed parents with absent values last and secondary sorts before positions', () => { + const field: GitHubProjectField = { + kind: 'field', + id: 'parent', + name: 'Parent issue', + dataType: 'PARENT_ISSUE' + } + const parent = (repo: string, number: number) => ({ + number, + title: 'Parent', + url: `https://github.com/${repo}/issues/${number}` + }) + const rows = [ + makeRow('high', 0, {}, parent('acme/repo', 101)), + makeRow('low', 1, {}, parent('acme/repo', 9)), + makeRow('absent', 2, { parent: { kind: 'number', fieldId: 'parent', number: 1 } }), + makeRow( + 'same', + 3, + { F_points: { kind: 'number', fieldId: 'F_points', number: 1 } }, + parent('acme/other', 101) + ) + ] + rows[0].fieldValuesByFieldId.F_points = { kind: 'number', fieldId: 'F_points', number: 9 } + for (const [direction, expected] of [ + ['ASC', ['low', 'same', 'high', 'absent']], + ['DESC', ['same', 'high', 'low', 'absent']] + ] as const) { + const view = { + ...makeView(field), + sortByFields: [ + { field, direction }, + { field: numberField, direction: 'ASC' as const } + ] + } + expect(sortRows(makeTable(view, rows), rows).map((row) => row.id)).toEqual(expected) + } +}) + +it('groups repositories from content and orders synthetic progress groups numerically', () => { + const field: GitHubProjectField = { + kind: 'field', + id: 'repo', + name: 'Repository', + dataType: 'REPOSITORY' + } + const rows = [makeRow('z', 0, {}), makeRow('a', 1, {}), makeRow('empty', 2, {})] + rows[0].content.repository = 'acme/z' + rows[1].content.repository = 'acme/a' + rows[2].content.repository = null + const table = makeTable( + { ...makeView(field, { field, direction: 'DESC' }), groupByFields: [field] }, + rows + ) + expect( + groupRows(table, rows).map((group) => [group.label, group.rows.map((row) => row.id)]) + ).toEqual([ + ['acme/a', ['a']], + ['acme/z', ['z']], + ['No Repository', ['empty']] + ]) + expect(sortRows(table, rows).map((row) => row.id)).toEqual(['z', 'a', 'empty']) + const progress: GitHubProjectField = { + kind: 'field', + id: 'progress', + name: 'Sub-issues progress', + dataType: 'SUB_ISSUES_PROGRESS' + } + const progressRows = [90, 100, 20, 0].map((percent, index) => { + const row = makeRow(`p${percent}`, index, {}) + row.content.subIssuesProgress = { + completed: percent / 10, + total: percent === 0 ? 0 : 10, + percentCompleted: percent + } + return row + }) + const progressTable = makeTable( + { ...makeView(progress, { field: progress, direction: 'DESC' }), groupByFields: [progress] }, + progressRows + ) + expect(groupRows(progressTable, progressRows).map((group) => group.label)).toEqual([ + '2/10 (20%)', + '9/10 (90%)', + '10/10 (100%)', + 'No Sub-issues progress' + ]) + expect(sortRows(progressTable, progressRows).map((row) => row.id)).toEqual([ + 'p100', + 'p90', + 'p20', + 'p0' + ]) +}) diff --git a/src/shared/github/project-content-field.ts b/src/shared/github/project-content-field.ts new file mode 100644 index 00000000000..62fb053469c --- /dev/null +++ b/src/shared/github/project-content-field.ts @@ -0,0 +1,68 @@ +import type { GitHubProjectRow } from './project-types' + +type ProjectContent = Pick< + GitHubProjectRow['content'], + 'repository' | 'linkedPullRequests' | 'subIssuesProgress' +> & { parentIssue?: GitHubProjectRow['content']['parentIssue'] } + +export type ProjectContentField = + | { kind: 'parent'; parent: NonNullable } + | { kind: 'repository'; repository: string } + | { kind: 'progress'; progress: NonNullable } + | { kind: 'linked'; linked: NonNullable } + +// Undefined leaves unsupported fields on the field-value path; null is authoritative emptiness. +export function projectContentField( + content: ProjectContent, + dataType: string +): ProjectContentField | null | undefined { + switch (dataType) { + case 'PARENT_ISSUE': + return content.parentIssue ? { kind: 'parent', parent: content.parentIssue } : null + case 'REPOSITORY': + return content.repository ? { kind: 'repository', repository: content.repository } : null + case 'SUB_ISSUES_PROGRESS': + return content.subIssuesProgress && content.subIssuesProgress.total !== 0 + ? { kind: 'progress', progress: content.subIssuesProgress } + : null + case 'LINKED_PULL_REQUESTS': + return content.linkedPullRequests && + (content.linkedPullRequests.pullRequests.length > 0 || + content.linkedPullRequests.totalCount > 0) + ? { kind: 'linked', linked: content.linkedPullRequests } + : null + default: + return undefined + } +} + +export function projectContentFieldLabel(value: ProjectContentField): string { + switch (value.kind) { + case 'parent': + return `#${value.parent.number}` + case 'repository': + return value.repository + case 'progress': + return `${value.progress.completed}/${value.progress.total} (${value.progress.percentCompleted}%)` + case 'linked': + return value.linked.pullRequests.map((pr) => `#${pr.number}`).join(', ') + } +} + +export function projectContentFieldSortValue( + value: ProjectContentField | null +): string | number | null { + if (!value) { + return null + } + switch (value.kind) { + case 'parent': + return value.parent.number + case 'repository': + return value.repository + case 'progress': + return value.progress.percentCompleted + case 'linked': + return value.linked.pullRequests[0]?.number ?? null + } +} diff --git a/src/shared/github/project-group-sort.ts b/src/shared/github/project-group-sort.ts index 3bc73864117..30f3d7fd097 100644 --- a/src/shared/github/project-group-sort.ts +++ b/src/shared/github/project-group-sort.ts @@ -6,6 +6,12 @@ import type { GitHubProjectTable } from './project-types' +import { + projectContentField, + projectContentFieldLabel, + projectContentFieldSortValue +} from './project-content-field' + export type ProjectGroup = { key: string label: string @@ -69,19 +75,19 @@ function getFieldValueForGrouping( field: GitHubProjectField, orderIndex: ReadonlyMap ): { key: string; label: string; orderHint: number; iteration: ProjectGroup['iteration'] } { - // GitHub returns no field value for Parent issue; the parent lives on the content (#38099). - const parent = field.dataType === 'PARENT_ISSUE' ? row.content.parentIssue : null - if (parent) { - // Key by URL: multi-repo projects can share parent issue numbers. + const contentValue = projectContentField(row.content, field.dataType) + if (contentValue && contentValue.kind !== 'linked') { + const label = projectContentFieldLabel(contentValue) + const order = projectContentFieldSortValue(contentValue) return { - key: parent.url, - label: `#${parent.number}`, - orderHint: parent.number, + key: contentValue.kind === 'parent' ? contentValue.parent.url : `raw:${label}`, + label, + orderHint: typeof order === 'number' ? order : UNKNOWN_INDEX_SENTINEL - 1, iteration: null } } - const value = row.fieldValuesByFieldId[field.id] - if (!hasNonEmptyFieldValue(value)) { + const value = contentValue === null ? undefined : row.fieldValuesByFieldId[field.id] + if (!value || !hasNonEmptyFieldValue(value)) { return { key: EMPTY_PROJECT_GROUP_KEY, label: labelForEmpty(field), @@ -194,7 +200,11 @@ export function groupRowsByField( if (groupField.kind === 'iteration' || groupField.kind === 'single-select') { return a[1].orderHint - b[1].orderHint } - if (groupField.dataType === 'NUMBER' || groupField.dataType === 'PARENT_ISSUE') { + if ( + groupField.dataType === 'NUMBER' || + groupField.dataType === 'PARENT_ISSUE' || + groupField.dataType === 'SUB_ISSUES_PROGRESS' + ) { return a[1].orderHint - b[1].orderHint || a[1].label.localeCompare(b[1].label) } return a[1].label.localeCompare(b[1].label) @@ -214,6 +224,20 @@ function compareSort( orderIndex: ReadonlyMap ): number { const field = sort.field + const aContent = projectContentField(a.content, field.dataType) + if (aContent !== undefined) { + const bContent = projectContentField(b.content, field.dataType) + const aOrder = projectContentFieldSortValue(aContent) + const bOrder = projectContentFieldSortValue(bContent ?? null) + if (aOrder === null || bOrder === null) { + return aOrder === bOrder ? 0 : aOrder === null ? 1 : -1 + } + const cmp = + typeof aOrder === 'number' && typeof bOrder === 'number' + ? aOrder - bOrder + : String(aOrder).localeCompare(String(bOrder)) + return sort.direction === 'DESC' ? -cmp : cmp + } const aValue = a.fieldValuesByFieldId[field.id] const bValue = b.fieldValuesByFieldId[field.id] // Why: return before the trailing DESC flip so empty sorts last in both directions. diff --git a/tests/e2e/github-project-provider-columns.unit.test.ts b/tests/e2e/github-project-provider-columns.unit.test.ts index f0c1aaeb91e..10394e4cd80 100644 --- a/tests/e2e/github-project-provider-columns.unit.test.ts +++ b/tests/e2e/github-project-provider-columns.unit.test.ts @@ -15,6 +15,8 @@ import { } from '../../src/main/github/project-view/project-view-cache' import { ghExecFileAsync } from '../../src/main/github/project-view/internals' import type { GitHubProjectRow, GitHubProjectTable } from '../../src/shared/github/project-types' +import { normalizeLinkedPullRequests } from '../../src/main/github/project-view/project-view-field-normalization' +import { projectRelationsTableFixture } from '../../src/shared/github/project-relations.test-fixture' import { sortRows, groupRows } from '../../src/shared/github/project-group-sort' import ProjectCell from '../../src/renderer/src/components/github-project/ProjectCell' @@ -464,18 +466,68 @@ describe('Project columns from the items response', () => { renderColumns(groups[0].rows[0]) expect(document.body.textContent).toBe('') cleanup() - // Existing builtin ordering still uses the field map, with no new relation value kind. for (const field of [prs, progress]) { const relationTable = { ...table, selectedView: { ...table.selectedView, - groupByFields: [field], + groupByFields: field === progress ? [field] : [], sortByFields: [{ field, direction: 'ASC' as const }] } } expect(sortRows(relationTable, table.rows).map((row) => row.id)).toEqual(['item-1', 'legacy']) - expect(groupRows(relationTable, table.rows).map((group) => group.key)).toEqual(['__empty__']) + if (field === progress) { + expect( + groupRows(relationTable, table.rows).map((group) => group.rows.map((row) => row.id)) + ).toEqual([['item-1'], ['legacy']]) + } } }) }) + +it('sorts linked PRs by their first number and treats count-only metadata as an unknown sort key', () => { + const field = { + kind: 'field', + id: 'prs', + name: 'Linked pull requests', + dataType: 'LINKED_PULL_REQUESTS' + } as const + const rows = ['ten', 'two-high', 'count-only', 'two-low', 'absent'].map((id, position) => ({ + ...normalized({ id, type: 'ISSUE', content: { title: id } }), + position + })) + const table = projectRelationsTableFixture() + table.rows = rows + for (const [index, numbers] of [ + [0, [10]], + [1, [2, 100]], + [3, [2, 9]] + ] as const) { + rows[index].content.linkedPullRequests = { + pullRequests: numbers.map((number) => ({ + number, + title: 'PR', + url: `https://github.com/acme/repo/pull/${number}` + })), + totalCount: numbers.length + } + } + rows[2].content.linkedPullRequests = normalizeLinkedPullRequests({ + __typename: 'ProjectV2ItemFieldPullRequestValue', + pullRequests: { nodes: [null, {}], totalCount: 3 } + }) + for (const [direction, expected] of [ + ['ASC', ['two-high', 'two-low', 'ten', 'count-only', 'absent']], + ['DESC', ['ten', 'two-high', 'two-low', 'count-only', 'absent']] + ] as const) { + expect( + sortRows( + { + ...table, + selectedView: { ...table.selectedView, sortByFields: [{ field, direction }] } + }, + rows + ).map((row) => row.id) + ).toEqual(expected) + } +})