tokens-studio / figma-plugin

Official repository of the plugin 'Tokens Studio for Figma' (Figma Tokens)
https://www.figma.com/community/plugin/843461159747178978
MIT License
1.34k stars 194 forks source link

Fix empty modify on JSON save or edit #2816

Closed macintoshhelper closed 2 months ago

macintoshhelper commented 2 months ago

Why does this PR exist?

Closes #2805

What does this pull request do?

Before After
image image
image image

Testing this change

To reproduce

  1. Go to JSON view
  2. Paste this JSON:
{
 "blue": {
    "value": "#ff0000",
    "type": "color",
    "$extensions": {
      "studio.tokens": {}
    }
  },
  "red": {
    "value": "#ff0000",
    "type": "color",
    "$extensions": {
      "studio.tokens": {
        "modify": {}
      }
    }
  },
 "valid": {
    "value": "#ff0000",
    "type": "color",
    "$extensions": {
      "studio.tokens": {
        "modify": {
          "type": "darken",
          "space": "srgb",
          "value": "0.5"
        }
      }
    }
  }
}

For existing tokens with empty modify:

  1. Right click and click Edit Token, then save.
  2. The empty modify should be stripped.

Additional Notes (if any)

A migration step would be nice to automatically strip empty extension objects when the plugin is opened/upgraded, but this would probably be better left for a future migration system with strong testing/error catching.

changeset-bot[bot] commented 2 months ago

⚠️ No Changeset found

Latest commit: a8804223ed4467a3b34e5434602285e56f03649d

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

cuserox commented 2 months ago

✅ Tested by copy pasting the JSON, and it works!

🤔 This might not be in scope for the fix, but now that there's the validateTokensStudioExtension helper, it could be applied to other cases where these empty modify object appears. I tried replicating the issue being faced by this user(for example, the border-radius video)

With your branch locally:

😫 This also adds an empty modify object

My hunch is that the remapping action is adding it somewhere, maybe? REMAP_TOKENS

Screenshot 2024-06-06 at 16 48 46

https://github.com/tokens-studio/figma-plugin/assets/114073780/7681da89-cfb1-4089-853d-94c5690d0a55