refactor(@backstage/plugin-azure-devops-backend): re-exported types from azure-devops-node-api

rexported types from `azure-devops-node-api` and consume those re-exported in `@backstage/plugin-azure-devops-frontend`.

Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
Marley Powell
2021-10-15 21:38:20 +01:00
parent 59e822b43c
commit 8a92dc3155
9 changed files with 100 additions and 75 deletions
+1 -1
View File
@@ -31,12 +31,12 @@
"@backstage/core-components": "^0.7.0",
"@backstage/core-plugin-api": "^0.1.10",
"@backstage/errors": "^0.1.2",
"@backstage/plugin-azure-devops-backend": "^0.1.2",
"@backstage/plugin-catalog-react": "^0.6.0",
"@backstage/theme": "^0.2.11",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.57",
"azure-devops-node-api": "^11.0.1",
"luxon": "^2.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
+1 -1
View File
@@ -17,7 +17,7 @@
import {
BuildResult,
BuildStatus,
} from 'azure-devops-node-api/interfaces/BuildInterfaces';
} from '@backstage/plugin-azure-devops-backend';
export type RepoBuild = {
id?: number;
@@ -14,26 +14,27 @@
* limitations under the License.
*/
import React from 'react';
import { DateTime } from 'luxon';
import {
Link,
Table,
TableColumn,
StatusError,
StatusOK,
StatusWarning,
StatusAborted,
StatusRunning,
StatusPending,
ResponseErrorPanel,
} from '@backstage/core-components';
import { Box, Typography } from '@material-ui/core';
import { RepoBuild } from '../../api/types';
import {
BuildResult,
BuildStatus,
} from 'azure-devops-node-api/interfaces/BuildInterfaces';
} from '@backstage/plugin-azure-devops-backend';
import {
Link,
ResponseErrorPanel,
StatusAborted,
StatusError,
StatusOK,
StatusPending,
StatusRunning,
StatusWarning,
Table,
TableColumn,
} from '@backstage/core-components';
import { DateTime } from 'luxon';
import React from 'react';
import { RepoBuild } from '../../api/types';
const getBuildResultComponent = (result: number | undefined) => {
switch (result) {
@@ -154,13 +155,13 @@ const columns: TableColumn[] = [
},
];
type Props = {
items?: RepoBuild[];
type BuildTableProps = {
items: RepoBuild[] | null;
loading: boolean;
error?: any;
error: Error | null;
};
export const BuildTable = ({ items, loading, error }: Props) => {
export const BuildTable = ({ items, loading, error }: BuildTableProps) => {
if (error) {
return (
<div>
@@ -180,7 +181,7 @@ export const BuildTable = ({ items, loading, error }: Props) => {
showEmptyDataSourceMessage: !loading,
}}
title={`Builds (${items ? items.length : 0})`}
data={items || []}
data={items ?? []}
/>
);
};
@@ -14,35 +14,38 @@
* limitations under the License.
*/
import { useAsync } from 'react-use';
import { Entity } from '@backstage/catalog-model';
import { useApi } from '@backstage/core-plugin-api';
import { azureDevOpsApiRef } from '../api';
import { RepoBuild, RepoBuildOptions } from '../api/types';
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
import { AZURE_DEVOPS_DEFAULT_TOP } from '../constants';
import { Entity } from '@backstage/catalog-model';
import { azureDevOpsApiRef } from '../api';
import { useApi } from '@backstage/core-plugin-api';
import { useAsync } from 'react-use';
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
export function useRepoBuilds(
entity: Entity,
defaultLimit?: number,
): {
items: RepoBuild[] | undefined;
items: RepoBuild[] | null;
loading: boolean;
error: any;
error: Error | null;
} {
const top = defaultLimit ?? AZURE_DEVOPS_DEFAULT_TOP;
const options: RepoBuildOptions = {
top: top,
};
const api = useApi(azureDevOpsApiRef);
const { project, repo } = useProjectRepoFromEntity(entity);
const { value, loading, error } = useAsync(() => {
return api.getRepoBuilds(project, repo, options);
}, [api, project, repo, entity]);
return {
items: value?.items,
items: value?.items ?? null,
loading,
error,
error: error ?? null,
};
}