Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/renderer/components/filters/FilterSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { mockSettings } from '../../__mocks__/state-mocks';

import { useFiltersStore } from '../../stores';

import { stateFilter } from '../../utils/notifications/filters';
import { issueStatusFilter, stateFilter } from '../../utils/notifications/filters';
import { FilterSection } from './FilterSection';

describe('renderer/components/filters/FilterSection.tsx', () => {
Expand Down Expand Up @@ -195,6 +195,37 @@ describe('renderer/components/filters/FilterSection.tsx', () => {
expect(after).toEqual(before);
});

it('preserves declared order for filters that opt in', () => {
renderWithProviders(
<FilterSection
filter={issueStatusFilter}
filterSetting="issueStatuses"
icon={MarkGithubIcon}
id={'FilterSectionTest'}
title={'FilterSectionTitle'}
/>,
{
settings: {
...mockSettings,
detailedNotifications: true,
},
},
);

expect(
screen.getAllByRole('checkbox').map((checkbox) => checkbox.getAttribute('name')),
).toEqual([
'issueStatuses-backlog',
'issueStatuses-todo',
'issueStatuses-in_progress',
'issueStatuses-in_review',
'issueStatuses-done',
'issueStatuses-not_planned',
'issueStatuses-duplicate',
'issueStatuses-other',
]);
});

function getCounterValues(): number[] {
return Array.from(document.querySelectorAll('span.text-gitify-counter-text')).map((el) =>
Number.parseInt(el.textContent ?? '0', 10),
Expand Down
69 changes: 36 additions & 33 deletions src/renderer/components/filters/FilterSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ function FilterSectionComponent<K extends keyof FiltersState>({
return counts;
}, [notifications, filter]);

const filterTypes = Object.keys(filter.FILTER_TYPES) as FiltersState[K][number][];
const orderedFilterTypes = filter.preserveFilterOrder
? filterTypes
: [...filterTypes].sort((a, b) => {
// Always pin the catch-all 'other' option to the end of the list.
if ((a as string) === 'other') {
return 1;
}
if ((b as string) === 'other') {
return -1;
}
return filter
.getTypeDetails(a)
.title.toLowerCase()
.localeCompare(filter.getTypeDetails(b).title.toLowerCase(), 'en');
});

return (
<fieldset id={id}>
<SectionHeading
Expand All @@ -66,40 +83,26 @@ function FilterSectionComponent<K extends keyof FiltersState>({
</SectionHeading>

<Stack direction={layout} gap={layout === 'horizontal' ? 'normal' : 'condensed'}>
{(Object.keys(filter.FILTER_TYPES) as FiltersState[K][number][])
.sort((a, b) => {
// Always pin the catch-all 'other' option to the end of the list.
if ((a as string) === 'other') {
return 1;
}
if ((b as string) === 'other') {
return -1;
}
return filter
.getTypeDetails(a)
.title.toLowerCase()
.localeCompare(filter.getTypeDetails(b).title.toLowerCase(), 'en');
})
.map((type) => {
const typeDetails = filter.getTypeDetails(type);
const typeTitle = typeDetails.title;
const typeDescription = typeDetails.description;
const isChecked = filter.isFilterSet(type);
const count = filterCounts.get(type) ?? 0;
{orderedFilterTypes.map((type) => {
const typeDetails = filter.getTypeDetails(type);
const typeTitle = typeDetails.title;
const typeDescription = typeDetails.description;
const isChecked = filter.isFilterSet(type);
const count = filterCounts.get(type) ?? 0;

return (
<FilterCheckbox
checked={isChecked}
counter={count}
disabled={filter.requiresDetailsNotifications && !detailedNotifications}
key={type as string}
label={typeTitle}
name={`${filterSetting}-${String(type)}`}
onChange={() => updateFilter(filterSetting, type, !isChecked)}
tooltip={typeDescription ? <Text>{typeDescription}</Text> : null}
/>
);
})}
return (
<FilterCheckbox
checked={isChecked}
counter={count}
disabled={filter.requiresDetailsNotifications && !detailedNotifications}
key={type as string}
label={typeTitle}
name={`${filterSetting}-${String(type)}`}
onChange={() => updateFilter(filterSetting, type, !isChecked)}
tooltip={typeDescription ? <Text>{typeDescription}</Text> : null}
/>
);
})}
</Stack>
</fieldset>
);
Expand Down
31 changes: 31 additions & 0 deletions src/renderer/components/filters/IssueStatusFilter.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { screen, within } from '@testing-library/react';

import { renderWithProviders } from '../../__helpers__/test-utils';
import { mockMultipleAccountNotifications } from '../../__mocks__/notifications-mocks';

import { issueStatusFilter } from '../../utils/notifications/filters';
import { IssueStatusFilter } from './IssueStatusFilter';

describe('renderer/components/filters/IssueStatusFilter.tsx', () => {
it('renders every issue status filter option', () => {
renderWithProviders(<IssueStatusFilter />, {
notifications: mockMultipleAccountNotifications,
});

const fieldset = screen.getByRole('heading', { name: 'Issue status' }).closest('fieldset');

if (!fieldset) {
throw new Error('Could not find the Issue status filter section');
}

const expectedCounts = new Map<string, number>();

for (const details of Object.values(issueStatusFilter.FILTER_TYPES)) {
expectedCounts.set(details.title, (expectedCounts.get(details.title) ?? 0) + 1);
}

for (const [option, count] of expectedCounts) {
expect(within(fieldset).getAllByRole('checkbox', { name: option })).toHaveLength(count);
}
});
});
29 changes: 29 additions & 0 deletions src/renderer/components/filters/IssueStatusFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useTranslation } from 'react-i18next';

import { IssueOpenedIcon } from '@primer/octicons-react';
import { Text } from '@primer/react';

import { issueStatusFilter } from '../../utils/notifications/filters';
import { FilterSection } from './FilterSection';

export function IssueStatusFilter() {
const { t } = useTranslation();

return (
<FilterSection
filter={issueStatusFilter}
filterSetting="issueStatuses"
icon={IssueOpenedIcon}
id="filter-issue-status"
title={t('filters.issue_status.title', 'Issue status')}
tooltip={
<Text>
{t(
'filters.issue_status.help',
'Show only issues in the selected statuses, such as In review or Done.',
)}
</Text>
}
/>
);
}
43 changes: 43 additions & 0 deletions src/renderer/components/metrics/IssueStatusPill.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { screen } from '@testing-library/react';

import { renderWithProviders } from '../../__helpers__/test-utils';

import { IconColor } from '../../types';

import { IssueStatusPill } from './IssueStatusPill';

describe('renderer/components/metrics/IssueStatusPill.tsx', () => {
it('renders nothing without a status', () => {
const tree = renderWithProviders(<IssueStatusPill />);

expect(tree.container).toBeEmptyDOMElement();
});

it('renders the status name', () => {
renderWithProviders(
<IssueStatusPill status={{ name: 'In review', kind: 'in_review', color: IconColor.GREEN }} />,
);

expect(screen.getByRole('button', { name: 'Issue status: In review' })).toHaveTextContent(
'In review',
);
});

it('exposes an accessible issue status label', () => {
renderWithProviders(
<IssueStatusPill status={{ name: 'Done', kind: 'done', color: IconColor.PURPLE }} />,
);

expect(screen.getByRole('button', { name: 'Issue status: Done' })).toBeInTheDocument();
});

it('renders an unknown status name with its neutral color', () => {
renderWithProviders(
<IssueStatusPill status={{ name: 'Blocked', kind: 'unknown', color: IconColor.GRAY }} />,
);

const status = screen.getByRole('button', { name: 'Issue status: Blocked' });
expect(status).toHaveTextContent('Blocked');
expect(status.querySelector('svg')).toHaveClass(IconColor.GRAY);
});
});
24 changes: 24 additions & 0 deletions src/renderer/components/metrics/IssueStatusPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { GitifyIssueStatus } from '../../types';

import { getIssueStatusIcon } from '../../icons/IssueStatusIcon';
import { MetricPill } from './MetricPill';

export interface IssueStatusPillProps {
status?: GitifyIssueStatus;
}

export function IssueStatusPill({ status }: Readonly<IssueStatusPillProps>) {
if (!status) {
return null;
}

return (
<MetricPill
ariaLabel={`Issue status: ${status.name}`}
color={status.color}
contents={status.name}
icon={getIssueStatusIcon(status.kind)}
metric={status.name}
/>
);
}
60 changes: 60 additions & 0 deletions src/renderer/components/metrics/MetricGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,66 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
expect(tree.getByText('Bug')).toBeInTheDocument();
});

it('renders the issue status pill when the subject has a status', async () => {
const props: MetricGroupProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
issueStatus: { name: 'In review', kind: 'in_review', color: IconColor.GREEN },
},
},
};

const tree = renderWithProviders(<MetricGroup {...props} />, {
settings: { ...mockSettings, showPills: true },
});

expect(tree.getByRole('button', { name: 'Issue status: In review' })).toBeInTheDocument();
});

