Skip to content

Commit

Permalink
fix: set input configuration on generated structures within blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed May 10, 2022
1 parent b4a684d commit ed0d6b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
11 changes: 7 additions & 4 deletions javascript-modules/generate/lib/structure-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const componentSlug = (componentKey) => {
})).join('_');
}

const generateDeepStructures = ({ blueprint, currentBlueprintKey, inputs }) => {
const generateDeepStructures = ({ blueprint, currentBlueprintKey, inputs, cascadeFields }) => {
if (blueprint && Array.isArray(blueprint)) {
if (typeof blueprint[0] === "object" && !Array.isArray(blueprint[0])) {
// This is an array of objects.
Expand All @@ -100,7 +100,8 @@ const generateDeepStructures = ({ blueprint, currentBlueprintKey, inputs }) => {
const structure = {
label: niceLabel(pluralize.singular(currentBlueprintKey)),
icon: "add_box",
value: generateDeepStructures({ blueprint: blueprint[0], currentBlueprintKey, inputs }),
value: generateDeepStructures({ blueprint: blueprint[0], currentBlueprintKey, inputs, cascadeFields }),
...cascadeFields,
};

inputs[currentBlueprintKey].type = "array";
Expand All @@ -117,7 +118,7 @@ const generateDeepStructures = ({ blueprint, currentBlueprintKey, inputs }) => {

for (let [key, value] of Object.entries(blueprint)) {
if (typeof value === "object") {
blueprint[key] = generateDeepStructures({ blueprint: blueprint[key], currentBlueprintKey: key, inputs });
blueprint[key] = generateDeepStructures({ blueprint: blueprint[key], currentBlueprintKey: key, inputs, cascadeFields });
}
}

Expand Down Expand Up @@ -291,14 +292,16 @@ export const buildStructures = async (options = {}) => {

const cascadeFields = Object.fromEntries(Object.entries(contents).filter(cascadeEntries));
cascadeFields._inputs = cascadeFields._inputs || {};
const cascadeFieldsCopy = JSON.parse(JSON.stringify(cascadeFields));

const structure = {
value: {
_bookshop_name: getComponentKey(componentFile),
...(generateDeepStructures({
blueprint: contents.blueprint || {},
currentBlueprintKey: "blueprint",
inputs: cascadeFields._inputs
inputs: cascadeFields._inputs,
cascadeFields: cascadeFieldsCopy
})),
},
label: niceLabel(getComponentKey(componentFile)), // Used as a fallback when no label is supplied inside [spec]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,33 @@ Feature: Bookshop Structure Generation
| _structures.blocks.values.0.value.my_links.0.text | "My link" |
| _structures.blocks.values.0._inputs.my_links.options | undefined |

Scenario: Object array structures get a copy of any configured settings
Given a component-lib/components/card/card.bookshop.toml file containing:
"""
[spec]
structures = ["blocks"]
[blueprint]
title = "Hello World"
[[blueprint.nested.my_links]]
text = "My link"
[_inputs]
text.comment = "Text comment"
[_misc]
something_else = true
"""
When I run "npm start" in the . directory
Then stderr should be empty
And stdout should contain "Added 1 structure from 1 Bookshop to 1 site."
Then I should see "site/public/_cloudcannon/info.json" containing the values:
| path | value |
| _structures.blocks.values.0._inputs.text.comment | "Text comment" |
| _structures.blocks.values.0._misc.something_else | true |
| _structures.blocks.values.0._inputs.my_links.options.structures.values.0._inputs.text.comment | "Text comment" |
| _structures.blocks.values.0._inputs.my_links.options.structures.values.0._misc.something_else | true |

Scenario: JSON config is supported
Given a component-lib/components/a/b/c/d/e/e.bookshop.json file containing:
"""
Expand Down

0 comments on commit ed0d6b3

Please sign in to comment.