Skip to content

Commit

Permalink
Use count rather than index for new slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Oct 4, 2024
1 parent 67e1d75 commit 526fc89
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/palette-edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export function deduplicateElementSlugs< T extends PaletteElement >(
) {
const slugCounts: { [ slug: string ]: number } = {};

return elements.map( ( element, index ) => {
return elements.map( ( element ) => {
let newSlug: string | undefined;

const { slug } = element;
slugCounts[ slug ] = ( slugCounts[ slug ] || 0 ) + 1;

if ( slugCounts[ slug ] > 1 ) {
newSlug = `${ slug }-${ index }`;
newSlug = `${ slug }-${ slugCounts[ slug ] - 1 }`;
}

return { ...element, slug: newSlug ?? slug };
Expand Down

0 comments on commit 526fc89

Please sign in to comment.