it('renders the issue status before the issue type', async () => {
const props: MetricGroupProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
issueStatus: { name: 'In review', kind: 'in_review', color: IconColor.GREEN },
issueType: { name: 'Bug', color: IconColor.RED },
},
},
};

const tree = renderWithProviders(<MetricGroup {...props} />, {
settings: { ...mockSettings, showPills: true },
});

const status = tree.getByRole('button', { name: 'Issue status: In review' });
const issueType = tree.getByRole('button', { name: 'Issue type: Bug' });

expect(
status.compareDocumentPosition(issueType) & Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
});

it('hides the issue status pill when pills are disabled', async () => {
const props: MetricGroupProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
issueStatus: { name: 'In review', kind: 'in_review', color: IconColor.GREEN },
},
},
};

const tree = renderWithProviders(<MetricGroup {...props} />, {
settings: { ...mockSettings, showPills: false },
});

expect(tree.container).toBeEmptyDOMElement();
});

it('renders the parent pill when the subject has a parent issue', async () => {
const props: MetricGroupProps = {
notification: {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/metrics/MetricGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { GitifyNotification } from '../../types';

import { ChecksPill } from './ChecksPill';
import { CommentsPill } from './CommentsPill';
import { IssueStatusPill } from './IssueStatusPill';
import { IssueTypesPill } from './IssueTypesPill';
import { LabelsPill } from './LabelsPill';
import { LinkedIssuesPill } from './LinkedIssuesPill';
Expand Down Expand Up @@ -35,6 +36,10 @@ export function MetricGroup({ notification }: Readonly<MetricGroupProps>) {
// all can measure and count them independently.
const pills: ReactElement[] = [];

if (subject.issueStatus) {
pills.push(<IssueStatusPill key="issue-status" status={subject.issueStatus} />);
}

if (subject.issueType) {
pills.push(<IssueTypesPill issueType={subject.issueType} key="issue-type" />);
}
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@
},
"clear_all_tooltip": "Clear all filters",
"clear_filters": "Clear filters",
"issue_status": {
"backlog": "Backlog",
"backlog_description": "Open issues waiting to be planned.",
"done": "Done",
"done_description": "Issues closed as completed.",
"duplicate": "Duplicate",
"duplicate_description": "Issues closed as duplicates of another issue.",
"help": "Show only issues in the selected statuses, such as In review or Done.",
"in_progress": "In progress",
"in_progress_description": "Open issues with work underway.",
"in_review": "In review",
"in_review_description": "Open issues with a pull request ready for review.",
"not_planned": "Not planned",
"not_planned_description": "Issues closed without completing the work.",
"other": "Other",
"other_description": "Notifications without an issue status.",
"title": "Issue status",
"todo": "Todo",
"todo_description": "Open issues ready to start."
},
"reason": {
"help": "Filter notifications by reason.",
"other": "Other",
Expand Down
Loading
Loading