Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/ui/layouts/secrets/Selector/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,34 @@ const Selector: React.FC<Props> = ({
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: '' }]);
}
Expand Down
40 changes: 27 additions & 13 deletions src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
</>
))}
{inputFields.map((inputField: any, index: any) => (

<FlexBox.Row key={`${inputField}~${index}`}>
<Box marginTop="lg">
<EditField
Expand Down Expand Up @@ -482,7 +481,30 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({

<FlexBox.Row>
<div className="form-row">
{mappedObject &&
{mappedObject && mappedObject[elementName].length < 1 ? (
<>
{' '}
<Fragment>
<div className="form-group col-sm-8">
<EditField
disabled
className={styles.field}
label={'Value'}
value={''}
placeholder={''}
/>
</div>
<div
className="col-sx-2 "
style={{
justifyContent: 'space-between',
display: 'flex',
marginTop: '10px',
}}
></div>
</Fragment>
</>
) : (
mappedObject[elementName]?.map((item: any, index: any) => (
<Fragment>
<div className="form-group col-sm-8">
Expand All @@ -501,18 +523,10 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
display: 'flex',
marginTop: '10px',
}}
>
<div
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}
></div>
</div>
></div>
</Fragment>
))}
))
)}
{/* {inputFields
?.filter((x: any) => x.hasOwnProperty(props.name))
.map((inputField: any, index: any) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down