Skip to content

Commit

Permalink
fix(report-portal): updated code as per suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Oswal <[email protected]>
  • Loading branch information
yashoswalyo committed Mar 19, 2024
1 parent 657abe2 commit 61481a0
Show file tree
Hide file tree
Showing 13 changed files with 2,472 additions and 2,156 deletions.
1 change: 1 addition & 0 deletions plugins/report-portal-backend/app-config.janus-idp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ reportPortal:
- host: ${REPORT_PORTAL_HOST}
baseUrl: ${REPORT_PORTAL_BASE_URL}
token: ${REPORT_PORTAL_TOKEN}
filterType: ${REPORT_PORTAL_FILTER_TYPE}
5 changes: 5 additions & 0 deletions plugins/report-portal-backend/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface Config {
* @visibility secret
*/
token: string;
/**
* Filter type to apply for current host
* @visibility frontend
*/
filterType: string;
}>;
};
}
4 changes: 4 additions & 0 deletions plugins/report-portal/app-config.janus-idp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ dynamicPlugins:
dynamicRoutes: []
mountPoints: []
routeBindings: []
reportPortal:
integrations:
- host: ${REPORT_PORTAL_HOST}
filterType: ${REPORT_PORTAL_FILTER_TYPE}
10 changes: 7 additions & 3 deletions plugins/report-portal/src/api/ReportPortalApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ApiRef, createApiRef } from '@backstage/core-plugin-api';

import { LaunchDetailsResp, ProjectDetails, ProjectListResp } from './types';
import {
LaunchDetailsResponse,
ProjectDetails,
ProjectListResponse,
} from './types';

/** @public */
export const reportPortalApiRef: ApiRef<ReportPortalApi> = createApiRef({
Expand All @@ -13,13 +17,13 @@ export type ReportPortalApi = {
projectId: string,
host: string,
filters: { [key: string]: string | number } | undefined,
) => Promise<LaunchDetailsResp>;
) => Promise<LaunchDetailsResponse>;
getProjectDetails: (
projectId: string,
host: string,
) => Promise<ProjectDetails>;
getInstanceDetails: (
host: string,
filters: { [key: string]: string | number } | undefined,
) => Promise<ProjectListResp>;
) => Promise<ProjectListResponse>;
};
10 changes: 7 additions & 3 deletions plugins/report-portal/src/api/ReportPortalClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { DiscoveryApi } from '@backstage/core-plugin-api';

import { ReportPortalApi } from './ReportPortalApi';
import { LaunchDetailsResp, ProjectDetails, ProjectListResp } from './types';
import {
LaunchDetailsResponse,
ProjectDetails,
ProjectListResponse,
} from './types';

