refactor: Update CopilotActionTypeElement import paths

This commit is contained in:
Simon Larsen 2024-09-03 11:33:18 +01:00
parent 4314920cd7
commit 4b0f71b4e4
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
6 changed files with 202 additions and 4 deletions

View File

@ -2,28 +2,38 @@ import Link from "Common/UI/Components/Link/Link";
import React, { FunctionComponent, ReactElement } from "react";
import CodeRepositoryType from "Common/Types/CodeRepository/CodeRepositoryType";
import URL from "Common/Types/API/URL";
import PullRequestStatusElement from "./PullRequestStatus";
import PullRequestState from "Common/Types/CodeRepository/PullRequestState";
export interface ComponentProps {
pullRequestId: string;
repoType: CodeRepositoryType;
organizationName: string;
repositoryName: string;
pullRequestStatus: PullRequestState
}
const PullRequestViewElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
if (props.repoType === CodeRepositoryType.GitHub) {
const to: URL = URL.fromString(
`https://github.com/${props.organizationName}/${props.repositoryName}/pull/${props.pullRequestId}`,
);
return (
<div className="space-x-3 flex">
<div>
<PullRequestStatusElement pullRequestStatus={props.pullRequestStatus} />
</div>
<Link to={to} className="hover:underline" openInNewTab={true}>
<>
<span>#</span>
{props.pullRequestId}
</>
</Link>
</div>
);
}

View File

@ -0,0 +1,36 @@
import { Gray500, Green500, Red500, Yellow500 } from "Common/Types/BrandColors";
import CopilotActionStatus from "Common/Types/Copilot/CopilotActionStatus";
import Pill from "Common/UI/Components/Pill/Pill";
import React, { FunctionComponent, ReactElement } from "react";
export interface ComponentProps {
copilotActionStatus: CopilotActionStatus;
}
const CopilotActionStatusElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
if (props.copilotActionStatus === CopilotActionStatus.PR_CREATED) {
return <Pill color={Green500} isMinimal={true} text={"PR Created"} />;
}
if (props.copilotActionStatus === CopilotActionStatus.NO_ACTION_REQUIRED) {
return <Pill color={Green500} isMinimal={true} text={"No Action Required"} />;
}
if (props.copilotActionStatus === CopilotActionStatus.CANNOT_FIX) {
return <Pill color={Red500} text={"Cannot Fix"} />;
}
if (props.copilotActionStatus === CopilotActionStatus.IN_QUEUE) {
return <Pill color={Gray500} text={"In Queue"} />;
}
if (props.copilotActionStatus === CopilotActionStatus.PROCESSING) {
return <Pill color={Yellow500} text={"Processing"} />;
}
return <></>;
};
export default CopilotActionStatusElement;

View File

