Skip to content

Commit

Permalink
feature(stackbit): further improve inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Jul 9, 2024
1 parent 6440d0c commit 7e716b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2stackbit",
"comment": "further improve inlining capabilities",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2stackbit"
}
16 changes: 10 additions & 6 deletions tools/jsonschema2stackbit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function convert({
traverse(
reduced,
({ value, parent }) => {
if (value && value.group && value.group === 'INLINE') {
if (value && value.group && value.group.startsWith('INLINE__')) {
const schema = parent?.find((field: Field) => isObjectModel(field) && field.name === value.name);
if (
schema &&
Expand All @@ -96,8 +96,8 @@ export function convert({
for (const field of schema.fields) {
parent.unshift({
...field,
name: `${value.name}_${field.name}`,
group: value.group
name: `${value.name}__${field.name}`,
group: value.name
});
}
}
Expand Down Expand Up @@ -162,9 +162,12 @@ function reduceFields(fields: Field[], subSchema: JSONSchema.Interface): [Field[
if (field.group && subSchema.properties) {
const schemaField = subSchema.properties[field.name];
if (isCmsAnnotatedSchema(schemaField)) {
const groupName = field.group.startsWith('INLINE__')
? field.group.replace('INLINE__', '')
: field.group;
fieldGroups[field.group] ||= {
name: field.group,
label: schemaField['x-cms-group-title'] || toPascalCase(field.group),
name: groupName,
label: schemaField['x-cms-group-title'] || toPascalCase(groupName),
icon: schemaField['x-cms-group-icon'] || 'circle-question'
};
}
Expand Down Expand Up @@ -287,7 +290,8 @@ function processObject({
};
if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-group-name'])
field.group = subSchema['x-cms-group-name'];
if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-group-inline']) field.group = 'INLINE';
if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-group-inline'])
field.group = `INLINE__${name.replace('-', '_')}`;

return { field };
}
Expand Down

0 comments on commit 7e716b5

Please sign in to comment.