export class ReportPortalClient implements ReportPortalApi {
constructor(private readonly discoveryApi: DiscoveryApi) {}
Expand Down Expand Up @@ -33,7 +37,7 @@ export class ReportPortalClient implements ReportPortalApi {
if (response.status !== 200) {
throw new Error('Failed to fetch launch details');
}
return (await response.json()) as LaunchDetailsResp;
return (await response.json()) as LaunchDetailsResponse;
}

async getProjectDetails(projectId: string, host: string) {
Expand Down Expand Up @@ -61,6 +65,6 @@ export class ReportPortalClient implements ReportPortalApi {
if (response.status !== 200) {
throw new Error('Failed to get instance details');
}
return (await response.json()) as ProjectListResp;
return (await response.json()) as ProjectListResponse;
}
}
4 changes: 2 additions & 2 deletions plugins/report-portal/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export type PageType = {
totalPages: number;
};

export type LaunchDetailsResp = {
export type LaunchDetailsResponse = {
content: LaunchDetails[];
page: PageType;
};

export type ProjectListResp = {
export type ProjectListResponse = {
content: ProjectDetails[];
page: PageType;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { IconButton, Link } from '@material-ui/core';
import Launch from '@material-ui/icons/Launch';
import { DateTime } from 'luxon';

import { LaunchDetailsResp, PageType, reportPortalApiRef } from '../../../api';
import {
LaunchDetailsResponse,
PageType,
reportPortalApiRef,
} from '../../../api';

type LaunchDetails = {
id: number;
Expand Down Expand Up @@ -67,7 +71,7 @@ export const LaunchesPageContent = (props: {
});
}

function responseHandler(res: LaunchDetailsResp) {
function responseHandler(res: LaunchDetailsResponse) {
const tempArr: LaunchDetails[] = [];
res.content.forEach(data => {
tempArr.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Skeleton } from '@material-ui/lab';

import {
ProjectDetails,
ProjectListResp,
ProjectListResponse,
reportPortalApiRef,
} from '../../../api';
import { launchRouteRef } from '../../../routes';
Expand Down Expand Up @@ -47,7 +47,7 @@ export const ProjectsPageContent = (props: { host: string }) => {
?.getString('filterType') ?? 'INTERNAL';

const [loading, setLoading] = useState(true);
const [tableData, setTableData] = useState<ProjectListResp>({
const [tableData, setTableData] = useState<ProjectListResponse>({
content: [],
page: {
number: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import MultiProgress from 'react-multi-progress';

import { InfoCard, InfoCardVariants } from '@backstage/core-components';
import { configApiRef, useApi } from '@backstage/core-plugin-api';
import { useEntity } from '@backstage/plugin-catalog-react';

import {
Expand All @@ -18,6 +19,7 @@ import {
import { Skeleton } from '@material-ui/lab';

import { useLaunchDetails, useProjectDetails } from '../../hooks';
import { isReportPortalAvailable } from '../../utils/isReportPortalAvailable';

const HeaderComponent = (props: { total: number }) => {
return (
Expand Down Expand Up @@ -74,13 +76,19 @@ const useStyles = makeStyles({
export const ReportPortalOverviewCard = (props: {
variant: InfoCardVariants;
}) => {
const { entity } = useEntity();
const classes = useStyles();
const config = useApi(configApiRef);
const hostsConfig = config.getConfigArray('reportPortal.integrations');

const { entity } = useEntity();
const projectId =
entity.metadata.annotations?.['reportportal.io/project-name'] ?? '';
const launchName =
entity.metadata.annotations?.['reportportal.io/launch-name'] ?? '';
const hostName = entity.metadata.annotations?.['reportportal.io/host'] ?? '';
const hostName =
entity.metadata.annotations?.['reportportal.io/host'] ??
hostsConfig[0].getString('host');

const [defects, setDefects] = useState<Defect[]>([]);
const [filters, _] = useState<{ [key: string]: string | number } | undefined>(
{
Expand Down Expand Up @@ -117,6 +125,8 @@ export const ReportPortalOverviewCard = (props: {
}
}, [loading, launchDetails, projectDetails]);

if (!isReportPortalAvailable(entity)) return null;

return (
<InfoCard
title={
Expand Down
9 changes: 4 additions & 5 deletions plugins/report-portal/src/hooks/useInstanceDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import React from 'react';

import { useApi } from '@backstage/core-plugin-api';

import { ProjectListResp, reportPortalApiRef } from '../api';
import { ProjectListResponse, reportPortalApiRef } from '../api';

export function useInstanceDetails(host: string, filterType: string) {
const reportPortalApi = useApi(reportPortalApiRef);
const [loading, setLoading] = React.useState(true);
const [projectListData, setProjectListData] = React.useState<ProjectListResp>(
{
const [projectListData, setProjectListData] =
React.useState<ProjectListResponse>({
content: [],
page: {
number: 1,
size: 10,
totalElements: 0,
totalPages: 1,
},
},
);
});

React.useEffect(() => {
setLoading(true);
Expand Down
2 changes: 1 addition & 1 deletion plugins/report-portal/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ReportPortalOverviewCard = reportPortalPlugin.provide(

export const ReportPortalGlobalPage = reportPortalPlugin.provide(
createRoutableExtension({
name: 'RportPortalGlobalPage',
name: 'ReportPortalGlobalPage',
mountPoint: rootRouteRef,
component: () => import('./components/Router').then(m => m.Router),
}),
Expand Down
3 changes: 1 addition & 2 deletions plugins/report-portal/src/utils/isReportPortalAvailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Entity } from '@backstage/catalog-model';
export const isReportPortalAvailable = (entity: Entity): boolean => {
return Boolean(
entity.metadata.annotations?.['reportportal.io/project-name'] &&
entity.metadata.annotations?.['reportportal.io/launch-name'] &&
entity.metadata.annotations?.['reportportal.io/host'],
entity.metadata.annotations?.['reportportal.io/launch-name'],
);
};
Loading

0 comments on commit 61481a0

Please sign in to comment.