Skip to content

Commit

Permalink
Merge pull request #1611 from dzemanov/fix-github-pull-requests-paging
Browse files Browse the repository at this point in the history
fix(github-pull-requests): introduce max 1000 item paging
  • Loading branch information
Xantier authored Sep 12, 2024
2 parents 1a0ca22 + 2b7f83f commit abe24d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-lies-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/backstage-plugin-github-pull-requests': patch
---

Limit paging to max 1000 results due to GitHub search API restrictions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Box,
ButtonGroup,
Button,
Tooltip,
} from '@material-ui/core';
import GitHubIcon from '@material-ui/icons/GitHub';
import ClearIcon from '@material-ui/icons/Clear';
Expand Down Expand Up @@ -118,6 +119,7 @@ type Props = {
prData?: PullRequest[];
onChangePage: (page: number) => void;
total: number;
totalResults: number;
pageSize: number;
onChangePageSize: (pageSize: number) => void;
StateFilterComponent?: FC<{}>;
Expand All @@ -133,6 +135,7 @@ export const PullRequestsTableView: FC<Props> = ({
onChangePage,
onChangePageSize,
total,
totalResults,
StateFilterComponent,
SearchComponent,
}) => {
Expand Down Expand Up @@ -165,10 +168,32 @@ export const PullRequestsTableView: FC<Props> = ({
alignItems="center"
>
<GitHubIcon />
<Box mr={1} />
<Typography variant="h6" noWrap>
{projectName}
</Typography>
<Box
ml={1}
display="flex"
flexDirection="row"
alignItems="baseline"
>
<Typography variant="h6" noWrap>
{projectName}
</Typography>
{totalResults > 1000 && (
<Tooltip
title={`Search results are limited to a maximum of ${(1000).toLocaleString()}
items. To refine your results, consider adjusting the search query.`}
arrow
>
<Typography
variant="body1"
noWrap
color="primary"
style={{ marginLeft: 10, cursor: 'pointer' }}
>
Total {totalResults.toLocaleString()}
</Typography>
</Tooltip>
)}
</Box>
</Box>
<Box
position="absolute"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ export function usePullRequests({
const auth = useApi(githubAuthApiRef);
const baseUrl = useBaseUrl();
const [total, setTotal] = useState(0);
const [totalResults, setTotalResults] = useState(0);
const [page, setPage] = useState(0);
const [pageSize, setPageSize] = useState(5);
const getElapsedTime = (start: string): string | null => {
return DateTime.fromISO(start).toRelative();
};

const handleTotal = (total_count: number) => {
setTotal(total_count > 1000 ? 1000 : total_count);
setTotalResults(total_count);
};

const {
loading,
value: prData,
Expand Down Expand Up @@ -88,7 +94,7 @@ export function usePullRequests({
pullRequestsData: SearchPullRequestsResponseData;
}) => {
if (total_count >= 0) {
setTotal(total_count);
handleTotal(total_count);
}
return items.map(
({
Expand Down Expand Up @@ -135,6 +141,7 @@ export function usePullRequests({
prData,
projectName: `${owner}/${repo}`,
total,
totalResults,
error,
},
{
Expand Down

0 comments on commit abe24d7

Please sign in to comment.