Skip to content

Commit 9242c91

Browse files
committed
Disabling fields in OCM readonly
1 parent 5ee0e5c commit 9242c91

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

libs/ui-lib/lib/common/components/staticIP/IPConfigFields.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import React from 'react';
22
import { FormGroup, Grid } from '@patternfly/react-core';
3+
import { TFunction } from 'react-i18next';
34

45
import { getFieldId, InputField, PopoverIcon } from '../ui';
56
import { MachineNetworkField } from './MachineNetworkField';
67
import { ProtocolVersion } from './types';
78
import { useTranslation } from '../../hooks';
8-
import { TFunction } from 'react-i18next';
9+
10+
type IpConfigFieldsProps = {
11+
fieldName: string;
12+
protocolVersion: ProtocolVersion;
13+
isDisabled?: boolean;
14+
};
915

1016
export const getProtocolVersionLabel = (protocolVersion: ProtocolVersion, t: TFunction) =>
1117
protocolVersion === ProtocolVersion.ipv4 ? t('ai:IPv4') : t('ai:IPv6');
1218

13-
export const IpConfigFields: React.FC<{
14-
fieldName: string;
15-
protocolVersion: ProtocolVersion;
16-
}> = ({ protocolVersion, fieldName }) => {
19+
export const IpConfigFields = ({
20+
protocolVersion,
21+
fieldName,
22+
isDisabled = false,
23+
}: IpConfigFieldsProps) => {
1724
const { t } = useTranslation();
1825

1926
return (
@@ -25,11 +32,11 @@ export const IpConfigFields: React.FC<{
2532
<MachineNetworkField
2633
fieldName={`${fieldName}.machineNetwork`}
2734
protocolVersion={protocolVersion}
28-
isDisabled={false} // todo
35+
isDisabled={isDisabled}
2936
/>
3037
<InputField
3138
isRequired
32-
isDisabled={false} //todo
39+
isDisabled={isDisabled}
3340
label={t('ai:Default gateway')}
3441
labelIcon={
3542
<PopoverIcon

libs/ui-lib/lib/common/components/staticIP/MachineNetworkField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getAddressObject } from './protocolVersion';
2323
export const MachineNetworkField = ({
2424
fieldName,
2525
protocolVersion,
26-
isDisabled,
26+
isDisabled = false,
2727
}: {
2828
fieldName: string;
2929
protocolVersion: ProtocolVersion;

libs/ui-lib/lib/ocm/components/clusterConfiguration/staticIp/components/FormViewNetworkWide/FormViewNetworkWideFields.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ButtonVariant,
1010
} from '@patternfly/react-core';
1111
import { useField, useFormikContext } from 'formik';
12+
import { useSelector } from 'react-redux';
1213
import {
1314
ConfirmationModal,
1415
getFieldId,
@@ -26,6 +27,7 @@ import { getShownProtocolVersions } from '../../../../../../common/components/st
2627
import { getEmptyIpConfig } from '../../data/emptyData';
2728
import { FormViewHost, FormViewNetworkWideValues } from '../../data/dataTypes';
2829
import { OcmCheckboxField, OcmInputField, OcmRadioField } from '../../../../ui/OcmFormFields';
30+
import { selectCurrentClusterPermissionsState } from '../../../../../store/slices/current-cluster/selectors';
2931

3032
import '../staticIp.css';
3133

@@ -66,6 +68,7 @@ export const ProtocolTypeSelect = () => {
6668
}
6769
};
6870
const isIpv4Selected = protocolType === 'ipv4';
71+
6972
return (
7073
<>
7174
<FormGroup
@@ -135,8 +138,11 @@ export const ProtocolTypeSelect = () => {
135138
</>
136139
);
137140
};
141+
138142
export const FormViewNetworkWideFields = ({ hosts }: { hosts: FormViewHost[] }) => {
143+
const { isViewerMode } = useSelector(selectCurrentClusterPermissionsState);
139144
const { values, setFieldValue } = useFormikContext<FormViewNetworkWideValues>();
145+
140146
return (
141147
<>
142148
<TextContent>
@@ -191,6 +197,7 @@ export const FormViewNetworkWideFields = ({ hosts }: { hosts: FormViewHost[] })
191197
fieldName={`ipConfigs.${protocolVersion}`}
192198
protocolVersion={protocolVersion}
193199
key={protocolVersion}
200+
isDisabled={isViewerMode}
194201
/>
195202
))}
196203
</>

0 commit comments

Comments
 (0)