Skip to content

Commit f395d77

Browse files
committed
fix(preferences): don't derive enableGenAIFeatures from org, it's already defaulted true on Compass
1 parent 8e96a1e commit f395d77

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

packages/compass-preferences-model/src/preferences-schema.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,7 @@ export const storedUserPreferencesProps: Required<{
472472
short: 'Enable AI Features',
473473
long: 'Allow the use of AI features in Compass which make requests to 3rd party services.',
474474
},
475-
deriveValue: deriveValueFromOtherPreferencesAsLogicalAnd(
476-
'enableGenAIFeatures',
477-
['enableGenAIFeaturesAtlasOrg', 'networkTraffic']
478-
),
475+
deriveValue: deriveNetworkTrafficOptionState('enableGenAIFeatures'),
479476
validator: z.boolean().default(true),
480477
type: 'boolean',
481478
},
@@ -1072,21 +1069,6 @@ function deriveNetworkTrafficOptionState<K extends keyof AllPreferences>(
10721069
});
10731070
}
10741071

1075-
/** Helper for deriving value/state for preferences from other preferences */
1076-
function deriveValueFromOtherPreferencesAsLogicalAnd<
1077-
K extends keyof AllPreferences
1078-
>(property: K, preferencesToDeriveFrom: K[]): DeriveValueFunction<boolean> {
1079-
return (v, s) => ({
1080-
value: v(property) && preferencesToDeriveFrom.every((p) => v(p)),
1081-
state:
1082-
s(property) ??
1083-
(preferencesToDeriveFrom.every((p) => v(p))
1084-
? preferencesToDeriveFrom.map((p) => s(p)).filter(Boolean)?.[0] ??
1085-
'derived'
1086-
: undefined),
1087-
});
1088-
}
1089-
10901072
/** Helper for defining how to derive value/state for feature-restricting preferences */
10911073
function deriveFeatureRestrictingOptionsState<K extends keyof AllPreferences>(
10921074
property: K

packages/compass-preferences-model/src/preferences.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ describe('Preferences class', function () {
132132
expect(states).to.deep.equal({
133133
trackUsageStatistics: 'set-global',
134134
enableMaps: 'set-cli',
135-
enableGenAIFeatures: 'derived',
136135
...expectedReleasedFeatureFlagsStates,
137136
});
138137
});
@@ -164,6 +163,7 @@ describe('Preferences class', function () {
164163
enableDevTools: 'set-global',
165164
networkTraffic: 'set-global',
166165
trackUsageStatistics: 'set-global',
166+
enableGenAIFeatures: 'set-global',
167167
enableMaps: 'set-cli',
168168
enableShell: 'set-cli',
169169
readOnly: 'set-global',
@@ -185,7 +185,6 @@ describe('Preferences class', function () {
185185

186186
expect(states).to.deep.equal({
187187
readOnly: 'set-global',
188-
enableGenAIFeatures: 'derived',
189188
...expectedReleasedFeatureFlagsStates,
190189
});
191190
});
@@ -296,15 +295,13 @@ describe('Preferences class', function () {
296295

297296
expect(mainPreferencesStates).to.deep.equal({
298297
trackUsageStatistics: 'set-global',
299-
enableGenAIFeatures: 'derived',
300298
enableMaps: 'set-cli',
301299
...expectedReleasedFeatureFlagsStates,
302300
});
303301

304302
const sandboxPreferencesStates = sandbox.getPreferenceStates();
305303
expect(sandboxPreferencesStates).to.deep.equal({
306304
enableDevTools: 'derived',
307-
enableGenAIFeatures: 'derived',
308305
trackUsageStatistics: 'set-global',
309306
enableMaps: 'set-cli',
310307
enableShell: 'derived',

packages/compass-preferences-model/src/utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,36 @@ export function getActiveUser(
3030
export function isAIFeatureEnabled(
3131
preferences: Pick<
3232
AllPreferences,
33-
'enableGenAIFeatures' | 'cloudFeatureRolloutAccess'
33+
| 'enableGenAIFeatures'
34+
| 'cloudFeatureRolloutAccess'
35+
| 'enableGenAIFeaturesAtlasOrg'
3436
>
3537
) {
3638
const {
3739
// a "kill switch" property from configuration file to be able to disable
3840
// feature in global config
3941
enableGenAIFeatures,
42+
enableGenAIFeaturesAtlasOrg,
4043
// based on mms backend rollout response
4144
cloudFeatureRolloutAccess,
4245
} = preferences;
43-
return enableGenAIFeatures && !!cloudFeatureRolloutAccess?.GEN_AI_COMPASS;
46+
return (
47+
enableGenAIFeatures &&
48+
enableGenAIFeaturesAtlasOrg &&
49+
!!cloudFeatureRolloutAccess?.GEN_AI_COMPASS
50+
);
4451
}
4552

4653
export function useIsAIFeatureEnabled() {
4754
const enableGenAIFeatures = usePreference('enableGenAIFeatures');
55+
const enableGenAIFeaturesAtlasOrg = usePreference(
56+
'enableGenAIFeaturesAtlasOrg'
57+
);
4858
const cloudFeatureRolloutAccess = usePreference('cloudFeatureRolloutAccess');
4959

5060
return isAIFeatureEnabled({
5161
enableGenAIFeatures,
62+
enableGenAIFeaturesAtlasOrg,
5263
cloudFeatureRolloutAccess,
5364
});
5465
}

0 commit comments

Comments
 (0)