feat: Added polling for pull requests and other small improvements.
Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
Content,
|
||||
Header,
|
||||
Page,
|
||||
Progress,
|
||||
ResponseErrorPanel,
|
||||
} from '@backstage/core-components';
|
||||
import { PullRequestGroup, PullRequestGroupConfig } from './lib/types';
|
||||
@@ -28,11 +29,6 @@ import { useDashboardPullRequests, useUserEmail } from '../../hooks';
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestGrid } from './lib/PullRequestGrid';
|
||||
|
||||
/**
|
||||
* @deprecated TEMPORARY - This will be configurable in a follow up PR.
|
||||
*/
|
||||
const PROJECT_NAME = 'projectName';
|
||||
|
||||
function usePullRequestGroupConfigs(
|
||||
userEmail: string | undefined,
|
||||
): PullRequestGroupConfig[] {
|
||||
@@ -73,8 +69,41 @@ function usePullRequestGroups(
|
||||
return pullRequestGroups;
|
||||
}
|
||||
|
||||
export const PullRequestsPage = () => {
|
||||
const { pullRequests, error } = useDashboardPullRequests(PROJECT_NAME);
|
||||
type PullRequestsPageContentProps = {
|
||||
pullRequestGroups: PullRequestGroup[];
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
};
|
||||
|
||||
const PullRequestsPageContent = ({
|
||||
pullRequestGroups,
|
||||
loading,
|
||||
error,
|
||||
}: PullRequestsPageContentProps) => {
|
||||
if (loading && pullRequestGroups.length <= 0) {
|
||||
return <Progress />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <ResponseErrorPanel error={error} />;
|
||||
}
|
||||
|
||||
return <PullRequestGrid pullRequestGroups={pullRequestGroups} />;
|
||||
};
|
||||
|
||||
type PullRequestsPageProps = {
|
||||
projectName?: string;
|
||||
pollingInterval?: number;
|
||||
};
|
||||
|
||||
export const PullRequestsPage = ({
|
||||
projectName,
|
||||
pollingInterval,
|
||||
}: PullRequestsPageProps) => {
|
||||
const { pullRequests, loading, error } = useDashboardPullRequests(
|
||||
projectName,
|
||||
pollingInterval,
|
||||
);
|
||||
const userEmail = useUserEmail();
|
||||
const pullRequestGroupConfigs = usePullRequestGroupConfigs(userEmail);
|
||||
const pullRequestGroups = usePullRequestGroups(
|
||||
@@ -82,16 +111,16 @@ export const PullRequestsPage = () => {
|
||||
pullRequestGroupConfigs,
|
||||
);
|
||||
|
||||
const pullRequestsContent = error ? (
|
||||
<ResponseErrorPanel error={error} />
|
||||
) : (
|
||||
<PullRequestGrid pullRequestGroups={pullRequestGroups} />
|
||||
);
|
||||
|
||||
return (
|
||||
<Page themeId="tool">
|
||||
<Header title="Azure Pull Requests" />
|
||||
<Content>{pullRequestsContent}</Content>
|
||||
<Content>
|
||||
<PullRequestsPageContent
|
||||
pullRequestGroups={pullRequestGroups}
|
||||
loading={loading}
|
||||
error={error}
|
||||
/>
|
||||
</Content>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ export const PullRequestCard = ({
|
||||
|
||||
const subheader = (
|
||||
<span>
|
||||
{repoLink}·{creationDate}
|
||||
{repoLink} · {creationDate}
|
||||
</span>
|
||||
);
|
||||
|
||||
|
||||
+1
@@ -67,6 +67,7 @@ function getPolicyIcon(policy: Policy): JSX.Element | null {
|
||||
return null;
|
||||
}
|
||||
case PolicyType.MinimumReviewers:
|
||||
case PolicyType.RequiredReviewers:
|
||||
return <PolicyRequiredIcon />;
|
||||
case PolicyType.Status:
|
||||
case PolicyType.Comments:
|
||||
|
||||
@@ -14,25 +14,55 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { errorApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import { useAsyncRetry, useInterval } from 'react-use';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { azureDevOpsApiRef } from '../api';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { useAsync } from 'react-use';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export function useDashboardPullRequests(project: string): {
|
||||
const POLLING_INTERVAL = 10000;
|
||||
|
||||
export function useDashboardPullRequests(
|
||||
project?: string,
|
||||
pollingInterval: number = POLLING_INTERVAL,
|
||||
): {
|
||||
pullRequests?: DashboardPullRequest[];
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
} {
|
||||
const api = useApi(azureDevOpsApiRef);
|
||||
const errorApi = useApi(errorApiRef);
|
||||
|
||||
const getDashboardPullRequests = useCallback(async (): Promise<
|
||||
DashboardPullRequest[]
|
||||
> => {
|
||||
if (!project) {
|
||||
return Promise.reject(new Error('Missing project name'));
|
||||
}
|
||||
|
||||
try {
|
||||
return await api.getDashboardPullRequests(project);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
errorApi.post(error);
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}, [project, api, errorApi]);
|
||||
|
||||
const {
|
||||
value: pullRequests,
|
||||
loading,
|
||||
error,
|
||||
} = useAsync(() => {
|
||||
return api.getDashboardPullRequests(project);
|
||||
}, [api, project]);
|
||||
retry,
|
||||
} = useAsyncRetry(
|
||||
() => getDashboardPullRequests(),
|
||||
[getDashboardPullRequests],
|
||||
);
|
||||
|
||||
useInterval(() => retry(), pollingInterval);
|
||||
|
||||
return {
|
||||
pullRequests,
|
||||
|
||||
Reference in New Issue
Block a user