-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathConnectionParameters.tsx
More file actions
84 lines (71 loc) · 3.57 KB
/
ConnectionParameters.tsx
File metadata and controls
84 lines (71 loc) · 3.57 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {ConnectionDefinition} from '@/shared/middleware/platform/configuration';
import {Fragment} from 'react';
const ConnectionParameters = ({
authorizationParameters,
connectionDefinition,
connectionParameters,
}: {
/* eslint-disable @typescript-eslint/no-explicit-any */
authorizationParameters?: {[key: string]: any};
connectionDefinition: ConnectionDefinition;
/* eslint-disable @typescript-eslint/no-explicit-any */
connectionParameters?: {[key: string]: any};
}) => {
const {authorizations, properties: connectionProperties} = connectionDefinition;
const existingAuthorizations = authorizations?.filter(
(authorization) =>
authorization.properties &&
authorization.properties.filter((property) => !!authorizationParameters![property.name!]).length > 0
);
if (
connectionParameters &&
Object.values(connectionParameters).every((parameter) => parameter === null || parameter === '') &&
authorizationParameters &&
Object.values(authorizationParameters).every((parameter) => parameter === null || parameter === '')
) {
return <></>;
}
const hasConnectionParameters =
connectionProperties && connectionParameters && !!Object.keys(connectionParameters).length;
const hasAuthorizationParameters =
existingAuthorizations && authorizationParameters && !!Object.keys(authorizationParameters).length;
return (
<div className="space-y-2">
<h2 className="heading-tertiary text-sm">
{hasConnectionParameters ? 'Connection' : 'Authorization'} Parameters
</h2>
<ul className="flex w-full flex-col text-sm">
{hasConnectionParameters &&
connectionProperties!
.filter((property) => !!connectionParameters![property.name!])
.map((property) => (
<li className="flex w-full" key={property.name}>
<span className="w-1/3 text-muted-foreground">{property.name}:</span>
<pre className="self-end text-xs">{connectionParameters![property.name!]}</pre>
</li>
))}
{hasAuthorizationParameters &&
existingAuthorizations.map((authorization) => (
<Fragment key={authorization.name}>
<li className="flex">
<span className="w-1/3 font-medium text-muted-foreground">Authorization:</span>
<span>{authorization.title}</span>
</li>
{authorization.properties &&
authorization.properties
.filter((property) => !!authorizationParameters![property.name!])
.map((property) => (
<li className="flex w-full" key={property.name}>
<span className="w-1/3 text-muted-foreground">{property.name}:</span>
<pre className="self-end text-xs">
{authorizationParameters![property.name!]}
</pre>
</li>
))}
</Fragment>
))}
</ul>
</div>
);
};
export default ConnectionParameters;