Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Conversation

leachj
Copy link

@leachj leachj commented May 20, 2021

I have added the implementation for the Gitlab supported strategies.

Tests and README have also been updated to reflect this.

@leachj
Copy link
Author

leachj commented May 20, 2021

Just been testing this and it looks like there is a problem with the userId hook. i will debug and commit an update

@leachj leachj marked this pull request as draft May 20, 2021 15:00
Copy link
Owner

@fvoordeckers fvoordeckers left a comment

Choose a reason for hiding this comment

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

Thank for the merge request but there seems to be an issue with the approach. I would not put all the strategy context in the main configuration object, it assumes you already know the strategy variables at the moment of initialisation. In some cases (like used ID) it might not be the case. Instead it would be better to pass the context when calling the flag. This way it will stay more flexible for future strategies.

Also added some inline notes in the code.

Thanks again for the MR! 🙏

Authorization: 'token123'
}
},
userId: userId,
Copy link
Owner

Choose a reason for hiding this comment

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

move this to a separate context object (explained in MR comment)

* Get the user ID using the hook passed into the config
*/
public getUserId(): string | undefined {
if(this.config.userId) { return this.config.userId}
Copy link
Owner

Choose a reason for hiding this comment

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

if statement can be removed. If this will be moved to the context the entire method can be removed as well

children: ReactNode,
};

const checkFlagStrategies = (flag: FlagValue, userId: string | undefined) => {
Copy link
Owner

Choose a reason for hiding this comment

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

would be nice to split up each strategy in a separate file to keep it maintainable when more and more complex strategies will be added


if (flag.enabled && flag.strategies) {
// check if strategies match
const flagStrategyResult = checkFlagStrategies(flag, flagsClient ? flagsClient.getUserId() : undefined);
Copy link
Owner

Choose a reason for hiding this comment

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

No need for a new variable here.
isEnabled = checkFlagStrategies(flag, flagsClient ? flagsClient.getUserId() : undefined);

isEnabled = flagStrategyResult;
} else {
// if the flag is disabled or no strategies are present then result is false
isEnabled = false;
Copy link
Owner

Choose a reason for hiding this comment

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

When no strategy is present we should always fall back to the default strategy. It is the default.

uri: process.env.REACT_APP_FLAGS_CTX_URI || DEFAULT_FEATURES_URI
uri: process.env.REACT_APP_FLAGS_CTX_URI || DEFAULT_FEATURES_URI,
// the userId to check strategies against
userId: process.env.REACT_APP_FLAGS_CTX_USER_ID || ''
Copy link
Owner

Choose a reason for hiding this comment

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

Chances of knowing the user ID at this point are really small. As suggested, this should be handled in a context which is passed to the client at the moment we need to check a flag.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants