Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import issue #3270

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Fix import issue #3270

wants to merge 14 commits into from

Conversation

akshay-gupta7
Copy link
Contributor

Why does this PR exist?

Fixes #3260

What does this pull request do?

Currently, when users import variables, the plugin only creates corresponding sets for collections and variables.

This PR adds the feature to create theme groups as well, containing the corresponding sets created as well.

Testing this change

  • Create a variable collection with multiple modes
  • Import it in the plugin
  • The new sets will be created
  • Now, new theme groups and options mapped to those sets will also be created

Additional Notes (if any)

@akshay-gupta7 akshay-gupta7 self-assigned this Feb 18, 2025
Copy link

changeset-bot bot commented Feb 18, 2025

🦋 Changeset detected

Latest commit: 7ef0d00

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tokens-studio/figma-plugin Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

github-actions bot commented Feb 18, 2025

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

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Commit SHA:188795cd7456f505bb1a779ecfacf6b78a432c1c

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: fix-import-issue 
Status File % Stmts % Branch % Funcs % Lines
🔴 total 66.98 (-0.04) 57.98 (-0.02) 63.86 (-0.06) 67.36 (-0.03)
🔴 packages/tokens-studio-for-figma/src/app/components/ImportedTokensDialog.tsx 96.51 (-3.49) 79.48 (-0.52) 94.11 (-5.89) 97.33 (-2.67)
🔴 packages/tokens-studio-for-figma/src/app/components/Initiator.tsx 72.34 (-1.57) 62.5 (-3.28) 66.66 (0) 71.73 (-1.6)
🟢 packages/tokens-studio-for-figma/src/app/store/useTokens.tsx 52.71 (0.19) 34.61 (0) 56.25 (0) 53.57 (0.21)
🔴 packages/tokens-studio-for-figma/src/app/store/models/tokenState.tsx 73.06 (-3.38) 61.19 (-1.88) 81.55 (-2.45) 73.25 (-3.26)
🟢 packages/tokens-studio-for-figma/src/plugin/pullVariables.ts 85.54 (-0.37) 62.29 (0.89) 100 (0) 84.81 (-0.26)
✨ 🆕 packages/tokens-studio-for-figma/src/selectors/importedThemesSelector.ts 100 100 100 100

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Commit SHA:188795cd7456f505bb1a779ecfacf6b78a432c1c
Current PR reduces the test coverage percentage by 1 for some tests

@akshay-gupta7 akshay-gupta7 requested a review from six7 February 19, 2025 08:03
@six7 six7 requested a review from Copilot February 19, 2025 18:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an import issue and extends the functionality of the variable pull process to create theme groups and options for pro users. The changes update type imports, function signatures, and tests to accommodate new parameters and update the notifier and UI state accordingly.

  • Updated pullVariables to accept themes and proUser parameters and process theme groups.
  • Adjusted async message handlers, notifiers, tests, and UI components to support the new theme functionality.
  • Updated types for async messages and plugin messages to include themes and proUser.

Changes

File Description
packages/tokens-studio-for-figma/src/plugin/pullVariables.ts Updated function signature, theme processing logic, and async handling for variable collections.
packages/tokens-studio-for-figma/src/plugin/pullVariables.test.ts Updated tests to pass themes and proUser parameters.
packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/pullVariables.ts Updated to pass new parameters to pullVariables.
packages/tokens-studio-for-figma/src/plugin/notifiers.ts Modified notifyVariableValues to support themes.
packages/tokens-studio-for-figma/src/app/components/Initiator.tsx Updated to dispatch themes received from plugin messages.
packages/tokens-studio-for-figma/src/app/store/useTokens.tsx Updated to derive proUser from license keys and pass themes/proUser to pullVariables.
packages/tokens-studio-for-figma/src/types/AsyncMessages.ts Updated PullVariablesAsyncMessage to include themes and proUser.
packages/tokens-studio-for-figma/src/types/messages.tsx Added themes field to the VariablesFromPluginMessage type.

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@@ -68,6 +70,9 @@ export default function useTokens() {
const store = useStore<RootState>();
const tokensContext = useContext(TokensContext);
const shouldConfirm = useMemo(() => updateMode === UpdateMode.DOCUMENT, [updateMode]);
const existingKey = useSelector(licenseKeySelector);
const licenseKeyError = useSelector(licenseKeyErrorSelector);
const proUser = Boolean(existingKey && !licenseKeyError);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we should have a prouser property in uiState somewhere - i might be wrong though. basically the one that we use to display the GET PRO badge or the PRO badge - is that this one?

}>();

localVariables.forEach(async (variable) => {
const collection = figma.variables.getVariableCollectionById(variable.variableCollectionId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a slow task? should we try to cache this? also.. this is deprecated according to the figma plugin api and we should use the async version: https://www.figma.com/plugin-docs/api/properties/figma-variables-getvariablecollectionbyid/

// Process themes if pro user
const updatedThemes = [...themes];
if (proUser) {
collections.forEach((collection) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we also instead of doing a forEach do a promise.all to have them run all at the same time?

Comment on lines 182 to 206
if (!modeExists) {
updatedThemes.push({
id: `${collection.name.toLowerCase()}-${mode.name.toLowerCase()}`,
name: mode.name,
group: collection.name,
selectedTokenSets: {
[`${collection.name}/${mode.name}`]: TokenSetStatus.ENABLED,
},
$figmaStyleReferences: {},
$figmaModeId: mode.modeId,
$figmaCollectionId: collection.id,
});
}
} else {
updatedThemes.push({
id: `${collection.name.toLowerCase()}-${mode.name.toLowerCase()}`,
name: mode.name,
group: collection.name,
selectedTokenSets: {
[`${collection.name}/${mode.name}`]: TokenSetStatus.ENABLED,
},
$figmaStyleReferences: {},
$figmaModeId: mode.modeId,
$figmaCollectionId: collection.id,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm having trouble finding the difference between these two 🤔 do we need the condition if they do the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I updated the logic a bit, to fix a bug for the variables being imported as themes even before clicking 'Import All'

@akshay-gupta7 akshay-gupta7 requested a review from six7 February 21, 2025 15:25
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.

When importing variables, import as Theme groups
2 participants