@ -0,0 +1,152 @@
import DashboardNavigation from "../../../Utils/Navigation";
import ModelTable from "Common/UI/Components/ModelTable/ModelTable";
import FieldType from "Common/UI/Components/Types/FieldType";
import React, {
Fragment,
FunctionComponent,
ReactElement,
} from "react";
import DropdownUtil from "Common/UI/Utils/Dropdown";
import PullRequestState from "Common/Types/CodeRepository/PullRequestState";
import PullRequestViewElement from "../../CodeRepository/PullRequestView";
import CopilotAction from "Common/Models/DatabaseModels/CopilotAction";
import Query from "Common/Types/BaseDatabase/Query";
import CopilotActionStatus from "Common/Types/Copilot/CopilotActionStatus";
import Columns from "Common/UI/Components/ModelTable/Columns";
import CopilotActionStatusElement from "./CopilotActionStatusElement";
import CodeRepositoryType from "Common/Types/CodeRepository/CodeRepositoryType";
export interface ComponentProps {
query: Query<CopilotAction>;
repoOrganizationName: string;
repoName: string;
repoType: CodeRepositoryType;
}
const LabelElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
let isPullRequestTable = false;
if (props.query.copilotActionStatus === CopilotActionStatus.PR_CREATED) {
isPullRequestTable = true;
}
const columns: Columns<CopilotAction> = [
{
field: {
copilotActionType: true,
},
title: "Action Type",
type: FieldType.Text,
},
{
field: {
createdAt: true,
},
title: "Created At",
type: FieldType.DateTime,
},
{
field: {
copilotActionStatus: true,
},
title: "Status",
type: FieldType.Element,
getElement: (item: CopilotAction): ReactElement => {
if (!item.copilotActionStatus) {
return <p>-</p>;
}
return (
<CopilotActionStatusElement copilotActionStatus={item.copilotActionStatus} />
);
},
},
];
if (isPullRequestTable) {
// then
columns.push({
field: {
copilotPullRequest: {
pullRequestId: true,
copilotPullRequestStatus: true,
},
},
title: "Pull Request",
type: FieldType.Element,
getElement: (item: CopilotAction): ReactElement => {
if (!item.copilotPullRequest) {
return <p>-</p>;
}
return (
<Fragment>
<PullRequestViewElement
pullRequestId={item.copilotPullRequest.pullRequestId!}
organizationName={props.repoOrganizationName}
repositoryName={props.repoName}
repoType={props.repoType}
pullRequestStatus={item.copilotPullRequest.copilotPullRequestStatus!}
/>
</Fragment>
);
}
});
}
return (
<ModelTable<CopilotAction>
modelType={CopilotAction}
id="table-copiolt-pull-requests"
name="Code Repository > Pull Requests"
isDeleteable={false}
isCreateable={false}
isEditable={false}
isViewable={false}
showViewIdButton={false}
query={{
projectId: DashboardNavigation.getProjectId()!,
...props.query
}}
selectMoreFields={{
copilotPullRequest: {
pullRequestId: true,
copilotPullRequestStatus: true
}
}}
cardProps={{
title: "Pull Requests",
description:
"List of pull requests created by OneUptime Copilot for this code repository.",
}}
noItemsMessage={
"No pull requests found. OneUptime Copilot has not created any pull requests for this code repository."
}
showRefreshButton={true}
filters={[
{
field: {
copilotActionType: true,
},
type: FieldType.Text,
title: "Action",
},
{
field: {
createdAt: true,
},
type: FieldType.DateTime,
title: "Created At",
}
]}
columns={columns}
/>
);
};
export default LabelElement;

View File

@ -10,7 +10,7 @@ import DashboardNavigation from "../../../../Utils/Navigation";
import SortOrder from "Common/Types/BaseDatabase/SortOrder";
import DropdownUtil from "Common/UI/Utils/Dropdown";
import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
import CopilotActionTypeElement from "../../../../Components/Copilot/CopilotActionTypeElement";
import CopilotActionTypeElement from "../../../../Components/Copilot/CopilotAction/CopilotActionTypeElement";
const CopilotPriorities: FunctionComponent<
PageComponentProps

View File

@ -23,6 +23,7 @@ import API from "Common/UI/Utils/API/API";
import PullRequestViewElement from "../../../../Components/CodeRepository/PullRequestView";
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
import CopilotLastRunAt from "../../../../Components/Copilot/LastRunMessage";
import CopilotAction from "Common/Models/DatabaseModels/CopilotAction";
const CopilotPullRequestPage: FunctionComponent<
PageComponentProps
@ -89,12 +90,11 @@ const CopilotPullRequestPage: FunctionComponent<
lastRunAt={codeRepository?.lastCopilotRunDateTime}
/>
<ModelTable<CopilotPullRequest>
modelType={CopilotPullRequest}
<ModelTable<CopilotAction>
modelType={CopilotAction}
id="table-copiolt-pull-requests"
name="Code Repository > Pull Requests"
isDeleteable={false}
createVerb={"Add"}
isCreateable={false}
isEditable={false}
isViewable={false}