From 632a3c18a67efa517e9ea0c218d33b67415a0dd5 Mon Sep 17 00:00:00 2001 From: Andres Van Reepingen Date: Sat, 11 Jul 2026 04:39:17 +0200 Subject: [PATCH] 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 Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> --- src/renderer/src/components/TaskPage.tsx | 98 ++++++- .../src/components/jira-issue-sorter.ts | 80 ++++++ .../task-page-jira-grouping.test.ts | 33 ++- .../components/task-page-jira-issue-list.tsx | 14 +- .../task-page-jira-sort-controls.test.tsx | 56 ++++ .../task-page-jira-sort-controls.tsx | 137 +++++++++ .../components/task-page-jira-sorting.test.ts | 269 ++++++++++++++++++ src/renderer/src/i18n/locales/en.json | 6 +- src/renderer/src/i18n/locales/es.json | 6 +- src/renderer/src/i18n/locales/ja.json | 6 +- src/renderer/src/i18n/locales/ko.json | 6 +- src/renderer/src/i18n/locales/zh.json | 6 +- 12 files changed, 693 insertions(+), 24 deletions(-) create mode 100644 src/renderer/src/components/jira-issue-sorter.ts create mode 100644 src/renderer/src/components/task-page-jira-sort-controls.test.tsx create mode 100644 src/renderer/src/components/task-page-jira-sort-controls.tsx create mode 100644 src/renderer/src/components/task-page-jira-sorting.test.ts diff --git a/src/renderer/src/components/TaskPage.tsx b/src/renderer/src/components/TaskPage.tsx index 5e74b874b..8d37800b8 100644 --- a/src/renderer/src/components/TaskPage.tsx +++ b/src/renderer/src/components/TaskPage.tsx @@ -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('updated') + const [jiraOrderDirection, setJiraOrderDirection] = useState('desc') + const [jiraPrioritiesBySite, setJiraPrioritiesBySite] = useState( + () => 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 { -
- {translate('auto.components.TaskPage.37e7ee311e', 'Key')} - {translate('auto.components.TaskPage.b1eaa18ace', 'Issue')} - {translate('auto.components.TaskPage.154b0fa623', 'Status')} - {translate('auto.components.TaskPage.c8d5bec5f7', 'Priority')} - - {translate('auto.components.TaskPage.d2a876ca53', 'Assignee')} - - {translate('auto.components.TaskPage.f362667d55', 'Updated')} - -
+
diff --git a/src/renderer/src/components/jira-issue-sorter.ts b/src/renderer/src/components/jira-issue-sorter.ts new file mode 100644 index 000000000..a95680c1c --- /dev/null +++ b/src/renderer/src/components/jira-issue-sorter.ts @@ -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 + +// Why: Jira instances can use synonymous names for the same standard priority tier. +export const JIRA_PRIORITY_ORDER: Record = { + 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 + }) +} diff --git a/src/renderer/src/components/task-page-jira-grouping.test.ts b/src/renderer/src/components/task-page-jira-grouping.test.ts index 2627b62a4..44d8bce4f 100644 --- a/src/renderer/src/components/task-page-jira-grouping.test.ts +++ b/src/renderer/src/components/task-page-jira-grouping.test.ts @@ -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( [ diff --git a/src/renderer/src/components/task-page-jira-issue-list.tsx b/src/renderer/src/components/task-page-jira-issue-list.tsx index f8b67d1c2..104f591ab 100644 --- a/src/renderer/src/components/task-page-jira-issue-list.tsx +++ b/src/renderer/src/components/task-page-jira-issue-list.tsx @@ -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() 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>(() => new Set()) const sections = useMemo( - () => groupJiraIssuesByStatus(issues, statusOrder), - [issues, statusOrder] + () => groupJiraIssuesByStatus(issues, statusOrder, statusDirection), + [issues, statusDirection, statusOrder] ) return ( diff --git a/src/renderer/src/components/task-page-jira-sort-controls.test.tsx b/src/renderer/src/components/task-page-jira-sort-controls.test.tsx new file mode 100644 index 000000000..8ad742bd8 --- /dev/null +++ b/src/renderer/src/components/task-page-jira-sort-controls.test.tsx @@ -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 { + return render( + + + + ) +} + +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') + }) +}) diff --git a/src/renderer/src/components/task-page-jira-sort-controls.tsx b/src/renderer/src/components/task-page-jira-sort-controls.tsx new file mode 100644 index 000000000..3ac00dbea --- /dev/null +++ b/src/renderer/src/components/task-page-jira-sort-controls.tsx @@ -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 ( + <> +
+ {columns.map((column) => ( + + ))} + +
+ +
+ + {sortByLabel} + + + + + + + + {toggleDirectionLabel} + + +
+ + ) +} diff --git a/src/renderer/src/components/task-page-jira-sorting.test.ts b/src/renderer/src/components/task-page-jira-sorting.test.ts new file mode 100644 index 000000000..767fbf7c1 --- /dev/null +++ b/src/renderer/src/components/task-page-jira-sorting.test.ts @@ -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([ + ['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([ + ['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') + }) + }) +}) diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index f5d65a28e..eb1b76a44 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -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", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index a67ef1173..36873744e 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -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", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 6a8e9f075..c4319b90e 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -1736,7 +1736,11 @@ "editReviewersWithCurrent": "レビュアーを編集: {{value0}}", "linearEmptyAttributeFilter": "選択したフィルターに一致するイシューがありません。フィルターを解除するか、異なる条件を試してください。", "linearEmptyUnfilteredScope": "このワークスペーススコープにイシューがありません。検索するか、チームを調整してください。", - "linearFetchMore": "さらに読み込む" + "linearFetchMore": "さらに読み込む", + "jiraSortAscending": "昇順", + "jiraSortDescending": "降順", + "jiraSortBy": "並べ替え", + "jiraToggleSortDirection": "{{value0}}に並べ替え" }, "Terminal": { "73768427cf": "閉じる", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index 75a5db8a4..d44092ab6 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -1736,7 +1736,11 @@ "editReviewersWithCurrent": "리뷰어 편집: {{value0}}", "linearEmptyAttributeFilter": "선택한 필터와 일치하는 이슈가 없습니다. 필터를 지우거나 다른 조건을 시도하세요.", "linearEmptyUnfilteredScope": "이 워크트리 범위에 이슈가 없습니다. 검색하거나 팀을 조정해 보세요.", - "linearFetchMore": "더 불러오기" + "linearFetchMore": "더 불러오기", + "jiraSortAscending": "오름차순", + "jiraSortDescending": "내림차순", + "jiraSortBy": "정렬 기준", + "jiraToggleSortDirection": "{{value0}}으로 정렬" }, "Terminal": { "73768427cf": "닫기", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index cc7d98f8a..7110ab9ad 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -1736,7 +1736,11 @@ "editReviewersWithCurrent": "编辑评审人:{{value0}}", "linearEmptyAttributeFilter": "没有匹配所选筛选条件的问题。请清除筛选条件或尝试其他条件。", "linearEmptyUnfilteredScope": "此工作区范围内没有问题。请尝试搜索或调整团队。", - "linearFetchMore": "加载更多" + "linearFetchMore": "加载更多", + "jiraSortAscending": "升序", + "jiraSortDescending": "降序", + "jiraSortBy": "排序方式", + "jiraToggleSortDirection": "按{{value0}}排序" }, "Terminal": { "73768427cf": "关闭",