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

Add possibility to override feature flags with environment variable FEATURE_FLAGS #1372

Merged
merged 5 commits into from
Oct 18, 2022

Conversation

ofreyssinet-ledger
Copy link
Contributor

@ofreyssinet-ledger ofreyssinet-ledger commented Sep 26, 2022

📝 Description

I did this because I needed to set a feature flag in a playwright test and doing it through an env variable made sense as playwright fixtures are already modifying env.

Now in playwright you can do this to enabled a feature flag:

test.use({ featureFlags: { mockFeature: { enabled: true } } });

It is working both on LLM and LLD.

I also made the appropriate changes in the feature flag debugging UIs in both LLM and LLD.

I'm sure this will be useful in the future for other purposes.

❓ Context

  • Impacted projects: ledger-live-mobile ledger-live-desktop types-live live-common
  • Linked resource(s): LIVE-3895

✅ Checklist

  • Test coverage
  • Atomic delivery
  • No breaking changes

📸 Demo

Compiling LLM with .env file in apps/ledger-live-mobile:

Screenshot 2022-09-26 at 16 29 21

Running LLD like this

FEATURE_FLAGS='{"mockFeature": {"enabled": false, "someRandomKey": "aCustomValue"}}' pnpm dev:lld

Screenshot 2022-09-26 at 16 51 24

🚀 Expectations to reach

Please make sure you follow these Important Steps.

Pull Requests must pass the CI and be internally validated in order to be merged.

@vercel
Copy link

vercel bot commented Sep 26, 2022

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

Name Status Preview Updated
live-common-tools ✅ Ready (Inspect) Visit Preview Oct 13, 2022 at 10:25AM (UTC)
3 Ignored Deployments
Name Status Preview Updated
ledger-live-github-bot ⬜️ Ignored (Inspect) Oct 13, 2022 at 10:25AM (UTC)
native-ui-storybook ⬜️ Ignored (Inspect) Oct 13, 2022 at 10:25AM (UTC)
react-ui-storybook ⬜️ Ignored (Inspect) Oct 13, 2022 at 10:25AM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Sep 26, 2022

🦋 Changeset detected

Latest commit: 571ca9a

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

This PR includes changesets to release 6 packages
Name Type
live-mobile Patch
ledger-live-desktop Patch
@ledgerhq/live-common Patch
@ledgerhq/types-live Patch
@ledgerhq/live-cli Patch
live-common-tools Patch

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

@github-actions github-actions bot added common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM labels Sep 26, 2022
@ofreyssinet-ledger ofreyssinet-ledger marked this pull request as ready for review September 26, 2022 14:58
@codecov
Copy link

codecov bot commented Sep 26, 2022

Codecov Report

Base: 47.61% // Head: 43.01% // Decreases project coverage by -4.60% ⚠️

Coverage data is based on head (8098f60) compared to base (2c3d6b5).
Patch coverage: 8.33% of modified lines in pull request are covered.

❗ Current head 8098f60 differs from pull request most recent head 571ca9a. Consider uploading reports for the commit 571ca9a to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1372      +/-   ##
===========================================
- Coverage    47.61%   43.01%   -4.61%     
===========================================
  Files          687      609      -78     
  Lines        30258    25477    -4781     
  Branches      7912     6979     -933     
===========================================
- Hits         14407    10958    -3449     
+ Misses       14632    13385    -1247     
+ Partials      1219     1134      -85     
Flag Coverage Δ
test 43.01% <8.33%> (-4.61%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...er-live-common/src/families/stellar/api/horizon.ts 22.85% <0.00%> (ø)
libs/ledger-live-common/src/env.ts 74.50% <20.00%> (-5.93%) ⬇️
libs/ledger-live-common/src/range.ts 94.87% <0.00%> (-2.57%) ⬇️
libs/ledgerjs/packages/hw-app-tezos/src/Tezos.ts
...s/ledgerjs/packages/cryptoassets/src/currencies.ts
.../ledgerjs/packages/hw-app-btc/src/finalizeInput.ts
libs/ledgerjs/packages/hw-app-eth/src/utils.ts
libs/ledgerjs/packages/errors/src/index.ts
...ibs/ledgerjs/packages/cryptoassets/data/stellar.js
...ledgerjs/packages/hw-transport-mocker/src/index.ts
... and 71 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link

github-actions bot commented Sep 26, 2022

@ofreyssinet-ledger

Screenshots: ✅

There are no changes in the screenshots for this PR. If this is expected, you are good to go.

Copy link
Contributor

@gre gre left a comment

Choose a reason for hiding this comment

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

some feedback. good overall.

if (feature)
return {
...feature,
overridesRemote: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

if it's overriden by env, should remove be false? 🤔

Copy link
Contributor Author

@ofreyssinet-ledger ofreyssinet-ledger Sep 27, 2022

Choose a reason for hiding this comment

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

It still overrides the remote value, if the name of the variable was different I would have done what you are suggesting

{focusedName === flagName ? (
<Flex flexDirection="column" pl={6} rowGap={3}>
<EditSection
value={inputValues[flagName] || JSON.stringify(pureValue)}
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer to cache this with a memo. stringify every time it re-renders isn't ideal. you may want to have an intermediary component to ease this as it's included in a "if", generally speaking the JSX tree is quite deep here and splitting into more components isn't bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks I'll do that 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👌
I split it in 3 components on both LLM & LLD -> FeatureFlagsSettings/index.tsx FeatureFlagDetails.tsx FeatureFlagEdit.tsx.
It's much clearer now I think

@github-actions
Copy link

github-actions bot commented Oct 6, 2022

@ofreyssinet-ledger

Screenshots: ✅

There are no changes in the screenshots for this PR. If this is expected, you are good to go.

Add feature flags parameter to playwright test fixtures


doc:ljs


Add env overriding of feature flags in LLM


changesets


Fix FeatureFlagsButton LLD


Fix FeatureFlagsButton


remove console log


Refactor feature flag settings on LLD


Add null to JSONValue type


Refactor FeatureFlagsSettings (split in components)


Move LLD's FeatureFlagEdit to own component


Apply switch toggle directly rather than just modifying the input


Remove useless badly typed tryParse
@ofreyssinet-ledger
Copy link
Contributor Author

ofreyssinet-ledger commented Oct 13, 2022

Force push: just a squash & rebase, then did some fixes on both apps

@nabil-brn nabil-brn self-requested a review October 17, 2022 16:10
@ofreyssinet-ledger ofreyssinet-ledger merged commit b53d648 into develop Oct 18, 2022
@ofreyssinet-ledger ofreyssinet-ledger deleted the support/env-feature-flags branch October 18, 2022 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants