Skip to content

Commit 433151d

Browse files
committed
collect inputs specific to module: basicAuth
1 parent 67a33de commit 433151d

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

src/components/Configure/layout/ProtectedConnectionLayout.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useCallback, useEffect } from "react";
22
import { useQueryClient } from "@tanstack/react-query";
33
import { useConnections } from "context/ConnectionsContextProvider";
44
import { useInstallIntegrationProps } from "context/InstallIIntegrationContextProvider/InstallIntegrationContextProvider";
5-
import { Connection } from "services/api";
5+
import { Connection, ProviderInfo, Integration } from "services/api";
66
import { SuccessTextBox } from "src/components/SuccessTextBox/SuccessTextBox";
77
import { Button } from "src/components/ui-base/Button";
88
import { handleServerError } from "src/utils/handleServerError";
@@ -22,6 +22,36 @@ import {
2222

2323
import { SHOW_CUSTOM_AUTH_TEST_DATA, testProviderInfo } from "./testdata";
2424

25+
/**
26+
* Determines the module to use based on provider configuration and integration settings
27+
* @param providerInfo Provider information containing module configuration
28+
* @param integrationObj Integration object that may override the default module
29+
* @returns The module to use, or undefined if no modules are configured
30+
* @throws Error if modules are configured but no default module is found
31+
*/
32+
function determineModule(
33+
providerInfo: ProviderInfo,
34+
integrationObj?: Integration | null
35+
): string | undefined {
36+
// If there's more than one module, we need to figure out the current module
37+
// to understand which inputs to collect from the user.
38+
if (providerInfo.modules && Object.keys(providerInfo.modules).length > 0) {
39+
let module = providerInfo.defaultModule;
40+
if (!module) {
41+
throw new Error("No default module found.");
42+
}
43+
44+
if (integrationObj?.latestRevision?.content?.module) {
45+
// The integration has a module, override the default module with the integration's module.
46+
module = integrationObj.latestRevision.content.module;
47+
}
48+
49+
return module;
50+
}
51+
52+
return undefined;
53+
}
54+
2555
interface ProtectedConnectionLayoutProps {
2656
provider?: string; // passed in from ConnectProvider Component
2757
consumerRef: string;
@@ -53,7 +83,7 @@ export function ProtectedConnectionLayout({
5383
providerName,
5484
selectedProvider,
5585
} = useProvider(provider);
56-
const { provider: providerFromProps, isIntegrationDeleted } =
86+
const { provider: providerFromProps, isIntegrationDeleted, integrationObj } =
5787
useInstallIntegrationProps();
5888
const { selectedConnection, setSelectedConnection } = useConnections();
5989
useConnectionHandler({ onSuccess });
@@ -105,6 +135,33 @@ export function ProtectedConnectionLayout({
105135
if (providerInfo == null)
106136
return <ComponentContainerError message="Provider info was not found." />;
107137

138+
let module: string | undefined;
139+
try {
140+
module = determineModule(providerInfo, integrationObj);
141+
} catch (error) {
142+
return <ComponentContainerError message={(error as Error).message} />;
143+
}
144+
145+
// Filter metadata fields based on the module
146+
const getmetadataFields = () => {
147+
const metadataFields = providerInfo.metadata?.input || [];
148+
149+
// If no module, show all fields
150+
if (!module) {
151+
return metadataFields;
152+
}
153+
154+
// If module exists, show fields that:
155+
// 1. Have no module dependencies (always show)
156+
// 2. Have module dependencies for this specific module
157+
return metadataFields.filter(field =>
158+
!field.moduleDependencies || // No dependencies = always show
159+
field.moduleDependencies[module] // Has dependency for this module
160+
);
161+
};
162+
163+
const metadataFields = getmetadataFields();
164+
108165
const sharedProps = {
109166
provider: selectedProvider,
110167
consumerRef,
@@ -115,6 +172,7 @@ export function ProtectedConnectionLayout({
115172
setSelectedConnection,
116173
providerName,
117174
providerInfo,
175+
metadataFields,
118176
onDisconnectSuccess,
119177
};
120178

src/components/auth/BasicAuth/BasicAuthContent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type BasicAuthFormProps = {
2525
handleSubmit: (form: BasicCreds) => void;
2626
isButtonDisabled?: boolean;
2727
buttonVariant?: "ghost";
28+
metadataFields: MetadataItemInput[];
2829
};
2930

3031
type FormData = {
@@ -39,12 +40,12 @@ export function BasicAuthForm({
3940
handleSubmit,
4041
isButtonDisabled,
4142
buttonVariant,
43+
metadataFields,
4244
}: BasicAuthFormProps) {
4345
const [formData, setFormData] = useState<FormData>({
4446
username: "",
4547
password: "",
4648
});
47-
const metadataFields = providerInfo.metadata?.input || [];
4849
const { username, password } = formData;
4950
const { providerName } = useProvider(provider);
5051

@@ -141,6 +142,7 @@ function BasicAuthContentForm({
141142
handleSubmit,
142143
error,
143144
isButtonDisabled,
145+
metadataFields,
144146
}: LandingContentProps) {
145147
const { providerName } = useProvider(provider);
146148

@@ -153,6 +155,7 @@ function BasicAuthContentForm({
153155
providerInfo={providerInfo}
154156
handleSubmit={handleSubmit}
155157
isButtonDisabled={isButtonDisabled}
158+
metadataFields={metadataFields}
156159
/>
157160
</AuthCardLayout>
158161
);

src/components/auth/BasicAuth/BasicAuthFlow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function BasicAuthFlow({
1717
groupName,
1818
children,
1919
selectedConnection,
20+
metadataFields,
2021
}: BasicAuthFlowProps) {
2122
const { projectIdOrName } = useProject();
2223
const createConnectionMutation = useCreateConnectionMutation();
@@ -61,6 +62,7 @@ export function BasicAuthFlow({
6162
providerInfo={providerInfo}
6263
handleSubmit={onNext}
6364
error={null}
65+
metadataFields={metadataFields}
6466
/>
6567
);
6668
}

src/components/auth/BasicAuth/BasicAuthFlowProps.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Connection, ProviderInfo } from "@generated/api/src";
1+
import { Connection, ProviderInfo, MetadataItemInput } from "@generated/api/src";
22

33
export type BasicAuthFlowProps = {
44
provider: string;
@@ -10,4 +10,5 @@ export type BasicAuthFlowProps = {
1010
children: JSX.Element;
1111
selectedConnection: Connection | null;
1212
setSelectedConnection: (connection: Connection | null) => void;
13+
metadataFields: MetadataItemInput[];
1314
};

src/components/auth/BasicAuth/LandingContentProps.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProviderInfo } from "@generated/api/src";
1+
import { ProviderInfo, MetadataItemInput } from "@generated/api/src";
22

33
import { ProviderMetadata } from "../providerMetadata";
44

@@ -14,4 +14,5 @@ export type LandingContentProps = {
1414
handleSubmit: (form: BasicCreds) => void;
1515
error: string | null;
1616
isButtonDisabled?: boolean;
17+
metadataFields: MetadataItemInput[];
1718
};

0 commit comments

Comments
 (0)