-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Add setting option to exclude mode from token value #309
Conversation
* new setting to allow to only preserve mode in token name but exclude it from token value * add documentation in README.md * extend Checkbox component to ember Info component inline to the checkbox label * update jest moduleMapper to resolve "@src"
@lukasoppermann hi! |
Hey @0m4r, this is good, I just have to review it. I will probably remove the contributors section. I am happy for it to be added, but then we need to do a new PR and add all people who contributed. |
Hey @0m4r I added a PR here: https://github.com/0m4r/design-tokens/pull/1 But it is still, not working. The name is not shown in the JSON structure. |
(I am not close to a computer to test at the moment) But, could you help me to replicate your settings with a screenshot? The "new" behavior should be setup by ticking off the "old" checkbox, and tick on the "new" one. ...now that I think about it may not be the best user experience, tho 😓 |
Hey, I updated the naming a bit but this does not matter. However, no matter if the new setting is on or off, it never adds the mode to the name. Adding to the name for me means it should be in the json structure {
base: { // <- (collection)
light: { // <- (mode)
green: {...} This is also how the name is referenced in the value (if the new setting is on). But this does not happen. I expect (but could not test it) that we are missing something in the export or somewhere. I also did not log the name to see if it is actually added. Just FYI I am on vacation for two weeks very soon, so I may not answer for two weeks. |
I have run a few tests and reported the findings here: |
Some updates but not working
Hey @0m4r are you still on this? I agree that the UX seems a bit confusing. Any idea how to fix it? |
Hi Lukas, I am still interested to fix this, but in the last weeks I have not really got a lot of time to spend on this. Let me come back to you with some ideas... |
Add setting configuration to add the mode name to the token name or value. Both token name and value can have the mode added, only one of them or none.
hi @lukasoppermann ,
by combining them, name and value can both be generated including the mode name, only one of them or none. The problem with values that reference variables in the same mode remains unresolved. (I have not updated screenshots and docs yet - I wanted to have a review of the current idea before completing all the work ) |
Pull Request Test Coverage Report for Build 11630838963Details
💛 - Coveralls |
@lukasoppermann I have now completed the work on this PR and updated the README.md. The code is not great, I know... still, what do you think? |
Hey @0m4r, sorry for the late reply. I added a few comments. However, it seems that this PR introduces a memory leak. You can see it if you run it locally. I ran it in a project with a lot of tokens and modes. It runs fine with only one mode. I did not test if just adding a mode breaks it already, but it may. Don't know if you have an idea. I don't know why it breaks. |
Uhm, I did try with a few different Figmna projects, but none of them is really "huge". |
Could be this. I have aliases from the same collection and from collections in other libraries. Happy to test again. If I can just disable the function to test if it is this one, let me know how |
yeah, that would help... (and, to be honest, I have not even considered the use case of variables in other libraries...) @lukasoppermann the easiest way is probably to edit (worth asking, I guess, I am trying to generate a huge design token file, what's the best way to import it back to Figma as Figma variables? I am trying some plugins but none of them does work...) |
src/utilities/getVariables.ts
Outdated
@@ -74,29 +110,31 @@ export const getVariables = (figma: PluginAPI, settings: Settings) => { | |||
// get collection name and modes | |||
const { variableCollectionId } = variable | |||
const { name: collection, modes } = collections[variableCollectionId] | |||
|
|||
if (modes.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0m4r, when I comment out this if clause and the content inside it does not break. So, the leak is probably in detectVariableReferencesInCollection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(you cannot share the Figma file you run your test, right?)
@lukasoppermann I found a fix that should work around the memory leak issue for now. let me know what you do think about this change |
Hey @0m4r I am still running into the issue. I tried to make some time to debug, but I am too blocked atm. Do you have an idea what creates this memory leak? |
Hi @lukasoppermann , yeah, the problem is that when it tries to "resolve" the same mode or same collection variable reference it iterates the current variable against any other. As far as I can tell, as of now, this is the only way to detect this situation (happy to be told wrong on this!). The problem is that when the numbers are huge, this generates a memory leak - and when it succeeds it takes anyway a huge amount of time. I am going to check this one again, but I think I would like to add an additional "beta flag" to enable resolving the same mode/collection variable references. This way, at least the initial problem of the mode names in the token name or value can probably be pushed forward. |
Hey @0m4r, so it is better. Only if I set It does nothing and just closes. I think if you can bring up a Figma error notification and abort, we could at least merge it.
I currently don't understand why this happens, so I would not know a better error code. We just need to deal with the error for now. |
@lukasoppermann I am not able to replicate the problem. I tried all the possible switches combinations for the mode name but I have got no errors. |
@0m4r there is no error, it just does nothing. I am assuming you abort due to some error? As you can see in the video, it works fine with the left option disabled. I waited for a couple minutes, but nothing happens once the option is enabled and I export. CleanShot.2024-11-01.at.12.32.42.mp4 |
Thanks for the video, I have been trying before to replicate the error you have shown in the recording but it did work for me. |
@0m4r I don't know if it is related to the tokens referencing tokens from another file? |
I am looking into it. I have noticed that if I use the plugin in watch mode (npm run start) it all seems working. |
@lukasoppermann I think I have nailed it down to where the issue occurs. I have tried changing a bit the code to optimize the way the data to download is generated (moved away from (code pushed) |
I am sorry for it taking so long. It is nearly perfect. We just need to change one thing. ATM when I open the plugin the json is generated, even if I open the settings. This means once the setting is turned on I am stuck. This can easily be solved by updating the index.ts file. Replace this // write tokens to json file
figma.ui.postMessage({
command: figma.command as PluginCommands,
payload: {
settings: {
...userSettings,
...{ accessToken: await getAccessToken(getFileId(figma)) }
},
data: stringifyJson(exportRawTokenArray(figma, userSettings)),
versionDifference: versionDifference,
metadata: {
filename: figma.root.name
}
}
} || {} as PluginMessage) With this: if([commands.export, commands.urlExport].includes(figma.command as PluginCommands)) {
// write tokens to json file
figma.ui.postMessage({
command: figma.command as PluginCommands,
payload: {
settings: {
...userSettings,
...{ accessToken: await getAccessToken(getFileId(figma)) }
},
data: stringifyJson(exportRawTokenArray(figma, userSettings)),
versionDifference: versionDifference,
metadata: {
filename: figma.root.name
}
}
} || {} as PluginMessage)
} else {
// write tokens to json file
figma.ui.postMessage({
command: figma.command as PluginCommands,
payload: {
settings: {
...userSettings,
...{ accessToken: await getAccessToken(getFileId(figma)) }
},
versionDifference: versionDifference,
metadata: {
filename: figma.root.name
}
}
} || {} as PluginMessage)
} |
I did notice this problem too but I thought it to be "a problem for another time" to avoid adding too much in here. |
@lukasoppermann this is ready for review too. |
Perfect, thank you for all the work. Sorry that it was such a long process |
Fix #308