Skip to content

Commit 72f0697

Browse files
c
1 parent 4e4dd30 commit 72f0697

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,3 +1193,17 @@ export function getSettingDescription<
11931193
type,
11941194
};
11951195
}
1196+
1197+
export function getSettingSelectableValues<
1198+
Name extends Exclude<keyof AllPreferences, keyof InternalUserPreferences>
1199+
>(
1200+
name: Name
1201+
): Pick<PreferenceDefinition<Name>, 'selectableValues'> & { type: unknown } {
1202+
const { selectableValues, type } = allPreferencesProps[
1203+
name
1204+
] as PreferenceDefinition<Name>;
1205+
return {
1206+
selectableValues,
1207+
type,
1208+
};
1209+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export {
1010
} from './utils';
1111
export { capMaxTimeMSAtPreferenceLimit } from './maxtimems';
1212
export { featureFlags } from './feature-flags';
13-
export { getSettingDescription } from './preferences-schema';
13+
export {
14+
getSettingDescription,
15+
getSettingSelectableValues,
16+
} from './preferences-schema';
1417
export type { AllPreferences } from './preferences-schema';
1518
export type { DevtoolsProxyOptions } from '@mongodb-js/devtools-proxy-support';

packages/compass-settings/src/components/settings/settings-list.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
22
import type { UserConfigurablePreferences } from 'compass-preferences-model';
33
import {
44
getSettingDescription,
5+
getSettingSelectableValues,
56
featureFlags,
67
} from 'compass-preferences-model/provider';
78
import { settingStateLabels } from './state-labels';
@@ -18,6 +19,7 @@ import {
1819
import { changeFieldValue } from '../../stores/settings';
1920
import type { RootState } from '../../stores';
2021
import { connect } from 'react-redux';
22+
import { get } from 'lodash';
2123

2224
type KeysMatching<T, V> = keyof {
2325
[P in keyof T as T[P] extends V ? P : never]: P;
@@ -170,6 +172,7 @@ function DropdownSetting<PreferenceName extends StringPreferences>({
170172
value: string | undefined;
171173
disabled: boolean;
172174
}) {
175+
selectableValues = JSON.parse(JSON.stringify(selectableValues));
173176
const onChangeEvent = useCallback(
174177
(event: React.ChangeEvent<HTMLSelectElement>) => {
175178
onChange(
@@ -301,7 +304,7 @@ function SettingsInput({
301304

302305
const { name, type, onChange, value, selectableValues } = props;
303306

304-
console.log('will we match');
307+
console.log('will we match, ', type);
305308
if (type === 'boolean') {
306309
input = (
307310
<BooleanSetting
@@ -312,7 +315,7 @@ function SettingsInput({
312315
/>
313316
);
314317
} else if (type === 'string' && selectableValues) {
315-
console.log('yay we matched');
318+
console.log('yay we matched ', selectableValues);
316319
input = (
317320
<DropdownSetting
318321
name={name}
@@ -362,11 +365,9 @@ const ConnectedSettingsInput = connect(
362365
const { name } = ownProps;
363366
const { type } = getSettingDescription(name);
364367

365-
console.log('settings: ', settings);
366-
console.log('preferenceStates: ', preferenceStates);
367368
return {
368369
value: settings[name],
369-
selectableValues: preferenceStates[name]?.selectableValues,
370+
selectableValues: getSettingSelectableValues(name).selectableValues,
370371
type: type,
371372
disabled: !!preferenceStates[name],
372373
stateLabel: settingStateLabels[preferenceStates[name] ?? ''],

0 commit comments

Comments
 (0)