feat(jira): sort Jira issues by key, issue, status, priority, assignee and updated (#7959)
* fix(jira): add sortable columns to Jira issues in task page Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(jira): add comprehensive tests for Jira issue sorting functionality Add test coverage for the new Jira issue sorting features including: - Priority weight calculation with fallback logic - Sorting by key, title, priority, assignee, and updated date - Issue grouping and section ordering after sorting - Handling of edge cases like unassigned assignees and unknown priorities Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: resolve coderabbit review comments on jira issue sorting - Extract getJiraPriorityWeight and sorting logic into a shared jira-issue-sorter module. - Fix grid column definitions on md viewports in TaskPage.tsx. - Implement cancelled flags in useEffect hooks in TaskPage.tsx to guard against stale responses. - Swapped priority weights mapping to blocker=99, lowest=1, missing=0 to sort ascending from lowest-to-highest priority using weightA - weightB. - Focus-ring enhancements on sort button headers and aria-expanded/chevron fix on collapsible groups. - Remove duplicate helpers from unit tests and verify the new sorting expectations. * fix(jira): harden issue sorting review gaps --------- Co-authored-by: Andres Van Reepingen <andres.vanreepingen@datacamp.com> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
co-authored by
Andres Van Reepingen
Devin
Jinjing
parent
6f4919c2e1
commit
632a3c18a6
@@ -284,6 +284,7 @@ import type {
|
||||
JiraIssueType,
|
||||
JiraProject,
|
||||
JiraProjectStatusOrder,
|
||||
JiraPriority,
|
||||
LinearIssue,
|
||||
LinearProjectDetail,
|
||||
LinearProjectSummary,
|
||||
@@ -323,8 +324,16 @@ import {
|
||||
jiraGetIssue,
|
||||
jiraListCreateFields,
|
||||
jiraListIssueTypes,
|
||||
jiraListProjects
|
||||
jiraListProjects,
|
||||
jiraListPriorities
|
||||
} from '@/runtime/runtime-jira-client'
|
||||
import {
|
||||
sortJiraIssues,
|
||||
type JiraIssueSortColumn,
|
||||
type JiraIssueSortDirection,
|
||||
type JiraPrioritiesBySite
|
||||
} from './jira-issue-sorter'
|
||||
import { TaskPageJiraSortControls } from './task-page-jira-sort-controls'
|
||||
import {
|
||||
normalizeVisibleTaskProviders,
|
||||
restoreAvailableDefaultTaskProvider,
|
||||
@@ -4589,6 +4598,66 @@ export default function TaskPage(): React.JSX.Element {
|
||||
order: JiraProjectStatusOrder
|
||||
scopeKey: string
|
||||
} | null>(null)
|
||||
const [jiraOrderBy, setJiraOrderBy] = useState<JiraIssueSortColumn>('updated')
|
||||
const [jiraOrderDirection, setJiraOrderDirection] = useState<JiraIssueSortDirection>('desc')
|
||||
const [jiraPrioritiesBySite, setJiraPrioritiesBySite] = useState<JiraPrioritiesBySite>(
|
||||
() => new Map()
|
||||
)
|
||||
const jiraPrioritySiteIdsKey = useMemo(() => {
|
||||
const siteIds =
|
||||
selectedJiraSiteId && selectedJiraSiteId !== 'all'
|
||||
? [selectedJiraSiteId]
|
||||
: jiraIssues.flatMap((issue) => (issue.siteId ? [issue.siteId] : []))
|
||||
// Why: result refreshes replace the issue array; depend on the represented sites, not identity.
|
||||
return JSON.stringify([...new Set(siteIds)].sort())
|
||||
}, [jiraIssues, selectedJiraSiteId])
|
||||
|
||||
useEffect(() => {
|
||||
if (taskSource !== 'jira' || !jiraConnected || jiraOrderBy !== 'priority') {
|
||||
setJiraPrioritiesBySite((current) => (current.size === 0 ? current : new Map()))
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
const jiraPrioritySiteIds = JSON.parse(jiraPrioritySiteIdsKey) as string[]
|
||||
void Promise.all(
|
||||
jiraPrioritySiteIds.map(async (siteId) => {
|
||||
try {
|
||||
return [
|
||||
siteId,
|
||||
await jiraListPriorities(jiraTaskSourceContext ?? settings, siteId)
|
||||
] as const
|
||||
} catch {
|
||||
return [siteId, [] as JiraPriority[]] as const
|
||||
}
|
||||
})
|
||||
).then((prioritiesBySite) => {
|
||||
if (!cancelled) {
|
||||
setJiraPrioritiesBySite(new Map(prioritiesBySite))
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [
|
||||
jiraConnected,
|
||||
jiraOrderBy,
|
||||
jiraPrioritySiteIdsKey,
|
||||
jiraTaskSourceContext,
|
||||
settings,
|
||||
taskSource
|
||||
])
|
||||
|
||||
const handleJiraSort = useCallback(
|
||||
(column: JiraIssueSortColumn) => {
|
||||
if (jiraOrderBy === column) {
|
||||
setJiraOrderDirection((prevDir) => (prevDir === 'asc' ? 'desc' : 'asc'))
|
||||
} else {
|
||||
setJiraOrderBy(column)
|
||||
setJiraOrderDirection(column === 'updated' || column === 'status' ? 'desc' : 'asc')
|
||||
}
|
||||
},
|
||||
[jiraOrderBy]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (taskResumeAppliedRef.current || !persistedUIReady || !settings) {
|
||||
@@ -5621,6 +5690,14 @@ export default function TaskPage(): React.JSX.Element {
|
||||
? jiraProjectStatusOrder.order
|
||||
: null
|
||||
|
||||
const sortedJiraIssues = useMemo(() => {
|
||||
return sortJiraIssues(
|
||||
displayedJiraIssues,
|
||||
jiraOrderBy,
|
||||
jiraOrderDirection,
|
||||
jiraPrioritiesBySite
|
||||
)
|
||||
}, [displayedJiraIssues, jiraOrderBy, jiraOrderDirection, jiraPrioritiesBySite])
|
||||
// New Linear project dialog state
|
||||
const [newLinearProjectOpen, setNewLinearProjectOpen] = useState(false)
|
||||
const [newLinearProjectName, setNewLinearProjectName] = useState('')
|
||||
@@ -10010,17 +10087,11 @@ export default function TaskPage(): React.JSX.Element {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid h-8 flex-none grid-cols-[90px_minmax(0,1fr)_128px_92px_80px] items-center gap-3 border-b border-border/50 bg-muted/25 px-3 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground max-md:!hidden lg:grid-cols-[96px_minmax(0,1.25fr)_132px_120px_136px_96px_64px] xl:grid-cols-[104px_minmax(0,1.45fr)_144px_132px_160px_128px_72px]">
|
||||
<span>{translate('auto.components.TaskPage.37e7ee311e', 'Key')}</span>
|
||||
<span>{translate('auto.components.TaskPage.b1eaa18ace', 'Issue')}</span>
|
||||
<span>{translate('auto.components.TaskPage.154b0fa623', 'Status')}</span>
|
||||
<span>{translate('auto.components.TaskPage.c8d5bec5f7', 'Priority')}</span>
|
||||
<span className="block max-lg:!hidden">
|
||||
{translate('auto.components.TaskPage.d2a876ca53', 'Assignee')}
|
||||
</span>
|
||||
<span>{translate('auto.components.TaskPage.f362667d55', 'Updated')}</span>
|
||||
<span />
|
||||
</div>
|
||||
<TaskPageJiraSortControls
|
||||
direction={jiraOrderDirection}
|
||||
onSort={handleJiraSort}
|
||||
orderBy={jiraOrderBy}
|
||||
/>
|
||||
|
||||
<div
|
||||
className="min-h-0 flex-1 overflow-y-auto scrollbar-sleek"
|
||||
@@ -10075,11 +10146,12 @@ export default function TaskPage(): React.JSX.Element {
|
||||
<TaskPageJiraIssueList
|
||||
formatUpdatedAt={formatRelativeTime}
|
||||
getStatusTone={getJiraStatusTone}
|
||||
issues={displayedJiraIssues}
|
||||
issues={sortedJiraIssues}
|
||||
onOpenIssue={openJiraDetailPage}
|
||||
onStartWorkspace={handleUseJiraItem}
|
||||
selectedIssue={selectedJiraIssue}
|
||||
showSiteContext={selectedJiraSiteId === 'all'}
|
||||
statusDirection={jiraOrderBy === 'status' ? jiraOrderDirection : 'asc'}
|
||||
statusOrder={displayedJiraStatusOrder}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import type { JiraIssue, JiraPriority } from '../../../shared/types'
|
||||
|
||||
export type JiraIssueSortColumn = 'key' | 'title' | 'status' | 'priority' | 'assignee' | 'updated'
|
||||
|
||||
export type JiraIssueSortDirection = 'asc' | 'desc'
|
||||
export type JiraPrioritiesBySite = ReadonlyMap<string, readonly JiraPriority[]>
|
||||
|
||||
// Why: Jira instances can use synonymous names for the same standard priority tier.
|
||||
export const JIRA_PRIORITY_ORDER: Record<string, number> = {
|
||||
blocker: 99,
|
||||
highest: 99,
|
||||
critical: 99,
|
||||
high: 75,
|
||||
major: 75,
|
||||
medium: 50,
|
||||
normal: 50,
|
||||
low: 25,
|
||||
minor: 25,
|
||||
lowest: 1,
|
||||
trivial: 1
|
||||
}
|
||||
|
||||
export function getJiraPriorityWeight(
|
||||
priorityName?: string,
|
||||
priorityId?: string,
|
||||
jiraPriorities: readonly JiraPriority[] = []
|
||||
): number {
|
||||
if (!priorityName) {
|
||||
return 0
|
||||
}
|
||||
if (jiraPriorities.length > 0) {
|
||||
const idx = jiraPriorities.findIndex(
|
||||
(p) => p.id === priorityId || p.name.toLowerCase() === priorityName.toLowerCase()
|
||||
)
|
||||
if (idx !== -1) {
|
||||
// Why: site schemes have different tier counts, so raw indices are not cross-site comparable.
|
||||
if (jiraPriorities.length === 1) {
|
||||
return 50
|
||||
}
|
||||
return 1 + ((jiraPriorities.length - 1 - idx) / (jiraPriorities.length - 1)) * 98
|
||||
}
|
||||
}
|
||||
const nameKey = priorityName.toLowerCase()
|
||||
if (nameKey in JIRA_PRIORITY_ORDER) {
|
||||
return JIRA_PRIORITY_ORDER[nameKey]
|
||||
}
|
||||
// Why: custom priority IDs are opaque identifiers, not ordering ranks.
|
||||
return 50
|
||||
}
|
||||
|
||||
export function sortJiraIssues(
|
||||
issues: readonly JiraIssue[],
|
||||
orderBy: JiraIssueSortColumn,
|
||||
orderDirection: JiraIssueSortDirection,
|
||||
jiraPrioritiesBySite: JiraPrioritiesBySite = new Map()
|
||||
): JiraIssue[] {
|
||||
return [...issues].sort((a, b) => {
|
||||
let comparison = 0
|
||||
if (orderBy === 'key') {
|
||||
comparison = a.key.localeCompare(b.key, undefined, { numeric: true })
|
||||
} else if (orderBy === 'title') {
|
||||
comparison = a.title.localeCompare(b.title)
|
||||
} else if (orderBy === 'status') {
|
||||
comparison = 0
|
||||
} else if (orderBy === 'priority') {
|
||||
const prioritiesA = jiraPrioritiesBySite.get(a.siteId ?? '')
|
||||
const prioritiesB = jiraPrioritiesBySite.get(b.siteId ?? '')
|
||||
const weightA = getJiraPriorityWeight(a.priority?.name, a.priority?.id, prioritiesA)
|
||||
const weightB = getJiraPriorityWeight(b.priority?.name, b.priority?.id, prioritiesB)
|
||||
comparison = weightA - weightB
|
||||
} else if (orderBy === 'assignee') {
|
||||
const userA = a.assignee?.displayName ?? ''
|
||||
const userB = b.assignee?.displayName ?? ''
|
||||
comparison = userA.localeCompare(userB)
|
||||
} else if (orderBy === 'updated') {
|
||||
comparison = new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime()
|
||||
}
|
||||
return orderDirection === 'asc' ? comparison : -comparison
|
||||
})
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { cleanup, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { sortJiraIssues } from './jira-issue-sorter'
|
||||
import { groupJiraIssuesByStatus, TaskPageJiraIssueList } from './task-page-jira-issue-list'
|
||||
import {
|
||||
getSingleJiraProjectScope,
|
||||
@@ -34,7 +35,7 @@ function jiraIssue(
|
||||
title: string,
|
||||
statusId: string,
|
||||
statusName: string,
|
||||
options: { projectKey?: string; siteId?: string } = {}
|
||||
options: { priority?: string; projectKey?: string; siteId?: string } = {}
|
||||
): JiraIssue {
|
||||
const siteId = options.siteId ?? 'site-1'
|
||||
const projectKey = options.projectKey ?? 'ALP'
|
||||
@@ -48,6 +49,7 @@ function jiraIssue(
|
||||
project: { id: projectKey, key: projectKey, name: projectKey, siteId },
|
||||
issueType: { id: '10001', name: 'Bug' },
|
||||
status: { id: statusId, name: statusName, categoryKey: 'new', categoryName: statusName },
|
||||
priority: options.priority ? { id: options.priority, name: options.priority } : undefined,
|
||||
labels: [],
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt: '2026-01-01T00:00:00.000Z'
|
||||
@@ -83,6 +85,35 @@ describe('Jira issue status grouping', () => {
|
||||
expect(sections.map((section) => section.label)).toEqual(['In Progress', 'To Do', 'Done'])
|
||||
})
|
||||
|
||||
it('reverses Jira column order for descending status sort', () => {
|
||||
const sections = groupJiraIssuesByStatus(
|
||||
[
|
||||
jiraIssue('ALP-1', 'Done issue', '3', 'Done'),
|
||||
jiraIssue('ALP-2', 'To do issue', '1', 'To Do'),
|
||||
jiraIssue('ALP-3', 'Progress issue', '2', 'In Progress')
|
||||
],
|
||||
statusOrder([['1', '2'], ['3']]),
|
||||
'desc'
|
||||
)
|
||||
|
||||
expect(sections.map((section) => section.label)).toEqual(['Done', 'To Do', 'In Progress'])
|
||||
})
|
||||
|
||||
it('preserves priority sorting inside the production status groups', () => {
|
||||
const sortedIssues = sortJiraIssues(
|
||||
[
|
||||
jiraIssue('ALP-1', 'High issue', '1', 'To Do', { priority: 'High' }),
|
||||
jiraIssue('ALP-2', 'Low issue', '1', 'To Do', { priority: 'Low' })
|
||||
],
|
||||
'priority',
|
||||
'asc'
|
||||
)
|
||||
|
||||
const sections = groupJiraIssuesByStatus(sortedIssues, statusOrder([['1']]))
|
||||
|
||||
expect(sections[0]?.issues.map((issue) => issue.key)).toEqual(['ALP-2', 'ALP-1'])
|
||||
})
|
||||
|
||||
it('places statuses missing from board configuration last in alphabetical order', () => {
|
||||
const sections = groupJiraIssuesByStatus(
|
||||
[
|
||||
|
||||
@@ -22,6 +22,7 @@ type TaskPageJiraIssueListProps = {
|
||||
onStartWorkspace: (issue: JiraIssue) => void
|
||||
selectedIssue: JiraIssue | null
|
||||
showSiteContext: boolean
|
||||
statusDirection?: 'asc' | 'desc'
|
||||
statusOrder: JiraProjectStatusOrder | null
|
||||
}
|
||||
|
||||
@@ -50,7 +51,8 @@ function sectionColumnRank(
|
||||
|
||||
export function groupJiraIssuesByStatus(
|
||||
issues: readonly JiraIssue[],
|
||||
statusOrder: JiraProjectStatusOrder | null
|
||||
statusOrder: JiraProjectStatusOrder | null,
|
||||
statusDirection: 'asc' | 'desc' = 'asc'
|
||||
): TaskPageJiraIssueSection[] {
|
||||
const sections = new Map<string, TaskPageJiraIssueSection>()
|
||||
for (const issue of issues) {
|
||||
@@ -67,11 +69,12 @@ export function groupJiraIssuesByStatus(
|
||||
const sectionRanks = new Map(
|
||||
[...sections.values()].map((section) => [section.key, sectionColumnRank(section, ranks)])
|
||||
)
|
||||
return [...sections.values()].sort((a, b) => {
|
||||
const sortedSections = [...sections.values()].sort((a, b) => {
|
||||
const rankA = sectionRanks.get(a.key) ?? Number.POSITIVE_INFINITY
|
||||
const rankB = sectionRanks.get(b.key) ?? Number.POSITIVE_INFINITY
|
||||
return rankA === rankB ? a.label.localeCompare(b.label) : rankA - rankB
|
||||
})
|
||||
return statusDirection === 'desc' ? sortedSections.toReversed() : sortedSections
|
||||
}
|
||||
|
||||
function isSelectedIssue(issue: JiraIssue, selectedIssue: JiraIssue | null): boolean {
|
||||
@@ -123,7 +126,7 @@ function JiraIssueRow({
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
'group/row grid min-h-12 cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-3 px-3 py-2 text-left transition hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring md:grid-cols-[90px_minmax(0,1fr)_128px_92px_80px] lg:grid-cols-[96px_minmax(0,1.25fr)_132px_120px_136px_96px_64px] xl:grid-cols-[104px_minmax(0,1.45fr)_144px_132px_160px_128px_72px]',
|
||||
'group/row grid min-h-12 cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-3 px-3 py-2 text-left transition hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring md:grid-cols-[90px_minmax(0,1fr)_128px_92px_80px_64px] lg:grid-cols-[96px_minmax(0,1.25fr)_132px_120px_136px_96px_64px] xl:grid-cols-[104px_minmax(0,1.45fr)_144px_132px_160px_128px_72px]',
|
||||
selected && 'bg-accent'
|
||||
)}
|
||||
>
|
||||
@@ -280,12 +283,13 @@ export function TaskPageJiraIssueList({
|
||||
onStartWorkspace,
|
||||
selectedIssue,
|
||||
showSiteContext,
|
||||
statusDirection = 'asc',
|
||||
statusOrder
|
||||
}: TaskPageJiraIssueListProps): React.JSX.Element {
|
||||
const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(() => new Set())
|
||||
const sections = useMemo(
|
||||
() => groupJiraIssuesByStatus(issues, statusOrder),
|
||||
[issues, statusOrder]
|
||||
() => groupJiraIssuesByStatus(issues, statusOrder, statusDirection),
|
||||
[issues, statusDirection, statusOrder]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { TaskPageJiraSortControls } from './task-page-jira-sort-controls'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
function renderControls(
|
||||
onSort = vi.fn(),
|
||||
orderBy: 'key' | 'title' | 'status' | 'priority' | 'assignee' | 'updated' = 'updated',
|
||||
direction: 'asc' | 'desc' = 'desc'
|
||||
): ReturnType<typeof render> {
|
||||
return render(
|
||||
<TooltipProvider>
|
||||
<TaskPageJiraSortControls direction={direction} onSort={onSort} orderBy={orderBy} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
|
||||
describe('TaskPage Jira sort controls', () => {
|
||||
it('exposes the active desktop column and translated direction', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onSort = vi.fn()
|
||||
renderControls(onSort)
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Updated, descending' })).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true'
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'Assignee' })).toHaveClass('flex', 'max-lg:!hidden')
|
||||
expect(screen.getByRole('button', { name: 'Assignee' })).not.toHaveClass('block')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Key' }))
|
||||
expect(onSort).toHaveBeenCalledWith('key')
|
||||
})
|
||||
|
||||
it('keeps mobile column and direction controls available below md', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onSort = vi.fn()
|
||||
renderControls(onSort)
|
||||
|
||||
expect(screen.getByTestId('jira-mobile-sort-controls')).toHaveClass('hidden', 'max-md:!flex')
|
||||
await user.click(screen.getByRole('combobox', { name: 'Sort by' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Priority' }))
|
||||
expect(onSort).toHaveBeenCalledWith('priority')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Sort ascending' }))
|
||||
expect(onSort).toHaveBeenCalledWith('updated')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,137 @@
|
||||
import { ArrowDown, ArrowUp } from 'lucide-react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { JiraIssueSortColumn, JiraIssueSortDirection } from './jira-issue-sorter'
|
||||
|
||||
type JiraSortColumn = {
|
||||
id: JiraIssueSortColumn
|
||||
label: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
type TaskPageJiraSortControlsProps = {
|
||||
direction: JiraIssueSortDirection
|
||||
onSort: (column: JiraIssueSortColumn) => void
|
||||
orderBy: JiraIssueSortColumn
|
||||
}
|
||||
|
||||
function getJiraSortColumns(): JiraSortColumn[] {
|
||||
return [
|
||||
{ id: 'key', label: translate('auto.components.TaskPage.37e7ee311e', 'Key') },
|
||||
{ id: 'title', label: translate('auto.components.TaskPage.b1eaa18ace', 'Issue') },
|
||||
{ id: 'status', label: translate('auto.components.TaskPage.154b0fa623', 'Status') },
|
||||
{ id: 'priority', label: translate('auto.components.TaskPage.c8d5bec5f7', 'Priority') },
|
||||
{
|
||||
id: 'assignee',
|
||||
label: translate('auto.components.TaskPage.d2a876ca53', 'Assignee'),
|
||||
className: 'max-lg:!hidden'
|
||||
},
|
||||
{ id: 'updated', label: translate('auto.components.TaskPage.f362667d55', 'Updated') }
|
||||
]
|
||||
}
|
||||
|
||||
export function TaskPageJiraSortControls({
|
||||
direction,
|
||||
onSort,
|
||||
orderBy
|
||||
}: TaskPageJiraSortControlsProps): React.JSX.Element {
|
||||
const columns = getJiraSortColumns()
|
||||
const directionLabel =
|
||||
direction === 'asc'
|
||||
? translate('auto.components.TaskPage.jiraSortAscending', 'ascending')
|
||||
: translate('auto.components.TaskPage.jiraSortDescending', 'descending')
|
||||
const nextDirectionLabel =
|
||||
direction === 'asc'
|
||||
? translate('auto.components.TaskPage.jiraSortDescending', 'descending')
|
||||
: translate('auto.components.TaskPage.jiraSortAscending', 'ascending')
|
||||
const sortByLabel = translate('auto.components.TaskPage.jiraSortBy', 'Sort by')
|
||||
const toggleDirectionLabel = translate(
|
||||
'auto.components.TaskPage.jiraToggleSortDirection',
|
||||
'Sort {{value0}}',
|
||||
{ value0: nextDirectionLabel }
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="grid h-8 flex-none grid-cols-[90px_minmax(0,1fr)_128px_92px_80px_64px] items-center gap-3 border-b border-border/50 bg-muted/25 px-3 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground max-md:!hidden lg:grid-cols-[96px_minmax(0,1.25fr)_132px_120px_136px_96px_64px] xl:grid-cols-[104px_minmax(0,1.45fr)_144px_132px_160px_128px_72px]">
|
||||
{columns.map((column) => (
|
||||
<button
|
||||
key={column.id}
|
||||
type="button"
|
||||
onClick={() => onSort(column.id)}
|
||||
aria-label={orderBy === column.id ? `${column.label}, ${directionLabel}` : column.label}
|
||||
aria-pressed={orderBy === column.id}
|
||||
className={cn(
|
||||
'flex items-center gap-1 rounded-sm text-left text-[11px] font-semibold tracking-[0.08em] uppercase select-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:outline-none',
|
||||
column.className
|
||||
)}
|
||||
>
|
||||
{column.label}
|
||||
{orderBy === column.id &&
|
||||
(direction === 'asc' ? (
|
||||
<ArrowUp aria-hidden="true" className="size-3" />
|
||||
) : (
|
||||
<ArrowDown aria-hidden="true" className="size-3" />
|
||||
))}
|
||||
</button>
|
||||
))}
|
||||
<span />
|
||||
</div>
|
||||
|
||||
<div
|
||||
data-testid="jira-mobile-sort-controls"
|
||||
className="hidden h-10 flex-none items-center gap-2 border-b border-border/50 bg-muted/25 px-3 max-md:!flex"
|
||||
>
|
||||
<span className="shrink-0 text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase">
|
||||
{sortByLabel}
|
||||
</span>
|
||||
<Select value={orderBy} onValueChange={(value) => onSort(value as JiraIssueSortColumn)}>
|
||||
<SelectTrigger
|
||||
size="sm"
|
||||
aria-label={sortByLabel}
|
||||
className="min-w-0 flex-1 border-border/50 bg-background text-xs shadow-none"
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{columns.map((column) => (
|
||||
<SelectItem key={column.id} value={column.id}>
|
||||
{column.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label={toggleDirectionLabel}
|
||||
onClick={() => onSort(orderBy)}
|
||||
>
|
||||
{direction === 'asc' ? (
|
||||
<ArrowUp aria-hidden="true" className="size-3.5" />
|
||||
) : (
|
||||
<ArrowDown aria-hidden="true" className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{toggleDirectionLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { JiraIssue, JiraPriority } from '../../../shared/types'
|
||||
import { getJiraPriorityWeight, sortJiraIssues } from './jira-issue-sorter'
|
||||
|
||||
describe('TaskPage Jira sorting functionality', () => {
|
||||
function jiraIssue(
|
||||
key: string,
|
||||
title: string,
|
||||
statusName: string,
|
||||
priorityName?: string,
|
||||
priorityId?: string,
|
||||
assigneeDisplayName?: string,
|
||||
updatedAt = '2026-01-01T00:00:00.000Z',
|
||||
siteId = 'site-1',
|
||||
categoryKey = 'new'
|
||||
): JiraIssue {
|
||||
return {
|
||||
id: `${siteId}:${key}`,
|
||||
key,
|
||||
title,
|
||||
url: `https://example.atlassian.net/browse/${key}`,
|
||||
siteId,
|
||||
siteName: 'Example Jira',
|
||||
project: { id: '10000', key: 'ALP', name: 'Alpha', siteId },
|
||||
issueType: { id: '10001', name: 'Bug' },
|
||||
status: { id: '1', name: statusName, categoryKey, categoryName: statusName },
|
||||
priority: priorityName ? { id: priorityId ?? '1', name: priorityName } : undefined,
|
||||
assignee: assigneeDisplayName
|
||||
? { accountId: 'user-1', displayName: assigneeDisplayName }
|
||||
: undefined,
|
||||
labels: [],
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
|
||||
function jiraPriority(id: string, name: string): JiraPriority {
|
||||
return { id, name }
|
||||
}
|
||||
|
||||
describe('getJiraPriorityWeight', () => {
|
||||
it('returns default weight for missing priority', () => {
|
||||
expect(getJiraPriorityWeight(undefined, undefined, [])).toBe(0)
|
||||
})
|
||||
|
||||
it('uses priority index from Jira priorities list when available', () => {
|
||||
const jiraPriorities: JiraPriority[] = [
|
||||
jiraPriority('1', 'Highest'),
|
||||
jiraPriority('2', 'High'),
|
||||
jiraPriority('3', 'Medium'),
|
||||
jiraPriority('4', 'Low')
|
||||
]
|
||||
|
||||
expect(getJiraPriorityWeight('High', '2', jiraPriorities)).toBeCloseTo(66.33, 2)
|
||||
expect(getJiraPriorityWeight('Medium', '3', jiraPriorities)).toBeCloseTo(33.67, 2)
|
||||
})
|
||||
|
||||
it('keeps missing priority below the lowest configured priority', () => {
|
||||
const jiraPriorities = [jiraPriority('1', 'High'), jiraPriority('2', 'Low')]
|
||||
|
||||
expect(getJiraPriorityWeight(undefined, undefined, jiraPriorities)).toBe(0)
|
||||
expect(getJiraPriorityWeight('Low', '2', jiraPriorities)).toBe(1)
|
||||
})
|
||||
|
||||
it('falls back to priority name mapping when not in priorities list', () => {
|
||||
expect(getJiraPriorityWeight('Blocker', '1', [])).toBe(99)
|
||||
expect(getJiraPriorityWeight('High', '2', [])).toBe(75)
|
||||
expect(getJiraPriorityWeight('Medium', '3', [])).toBe(50)
|
||||
expect(getJiraPriorityWeight('Low', '4', [])).toBe(25)
|
||||
expect(getJiraPriorityWeight('Lowest', '5', [])).toBe(1)
|
||||
})
|
||||
|
||||
it('does not treat opaque custom priority IDs as ordering ranks', () => {
|
||||
expect(getJiraPriorityWeight('Custom Priority', '10', [])).toBe(50)
|
||||
expect(getJiraPriorityWeight('Another', '5', [])).toBe(50)
|
||||
expect(getJiraPriorityWeight('Unknown Priority', 'invalid', [])).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
describe('issue sorting', () => {
|
||||
it('sorts by key in ascending order', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-10', 'Issue 10', 'To Do'),
|
||||
jiraIssue('ALP-2', 'Issue 2', 'To Do'),
|
||||
jiraIssue('ALP-1', 'Issue 1', 'To Do')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'key', 'asc')
|
||||
|
||||
expect(sorted[0].key).toBe('ALP-1')
|
||||
expect(sorted[1].key).toBe('ALP-2')
|
||||
expect(sorted[2].key).toBe('ALP-10')
|
||||
})
|
||||
|
||||
it('sorts by key in descending order', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-1', 'Issue 1', 'To Do'),
|
||||
jiraIssue('ALP-2', 'Issue 2', 'To Do'),
|
||||
jiraIssue('ALP-10', 'Issue 10', 'To Do')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'key', 'desc')
|
||||
|
||||
expect(sorted[0].key).toBe('ALP-10')
|
||||
expect(sorted[1].key).toBe('ALP-2')
|
||||
expect(sorted[2].key).toBe('ALP-1')
|
||||
})
|
||||
|
||||
it('sorts by title alphabetically', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-1', 'Zebra Issue', 'To Do'),
|
||||
jiraIssue('ALP-2', 'Apple Issue', 'To Do'),
|
||||
jiraIssue('ALP-3', 'Banana Issue', 'To Do')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'title', 'asc')
|
||||
|
||||
expect(sorted[0].title).toBe('Apple Issue')
|
||||
expect(sorted[1].title).toBe('Banana Issue')
|
||||
expect(sorted[2].title).toBe('Zebra Issue')
|
||||
})
|
||||
|
||||
it('sorts by priority weight (lowest priority first)', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-1', 'Issue 1', 'To Do', 'Low', '4'),
|
||||
jiraIssue('ALP-2', 'Issue 2', 'To Do', 'High', '2'),
|
||||
jiraIssue('ALP-3', 'Issue 3', 'To Do', 'Medium', '3')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'priority', 'asc')
|
||||
|
||||
expect(sorted[0].priority?.name).toBe('Low')
|
||||
expect(sorted[1].priority?.name).toBe('Medium')
|
||||
expect(sorted[2].priority?.name).toBe('High')
|
||||
})
|
||||
|
||||
it('uses each Jira site priority order when sorting an all-sites list', () => {
|
||||
const issues = [
|
||||
jiraIssue(
|
||||
'BRV-1',
|
||||
'Site B low by name',
|
||||
'To Do',
|
||||
'Low',
|
||||
'2',
|
||||
undefined,
|
||||
undefined,
|
||||
'site-b'
|
||||
),
|
||||
jiraIssue(
|
||||
'BRV-2',
|
||||
'Site B high by name',
|
||||
'To Do',
|
||||
'High',
|
||||
'1',
|
||||
undefined,
|
||||
undefined,
|
||||
'site-b'
|
||||
)
|
||||
]
|
||||
const prioritiesBySite = new Map<string, JiraPriority[]>([
|
||||
['site-a', [jiraPriority('1', 'High'), jiraPriority('2', 'Low')]],
|
||||
['site-b', [jiraPriority('2', 'Low'), jiraPriority('1', 'High')]]
|
||||
])
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'priority', 'asc', prioritiesBySite)
|
||||
|
||||
expect(sorted.map((issue) => issue.key)).toEqual(['BRV-2', 'BRV-1'])
|
||||
})
|
||||
|
||||
it('normalizes priority ranks across sites with different tier counts', () => {
|
||||
const issues = [
|
||||
jiraIssue(
|
||||
'ALP-1',
|
||||
'Site A highest',
|
||||
'To Do',
|
||||
'Highest',
|
||||
'1',
|
||||
undefined,
|
||||
undefined,
|
||||
'site-a'
|
||||
),
|
||||
jiraIssue('BRV-1', 'Site B medium', 'To Do', 'Medium', '3', undefined, undefined, 'site-b')
|
||||
]
|
||||
const prioritiesBySite = new Map<string, JiraPriority[]>([
|
||||
['site-a', [jiraPriority('1', 'Highest'), jiraPriority('2', 'Lowest')]],
|
||||
[
|
||||
'site-b',
|
||||
[
|
||||
jiraPriority('1', 'Highest'),
|
||||
jiraPriority('2', 'High'),
|
||||
jiraPriority('3', 'Medium'),
|
||||
jiraPriority('4', 'Low'),
|
||||
jiraPriority('5', 'Lowest')
|
||||
]
|
||||
]
|
||||
])
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'priority', 'asc', prioritiesBySite)
|
||||
|
||||
expect(sorted.map((issue) => issue.key)).toEqual(['BRV-1', 'ALP-1'])
|
||||
})
|
||||
|
||||
it('sorts by assignee alphabetically', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-1', 'Issue 1', 'To Do', undefined, undefined, 'Zoe'),
|
||||
jiraIssue('ALP-2', 'Issue 2', 'To Do', undefined, undefined, 'Alice'),
|
||||
jiraIssue('ALP-3', 'Issue 3', 'To Do', undefined, undefined, 'Bob')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'assignee', 'asc')
|
||||
|
||||
expect(sorted[0].assignee?.displayName).toBe('Alice')
|
||||
expect(sorted[1].assignee?.displayName).toBe('Bob')
|
||||
expect(sorted[2].assignee?.displayName).toBe('Zoe')
|
||||
})
|
||||
|
||||
it('sorts by updated date (newest first)', () => {
|
||||
const issues = [
|
||||
jiraIssue(
|
||||
'ALP-1',
|
||||
'Issue 1',
|
||||
'To Do',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'2026-01-01T00:00:00.000Z'
|
||||
),
|
||||
jiraIssue(
|
||||
'ALP-2',
|
||||
'Issue 2',
|
||||
'To Do',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'2026-01-03T00:00:00.000Z'
|
||||
),
|
||||
jiraIssue(
|
||||
'ALP-3',
|
||||
'Issue 3',
|
||||
'To Do',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'2026-01-02T00:00:00.000Z'
|
||||
)
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'updated', 'desc')
|
||||
|
||||
expect(sorted[0].key).toBe('ALP-2')
|
||||
expect(sorted[1].key).toBe('ALP-3')
|
||||
expect(sorted[2].key).toBe('ALP-1')
|
||||
})
|
||||
|
||||
it('handles unassigned assignees in sorting', () => {
|
||||
const issues = [
|
||||
jiraIssue('ALP-1', 'Issue 1', 'To Do', undefined, undefined, 'Alice'),
|
||||
jiraIssue('ALP-2', 'Issue 2', 'To Do', undefined, undefined, undefined),
|
||||
jiraIssue('ALP-3', 'Issue 3', 'To Do', undefined, undefined, 'Bob')
|
||||
]
|
||||
|
||||
const sorted = sortJiraIssues(issues, 'assignee', 'asc')
|
||||
|
||||
expect(sorted[0].assignee?.displayName).toBeUndefined()
|
||||
expect(sorted[1].assignee?.displayName).toBe('Alice')
|
||||
expect(sorted[2].assignee?.displayName).toBe('Bob')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1736,7 +1736,11 @@
|
||||
"editReviewersWithCurrent": "Edit reviewers: {{value0}}",
|
||||
"linearEmptyAttributeFilter": "No issues match the selected filters. Clear a filter or try different criteria.",
|
||||
"linearEmptyUnfilteredScope": "No issues in this workspace scope. Try searching or adjusting teams.",
|
||||
"linearFetchMore": "Fetch more"
|
||||
"linearFetchMore": "Fetch more",
|
||||
"jiraSortAscending": "ascending",
|
||||
"jiraSortDescending": "descending",
|
||||
"jiraSortBy": "Sort by",
|
||||
"jiraToggleSortDirection": "Sort {{value0}}"
|
||||
},
|
||||
"Terminal": {
|
||||
"73768427cf": "Close",
|
||||
|
||||
@@ -1736,7 +1736,11 @@
|
||||
"editReviewersWithCurrent": "Editar revisores: {{value0}}",
|
||||
"linearEmptyAttributeFilter": "Ningún issue coincide con los filtros seleccionados. Limpia un filtro o prueba con otros criterios.",
|
||||
"linearEmptyUnfilteredScope": "No hay issues en el alcance de este espacio de trabajo. Intenta buscar o ajustar los equipos.",
|
||||
"linearFetchMore": "Cargar más"
|
||||
"linearFetchMore": "Cargar más",
|
||||
"jiraSortAscending": "ascendente",
|
||||
"jiraSortDescending": "descendente",
|
||||
"jiraSortBy": "Ordenar por",
|
||||
"jiraToggleSortDirection": "Ordenar de forma {{value0}}"
|
||||
},
|
||||
"Terminal": {
|
||||
"73768427cf": "Cerrar",
|
||||
|
||||
@@ -1736,7 +1736,11 @@
|
||||
"editReviewersWithCurrent": "レビュアーを編集: {{value0}}",
|
||||
"linearEmptyAttributeFilter": "選択したフィルターに一致するイシューがありません。フィルターを解除するか、異なる条件を試してください。",
|
||||
"linearEmptyUnfilteredScope": "このワークスペーススコープにイシューがありません。検索するか、チームを調整してください。",
|
||||
"linearFetchMore": "さらに読み込む"
|
||||
"linearFetchMore": "さらに読み込む",
|
||||
"jiraSortAscending": "昇順",
|
||||
"jiraSortDescending": "降順",
|
||||
"jiraSortBy": "並べ替え",
|
||||
"jiraToggleSortDirection": "{{value0}}に並べ替え"
|
||||
},
|
||||
"Terminal": {
|
||||
"73768427cf": "閉じる",
|
||||
|
||||
@@ -1736,7 +1736,11 @@
|
||||
"editReviewersWithCurrent": "리뷰어 편집: {{value0}}",
|
||||
"linearEmptyAttributeFilter": "선택한 필터와 일치하는 이슈가 없습니다. 필터를 지우거나 다른 조건을 시도하세요.",
|
||||
"linearEmptyUnfilteredScope": "이 워크트리 범위에 이슈가 없습니다. 검색하거나 팀을 조정해 보세요.",
|
||||
"linearFetchMore": "더 불러오기"
|
||||
"linearFetchMore": "더 불러오기",
|
||||
"jiraSortAscending": "오름차순",
|
||||
"jiraSortDescending": "내림차순",
|
||||
"jiraSortBy": "정렬 기준",
|
||||
"jiraToggleSortDirection": "{{value0}}으로 정렬"
|
||||
},
|
||||
"Terminal": {
|
||||
"73768427cf": "닫기",
|
||||
|
||||
@@ -1736,7 +1736,11 @@
|
||||
"editReviewersWithCurrent": "编辑评审人:{{value0}}",
|
||||
"linearEmptyAttributeFilter": "没有匹配所选筛选条件的问题。请清除筛选条件或尝试其他条件。",
|
||||
"linearEmptyUnfilteredScope": "此工作区范围内没有问题。请尝试搜索或调整团队。",
|
||||
"linearFetchMore": "加载更多"
|
||||
"linearFetchMore": "加载更多",
|
||||
"jiraSortAscending": "升序",
|
||||
"jiraSortDescending": "降序",
|
||||
"jiraSortBy": "排序方式",
|
||||
"jiraToggleSortDirection": "按{{value0}}排序"
|
||||
},
|
||||
"Terminal": {
|
||||
"73768427cf": "关闭",
|
||||
|
||||
Reference in New Issue
Block a user