From 2890b4ee469460e23d200642cb78de44d852aa7a Mon Sep 17 00:00:00 2001 From: talhainvenxion Date: Fri, 21 Apr 2023 17:40:31 +0500 Subject: [PATCH 1/2] fixed secrets pre-polulated values --- src/ui/layouts/secrets/Selector/Selector.tsx | 51 +++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/ui/layouts/secrets/Selector/Selector.tsx b/src/ui/layouts/secrets/Selector/Selector.tsx index f4191a2d3..33196141f 100644 --- a/src/ui/layouts/secrets/Selector/Selector.tsx +++ b/src/ui/layouts/secrets/Selector/Selector.tsx @@ -32,29 +32,34 @@ const Selector: React.FC = ({ useEffect(() => { // ...values, // { key: '', value: '' }, - if (routeState?.state?.routeFromComponent) { - const secretKeyValuefromRoute: any = { - key: routeState?.state?.secretKey, - value: routeState?.state?.inputData[routeState?.state?.secretKey], - }; - - setInputFields([...inputFields, secretKeyValuefromRoute]); - } else if (values?.length && !routeState?.state?.routeFromComponent) { - setInputFields([...values]); - } else { - setInputFields([{ key: '', value: '' }]); - } - - if (routeState?.state?.routeFromEditComponent) { - const secretKeyValuefromRoute: any = { - key: routeState?.state?.secretKey, - value: - routeState?.state?.mappedConfiguration[routeState?.state?.secretKey], - }; - - setInputFields([...inputFields, secretKeyValuefromRoute]); - } else if (values?.length && !routeState?.state?.routeFromEditComponent) { - setInputFields([...values]); + if ( + routeState?.state?.routeFromComponent || + routeState?.state?.routeFromEditComponent + ) { + if (routeState?.state?.routeFromComponent) { + const secretKeyValuefromRoute: any = { + key: routeState?.state?.secretKey, + value: routeState?.state?.inputData[routeState?.state?.secretKey], + }; + + setInputFields([...inputFields, secretKeyValuefromRoute]); + } else if (values?.length && !routeState?.state?.routeFromComponent) { + setInputFields([...values]); + } + + if (routeState?.state?.routeFromEditComponent) { + const secretKeyValuefromRoute: any = { + key: routeState?.state?.secretKey, + value: + routeState?.state?.mappedConfiguration[ + routeState?.state?.secretKey + ], + }; + + setInputFields([...inputFields, secretKeyValuefromRoute]); + } else if (values?.length && !routeState?.state?.routeFromEditComponent) { + setInputFields([...values]); + } } else { setInputFields([{ key: '', value: '' }]); } From 27986b8ab0c66299df3314de56f6f72433bb6fdc Mon Sep 17 00:00:00 2001 From: talhainvenxion Date: Fri, 21 Apr 2023 20:08:10 +0500 Subject: [PATCH 2/2] fixed array type issue --- .../StackDetail/Configuration/index.tsx | 40 ++++++---- .../UpdateComponent/UpdateConfig/index.tsx | 73 ++++++++++--------- 2 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx b/src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx index 1754a4cfb..7457a94f6 100644 --- a/src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx +++ b/src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx @@ -423,7 +423,6 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({ ))} {inputFields.map((inputField: any, index: any) => ( - = ({
- {mappedObject && + {mappedObject && mappedObject[elementName].length < 1 ? ( + <> + {' '} + +
+ +
+
+
+ + ) : ( mappedObject[elementName]?.map((item: any, index: any) => (
@@ -501,18 +523,10 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({ display: 'flex', marginTop: '10px', }} - > -
-
+ >
- ))} + )) + )} {/* {inputFields ?.filter((x: any) => x.hasOwnProperty(props.name)) .map((inputField: any, index: any) => ( diff --git a/src/ui/layouts/stackComponents/UpdateComponent/UpdateConfig/index.tsx b/src/ui/layouts/stackComponents/UpdateComponent/UpdateConfig/index.tsx index 067a739a2..bd3ff45fc 100644 --- a/src/ui/layouts/stackComponents/UpdateComponent/UpdateConfig/index.tsx +++ b/src/ui/layouts/stackComponents/UpdateComponent/UpdateConfig/index.tsx @@ -151,16 +151,19 @@ export const UpdateConfig: React.FC<{ function (r: any, name: any) { return ( (r[name] = - flavor?.configSchema?.properties[name].type === 'string' && - flavor?.configSchema?.properties[name].default === undefined + flavor?.configSchema?.properties[name]?.type === 'string' && + flavor?.configSchema?.properties[name]?.default === undefined ? '' - : flavor?.configSchema?.properties[name].default), + : flavor?.configSchema?.properties[name]?.type === 'array' && + !flavor?.configSchema?.properties[name]?.default?.length + ? [''] + : flavor?.configSchema?.properties[name]?.default), r ); }, {}, ); - + console.log(result, 'asdasdasd23232'); const mappedObject = { ...result, ...stackComponent?.configuration, @@ -209,41 +212,45 @@ export const UpdateConfig: React.FC<{ let tempFinal: any = {}; Object.keys(inputFields).forEach((key) => { - const newObj: any = {}; - inputFields[key].forEach((obj: any) => { - if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) { - if (newObj[obj.key] !== undefined) { - dispatch( - showToasterAction({ - description: 'Key already exists.', - type: toasterTypes.failure, - }), - ); - } else { - newObj[obj.key] = obj.value; + if (flavor?.configSchema?.properties[key].type !== 'array') { + const newObj: any = {}; + inputFields[key].forEach((obj: any) => { + if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) { + if (newObj[obj.key] !== undefined) { + dispatch( + showToasterAction({ + description: 'Key already exists.', + type: toasterTypes.failure, + }), + ); + } else { + newObj[obj.key] = obj.value; + } } - } - }); - tempFinal[key] = newObj; + }); + tempFinal[key] = newObj; + } }); const final: any = {}; Object.keys(inputFields).forEach((key) => { - const newObj: any = {}; - inputFields[key].forEach((obj: any) => { - if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) { - if (newObj[obj.key] !== undefined) { - dispatch( - showToasterAction({ - description: 'Key already exists.', - type: toasterTypes.failure, - }), - ); + if (flavor?.configSchema?.properties[key].type !== 'array') { + const newObj: any = {}; + inputFields[key].forEach((obj: any) => { + if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) { + if (newObj[obj.key] !== undefined) { + dispatch( + showToasterAction({ + description: 'Key already exists.', + type: toasterTypes.failure, + }), + ); + } + newObj[obj.key] = obj.value; } - newObj[obj.key] = obj.value; - } - }); - final[key] = newObj; + }); + final[key] = newObj; + } }); const body = {