Skip to content

extended collections#3911

Open
akshay-gupta7 wants to merge 18 commits into
mainfrom
akshay/extended-collections-2
Open

extended collections#3911
akshay-gupta7 wants to merge 18 commits into
mainfrom
akshay/extended-collections-2

Conversation

@akshay-gupta7

@akshay-gupta7 akshay-gupta7 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Why does this PR exist?

Closes #0000

When exporting child (extended) themes, two bugs existed:

  1. Variables in child collections showed resolved values (e.g. #D6D6D6) instead of variable aliases/references.
  2. All child collection variables appeared blue (explicit override) even when they matched the parent — they should appear white (inherited).

Additionally, the Export to Figma theme selector had no enforcement of parent/child dependencies — a user could check a child theme without its parent, causing broken exports.

What does this pull request do?

Bug: aliases resolved instead of linked (extended collections)

  • Removed a silent clearValueForMode call in setter functions that was failing at runtime (not in Figma's public TypeScript typings) and blocking setValueForMode from running, leaving stale resolved values in place.

Bug: all child variables show as blue/overridden

  • Implemented a two-pass export strategy:
    • Pass 1: write all values and aliases to both the composite child mode and the parent mode.
    • Pass 2 (updateVariablesToReference): when setting an alias on a composite mode, check if the parent mode already has the same alias — if so, call clearValueForMode on the child mode so Figma shows it as inherited (white) rather than overridden (blue).
  • Scalar setters (setColorValuesOnVariable, setNumberValuesOnVariable, etc.) compare the value being written against the parent mode's current value and call clearValueForMode instead of setValueForMode when they match.

Feature: auto-select parent theme in export dialog

  • Checking a child theme in the Export to Figma dialog now automatically checks all ancestor themes.
  • Unchecking a parent theme is blocked (and the checkbox is visually disabled) while any of its descendants remain checked.

Lint fixes

  • Removed unused imports (IconPencil, separateCollectionsByType, createExtendedVariableCollection, findParentCollection, isExtendedCollectionTheme, createVariableMode).
  • Replaced continue statements in createNecessaryVariableCollections with a processTheme helper using early return.
  • Fixed use-before-define in createExtendedCollections.ts by reordering function declarations.
  • Replaced inline require() in test files with top-level imports.
  • Extracted inline JSX arrow functions and IIFE patterns to named callbacks/variables to satisfy react/jsx-no-bind and react/no-unstable-nested-components.
  • Escaped unescaped " entity in OptionsModal.

Testing this change

  1. Set up a Figma Enterprise file with a parent variable collection and at least one extended child collection.
  2. In Tokens Studio, configure a parent theme and one or more child (extended) themes with $figmaIsExtension: true.
  3. Export selecting only child themes — confirm the parent is auto-checked and cannot be unchecked while the child is selected.
  4. Export both parent and child themes together — verify:
    • Variables that reference another variable show as aliases (not resolved hex values).
    • Variables whose value matches the parent mode appear white (inherited), not blue (overridden).
    • Variables that genuinely differ from the parent remain blue.

Additional Notes (if any)

clearValueForMode is not in Figma's public TypeScript typings but exists at runtime on Enterprise clients. It is called via (variable as any).clearValueForMode(modeId). If the method is absent (non-Enterprise), the call is guarded and fails silently without breaking the export.

@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b96922f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@akshay-gupta7 akshay-gupta7 self-assigned this Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

⤵️ 📦 ✨ The artifact was successfully created! Want to test it? Download it here 👀 🎁

@anathaniel-TS

Copy link
Copy Markdown

🛡️ Hyma Compliance Check

No compliance-relevant changes detected

~25 file(s) scanned · 0 findings

ℹ️ This check is informational.
🛡️ Hyma Compliance Check · automated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces robust support for Figma extended (child) variable collections across import/export and theme management, fixing alias linking and “inherited vs overridden” presentation for child collections, and adding UI enforcement around parent/child dependencies and Enterprise-only capabilities.

Changes:

  • Fixes extended-collection export so variable aliases remain aliases (not resolved raw values) and child values that match the parent are shown as inherited (not explicit overrides).
  • Adds Enterprise detection and extends UI flows to support creating/managing extended theme groups and enforcing selection constraints (parent/child and mutual exclusivity).
  • Expands types, schemas, selectors, plugin handlers, and tests to carry/handle extended collection metadata (parent IDs, parent modes, overrides).

Reviewed changes

Copilot reviewed 57 out of 58 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/tokens-studio-for-figma/src/utils/themeListToTree.ts Sort themes/groups to display parent before extended children
packages/tokens-studio-for-figma/src/utils/dragDropOrder/findOrderableTargetIndexesInThemeList.tsx Prevent reordering targets involving extended themes
packages/tokens-studio-for-figma/src/types/VariableCollectionSelection.ts Add extended-collection metadata to selection types
packages/tokens-studio-for-figma/src/types/ThemeObject.ts Add extended theme metadata fields
packages/tokens-studio-for-figma/src/types/AsyncMessages.ts Add CHECK_FIGMA_ENTERPRISE async message types
packages/tokens-studio-for-figma/src/storage/schemas/themeObjectSchema.ts Persist extended theme metadata in schema
packages/tokens-studio-for-figma/src/selectors/isFigmaEnterpriseSelector.ts Selector for Enterprise capability
packages/tokens-studio-for-figma/src/selectors/index.ts Export new selectors
packages/tokens-studio-for-figma/src/selectors/exportExtendedCollectionsSelector.ts Selector for exportExtendedCollections setting
packages/tokens-studio-for-figma/src/plugin/updateVariablesToReference.ts Alias linking updates + extended-mode inheritance logic
packages/tokens-studio-for-figma/src/plugin/updateVariablesFromPlugin.ts Live variable updates respect parent-mode inheritance rules
packages/tokens-studio-for-figma/src/plugin/updateVariables.ts Extended-collection-aware variable lookup + safe removal behavior
packages/tokens-studio-for-figma/src/plugin/setValuesOnVariable.ts Extended-collection aware variable set/alias queuing
packages/tokens-studio-for-figma/src/plugin/setStringValuesOnVariable.ts Clear child override when matching parent string
packages/tokens-studio-for-figma/src/plugin/setNumberValuesOnVariable.ts Clear child override when matching parent number
packages/tokens-studio-for-figma/src/plugin/setColorValuesOnVariable.ts Clear child override when matching parent color
packages/tokens-studio-for-figma/src/plugin/setBooleanValuesOnVariable.ts Clear child override when matching parent boolean
packages/tokens-studio-for-figma/src/plugin/pullVariables.ts Import tokens/themes with extended collection overrides + hierarchy
packages/tokens-studio-for-figma/src/plugin/pullVariables.test.ts Mock new Figma collections API for tests
packages/tokens-studio-for-figma/src/plugin/extendedCollections/index.ts Expose extended collections helpers
packages/tokens-studio-for-figma/src/plugin/extendedCollections/importExtendedCollections.ts Build theme hierarchy metadata during import
packages/tokens-studio-for-figma/src/plugin/extendedCollections/createExtendedCollections.ts Create/update extended collections via extend()
packages/tokens-studio-for-figma/src/plugin/createNecessaryVariableCollections.ts Export-time collection creation supports extended collections
packages/tokens-studio-for-figma/src/plugin/createLocalVariablesWithoutModesInPlugin.ts Pass settings into collection creation
packages/tokens-studio-for-figma/src/plugin/createLocalVariablesInPlugin.ts Ensure parent themes processed before extended themes
packages/tokens-studio-for-figma/src/plugin/controller.ts Register Enterprise-check handler
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/swapFigmaModes.ts Enforce mutual exclusivity of parent vs extended active collections
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/index.ts Export new async handler
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/getAvailableVariableCollections.ts Return extended collection/mode metadata to UI
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/checkFigmaEnterprise.ts Probe Enterprise support via extend()
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/tests/getAvailableVariableCollections.test.ts Update expectations for new collection fields
packages/tokens-studio-for-figma/src/plugin/tests/extendedCollectionsOverrides.test.ts Unit tests for override-clearing behavior
packages/tokens-studio-for-figma/src/plugin/tests/extendedCollections.test.ts Integration tests for import/export extended collections
packages/tokens-studio-for-figma/src/app/store/models/userState.ts Track isFigmaEnterprise in state
packages/tokens-studio-for-figma/src/app/store/models/settings.tsx Add exportExtendedCollections setting
packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/saveTheme.ts Preserve/cascade extended theme metadata & mirroring
packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/index.ts Export deleteThemeGroup reducer
packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/deleteThemeGroup.ts Delete whole theme groups (esp. extended groups)
packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/deleteTheme.ts Delete a theme and its extended descendants
packages/tokens-studio-for-figma/src/app/store/models/reducers/settingsState/setExportExtendedCollections.ts Reducer for exportExtendedCollections
packages/tokens-studio-for-figma/src/app/store/models/reducers/settingsState/index.ts Export new settings reducer
packages/tokens-studio-for-figma/src/app/store/models/effects/settingsState/setExportExtendedCollections.ts Effect wiring for exportExtendedCollections
packages/tokens-studio-for-figma/src/app/store/models/effects/settingsState/index.ts Export new settings effect
packages/tokens-studio-for-figma/src/app/components/ThemeSelector/ThemeSelector.tsx Enforce parent/extended mutual exclusivity when applying themes
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/TokenSetThemeItem.tsx Add disabled state for token set controls
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ThemeListItemContent.tsx Indentation + disable reorder for extended themes
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ThemeListGroupHeader.tsx Group actions menu (extend/delete) + indentation
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/StyledExtendedThemeGroup.tsx Styling wrappers for extended group visuals
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/SingleThemeEntry.tsx Formatting/lint adjustments
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ManageThemesModal.tsx Extend group creation, hierarchy UI, enterprise detection, reorder cascade
packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/CreateOrEditThemeForm.tsx Extend-mode UI + mirror-parent toggle for extended themes
packages/tokens-studio-for-figma/src/app/components/ManageStylesAndVariables/OptionsModal.tsx Add “Export extended collections” toggle (Enterprise-only)
packages/tokens-studio-for-figma/src/app/components/ManageStylesAndVariables/LabelledCheckbox.tsx Add disabled support for labelled checkbox
packages/tokens-studio-for-figma/src/app/components/ManageStylesAndVariables/ExportThemesTab.tsx Auto-select ancestors + disable unchecking parents with selected descendants
packages/tokens-studio-for-figma/src/app/components/ImportVariablesDialog.tsx Filter unsupported multi-level extensions (via extensionDepth)
packages/tokens-studio-for-figma/src/app/components/ExportProvider/SingleFileExport.tsx Strip internal extended metadata from exported themes JSON
packages/tokens-studio-for-figma/src/app/components/ExportProvider/MultiFilesExport.tsx Strip internal extended metadata from exported themes JSON
packages/tokens-studio-for-figma/src/app/components/AppContainer/tests/AppContainerIntegration.test.tsx Update startup params test fixture

Comment thread packages/tokens-studio-for-figma/src/plugin/updateVariablesFromPlugin.ts Outdated
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Commit SHA:8145ee6f6e9ffc7eb8ed10560a301884c02aa908

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: akshay/extended-collections-2 
Status File % Stmts % Branch % Funcs % Lines
🔴 total 59.29 (-0.35) 51.03 (-0.26) 57.32 (-0.66) 59.81 (-0.32)
🟢 packages/tokens-studio-for-figma/src/app/components/ImportVariablesDialog.tsx 31.81 (4.23) 18.75 (2.09) 12 (3.31) 34.42 (4.24)
🔴 packages/tokens-studio-for-figma/src/app/components/ExportProvider/MultiFilesExport.tsx 64 (-4.18) 100 (0) 50 (-7.14) 64 (-4.18)
🟢 packages/tokens-studio-for-figma/src/app/components/ExportProvider/SingleFileExport.tsx 91.66 (0.76) 100 (0) 81.81 (1.81) 91.42 (0.8)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageStylesAndVariables/LabelledCheckbox.tsx 50 (0) 0 (-100) 0 (0) 50 (0)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageStylesAndVariables/OptionsModal.tsx 1.66 (-0.26) 0 (0) 0 (0) 1.72 (-0.28)
🟢 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/CreateOrEditThemeForm.tsx 44.69 (2.76) 39.42 (5.55) 40.9 (2.44) 46.55 (3.03)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ManageThemesModal.tsx 42.19 (-9.7) 34.32 (-11.26) 41.46 (-0.64) 41.61 (-9.7)
✨ 🆕 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/StyledExtendedThemeGroup.tsx 0 100 100 0
🟢 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ThemeGroupDropDownMenu.tsx 60 (50) 75 (75) 40 (40) 62.5 (50)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ThemeListGroupHeader.tsx 51.72 (1.72) 14.81 (-10.19) 11.11 (-3.17) 51.72 (1.72)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/ThemeListItemContent.tsx 87.5 (4.17) 50 (-50) 50 (0) 87.5 (4.17)
🔴 packages/tokens-studio-for-figma/src/app/components/ManageThemesModal/TokenSetThemeItem.tsx 83.33 (0) 57.89 (-17.11) 66.66 (0) 83.33 (0)
🔴 packages/tokens-studio-for-figma/src/app/components/ThemeSelector/ThemeSelector.tsx 65.21 (-19.57) 51.72 (-24.94) 66.66 (-14.59) 63.15 (-20.63)
🔴 packages/tokens-studio-for-figma/src/app/store/models/userState.ts 90.9 (-4.33) 100 (0) 81.81 (-8.19) 90.9 (-4.33)
✨ 🆕 packages/tokens-studio-for-figma/src/app/store/models/effects/settingsState/setExportExtendedCollections.ts 50 100 50 50
✨ 🆕 packages/tokens-studio-for-figma/src/app/store/models/reducers/settingsState/setExportExtendedCollections.ts 0 100 0 0
🟢 packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/deleteTheme.ts 69.23 (2.57) 0 (0) 57.14 (-9.52) 75 (8.34)
🔴 packages/tokens-studio-for-figma/src/app/store/models/reducers/tokenState/saveTheme.ts 80 (-5) 69.81 (-0.19) 80 (5) 78.37 (-5.84)
🟢 packages/tokens-studio-for-figma/src/plugin/controller.ts 98.3 (0.03) 100 (0) 75 (0) 100 (0)
🔴 packages/tokens-studio-for-figma/src/plugin/createLocalVariablesInPlugin.ts 24.28 (-2.28) 18.6 (-4.25) 22.22 (-2.78) 24.61 (-1.61)
🔴 packages/tokens-studio-for-figma/src/plugin/createNecessaryVariableCollections.ts 96.92 (-3.08) 83.6 (-11.85) 100 (0) 96.61 (-3.39)
🟢 packages/tokens-studio-for-figma/src/plugin/notifiers.ts 100 (0) 50 (25) 100 (0) 100 (0)
🔴 packages/tokens-studio-for-figma/src/plugin/pullVariables.ts 75.09 (-3.28) 62.4 (2.63) 82.35 (-1.65) 75.6 (-3.25)
🟢 packages/tokens-studio-for-figma/src/plugin/setBooleanValuesOnVariable.ts 94.11 (5.23) 94.11 (-5.89) 100 (0) 93.75 (4.87)
🔴 packages/tokens-studio-for-figma/src/plugin/setColorValuesOnVariable.ts 100 (0) 91.17 (-4.66) 100 (0) 100 (0)
🔴 packages/tokens-studio-for-figma/src/plugin/setNumberValuesOnVariable.ts 100 (0) 95.45 (-4.55) 100 (0) 100 (0)
🟢 packages/tokens-studio-for-figma/src/plugin/setStringValuesOnVariable.ts 93.75 (6.25) 94.11 (1.81) 100 (0) 93.33 (5.83)
🔴 packages/tokens-studio-for-figma/src/plugin/setValuesOnVariable.ts 77.72 (-6.81) 71.67 (-5.51) 77.77 (-4.58) 77.88 (-6.86)
🔴 packages/tokens-studio-for-figma/src/plugin/updateVariables.ts 77.14 (-19.01) 68.18 (-10.39) 66.66 (-33.34) 81.25 (-14.9)
🔴 packages/tokens-studio-for-figma/src/plugin/updateVariablesFromPlugin.ts 67.6 (-5.98) 47.22 (-6.48) 80 (-20) 72.72 (-0.86)
🟢 packages/tokens-studio-for-figma/src/plugin/updateVariablesToReference.ts 89.74 (2.24) 88.63 (16.41) 90 (-10) 89.61 (0.14)
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/checkFigmaEnterprise.ts 10 0 0 12.5
🔴 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/getAvailableVariableCollections.ts 88.23 (-11.77) 54.54 (4.54) 100 (0) 87.5 (-12.5)
🔴 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/swapFigmaModes.ts 92.98 (-2.47) 76.66 (-7.55) 100 (0) 92.59 (-2.53)
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/extendedCollections/importExtendedCollections.ts 78.57 100 40 78.57
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/extendedCollections/index.ts 100 100 100 100
✨ 🆕 packages/tokens-studio-for-figma/src/selectors/exportExtendedCollectionsSelector.ts 50 100 0 50
✨ 🆕 packages/tokens-studio-for-figma/src/selectors/isFigmaEnterpriseSelector.ts 100 100 100 100
🟢 packages/tokens-studio-for-figma/src/utils/themeListToTree.ts 87.5 (23.87) 52.17 (5.75) 86.66 (36.66) 86.48 (22.85)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Commit SHA:8145ee6f6e9ffc7eb8ed10560a301884c02aa908
Current PR reduces the test coverage percentage by 1 for some tests

@akshay-gupta7 akshay-gupta7 marked this pull request as ready for review July 3, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants