mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
fix(github-project): group by Parent issue using the row's parent (#38212)
GitHub returns no field value for the built-in Parent issue field, so grouping by it put every row in "No Parent issue". Group by row.content.parentIssue (keyed by URL so multi-repo projects with the same issue number stay separate) and order groups by issue number. Fixes #38099
This commit is contained in:
@@ -36,7 +36,8 @@ const numberField: GitHubProjectField = {
|
||||
function makeRow(
|
||||
id: string,
|
||||
position: number,
|
||||
values: GitHubProjectRow['fieldValuesByFieldId']
|
||||
values: GitHubProjectRow['fieldValuesByFieldId'],
|
||||
parentIssue: GitHubProjectRow['content']['parentIssue'] = null
|
||||
): GitHubProjectRow {
|
||||
return {
|
||||
id,
|
||||
@@ -52,7 +53,7 @@ function makeRow(
|
||||
repository: 'acme/repo',
|
||||
assignees: [],
|
||||
labels: [],
|
||||
parentIssue: null,
|
||||
parentIssue,
|
||||
issueType: null
|
||||
},
|
||||
fieldValuesByFieldId: values,
|
||||
@@ -182,6 +183,37 @@ describe('groupRows', () => {
|
||||
|
||||
expect(groups.map((group) => group.label)).toEqual(['-10', '-2', '1', '2', '8', '10'])
|
||||
})
|
||||
|
||||
it('groups by Parent issue from row content, since GitHub returns no field value for it', () => {
|
||||
const parentField: GitHubProjectField = {
|
||||
kind: 'field',
|
||||
id: 'F_parent',
|
||||
name: 'Parent issue',
|
||||
dataType: 'PARENT_ISSUE'
|
||||
}
|
||||
const view = { ...makeView(parentField), groupByFields: [parentField] }
|
||||
const parent = (repo: string, number: number) => ({
|
||||
number,
|
||||
title: `Parent ${number}`,
|
||||
url: `https://github.com/${repo}/issues/${number}`
|
||||
})
|
||||
const rows = [
|
||||
makeRow('a1', 0, {}, parent('acme/repo', 101)),
|
||||
makeRow('b', 1, {}, parent('acme/repo', 9)),
|
||||
makeRow('orphan', 2, {}),
|
||||
makeRow('a2', 3, {}, parent('acme/repo', 101)),
|
||||
makeRow('other-repo', 4, {}, parent('acme/other', 101))
|
||||
]
|
||||
|
||||
const groups = groupRows(makeTable(view, rows), rows)
|
||||
|
||||
expect(groups.map((group) => [group.label, group.rows.map((r) => r.id)])).toEqual([
|
||||
['#9', ['b']],
|
||||
['#101', ['a1', 'a2']],
|
||||
['#101', ['other-repo']],
|
||||
['No Parent issue', ['orphan']]
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('uses the first iteration ordering and metadata when legacy field IDs repeat', () => {
|
||||
|
||||
@@ -69,6 +69,17 @@ 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.
|
||||
return {
|
||||
key: parent.url,
|
||||
label: `#${parent.number}`,
|
||||
orderHint: parent.number,
|
||||
iteration: null
|
||||
}
|
||||
}
|
||||
const value = row.fieldValuesByFieldId[field.id]
|
||||
if (!hasNonEmptyFieldValue(value)) {
|
||||
return {
|
||||
@@ -183,7 +194,7 @@ export function groupRowsByField(
|
||||
if (groupField.kind === 'iteration' || groupField.kind === 'single-select') {
|
||||
return a[1].orderHint - b[1].orderHint
|
||||
}
|
||||
if (groupField.dataType === 'NUMBER') {
|
||||
if (groupField.dataType === 'NUMBER' || groupField.dataType === 'PARENT_ISSUE') {
|
||||
return a[1].orderHint - b[1].orderHint || a[1].label.localeCompare(b[1].label)
|
||||
}
|
||||
return a[1].label.localeCompare(b[1].label)
|
||||
|
||||
Reference in New Issue
Block a user