Skip to content

Commit

Permalink
2427-renaming-tokens-in-the-other-type-breaks-references (#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinhoodie0823 authored Jan 8, 2024
1 parent c306ddf commit 1424c9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-carrots-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/figma-plugin': patch
---

Fix the renaming tokens in the other type breaks references
24 changes: 24 additions & 0 deletions src/app/store/models/tokenState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { CompareStateType, findDifferentState } from '@/utils/findDifferentState
import { RenameTokensAcrossSetsPayload } from '@/types/payloads/RenameTokensAcrossSets';
import { wrapTransaction } from '@/profiling/transaction';
import addIdPropertyToTokens from '@/utils/addIdPropertyToTokens';
import { ColorModifier } from '@/types/Modifier';

export interface TokenState {
tokens: Record<string, AnyTokenList>;
Expand Down Expand Up @@ -502,6 +503,29 @@ export const tokenState = createModel<RootModel>()({
} as SingleToken;
}

if (token.$extensions?.['studio.tokens'] && token.$extensions?.['studio.tokens']?.modify && token.$extensions?.['studio.tokens'].modify.value) {
const updatedModify = Object.entries(token.$extensions?.['studio.tokens'].modify).reduce<ColorModifier>((modify, [key, value]: string[]) => {
modify = {
...modify,
[key]: value.replace(data.oldName, data.newName),
};
return modify;
}, {} as ColorModifier);

return {
...token,
$extensions: {
...token.$extensions,
'studio.tokens': {
...token.$extensions['studio.tokens'],
modify: {
...updatedModify,
},
},
},
} as SingleToken;
}

return {
...token,
value: replaceReferences(token.value.toString(), data.oldName, data.newName),
Expand Down

0 comments on commit 1424c9f

Please sign in to comment.