Skip to content

Commit 0689895

Browse files
authored
ci: fix empty view spec fields (#9)
1 parent a3030e1 commit 0689895

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

src/stories/components/InputPreview/constants.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const order: ArraySpec = {
288288
viewSpec: {type: 'base', layout: 'accordeon', layoutTitle: 'Order'},
289289
};
290290

291-
export const arrayOptions: ObjectSpec = {
291+
export const getArrayOptions = (): ObjectSpec => ({
292292
type: SpecTypes.Object,
293293
required: true,
294294
properties: {
@@ -338,9 +338,9 @@ export const arrayOptions: ObjectSpec = {
338338
'viewSpec',
339339
],
340340
},
341-
};
341+
});
342342

343-
export const booleanOptions: ObjectSpec = {
343+
export const getBooleanOptions = (): ObjectSpec => ({
344344
type: SpecTypes.Object,
345345
required: true,
346346
properties: {
@@ -363,9 +363,9 @@ export const booleanOptions: ObjectSpec = {
363363
layout: 'section',
364364
order: ['required', 'validator', 'viewSpec'],
365365
},
366-
};
366+
});
367367

368-
export const numberOptions: ObjectSpec = {
368+
export const getNumberOptions = (): ObjectSpec => ({
369369
type: SpecTypes.Object,
370370
required: true,
371371
properties: {
@@ -400,9 +400,9 @@ export const numberOptions: ObjectSpec = {
400400
layout: 'section',
401401
order: ['required', 'maximum', 'minimum', 'format', 'validator', 'viewSpec'],
402402
},
403-
};
403+
});
404404

405-
export const objectOptions: ObjectSpec = {
405+
export const getObjectOptions = (): ObjectSpec => ({
406406
type: SpecTypes.Object,
407407
required: true,
408408
properties: {
@@ -436,9 +436,9 @@ export const objectOptions: ObjectSpec = {
436436
layout: 'section',
437437
order: ['required', 'properties', 'description', 'validator', 'viewSpec'],
438438
},
439-
};
439+
});
440440

441-
export const stringOptions: ObjectSpec = {
441+
export const getStringOptions = (): ObjectSpec => ({
442442
type: SpecTypes.Object,
443443
required: true,
444444
properties: {
@@ -498,4 +498,4 @@ export const stringOptions: ObjectSpec = {
498498
'viewSpec',
499499
],
500500
},
501-
};
501+
});

src/stories/components/InputPreview/utils.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
} from '../../../lib';
1313

1414
import {
15-
arrayOptions,
16-
booleanOptions,
17-
numberOptions,
18-
objectOptions,
19-
stringOptions,
15+
getArrayOptions,
16+
getBooleanOptions,
17+
getNumberOptions,
18+
getObjectOptions,
19+
getStringOptions,
2020
} from './constants';
2121

2222
export const transformCorrect = (spec: Spec) => {
@@ -137,51 +137,41 @@ export const getOptionsSpec = (spec: Spec, excludeOptions?: string[]) => {
137137
let result: ObjectSpec | null = null;
138138

139139
if (isArraySpec(spec)) {
140-
result = arrayOptions;
140+
result = getArrayOptions();
141141
}
142142

143143
if (isBooleanSpec(spec)) {
144-
result = booleanOptions;
144+
result = getBooleanOptions();
145145
}
146146

147147
if (isNumberSpec(spec)) {
148-
result = numberOptions;
148+
result = getNumberOptions();
149149
}
150150

151151
if (isObjectSpec(spec)) {
152-
result = objectOptions;
152+
result = getObjectOptions();
153153
}
154154

155155
if (isStringSpec(spec)) {
156-
result = stringOptions;
156+
result = getStringOptions();
157157
}
158158

159159
if (result) {
160-
let viewSpec: ObjectSpec | undefined;
161-
162160
if (result.properties?.viewSpec) {
163-
viewSpec = result.properties?.viewSpec as ObjectSpec;
164-
viewSpec.viewSpec = {
165-
...viewSpec.viewSpec,
166-
order: viewSpec.viewSpec.order?.filter(
167-
(key) => !excludeOptions?.find((k) => k === `viewSpec.${key}`),
168-
),
169-
};
161+
const viewSpecOrder = (result.properties.viewSpec as ObjectSpec).viewSpec.order?.filter(
162+
(key) => !excludeOptions?.find((k) => k === `viewSpec.${key}`),
163+
);
164+
165+
(result.properties.viewSpec as ObjectSpec).viewSpec.order = viewSpecOrder?.length
166+
? viewSpecOrder
167+
: undefined;
170168
}
171169

172-
result = {
173-
...result,
174-
properties: {
175-
...(result.properties || {}),
176-
...(viewSpec ? {viewSpec} : {}),
177-
},
178-
viewSpec: {
179-
...result.viewSpec,
180-
order: result.viewSpec.order?.filter(
181-
(key) => !excludeOptions?.find((k) => k === key),
182-
),
183-
},
184-
};
170+
const order = result.viewSpec.order?.filter(
171+
(key) => !excludeOptions?.find((k) => k === key),
172+
);
173+
174+
result.viewSpec.order = order?.length ? order : undefined;
185175
}
186176

187177
return result;

0 commit comments

Comments
 (0)