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: Handle invalid colour codes on tags, allow default colours #4822

Merged
merged 10 commits into from
Nov 19, 2024

Conversation

rolodato
Copy link
Member

@rolodato rolodato commented Nov 8, 2024

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Fixes the frontend breaking when rendering tags that have an invalid colour.

To reproduce, create a tag with a colour code that is not accepted by color. Example (missing #):

curl 'http://localhost:8000/api/v1/projects/34/tags/' -X POST -H 'authorization: Token ...' -H 'content-type: application/json' --data-raw '{"color":"ff0000","label":"my-tag"}'

Trying to render a tag with this colour crashes the frontend:

Error: Unable to parse color from string: ff0000
    at new c (index.js:53:10)
    at c (index.js:28:10)
    at TagContent.tsx:98:38
    at t.default (TagContent.tsx:137:8)
    at Ja (react-dom.production.min.js:153:146)
    at ks (react-dom.production.min.js:261:496)
    at Cl (react-dom.production.min.js:246:265)
    at Sl (react-dom.production.min.js:246:194)
    at gl (react-dom.production.min.js:239:172)
    at react-dom.production.min.js:123:115

The reporter of this bug found it when creating a tag using our Terraform provider: https://registry.terraform.io/providers/Flagsmith/flagsmith/latest/docs/resources/tag#tag_colour-1.

The API currently requires forces tags to be created with a colour. Tag colours are entirely visual so there is no reason to force users to provide a value. This change also allows creating tags in the API without specifying a colour.

Flagsmith/terraform-provider-flagsmith#166 makes tag colours optional in the Terraform provider.

How did you test this code?

Manually by looking at tags rendered in different parts of the app.

@rolodato rolodato requested review from a team as code owners November 8, 2024 18:09
@rolodato rolodato requested review from kyle-ssg and matthewelwell and removed request for a team November 8, 2024 18:09
Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 1:36pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 1:36pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Nov 15, 2024 1:36pm

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard api Issue related to the REST API labels Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-4822 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-4822 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-4822 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4822 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4822 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-4822 Finished ✅ Results

@github-actions github-actions bot added fix and removed fix labels Nov 8, 2024
@rolodato rolodato changed the title fix: Handle invalid color codes on tags fix: Handle invalid colour codes on tags, allow default colours Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Uffizzi Preview deployment-58115 was deleted.

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.35%. Comparing base (e6f1bac) to head (aff5f86).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4822      +/-   ##
==========================================
+ Coverage   97.33%   97.35%   +0.02%     
==========================================
  Files        1180     1183       +3     
  Lines       41223    41276      +53     
==========================================
+ Hits        40123    40183      +60     
+ Misses       1100     1093       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@rolodato rolodato marked this pull request as draft November 8, 2024 22:35
@github-actions github-actions bot removed the fix label Nov 15, 2024
@matthewelwell matthewelwell merged commit a33633f into main Nov 19, 2024
54 checks passed
@matthewelwell matthewelwell deleted the fix/invalid-tag-colour branch November 19, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API fix front-end Issue related to the React Front End Dashboard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants