cleaning up frontend

Signed-off-by: mo <mcassidy@hchb.com>
This commit is contained in:
mo
2022-05-02 12:16:42 -05:00
parent 75b0a51d1a
commit 86e9497023
6 changed files with 16 additions and 59 deletions
@@ -27,7 +27,6 @@ import {
Policy,
PullRequest,
PullRequestOptions,
PullRequestStatus,
RepoBuild,
Team,
TeamMember,
@@ -42,7 +42,6 @@ export interface AzureDevOpsApi {
getGitTags(
projectName: string,
repoName: string,
options?: PullRequestOptions,
): Promise<{ items: GitTag[] }>;
getPullRequests(
@@ -62,18 +62,10 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
public async getGitTags(
projectName: string,
repoName: string,
options?: PullRequestOptions,
): Promise<{ items: GitTag[] }> {
const queryString = new URLSearchParams();
if (options?.top) {
queryString.append('top', options.top.toString());
}
if (options?.status) {
queryString.append('status', options.status.toString());
}
const urlSegment = `git-tags/${encodeURIComponent(
projectName,
)}/${encodeURIComponent(repoName)}?${queryString}`;
)}/${encodeURIComponent(repoName)}`;
const items = await this.get<GitTag[]>(urlSegment);
return { items };
@@ -22,5 +22,5 @@ export const EntityPageAzureGitTags = ({
}: {
defaultLimit?: number;
}) => {
return <GitTagTable defaultLimit={defaultLimit} />;
return <GitTagTable />;
};
@@ -14,22 +14,17 @@
* limitations under the License.
*/
import { Box, Chip } from '@material-ui/core';
import { Box } from '@material-ui/core';
import {
Link,
ResponseErrorPanel,
Table,
TableColumn,
} from '@backstage/core-components';
import {
PullRequest,
PullRequestStatus,
} from '@backstage/plugin-azure-devops-common';
import React, { useState } from 'react';
import { GitTag } from '@backstage/plugin-azure-devops-common';
import React from 'react';
import { AzurePullRequestsIcon } from '../AzurePullRequestsIcon';
import { DateTime } from 'luxon';
import { PullRequestStatusButtonGroup } from '../PullRequestStatusButtonGroup';
import { useEntity } from '@backstage/plugin-catalog-react';
import { useGitTags } from '../../hooks/useGitTags';
@@ -39,6 +34,11 @@ const columns: TableColumn[] = [
field: 'name',
highlight: false,
width: 'auto',
render: (row: Partial<GitTag>) => (
<Box display="flex" alignItems="center">
<Link to={row.link ?? ''}>{row.name}</Link>
</Box>
),
},
{
title: 'Commit',
@@ -52,20 +52,10 @@ const columns: TableColumn[] = [
},
];
type PullRequestTableProps = {
defaultLimit?: number;
};
export const GitTagTable = ({ defaultLimit }: PullRequestTableProps) => {
const [pullRequestStatusState, setPullRequestStatusState] =
useState<PullRequestStatus>(PullRequestStatus.Active);
export const GitTagTable = () => {
const { entity } = useEntity();
const { items, loading, error } = useGitTags(
entity,
defaultLimit,
pullRequestStatusState,
);
const { items, loading, error } = useGitTags(entity);
if (error) {
return (
@@ -90,12 +80,6 @@ export const GitTagTable = ({ defaultLimit }: PullRequestTableProps) => {
<AzurePullRequestsIcon style={{ fontSize: 30 }} />
<Box mr={1} />
Azure Repos - Git Tags ({items ? items.length : 0})
<Box position="absolute" right={320} top={20}>
<PullRequestStatusButtonGroup
status={pullRequestStatusState}
setStatus={setPullRequestStatusState}
/>
</Box>
</Box>
}
data={items ?? []}
+4 -21
View File
@@ -14,42 +14,25 @@
* limitations under the License.
*/
import {
GitTag,
PullRequestOptions,
PullRequestStatus,
} from '@backstage/plugin-azure-devops-common';
import { GitTag } from '@backstage/plugin-azure-devops-common';
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/lib/useAsync';
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
export function useGitTags(
// TODO: Keep iterating down this rabbit hole on the client once the service has caught up
entity: Entity,
defaultLimit?: number,
requestedStatus?: PullRequestStatus,
): {
export function useGitTags(entity: Entity): {
items?: GitTag[];
loading: boolean;
error?: Error;
} {
const top = defaultLimit ?? AZURE_DEVOPS_DEFAULT_TOP;
const status = requestedStatus ?? PullRequestStatus.Active;
const options: PullRequestOptions = {
top,
status,
};
const api = useApi(azureDevOpsApiRef);
const { project, repo } = useProjectRepoFromEntity(entity);
const { value, loading, error } = useAsync(() => {
return api.getGitTags(project, repo, options);
}, [api, project, repo, top, status]);
return api.getGitTags(project, repo);
}, [api, project, repo]);
return {
items: value?.items,