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
15 changes: 2 additions & 13 deletions src/components/miners/MinerOpenDiscoveryIssuesByRepo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import type { MinerIssue } from '../../api/models/Dashboard';
import {
getRepositoryOwnerAvatarSrc,
getScoringWindowStartIso,
isIssueStatusFilter,
isOutsideScoringWindow,
paginateItems,
type IssueStatusFilter,
} from '../../utils';
import {
DataTable,
Expand All @@ -30,19 +32,11 @@ import { ClearSearchAdornment } from '../common/ClearSearchAdornment';
import TablePagination from '../common/TablePagination';
import { tooltipSlotProps } from '../../theme';

type IssueStatusFilter = 'all' | 'open' | 'solved' | 'closed';
type IssueSortField = 'number' | 'repository' | 'date';
type SortDir = 'asc' | 'desc';

const PAGE_SIZE = 20;

const ISSUE_STATUS_FILTERS: readonly IssueStatusFilter[] = [
'all',
'open',
'solved',
'closed',
];

const DEFAULT_SORT_DIR: Record<IssueSortField, SortDir> = {
number: 'desc',
repository: 'asc',
Expand All @@ -55,11 +49,6 @@ const isSolvedIssue = (i: MinerIssue) =>
const isClosedIssue = (i: MinerIssue) =>
i.state === 'CLOSED' && !i.solving_pr?.merged_at;

const isIssueStatusFilter = (
value: string | null,
): value is IssueStatusFilter =>
value !== null && (ISSUE_STATUS_FILTERS as readonly string[]).includes(value);

const filterIssues = (
issues: MinerIssue[],
{
Expand Down
11 changes: 1 addition & 10 deletions src/components/miners/MinerPRsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getRepositoryOwnerAvatarSrc,
getPrStatusCounts,
isOutsideScoringWindow,
isPrStatusFilter,
paginateItems,
type PrStatusFilter,
} from '../../utils';
Expand Down Expand Up @@ -63,13 +64,6 @@ type SortDir = 'asc' | 'desc';

const PAGE_SIZE = 20;

const PR_STATUS_FILTERS: readonly PrStatusFilter[] = [
'all',
'open',
'merged',
'closed',
];

// Direction applied when a user first clicks a column header — string
// columns feel natural ascending, numeric/date columns descending.
const DEFAULT_SORT_DIR: Record<PrSortField, SortDir> = {
Expand Down Expand Up @@ -103,9 +97,6 @@ const getScoreTooltip = (pr: CommitLog): string | null => {
return parts.join(' · ');
};

const isPrStatusFilter = (value: string | null): value is PrStatusFilter =>
value !== null && (PR_STATUS_FILTERS as readonly string[]).includes(value);

// Stable per-PR key — shared by the DataTable row key and the expanded-row
// tracking set so the two never drift.
const prRowKey = (pr: CommitLog): string =>
Expand Down
10 changes: 6 additions & 4 deletions src/components/repositories/RepositoryPRsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
useWatchlist,
} from '../../hooks/useWatchlist';
import theme, { TEXT_OPACITY, scrollbarSx } from '../../theme';
import { filterPrs, getPrStatusCounts, type PrStatusFilter } from '../../utils';
import {
filterPrs,
getPrStatusCounts,
isPrStatusFilter,
type PrStatusFilter,
} from '../../utils';
import { getRepositoryOwnerAvatarSrc } from '../../utils/avatar';
import { formatDate } from '../../utils/format';
import FilterButton from '../FilterButton';
Expand All @@ -52,9 +57,6 @@ interface RepositoryPRsTableProps {
state?: 'open' | 'closed' | 'merged' | 'all';
}

const isPrStatusFilter = (v: unknown): v is PrStatusFilter =>
v === 'all' || v === 'open' || v === 'merged' || v === 'closed';

const PR_PAGE_SIZE = 20;

const RepositoryPRsTable: React.FC<RepositoryPRsTableProps> = ({
Expand Down
9 changes: 4 additions & 5 deletions src/pages/WatchlistPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ import { usePrSourceFilter } from '../hooks/usePrSourceFilter';
import {
isMergedPr,
isClosedUnmergedPr,
isPrStatusFilter,
getPrStatusCounts,
type PrStatusFilter,
} from '../utils/prStatus';
import { filterPrs, type PrStatusFilter } from '../utils/prTable';
import { filterPrs } from '../utils/prTable';
import { getIssueStatusMeta } from '../utils/issueStatus';
import { formatDate, formatTokenAmount, formatWeight } from '../utils/format';
import { getRepositoryOwnerAvatarSrc } from '../utils/avatar';
Expand Down Expand Up @@ -1029,9 +1031,6 @@ type WatchedRepoStats = Repository & {
discoveryContributors: Set<string>;
};

const isPrStatusFilterStored = (v: unknown): v is PrStatusFilter =>
v === 'all' || v === 'open' || v === 'merged' || v === 'closed';

type RepoSortKey =
| 'name'
| 'weight'
Expand Down Expand Up @@ -3238,7 +3237,7 @@ const PRsList: React.FC<{ itemKeys: string[] }> = ({ itemKeys }) => {
const [statusFilter, setStatusFilter] = useSessionStoredState<PrStatusFilter>(
'watchlist:prs:statusFilter',
'all',
isPrStatusFilterStored,
isPrStatusFilter,
);
const [viewMode, setViewMode] = useWatchlistViewMode();
const [page, setPage] = useState(0);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/issueStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { alpha } from '@mui/material/styles';
import { STATUS_COLORS } from '../theme';

export type IssueStatusFilter = 'all' | 'open' | 'solved' | 'closed';

export const ISSUE_STATUS_FILTERS: readonly IssueStatusFilter[] = [
'all',
'open',
'solved',
'closed',
];

export const isIssueStatusFilter = (
value: unknown,
): value is IssueStatusFilter =>
typeof value === 'string' &&
(ISSUE_STATUS_FILTERS as readonly string[]).includes(value);

interface IssueStatusMeta {
bgColor: string;
borderColor: string;
Expand Down
13 changes: 13 additions & 0 deletions src/utils/prStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ interface PrStatusLike {
prState?: string | null;
}

export type PrStatusFilter = 'all' | 'open' | 'merged' | 'closed';

export const PR_STATUS_FILTERS: readonly PrStatusFilter[] = [
'all',
'open',
'merged',
'closed',
];

export const isPrStatusFilter = (value: unknown): value is PrStatusFilter =>
typeof value === 'string' &&
(PR_STATUS_FILTERS as readonly string[]).includes(value);

export const isOpenPr = (pr: PrStatusLike): boolean =>
pr.prState === 'OPEN' || (!pr.prState && !pr.mergedAt);

Expand Down
9 changes: 6 additions & 3 deletions src/utils/prTable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { type CommitLog } from '../api';
import { isClosedUnmergedPr, isMergedPr, isOpenPr } from './prStatus';
import {
isClosedUnmergedPr,
isMergedPr,
isOpenPr,
type PrStatusFilter,
} from './prStatus';

/** Substring match against merged timestamp (ISO, locale date/time, year). */
const mergedAtMatchesSearch = (
Expand All @@ -16,8 +21,6 @@ const mergedAtMatchesSearch = (
return false;
};

export type PrStatusFilter = 'all' | 'open' | 'merged' | 'closed';

interface FilterPrsOptions {
author?: string | null;
includeNumber?: boolean;
Expand Down
Loading