@@ -2,7 +2,7 @@ import { useCallback, useEffect } from "react";
2
2
import { useQueryClient } from "@tanstack/react-query" ;
3
3
import { useConnections } from "context/ConnectionsContextProvider" ;
4
4
import { useInstallIntegrationProps } from "context/InstallIIntegrationContextProvider/InstallIntegrationContextProvider" ;
5
- import { Connection } from "services/api" ;
5
+ import { Connection , ProviderInfo , Integration } from "services/api" ;
6
6
import { SuccessTextBox } from "src/components/SuccessTextBox/SuccessTextBox" ;
7
7
import { Button } from "src/components/ui-base/Button" ;
8
8
import { handleServerError } from "src/utils/handleServerError" ;
@@ -22,6 +22,36 @@ import {
22
22
23
23
import { SHOW_CUSTOM_AUTH_TEST_DATA , testProviderInfo } from "./testdata" ;
24
24
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
+
25
55
interface ProtectedConnectionLayoutProps {
26
56
provider ?: string ; // passed in from ConnectProvider Component
27
57
consumerRef : string ;
@@ -53,7 +83,7 @@ export function ProtectedConnectionLayout({
53
83
providerName,
54
84
selectedProvider,
55
85
} = useProvider ( provider ) ;
56
- const { provider : providerFromProps , isIntegrationDeleted } =
86
+ const { provider : providerFromProps , isIntegrationDeleted, integrationObj } =
57
87
useInstallIntegrationProps ( ) ;
58
88
const { selectedConnection, setSelectedConnection } = useConnections ( ) ;
59
89
useConnectionHandler ( { onSuccess } ) ;
@@ -105,6 +135,33 @@ export function ProtectedConnectionLayout({
105
135
if ( providerInfo == null )
106
136
return < ComponentContainerError message = "Provider info was not found." /> ;
107
137
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
+
108
165
const sharedProps = {
109
166
provider : selectedProvider ,
110
167
consumerRef,
@@ -115,6 +172,7 @@ export function ProtectedConnectionLayout({
115
172
setSelectedConnection,
116
173
providerName,
117
174
providerInfo,
175
+ metadataFields,
118
176
onDisconnectSuccess,
119
177
} ;
120
178
0 commit comments