Skip to content

Commit

Permalink
chore(preferences-model): add dev feature flag to bypass the incremen…
Browse files Browse the repository at this point in the history
…tal rollout check COMPASS-7221 (#4862)
  • Loading branch information
Anemy authored Sep 18, 2023
1 parent a48aee7 commit 8d6b65f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/atlas-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export async function throwIfNotOk(

function throwIfAINotEnabled(atlasService: typeof AtlasService) {
if (
!preferences.getPreferences().cloudFeatureRolloutAccess?.GEN_AI_COMPASS ||
(!preferences.getPreferences().cloudFeatureRolloutAccess?.GEN_AI_COMPASS &&
!preferences.getPreferences().enableAIWithoutRolloutAccess) ||
!preferences.getPreferences().enableAIFeatures
) {
throw new Error(
Expand Down
13 changes: 13 additions & 0 deletions packages/compass-preferences-model/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type FeatureFlagDefinition = {

export type FeatureFlags = {
enableAIExperience: boolean;
enableAIWithoutRolloutAccess: boolean;
enableLgDarkmode: boolean;
enableOidc: boolean; // Not capitalized "OIDC" for spawn arg casing.
enableStageWizard: boolean;
Expand All @@ -38,6 +39,18 @@ export const featureFlags: Required<{
},
},

/**
* Temporary feature flag for bypassing our incremental rollout for ai access.
* Ticket to remove: COMPASS-7226
*/
enableAIWithoutRolloutAccess: {
stage: 'development',
description: {
short: 'Enable AI Features Without Rollout Access',
long: 'Bypass the public preview rollout access for the AI features in Compass. Do not use this feature with sensitive data.',
},
},

/**
* Currently Compass uses `darkreader` to globally change the views of
* Compass to a dark theme. Turning on this feature flag stops darkreader
Expand Down
10 changes: 9 additions & 1 deletion packages/compass-preferences-model/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ export function capMaxTimeMSAtPreferenceLimit<T>(value: T): T | number {
}

export function useIsAIFeatureEnabled(React: ReactHooks) {
const enableAIWithoutRolloutAccess = usePreference(
'enableAIWithoutRolloutAccess',
React
);
const enableAIExperience = usePreference('enableAIExperience', React);
const isAIFeatureEnabled = usePreference(
'cloudFeatureRolloutAccess',
React
)?.GEN_AI_COMPASS;
const enableAIFeatures = usePreference('enableAIFeatures', React);

return enableAIExperience && isAIFeatureEnabled && enableAIFeatures;
return (
enableAIExperience &&
(enableAIWithoutRolloutAccess || isAIFeatureEnabled) &&
enableAIFeatures
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ export function useShouldShowFeaturePreviewSettings(): boolean {
// - we are in a development environment or 'showDevFeatureFlags' is explicitly enabled
// - and there are feature flags in 'development' stage.
// - AI feature flag is enabled
const enableAIWithoutRolloutAccess = usePreference(
'enableAIWithoutRolloutAccess',
React
);
const enableAIExperience = usePreference('enableAIExperience', React);
const showDevFeatures = useShouldShowDevFeatures();
const showPreviewFeatures = useShouldShowPreviewFeatures();
return enableAIExperience || showPreviewFeatures || showDevFeatures;
return (
enableAIWithoutRolloutAccess ||
enableAIExperience ||
showPreviewFeatures ||
showDevFeatures
);
}

const atlasSettingsContainerStyles = css({
Expand Down Expand Up @@ -89,6 +98,7 @@ export default withPreferences(
state: RootState,
ownProps: {
enableAIExperience?: boolean;
enableAIWithoutRolloutAccess?: boolean;
cloudFeatureRolloutAccess?: UserPreferences['cloudFeatureRolloutAccess'];
}
) => {
Expand All @@ -97,10 +107,15 @@ export default withPreferences(
state.settings.settings.enableAIExperience ||
['authenticated', 'in-progress'].includes(state.atlasLogin.status) ||
ownProps.enableAIExperience ||
ownProps.enableAIWithoutRolloutAccess ||
ownProps.cloudFeatureRolloutAccess?.GEN_AI_COMPASS,
};
}
)(FeaturePreviewSettings),
['enableAIExperience', 'cloudFeatureRolloutAccess'],
[
'enableAIExperience',
'cloudFeatureRolloutAccess',
'enableAIWithoutRolloutAccess',
],
React
);

0 comments on commit 8d6b65f

Please sign in to comment.