Skip to content

Commit 27986b8

Browse files
fixed array type issue
1 parent 2890b4e commit 27986b8

File tree

2 files changed

+67
-46
lines changed
  • src/ui/layouts/stackComponents

2 files changed

+67
-46
lines changed

src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
423423
</>
424424
))}
425425
{inputFields.map((inputField: any, index: any) => (
426-
427426
<FlexBox.Row key={`${inputField}~${index}`}>
428427
<Box marginTop="lg">
429428
<EditField
@@ -482,7 +481,30 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
482481

483482
<FlexBox.Row>
484483
<div className="form-row">
485-
{mappedObject &&
484+
{mappedObject && mappedObject[elementName].length < 1 ? (
485+
<>
486+
{' '}
487+
<Fragment>
488+
<div className="form-group col-sm-8">
489+
<EditField
490+
disabled
491+
className={styles.field}
492+
label={'Value'}
493+
value={''}
494+
placeholder={''}
495+
/>
496+
</div>
497+
<div
498+
className="col-sx-2 "
499+
style={{
500+
justifyContent: 'space-between',
501+
display: 'flex',
502+
marginTop: '10px',
503+
}}
504+
></div>
505+
</Fragment>
506+
</>
507+
) : (
486508
mappedObject[elementName]?.map((item: any, index: any) => (
487509
<Fragment>
488510
<div className="form-group col-sm-8">
@@ -501,18 +523,10 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
501523
display: 'flex',
502524
marginTop: '10px',
503525
}}
504-
>
505-
<div
506-
style={{
507-
display: 'flex',
508-
flexDirection: 'row',
509-
justifyContent: 'space-between',
510-
alignItems: 'center',
511-
}}
512-
></div>
513-
</div>
526+
></div>
514527
</Fragment>
515-
))}
528+
))
529+
)}
516530
{/* {inputFields
517531
?.filter((x: any) => x.hasOwnProperty(props.name))
518532
.map((inputField: any, index: any) => (

src/ui/layouts/stackComponents/UpdateComponent/UpdateConfig/index.tsx

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,19 @@ export const UpdateConfig: React.FC<{
151151
function (r: any, name: any) {
152152
return (
153153
(r[name] =
154-
flavor?.configSchema?.properties[name].type === 'string' &&
155-
flavor?.configSchema?.properties[name].default === undefined
154+
flavor?.configSchema?.properties[name]?.type === 'string' &&
155+
flavor?.configSchema?.properties[name]?.default === undefined
156156
? ''
157-
: flavor?.configSchema?.properties[name].default),
157+
: flavor?.configSchema?.properties[name]?.type === 'array' &&
158+
!flavor?.configSchema?.properties[name]?.default?.length
159+
? ['']
160+
: flavor?.configSchema?.properties[name]?.default),
158161
r
159162
);
160163
},
161164
{},
162165
);
163-
166+
console.log(result, 'asdasdasd23232');
164167
const mappedObject = {
165168
...result,
166169
...stackComponent?.configuration,
@@ -209,41 +212,45 @@ export const UpdateConfig: React.FC<{
209212
let tempFinal: any = {};
210213

211214
Object.keys(inputFields).forEach((key) => {
212-
const newObj: any = {};
213-
inputFields[key].forEach((obj: any) => {
214-
if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) {
215-
if (newObj[obj.key] !== undefined) {
216-
dispatch(
217-
showToasterAction({
218-
description: 'Key already exists.',
219-
type: toasterTypes.failure,
220-
}),
221-
);
222-
} else {
223-
newObj[obj.key] = obj.value;
215+
if (flavor?.configSchema?.properties[key].type !== 'array') {
216+
const newObj: any = {};
217+
inputFields[key].forEach((obj: any) => {
218+
if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) {
219+
if (newObj[obj.key] !== undefined) {
220+
dispatch(
221+
showToasterAction({
222+
description: 'Key already exists.',
223+
type: toasterTypes.failure,
224+
}),
225+
);
226+
} else {
227+
newObj[obj.key] = obj.value;
228+
}
224229
}
225-
}
226-
});
227-
tempFinal[key] = newObj;
230+
});
231+
tempFinal[key] = newObj;
232+
}
228233
});
229234
const final: any = {};
230235

231236
Object.keys(inputFields).forEach((key) => {
232-
const newObj: any = {};
233-
inputFields[key].forEach((obj: any) => {
234-
if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) {
235-
if (newObj[obj.key] !== undefined) {
236-
dispatch(
237-
showToasterAction({
238-
description: 'Key already exists.',
239-
type: toasterTypes.failure,
240-
}),
241-
);
237+
if (flavor?.configSchema?.properties[key].type !== 'array') {
238+
const newObj: any = {};
239+
inputFields[key].forEach((obj: any) => {
240+
if (obj.key !== undefined && (obj.key !== '' || obj.value !== '')) {
241+
if (newObj[obj.key] !== undefined) {
242+
dispatch(
243+
showToasterAction({
244+
description: 'Key already exists.',
245+
type: toasterTypes.failure,
246+
}),
247+
);
248+
}
249+
newObj[obj.key] = obj.value;
242250
}
243-
newObj[obj.key] = obj.value;
244-
}
245-
});
246-
final[key] = newObj;
251+
});
252+
final[key] = newObj;
253+
}
247254
});
248255

249256
const body = {

0 commit comments

Comments
 (0)