Add UI support for github configs

This commit is contained in:
Weves 2024-07-03 17:26:21 -07:00 committed by Chris Weaver
parent 72d6a0ef71
commit fa049f4f98
2 changed files with 34 additions and 4 deletions

View File

@ -2,7 +2,10 @@
import * as Yup from "yup";
import { GithubIcon, TrashIcon } from "@/components/icons/icons";
import { TextFormField } from "@/components/admin/connectors/Field";
import {
BooleanFormField,
TextFormField,
} from "@/components/admin/connectors/Field";
import { HealthCheckBanner } from "@/components/health/healthcheck";
import useSWR, { useSWRConfig } from "swr";
import { errorHandlingFetcher } from "@/lib/fetcher";
@ -150,8 +153,8 @@ const Main = () => {
{githubConnectorIndexingStatuses.length > 0 && (
<>
<Text className="mb-2">
We pull the latest Pull Requests from each repository listed below
every <b>10</b> minutes.
We pull the latest Pull Requests and/or Issues from each repository
listed below every <b>10</b> minutes.
</Text>
<div className="mb-2">
<ConnectorsTable<GithubConfig, GithubCredentialJson>
@ -188,7 +191,12 @@ const Main = () => {
{githubCredential ? (
<Card className="mt-4">
<h2 className="font-bold mb-3">Connect to a New Repository</h2>
<h2 className="font-bold mb-1">Connect to a New Repository</h2>
<Text className="mb-4">
The Github connector can index Pull Requests and Issues.
</Text>
<ConnectorForm<GithubConfig>
nameBuilder={(values) =>
`GithubConnector-${values.repo_owner}/${values.repo_name}`
@ -202,6 +210,16 @@ const Main = () => {
<>
<TextFormField name="repo_owner" label="Repository Owner:" />
<TextFormField name="repo_name" label="Repository Name:" />
<BooleanFormField
name="include_prs"
label="Include Pull Requests"
subtext="Index pull requests from this repository"
/>
<BooleanFormField
name="include_issues"
label="Include Issues"
subtext="Index issues from this repository"
/>
</>
}
validationSchema={Yup.object().shape({
@ -214,6 +232,15 @@ const Main = () => {
include_prs: Yup.boolean().required(),
include_issues: Yup.boolean().required(),
})}
validate={(values) => {
if (values.include_prs || values.include_issues) {
return {} as Record<string, string>;
}
return {
include_issues:
"Please select at least one of Pull Requests or Issues",
};
}}
initialValues={{
repo_owner: "",
repo_name: "",

View File

@ -66,6 +66,7 @@ interface BaseProps<T extends Yup.AnyObject> {
formBody?: JSX.Element | null;
formBodyBuilder?: FormBodyBuilder<T>;
validationSchema: Yup.ObjectSchema<T>;
validate?: (values: T) => Record<string, string>;
initialValues: T;
onSubmit?: (
isSuccess: boolean,
@ -92,6 +93,7 @@ export function ConnectorForm<T extends Yup.AnyObject>({
formBody,
formBodyBuilder,
validationSchema,
validate,
initialValues,
refreshFreq,
pruneFreq,
@ -136,6 +138,7 @@ export function ConnectorForm<T extends Yup.AnyObject>({
...initialValues,
}}
validationSchema={finalValidationSchema}
validate={validate}
onSubmit={async (values, formikHelpers) => {
formikHelpers.setSubmitting(true);
const connectorName = nameBuilder(values);