mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
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
This commit is contained in:
@@ -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<ProjectContent['parentIssue']> }
|
||||
| { kind: 'repository'; repository: string }
|
||||
| { kind: 'progress'; progress: NonNullable<ProjectContent['subIssuesProgress']> }
|
||||
| { kind: 'linked'; linked: NonNullable<ProjectContent['linkedPullRequests']> }
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -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<string, number>
|
||||
): { 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<string, number>
|
||||
): 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.
|
||||
|
||||
Reference in New Issue
Block a user