added topTeams to PullRequestsPageProps and implemented through to backend
Signed-off-by: Quadman <QuadmanSWE@gmail.com>
This commit is contained in:
@@ -25,7 +25,7 @@ import { AzureDevOpsApi } from './AzureDevOpsApi';
|
||||
import { Logger } from 'winston';
|
||||
import limiterFactory from 'p-limit';
|
||||
|
||||
const DEFAULT_TOP_TEAMS = 100;
|
||||
export const DEFAULT_TOP_TEAMS = 100;
|
||||
|
||||
export class PullRequestsDashboardProvider {
|
||||
private teams = new Map<string, Team>();
|
||||
@@ -108,11 +108,12 @@ export class PullRequestsDashboardProvider {
|
||||
public async getDashboardPullRequests(
|
||||
projectName: string,
|
||||
options: PullRequestOptions,
|
||||
topTeams?: number,
|
||||
): Promise<DashboardPullRequest[]> {
|
||||
const dashboardPullRequests =
|
||||
await this.azureDevOpsApi.getDashboardPullRequests(projectName, options);
|
||||
|
||||
await this.getAllTeams(); // Make sure team members are loaded
|
||||
await this.getAllTeams(topTeams); // Make sure team members are loaded
|
||||
|
||||
return dashboardPullRequests.map(pr => {
|
||||
if (pr.createdBy?.id) {
|
||||
|
||||
@@ -23,7 +23,10 @@ import {
|
||||
import { AzureDevOpsApi } from '../api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import { PullRequestsDashboardProvider } from '../api/PullRequestsDashboardProvider';
|
||||
import {
|
||||
PullRequestsDashboardProvider,
|
||||
DEFAULT_TOP_TEAMS,
|
||||
} from '../api/PullRequestsDashboardProvider';
|
||||
import Router from 'express-promise-router';
|
||||
import { errorHandler, UrlReader } from '@backstage/backend-common';
|
||||
import express from 'express';
|
||||
@@ -227,6 +230,9 @@ export async function createRouter(
|
||||
const { projectName } = req.params;
|
||||
|
||||
const top = req.query.top ? Number(req.query.top) : DEFAULT_TOP;
|
||||
const topTeams = req.query.topTeams
|
||||
? Number(req.query.topTeams)
|
||||
: DEFAULT_TOP_TEAMS;
|
||||
|
||||
const status = req.query.status
|
||||
? Number(req.query.status)
|
||||
@@ -261,6 +267,7 @@ export async function createRouter(
|
||||
await pullRequestsDashboardProvider.getDashboardPullRequests(
|
||||
projectName,
|
||||
pullRequestOptions,
|
||||
topTeams,
|
||||
);
|
||||
|
||||
res.status(200).json(pullRequests);
|
||||
|
||||
@@ -64,6 +64,7 @@ export interface AzureDevOpsApi {
|
||||
|
||||
getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
): Promise<DashboardPullRequest[]>;
|
||||
|
||||
getAllTeams(topTeams?: number): Promise<Team[]>;
|
||||
|
||||
@@ -124,10 +124,15 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
|
||||
public getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
): Promise<DashboardPullRequest[]> {
|
||||
return this.get<DashboardPullRequest[]>(
|
||||
`dashboard-pull-requests/${projectName}?top=100`,
|
||||
);
|
||||
const queryString = new URLSearchParams();
|
||||
queryString.append('top', '100');
|
||||
if (topTeams) {
|
||||
queryString.append('topTeams', topTeams.toString());
|
||||
}
|
||||
const urlSegment = `dashboard-pull-requests/${projectName}?${queryString}`;
|
||||
return this.get<DashboardPullRequest[]>(urlSegment);
|
||||
}
|
||||
|
||||
public getAllTeams(topTeams?: number): Promise<Team[]> {
|
||||
|
||||
@@ -70,14 +70,17 @@ type PullRequestsPageProps = {
|
||||
projectName?: string;
|
||||
pollingInterval?: number;
|
||||
defaultColumnConfigs?: PullRequestColumnConfig[];
|
||||
topTeams?: number;
|
||||
};
|
||||
|
||||
export const PullRequestsPage = (props: PullRequestsPageProps) => {
|
||||
const { projectName, pollingInterval, defaultColumnConfigs } = props;
|
||||
const { projectName, pollingInterval, defaultColumnConfigs, topTeams } =
|
||||
props;
|
||||
|
||||
const { pullRequests, loading, error } = useDashboardPullRequests(
|
||||
projectName,
|
||||
pollingInterval,
|
||||
topTeams,
|
||||
);
|
||||
|
||||
const [columnConfigs] = useState(
|
||||
|
||||
@@ -27,6 +27,7 @@ const POLLING_INTERVAL = 10000;
|
||||
export function useDashboardPullRequests(
|
||||
project?: string,
|
||||
pollingInterval: number = POLLING_INTERVAL,
|
||||
topTeams?: number,
|
||||
): {
|
||||
pullRequests?: DashboardPullRequest[];
|
||||
loading: boolean;
|
||||
@@ -43,7 +44,7 @@ export function useDashboardPullRequests(
|
||||
}
|
||||
|
||||
try {
|
||||
return await api.getDashboardPullRequests(project);
|
||||
return await api.getDashboardPullRequests(project, topTeams);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
errorApi.post(error);
|
||||
@@ -51,7 +52,7 @@ export function useDashboardPullRequests(
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}, [project, api, errorApi]);
|
||||
}, [project, api, topTeams, errorApi]);
|
||||
|
||||
const {
|
||||
value: pullRequests,
|
||||
|
||||
Reference in New Issue
Block a user