Skip to content

Commit ab11ab7

Browse files
committed
Resolves: MTV-3743 | Standardize editing settings
Signed-off-by: Aviv Turgeman <[email protected]>
1 parent 6e9529b commit ab11ab7

24 files changed

+453
-518
lines changed

locales/en/plugin__forklift-console-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
"Affinity rules": "Affinity rules",
134134
"Affinity rules allows you to specify hard-and soft-affinity for virtual machines. It is possible to write matching rules against workloads (virtual machines and Pods) and Nodes.": "Affinity rules allows you to specify hard-and soft-affinity for virtual machines. It is possible to write matching rules against workloads (virtual machines and Pods) and Nodes.",
135135
"All": "All",
136-
"All changes saved": "All changes saved",
137136
"All networks detected on the selected VMs require a mapping.": "All networks detected on the selected VMs require a mapping.",
138137
"All past migration runs for this plan. This includes both successful and failed attempts, but detailed logs and other data are not available after the migration pods are deleted. If you retry an incomplete migration, only the failed VMs will migrate again.": "All past migration runs for this plan. This includes both successful and failed attempts, but detailed logs and other data are not available after the migration pods are deleted. If you retry an incomplete migration, only the failed VMs will migrate again.",
139138
"All storages detected on the selected VMs require a mapping.": "All storages detected on the selected VMs require a mapping.",
@@ -330,6 +329,7 @@
330329
"Edit provider web UI link": "Edit provider web UI link",
331330
"Edit PVC name template": "Edit PVC name template",
332331
"Edit root device": "Edit root device",
332+
"Edit Settings": "Edit Settings",
333333
"Edit step": "Edit step",
334334
"Edit storage map": "Edit storage map",
335335
"Edit target name": "Edit target name",

src/components/headers/SectionHeading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { FC, ReactNode } from 'react';
22

33
import { Title, type TitleProps } from '@patternfly/react-core';
44

5-
type SectionHeadingProps = {
5+
export type SectionHeadingProps = {
66
text: ReactNode;
77
className?: string;
88
id?: string;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { FC } from 'react';
2+
3+
import { Button, ButtonVariant, Flex } from '@patternfly/react-core';
4+
import { PencilAltIcon } from '@patternfly/react-icons';
5+
import { useForkliftTranslation } from '@utils/i18n';
6+
7+
import SectionHeading, { type SectionHeadingProps } from './SectionHeading';
8+
9+
type SectionHeadingWithEditProps = Omit<
10+
{
11+
title: string;
12+
editable: boolean;
13+
onClick: () => void;
14+
} & SectionHeadingProps,
15+
'text'
16+
>;
17+
18+
const SectionHeadingWithEdit: FC<SectionHeadingWithEditProps> = ({
19+
editable,
20+
onClick,
21+
title,
22+
...rest
23+
}) => {
24+
const { t } = useForkliftTranslation();
25+
return (
26+
<SectionHeading
27+
{...rest}
28+
text={
29+
<Flex direction={{ default: 'row' }} gap={{ default: 'gapSm' }}>
30+
{title}
31+
<Button
32+
icon={<PencilAltIcon />}
33+
variant={ButtonVariant.link}
34+
onClick={onClick}
35+
isDisabled={!editable}
36+
>
37+
{t('Edit')}
38+
</Button>
39+
</Flex>
40+
}
41+
/>
42+
);
43+
};
44+
45+
export default SectionHeadingWithEdit;
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
getValueByJsonPath,
3-
jsonPathToPatch,
3+
openApiJsonPathToPatch,
44
} from 'src/modules/Providers/utils/helpers/getValueByJsonPath';
55

66
import type { OpenApiJsonPath } from '@components/common/utils/types';
@@ -25,39 +25,18 @@ export const defaultOnConfirm = async ({
2525
jsonPath: OpenApiJsonPath;
2626
model: K8sModel;
2727
}) => {
28-
const path = getValueByJsonPath(resource, jsonPath);
29-
const op = path ? REPLACE : ADD;
28+
const value = getValueByJsonPath(resource, jsonPath);
29+
const op = value ? REPLACE : ADD;
3030

3131
return k8sPatch<K8sResourceCommon>({
3232
data: [
3333
{
3434
op,
35-
path: jsonPathToPatch(path),
35+
path: openApiJsonPathToPatch(resource, jsonPath),
3636
value: newValue,
3737
},
3838
],
3939
model,
4040
resource,
4141
});
4242
};
43-
44-
/**
45-
* Wraps the defaultOnConfirm method to convert the newValue from string to int before patching.
46-
*/
47-
export const defaultOnConfirmWithIntValue = async ({
48-
jsonPath,
49-
model,
50-
newValue,
51-
resource,
52-
}: {
53-
resource: K8sResourceCommon;
54-
newValue: unknown;
55-
jsonPath: OpenApiJsonPath;
56-
model: K8sModel;
57-
}) => {
58-
// Convert the newValue from string to int
59-
const intValue = parseInt(String(newValue), 10);
60-
61-
// Call the original method with the converted value
62-
return defaultOnConfirm({ jsonPath, model, newValue: intValue, resource });
63-
};

src/modules/Providers/utils/helpers/getValueByJsonPath.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ export const getValueByJsonPath = (obj: unknown, pathOrFunction: OpenApiJsonPath
1818
return pathParts.reduce((path: any, key: string) => path?.[key], obj) as string;
1919
};
2020

21-
export const jsonPathToPatch = (path: string | string[]) => {
22-
let pathParts = typeof path === 'string' ? path.split('.') : path;
21+
/**
22+
* Converts a JSON path in dot notation to a JSON Patch path.
23+
*
24+
* @param obj - The object (not used in this function but kept for consistency with getValueByJsonPath).
25+
* @param pathOrFunction - The JSON path (dot notation) or a function that returns the desired path.
26+
* @returns The JSON Patch path as a string.
27+
*/
28+
export const openApiJsonPathToPatch = (obj: unknown, pathOrFunction: OpenApiJsonPath) => {
29+
if (typeof pathOrFunction === 'function') {
30+
return pathOrFunction(obj);
31+
}
32+
33+
let pathParts = typeof pathOrFunction === 'string' ? pathOrFunction.split('.') : pathOrFunction;
2334

2435
pathParts = pathParts.map((pathPart) => pathPart.replaceAll('/', '~1'));
2536

src/overview/tabs/Settings/ForkliftControllerSettingsTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useK8sWatchForkliftController } from 'src/overview/hooks/useK8sWatchFor
44

55
import { Bullseye } from '@patternfly/react-core';
66

7-
import SettingsCard from './cards/SettingsCard';
7+
import SettingsCard from './components/SettingsCard';
88

99
const ForkliftControllerSettingsTab: FC = () => {
1010
const [forkliftController, controllerLoaded, controllerLoadError] =

src/overview/tabs/Settings/cards/EditField.tsx

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/overview/tabs/Settings/cards/EditFieldTypes.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)