Skip to content

Commit

Permalink
fix: add preview template support to storyblok ref arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Oct 25, 2024
1 parent 5594dd5 commit 4a12f96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2storyblok",
"comment": "add preview template to ref arrays",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2storyblok"
}
3 changes: 3 additions & 0 deletions tools/jsonschema2storyblok/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export interface IStoryblokSchemaElement {
// type: `custom`
field_type?: string;

// our own processing helpers
objectFields?: IStoryblokSchemaElement[];
preview_tmpl?: string;
preview_field?: string;
}

export interface IStoryblokSchemaElementOption {
Expand Down
20 changes: 15 additions & 5 deletions tools/jsonschema2storyblok/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ function processObject({

if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-preview']) {
if (subSchema['x-cms-preview'].startsWith('field:')) {
blok.preview_field = subSchema['x-cms-preview'].split(':')[1];
blok.preview_field = subSchema['x-cms-preview'].replace('field:', '');
} else if (subSchema['x-cms-preview'].startsWith('template:')) {
blok.preview_tmpl = subSchema['x-cms-preview'].split(':')[1];
blok.preview_tmpl = subSchema['x-cms-preview'].replace('template:', '');
}
}
if (description) field.description = description;
Expand All @@ -287,6 +287,14 @@ function processObject({
objectFields: fields
};

if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-preview']) {
if (subSchema['x-cms-preview'].startsWith('field:')) {
field.preview_field = subSchema['x-cms-preview'].replace('field:', '');
} else if (subSchema['x-cms-preview'].startsWith('template:')) {
field.preview_tmpl = subSchema['x-cms-preview'].replace('template:', '');
}
}

return { field };
} else {
const tabId = `tab-${uuidv4()}`;
Expand Down Expand Up @@ -414,9 +422,9 @@ function processRef({

if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-preview']) {
if (subSchema['x-cms-preview'].startsWith('field:')) {
blok.preview_field = subSchema['x-cms-preview'].split(':')[1];
blok.preview_field = subSchema['x-cms-preview'].replace('field:', '');
} else if (subSchema['x-cms-preview'].startsWith('template:')) {
blok.preview_tmpl = subSchema['x-cms-preview'].split(':')[1];
blok.preview_tmpl = subSchema['x-cms-preview'].replace('template:', '');
}
}

Expand Down Expand Up @@ -463,7 +471,9 @@ function processRefArray({
color: colors[field.key] || '#05566a',
icon: icons[field.key] || 'block-wallet',
component_group_uuid: componentGroups[name],
component_group_name: toPascalCase(name)
component_group_name: toPascalCase(name),
preview_field: field.preview_field,
preview_tmpl: field.preview_tmpl
};
})
);
Expand Down

0 comments on commit 4a12f96

Please sign in to comment.