Skip to content

Commit 240623d

Browse files
authored
feat: Made early indexes variables update when changed CLOUDP-317478 (#6901)
* made early indexes variables update when changed * added comments
1 parent 4cd63c6 commit 240623d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

packages/compass-preferences-model/src/compass-web-preferences-access.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { InMemoryStorage } from './preferences-in-memory-storage';
66
import { getActiveUser } from './utils';
77

88
const editablePreferences: (keyof UserPreferences)[] = [
9+
// Value can change from false to true during allocation / checking
910
'optInDataExplorerGenAIFeatures',
1011
'cloudFeatureRolloutAccess',
12+
// TODO(COMPASS-9353): Provide a standard for updating Compass preferences in web
13+
'enableIndexesGuidanceExp',
14+
'showIndexesGuidanceVariant',
1115

1216
// Exposed for testing purposes.
1317
'enableGenAISampleDocumentPassingOnAtlasProject',
@@ -27,9 +31,9 @@ export class CompassWebPreferencesAccess implements PreferencesAccess {
2731
savePreferences(_attributes: Partial<UserPreferences>) {
2832
// Only allow runtime updating certain preferences.
2933
if (
30-
Object.keys(_attributes).length === 1 &&
31-
editablePreferences.includes(
32-
Object.keys(_attributes)[0] as keyof UserPreferences
34+
Object.keys(_attributes).length >= 1 &&
35+
Object.keys(_attributes).every((attribute) =>
36+
editablePreferences.includes(attribute as keyof UserPreferences)
3337
)
3438
) {
3539
return Promise.resolve(this._preferences.savePreferences(_attributes));

packages/compass-web/src/entrypoint.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ const CompassWeb = ({
273273
onLog,
274274
onDebug,
275275
});
276-
277276
const preferencesAccess = useCompassWebPreferences(initialPreferences);
278-
279277
const initialWorkspaceRef = useRef(initialWorkspace);
280278
const initialWorkspaceTabsRef = useRef(
281279
initialWorkspaceRef.current ? [initialWorkspaceRef.current] : []
@@ -296,6 +294,23 @@ const CompassWeb = ({
296294
preferences: preferencesAccess.current,
297295
});
298296

297+
useEffect(() => {
298+
// TODO(COMPASS-9353): Provide a standard way of updating Compass' preferences from web.
299+
// Avoid duplicating this pattern until we address this ticket.
300+
const updateEarlyIndexesPreferences = async () => {
301+
await preferencesAccess.current.savePreferences({
302+
enableIndexesGuidanceExp: initialPreferences?.enableIndexesGuidanceExp,
303+
showIndexesGuidanceVariant:
304+
initialPreferences?.showIndexesGuidanceVariant,
305+
});
306+
};
307+
void updateEarlyIndexesPreferences();
308+
}, [
309+
initialPreferences?.enableIndexesGuidanceExp,
310+
initialPreferences?.showIndexesGuidanceVariant,
311+
preferencesAccess,
312+
]);
313+
299314
return (
300315
<GlobalAppRegistryProvider value={appRegistry.current}>
301316
<AppRegistryProvider scopeName="Compass Web Root">

0 commit comments

Comments
 (0)