This commit is contained in:
carlosmonastyrski
2025-06-25 00:24:24 -03:00
parent 18e733c71f
commit 0366e58a5b
14 changed files with 64 additions and 63 deletions
@@ -22,8 +22,8 @@ import { useGetAppConnectionOption } from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { GitLabAccessTokenType } from "@app/hooks/api/appConnections/gitlab";
import {
GitlabConnectionMethod,
TGitlabConnection
GitLabConnectionMethod,
TGitLabConnection
} from "@app/hooks/api/appConnections/types/gitlab-connection";
import {
@@ -32,14 +32,14 @@ import {
} from "./GenericAppConnectionFields";
type Props = {
appConnection?: TGitlabConnection;
appConnection?: TGitLabConnection;
onSubmit: (formData: FormData) => Promise<void>;
};
const formSchema = z.discriminatedUnion("method", [
genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.Gitlab),
method: z.literal(GitlabConnectionMethod.AccessToken),
method: z.literal(GitLabConnectionMethod.AccessToken),
credentials: z.object({
accessToken: z.string().min(1, "Access token is required"),
accessTokenType: z.nativeEnum(GitLabAccessTokenType),
@@ -55,7 +55,7 @@ const formSchema = z.discriminatedUnion("method", [
}),
genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.Gitlab),
method: z.literal(GitlabConnectionMethod.OAuth),
method: z.literal(GitLabConnectionMethod.OAuth),
credentials: z.object({
code: z.string().min(1, "Code is required"),
instanceUrl: z
@@ -84,12 +84,12 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
const form = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues:
appConnection?.method === GitlabConnectionMethod.OAuth
appConnection?.method === GitLabConnectionMethod.OAuth
? { ...appConnection, credentials: { code: "custom" } }
: (appConnection ??
({
app: AppConnection.Gitlab,
method: GitlabConnectionMethod.AccessToken,
method: GitLabConnectionMethod.AccessToken,
credentials: {
accessToken: "",
accessTokenType: GitLabAccessTokenType.Personal,
@@ -112,11 +112,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
const onSubmit = async (formData: FormData) => {
try {
switch (formData.method) {
case GitlabConnectionMethod.AccessToken:
case GitLabConnectionMethod.AccessToken:
await formSubmit(formData);
break;
case GitlabConnectionMethod.OAuth:
case GitLabConnectionMethod.OAuth:
if (!oauthClientId) {
return;
}
@@ -165,10 +165,10 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
let isMissingConfig: boolean;
switch (selectedMethod) {
case GitlabConnectionMethod.OAuth:
case GitLabConnectionMethod.OAuth:
isMissingConfig = !oauthClientId;
break;
case GitlabConnectionMethod.AccessToken:
case GitLabConnectionMethod.AccessToken:
isMissingConfig = false;
break;
default:
@@ -210,7 +210,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
APP_CONNECTION_MAP[AppConnection.Gitlab].name
}. This field cannot be changed after creation.`}
errorText={
!isLoading && isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth
!isLoading && isMissingConfig && selectedMethod === GitLabConnectionMethod.OAuth
? `Environment variables have not been configured. ${
isInfisicalCloud()
? "Please contact Infisical."
@@ -226,7 +226,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
value={value}
onValueChange={(val) => {
onChange(val);
if (val === GitlabConnectionMethod.OAuth) {
if (val === GitLabConnectionMethod.OAuth) {
setValue("credentials.code", "custom");
}
}}
@@ -234,11 +234,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
position="popper"
dropdownContainerClassName="max-w-none"
>
{Object.values(GitlabConnectionMethod).map((method) => {
{Object.values(GitLabConnectionMethod).map((method) => {
return (
<SelectItem value={method} key={method}>
{getAppConnectionMethodDetails(method).name}{" "}
{method === GitlabConnectionMethod.AccessToken ? " (Recommended)" : ""}
{method === GitLabConnectionMethod.AccessToken ? " (Recommended)" : ""}
</SelectItem>
);
})}
@@ -247,7 +247,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
)}
/>
{selectedMethod === GitlabConnectionMethod.AccessToken && (
{selectedMethod === GitLabConnectionMethod.AccessToken && (
<>
<Controller
name="credentials.accessTokenType"
@@ -263,7 +263,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
value={value}
onValueChange={(val) => {
onChange(val);
if (val === GitlabConnectionMethod.OAuth) {
if (val === GitLabConnectionMethod.OAuth) {
setValue("credentials.code", "custom");
}
}}
@@ -313,11 +313,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
isDisabled={
isSubmitting ||
(!isUpdate && !isDirty) ||
(isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth) ||
(isMissingConfig && selectedMethod === GitLabConnectionMethod.OAuth) ||
isRedirecting
}
>
{isRedirecting && selectedMethod === GitlabConnectionMethod.OAuth
{isRedirecting && selectedMethod === GitLabConnectionMethod.OAuth
? "Redirecting to GitLab..."
: isUpdate
? "Reconnect to GitLab"
@@ -11,14 +11,14 @@ import {
AzureDevOpsConnectionMethod,
AzureKeyVaultConnectionMethod,
GitHubConnectionMethod,
GitlabConnectionMethod,
GitLabConnectionMethod,
TAzureAppConfigurationConnection,
TAzureClientSecretsConnection,
TAzureDevOpsConnection,
TAzureKeyVaultConnection,
TGitHubConnection,
TGitHubRadarConnection,
TGitlabConnection,
TGitLabConnection,
useCreateAppConnection,
useUpdateAppConnection
} from "@app/hooks/api/appConnections";
@@ -35,7 +35,7 @@ type GithubFormData = BaseFormData & Pick<TGitHubConnection, "name" | "method" |
type GithubRadarFormData = BaseFormData &
Pick<TGitHubRadarConnection, "name" | "method" | "description">;
type GitlabFormData = BaseFormData & Pick<TGitlabConnection, "name" | "method" | "description">;
type GitLabFormData = BaseFormData & Pick<TGitLabConnection, "name" | "method" | "description">;
type AzureKeyVaultFormData = BaseFormData &
Pick<TAzureKeyVaultConnection, "name" | "method" | "description"> &
@@ -65,7 +65,7 @@ type AzureDevOpsFormData = BaseFormData &
type FormDataMap = {
[AppConnection.GitHub]: GithubFormData & { app: AppConnection.GitHub };
[AppConnection.GitHubRadar]: GithubRadarFormData & { app: AppConnection.GitHubRadar };
[AppConnection.Gitlab]: GitlabFormData & { app: AppConnection.Gitlab };
[AppConnection.Gitlab]: GitLabFormData & { app: AppConnection.Gitlab };
[AppConnection.AzureKeyVault]: AzureKeyVaultFormData & { app: AppConnection.AzureKeyVault };
[AppConnection.AzureAppConfiguration]: AzureAppConfigurationFormData & {
app: AppConnection.AzureAppConfiguration;
@@ -162,7 +162,7 @@ export const OAuthCallbackPage = () => {
app: AppConnection.Gitlab,
name,
description,
method: GitlabConnectionMethod.OAuth,
method: GitLabConnectionMethod.OAuth,
credentials: {
code: code as string
}
@@ -1,10 +1,10 @@
import { TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { TGitLabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { getSecretSyncDestinationColValues } from "../helpers";
import { SecretSyncTableCell } from "../SecretSyncTableCell";
type Props = {
secretSync: TGitlabSync;
secretSync: TGitLabSync;
};
export const GitLabSyncDestinationCol = ({ secretSync }: Props) => {
@@ -5,7 +5,7 @@ import {
GitHubSyncScope,
GitHubSyncVisibility
} from "@app/hooks/api/secretSyncs/types/github-sync";
import { GitlabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { HumanitecSyncScope } from "@app/hooks/api/secretSyncs/types/humanitec-sync";
// This functional ensures parity across what is displayed in the destination column
@@ -130,10 +130,10 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
secondaryText = "App ID";
break;
case SecretSync.GitLab:
if (destinationConfig.scope === GitlabSyncScope.Project) {
if (destinationConfig.scope === GitLabSyncScope.Project) {
primaryText = destinationConfig.projectName;
secondaryText = destinationConfig.projectId;
} else if (destinationConfig.scope === GitlabSyncScope.Group) {
} else if (destinationConfig.scope === GitLabSyncScope.Group) {
primaryText = destinationConfig.groupName;
secondaryText = destinationConfig.groupId;
} else {
@@ -1,8 +1,8 @@
import { GenericFieldLabel } from "@app/components/secret-syncs";
import { GitlabSyncScope, TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { GitLabSyncScope, TGitLabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
type Props = {
secretSync: TGitlabSync;
secretSync: TGitLabSync;
};
export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
@@ -17,7 +17,7 @@ export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
return (
<>
{secretSync.destinationConfig.scope === GitlabSyncScope.Project && (
{secretSync.destinationConfig.scope === GitLabSyncScope.Project && (
<>
<GenericFieldLabel label="Project Name">
{secretSync.destinationConfig.projectName}
@@ -27,7 +27,7 @@ export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
</GenericFieldLabel>
</>
)}
{secretSync.destinationConfig.scope === GitlabSyncScope.Group && (
{secretSync.destinationConfig.scope === GitLabSyncScope.Group && (
<>
<GenericFieldLabel label="Group Name">
{secretSync.destinationConfig.groupName}
@@ -4,7 +4,7 @@ import { useNavigate, useSearch } from "@tanstack/react-router";
import { ROUTE_PATHS } from "@app/const/routes";
import { useWorkspace } from "@app/context";
import { useCreateAppConnection, useUpdateAppConnection } from "@app/hooks/api/appConnections";
import { GitlabConnectionMethod } from "@app/hooks/api/appConnections/types/gitlab-connection";
import { GitLabConnectionMethod } from "@app/hooks/api/appConnections/types/gitlab-connection";
export const GitLabOAuthCallbackPage = () => {
const navigate = useNavigate();
@@ -49,7 +49,7 @@ export const GitLabOAuthCallbackPage = () => {
// Prepare app connection data with OAuth credentials
const connectionData = {
...formData,
method: GitlabConnectionMethod.OAuth,
method: GitLabConnectionMethod.OAuth,
credentials: {
code: code as string
}