From fb6d19ff7128f017aedd94d6b89884a3f12c8de3 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 15 Feb 2024 18:17:42 +0000 Subject: [PATCH] Fix patterns with the same are overwritten on the zip. --- .../components/page-patterns/dataviews-pattern-actions.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js b/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js index 5d3948685db876..8dfe09f26c76f0 100644 --- a/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js +++ b/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js @@ -68,9 +68,15 @@ export const exportJSONaction = { 'application/json' ); } + const nameCount = {}; const filesToZip = items.map( ( item ) => { + const name = kebabCase( item.title || item.name ); + nameCount[ name ] = ( nameCount[ name ] || 0 ) + 1; return { - name: `${ kebabCase( item.title || item.name ) }.json`, + name: `${ + name + + ( nameCount[ name ] > 1 ? '-' + nameCount[ name ] : '' ) + }.json`, lastModified: new Date(), input: getJsonFromItem( item ), };