generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from alleyinteractive/feature/smart-dedupe-slo…
…t-fill Feature: Hide Deduplicate Slot Fill
- Loading branch information
Showing
7 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const blocksWithColumns = [ | ||
{ | ||
clientId: '98c6ea3e-58fe-4f5b-b881-9a7ab2efc808', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
{ | ||
clientId: '80828f03-6611-4303-8d31-9cfc78a8ef5b', | ||
name: 'wp-curate/query', | ||
innerBlocks: [], | ||
}, | ||
{ | ||
clientId: 'e390aca0-c655-460b-ac01-49b7585ad0b3', | ||
name: 'core/columns', | ||
innerBlocks: [ | ||
{ | ||
clientId: '0af1fbf8-dfb3-4114-873b-85918473e3bd', | ||
name: 'core/column', | ||
innerBlocks: [ | ||
{ | ||
clientId: 'd99fb4c3-e941-471b-9687-3ca114667ce0', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
clientId: '692cfd82-cb31-4cd1-8d20-46ef2f02c246', | ||
name: 'core/column', | ||
innerBlocks: [ | ||
{ | ||
clientId: 'f54f92fb-b299-4069-ace7-141656b827b7', | ||
name: 'wp-curate/query', | ||
innerBlocks: [ | ||
{ | ||
clientId: 'd2092cce-30ea-41a4-84ed-7fac3168ce24', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
clientId: '4cd14787-9326-47de-b8e1-9b07ff084690', | ||
name: 'wp-curate/query', | ||
innerBlocks: [], | ||
}, | ||
]; | ||
|
||
export const blocksWithNoQueryBlocks = [ | ||
{ | ||
clientId: '98c6ea3e-58fe-4f5b-b881-9a7ab2efc808', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
{ | ||
clientId: 'e390aca0-c655-460b-ac01-49b7585ad0b3', | ||
name: 'core/columns', | ||
innerBlocks: [ | ||
{ | ||
clientId: '0af1fbf8-dfb3-4114-873b-85918473e3bd', | ||
name: 'core/column', | ||
innerBlocks: [ | ||
{ | ||
clientId: 'd99fb4c3-e941-471b-9687-3ca114667ce0', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
clientId: '692cfd82-cb31-4cd1-8d20-46ef2f02c246', | ||
name: 'core/column', | ||
innerBlocks: [ | ||
{ | ||
clientId: 'f54f92fb-b299-4069-ace7-141656b827b7', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
clientId: '4cd14787-9326-47de-b8e1-9b07ff084690', | ||
name: 'core/heading', | ||
innerBlocks: [], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { blocksWithColumns, blocksWithNoQueryBlocks } from './blocksStub'; | ||
import countBlocksByName from './index'; | ||
|
||
describe('countBlocksByName', () => { | ||
it('should return 3 when there are 3 query blocks', () => { | ||
const count = countBlocksByName(blocksWithColumns, 'wp-curate/query'); | ||
expect(count).toBe(3); | ||
}); | ||
|
||
it('should return 0 when there are no query blocks', () => { | ||
const count = countBlocksByName(blocksWithNoQueryBlocks, 'wp-curate/query'); | ||
expect(count).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface Block { | ||
clientId: string; | ||
name: string; | ||
innerBlocks: Block[]; | ||
} | ||
|
||
/** | ||
* Count blocks by name. | ||
* | ||
* @param blocks An array of blocks. | ||
* @param blockName The name of the block to count. | ||
* @param count The current count. | ||
*/ | ||
export default function countBlocksByName( | ||
blocks: Block[], | ||
blockName: string, | ||
count = 0, | ||
): number { | ||
let newCount = count; | ||
for (const block of blocks) { | ||
if (block.name === blockName) { | ||
newCount += 1; | ||
} | ||
if (block.innerBlocks && block.innerBlocks.length > 0) { | ||
newCount = countBlocksByName(block.innerBlocks, blockName, newCount); | ||
} | ||
} | ||
return newCount; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters