-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathgitlabConnectionCreationForm.tsx
More file actions
49 lines (42 loc) · 1.75 KB
/
gitlabConnectionCreationForm.tsx
File metadata and controls
49 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use client';
import { GitlabConnectionConfig } from "@sourcebot/schemas/v3/gitlab.type";
import { gitlabSchema } from "@sourcebot/schemas/v3/gitlab.schema";
import { gitlabQuickActions } from "../../connections/quickActions";
import SharedConnectionCreationForm from "./sharedConnectionCreationForm";
interface GitLabConnectionCreationFormProps {
onCreated?: (id: number) => void;
}
const additionalConfigValidation = (config: GitlabConnectionConfig): { message: string, isValid: boolean } => {
const hasProjects = config.projects && config.projects.length > 0 && config.projects.some(p => p.trim().length > 0);
const hasUsers = config.users && config.users.length > 0 && config.users.some(u => u.trim().length > 0);
const hasGroups = config.groups && config.groups.length > 0 && config.groups.some(g => g.trim().length > 0);
const hasAll = config.all;
if (!hasProjects && !hasUsers && !hasGroups && !hasAll) {
return {
message: "At least one project, user, or group must be specified",
isValid: false,
}
}
return {
message: "Valid",
isValid: true,
}
}
export const GitLabConnectionCreationForm = ({ onCreated }: GitLabConnectionCreationFormProps) => {
const defaultConfig: GitlabConnectionConfig = {
type: 'gitlab',
}
return (
<SharedConnectionCreationForm<GitlabConnectionConfig>
type="gitlab"
title="Create a GitLab connection"
defaultValues={{
config: JSON.stringify(defaultConfig, null, 2),
}}
schema={gitlabSchema}
quickActions={gitlabQuickActions}
additionalConfigValidation={additionalConfigValidation}
onCreated={onCreated}
/>
)
}