Skip to content

Commit 88e637d

Browse files
authored
fix static components (#4423)
1 parent f84d2b4 commit 88e637d

File tree

6 files changed

+102
-76
lines changed

6 files changed

+102
-76
lines changed

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default defineConfig(
3939
'react-hooks/preserve-manual-memoization': 'warn',
4040
'react-hooks/immutability': 'warn',
4141
'react-hooks/purity': 'warn',
42-
'react-hooks/static-components': 'warn',
4342
'react-hooks/use-memo': 'warn',
4443

4544
// TypeScript

src/components/Clusters/components/ClusterPreview.tsx

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,76 @@ import {
66
findInitialValues,
77
} from '../views/EditCluster/EditCluster';
88
import { getUserIndex } from '../shared';
9-
import { Tokens } from 'shared/components/Tokens';
109
import {
1110
Kubeconfig,
1211
KubeconfigNonOIDCAuthToken,
1312
KubeconfigOIDCAuth,
1413
} from 'types';
14+
import { Tokens } from 'shared/components/Tokens';
15+
16+
const TokenData = ({ token }: { token: string }) => {
17+
const { t } = useTranslation();
18+
19+
return (
20+
<>
21+
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
22+
{`${t('clusters.token')}:`}
23+
</p>
24+
{token && <div className="cluster-preview__token">{token}</div>}
25+
</>
26+
);
27+
};
28+
29+
const OidcData = ({
30+
issuerUrl,
31+
clientId,
32+
clientSecret,
33+
extraScopes,
34+
}: {
35+
issuerUrl?: string;
36+
clientId?: string;
37+
clientSecret?: string;
38+
extraScopes?: string[];
39+
}) => {
40+
const { t } = useTranslation();
41+
42+
return (
43+
<>
44+
{issuerUrl && (
45+
<>
46+
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
47+
{t('clusters.labels.issuer-url')}:
48+
</p>
49+
<div>{issuerUrl}</div>
50+
</>
51+
)}
52+
{clientId && (
53+
<>
54+
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
55+
{t('clusters.labels.client-id')}:
56+
</p>
57+
<div>{clientId}</div>
58+
</>
59+
)}
60+
{clientSecret && (
61+
<>
62+
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
63+
{t('clusters.labels.client-secret')}:
64+
</p>
65+
<div>{clientSecret}</div>
66+
</>
67+
)}
68+
{extraScopes && (
69+
<>
70+
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
71+
{t('clusters.labels.scopes')}:
72+
</p>
73+
{<Tokens tokens={extraScopes} />}
74+
</>
75+
)}
76+
</>
77+
);
78+
};
1579

1680
interface ClusterPreviewProps {
1781
kubeconfig: Kubeconfig;
@@ -34,76 +98,22 @@ export function ClusterPreview({
3498
? 'oidc'
3599
: 'token';
36100

37-
const OidcData = () => {
38-
const issuerUrl = findInitialValue(
39-
kubeconfig,
40-
'oidc-issuer-url',
41-
userIndex,
42-
);
43-
const clientId = findInitialValue(kubeconfig, 'oidc-client-id', userIndex);
44-
const clientSecret = findInitialValue(
45-
kubeconfig,
46-
'oidc-client-secret',
47-
userIndex,
48-
);
49-
const extraScopes = findInitialValues(
50-
kubeconfig,
51-
'oidc-extra-scope',
52-
userIndex,
53-
);
54-
55-
return (
56-
<>
57-
{issuerUrl && (
58-
<>
59-
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
60-
{t('clusters.labels.issuer-url')}:
61-
</p>
62-
<div>{issuerUrl}</div>
63-
</>
64-
)}
65-
{clientId && (
66-
<>
67-
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
68-
{t('clusters.labels.client-id')}:
69-
</p>
70-
<div>{clientId}</div>
71-
</>
72-
)}
73-
{clientSecret && (
74-
<>
75-
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
76-
{t('clusters.labels.client-secret')}:
77-
</p>
78-
<div>{clientSecret}</div>
79-
</>
80-
)}
81-
{extraScopes && (
82-
<>
83-
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
84-
{t('clusters.labels.scopes')}:
85-
</p>
86-
{<Tokens tokens={extraScopes} />}
87-
</>
88-
)}
89-
</>
90-
);
91-
};
92-
93-
const TokenData = () => {
94-
const token = (
95-
kubeconfig?.users?.[userIndex]?.user as KubeconfigNonOIDCAuthToken
96-
)?.token;
101+
const issuerUrl = findInitialValue(kubeconfig, 'oidc-issuer-url', userIndex);
102+
const clientId = findInitialValue(kubeconfig, 'oidc-client-id', userIndex);
103+
const clientSecret = findInitialValue(
104+
kubeconfig,
105+
'oidc-client-secret',
106+
userIndex,
107+
);
108+
const extraScopes = findInitialValues(
109+
kubeconfig,
110+
'oidc-extra-scope',
111+
userIndex,
112+
);
97113

98-
return (
99-
<>
100-
<p className="cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny">
101-
{`${t('clusters.token')}:`}
102-
</p>
103-
{token && <div className="cluster-preview__token">{token}</div>}
104-
</>
105-
);
106-
};
114+
const token = (
115+
kubeconfig?.users?.[userIndex]?.user as KubeconfigNonOIDCAuthToken
116+
)?.token;
107117

108118
return (
109119
<div className="cluster-preview">
@@ -138,7 +148,16 @@ export function ClusterPreview({
138148

139149
<div className="cluster-preview__content sap-margin-top-small sap-margin-bottom-tiny">
140150
<div className="cluster-preview__auth">
141-
{authenticationType === 'token' ? <TokenData /> : <OidcData />}
151+
{authenticationType === 'token' ? (
152+
<TokenData token={token} />
153+
) : (
154+
<OidcData
155+
issuerUrl={issuerUrl}
156+
clientId={clientId}
157+
clientSecret={clientSecret}
158+
extraScopes={extraScopes}
159+
/>
160+
)}
142161
</div>
143162
<Button
144163
design="Transparent"

src/components/Extensibility/plugins/ContextSwitcher.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { getNextPlugin } from '@ui-schema/ui-schema/PluginStack';
33
export function ContextSwitcher({ currentPluginIndex, ...props }) {
44
const nextPluginIndex = currentPluginIndex + 1;
55
const Plugin = getNextPlugin(nextPluginIndex, props.widgets);
6-
6+
// eslint-disable-next-line react-hooks/static-components
77
return <Plugin {...props} currentPluginIndex={nextPluginIndex} />;
88
}

src/components/Extensibility/plugins/CustomFieldInjector.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function CustomFieldInjector({
2121

2222
if (path || !storeKeys.size) {
2323
return (
24+
// eslint-disable-next-line react-hooks/static-components
2425
<Plugin
2526
{...props}
2627
currentPluginIndex={nextPluginIndex}
@@ -42,6 +43,7 @@ export function CustomFieldInjector({
4243
const varPath = `$.${varName}${varSuffix}`;
4344

4445
return (
46+
// eslint-disable-next-line react-hooks/static-components
4547
<Plugin
4648
{...props}
4749
currentPluginIndex={nextPluginIndex}
@@ -60,6 +62,7 @@ export function CustomFieldInjector({
6062
}
6163

6264
return (
65+
// eslint-disable-next-line react-hooks/static-components
6366
<Plugin
6467
{...props}
6568
currentPluginIndex={nextPluginIndex}

src/components/Extensibility/plugins/SchemaRulesInjector.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function SchemaRulesInjector({
5252
}
5353

5454
return (
55+
// eslint-disable-next-line react-hooks/static-components
5556
<Plugin
5657
{...props}
5758
currentPluginIndex={nextPluginIndex}

src/resources/Roles/RuleTitle.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useTranslation } from 'react-i18next';
2-
import { isRuleInvalid, hasRuleRequiredProperties } from './helpers';
2+
import { hasRuleRequiredProperties, isRuleInvalid } from './helpers';
33
import { Tooltip } from 'shared/components/Tooltip/Tooltip';
44
import { Icon } from '@ui5/webcomponents-react';
55

6-
export function RuleTitle({ rule, i }) {
6+
const Alert = ({ tooltipContent }) => {
77
const { t } = useTranslation();
88

9-
const Alert = ({ tooltipContent }) => (
9+
return (
1010
<Tooltip position="right" content={tooltipContent} delay={0}>
1111
<Icon
1212
className="bsl-color--warning"
@@ -15,6 +15,10 @@ export function RuleTitle({ rule, i }) {
1515
/>
1616
</Tooltip>
1717
);
18+
};
19+
20+
export function RuleTitle({ rule, i }) {
21+
const { t } = useTranslation();
1822

1923
if (isRuleInvalid(rule)) {
2024
return (

0 commit comments

Comments
 (0)