Skip to content

Commit

Permalink
Clarify flow block search filter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukestanley committed Oct 24, 2023
1 parent 3a9a1a4 commit 349aa3a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/extract-example-block-usage-from-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ const generateGroupedJson = (inputFilePath, outputFilePath, blockType, propertyO
for (const flow of flowsData) {
let flowBlocks = []; // To store the blocks with the property of interest for this flow


if (flow.blocks) {
for (const block of flow.blocks) {
if (block.type === blockType && (!propertyOfInterest || (block[propertyOfInterest] && Object.keys(block[propertyOfInterest]).length > 0))) {
const hasMatchingBlock = block.type === blockType;
let hasPropertyOfInterest;
// If no property of interest is specified, so all properties are interesting!
if (!propertyOfInterest) {
hasPropertyOfInterest = true;
}

if (propertyOfInterest) {
// If the object has a specific property that matches our interest and it's not empty, then it's interesting!
hasPropertyOfInterest = block[propertyOfInterest] && Object.keys(block[propertyOfInterest]).length > 0;
}

if (hasMatchingBlock && hasPropertyOfInterest) {
flowBlocks.push(block);
}
}
Expand Down

0 comments on commit 349aa3a

Please sign in to comment.