Skip to content

Commit 617f445

Browse files
committed
Improve dashboard admin UI settings implementation
Signed-off-by: Owen Wang <[email protected]>
1 parent 8b7d289 commit 617f445

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/core/server/ui_settings/saved_objects/permission_controlled_ui_settings_wrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export class PermissionControlledUiSettingsWrapper {
5353
): Promise<SavedObjectsUpdateResponse<T>> => {
5454
if (type === 'config' && id === DASHBOARD_ADMIN_SETTINGS_ID) {
5555
try {
56-
return ((await wrapperOptions.client.update<SavedObject<T>>(
56+
return await wrapperOptions.client.update<T>(
5757
type,
5858
DASHBOARD_ADMIN_SETTINGS_ID,
5959
attributes,
6060
options
61-
)) as unknown) as SavedObjectsUpdateResponse<T>;
61+
);
6262
} catch (error) {
6363
if (SavedObjectsErrorHelpers.isNotFoundError(error)) {
6464
return this.createPermissionUiSetting(attributes, options, wrapperOptions);

src/core/server/ui_settings/ui_settings_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ export class UiSettingsClient implements IUiSettingsClient {
348348
this.log.warn(
349349
`Deprecation warning: The setting "${key}" has multiple scopes. Please specify a scope when updating it.`
350350
);
351-
} else if (this.userLevelSettingsKeys.includes(key)) {
352-
groupedChanges[UiSettingScope.USER][key] = val;
353351
} else if (this.adminUiSettingsKeys.includes(key)) {
354352
groupedChanges[UiSettingScope.DASHBOARD_ADMIN][key] = val;
353+
} else if (this.userLevelSettingsKeys.includes(key)) {
354+
groupedChanges[UiSettingScope.USER][key] = val;
355355
} else if (this.workspaceLevelSettingsKeys.includes(key)) {
356356
groupedChanges[UiSettingScope.WORKSPACE][key] = val;
357357
} else {

src/core/server/ui_settings/ui_settings_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ export class UiSettingsService
101101
// Use uiSettings.defaults from the config file
102102
this.validateAndUpdateConfiguredDefaults(config.uiSettingsConfig.defaults);
103103

104+
this.register(getAIFeaturesSetting());
105+
104106
const permissionControlledUiSettingsWrapper = new PermissionControlledUiSettingsWrapper(
105107
config.savedObjectsConfig.permission.enabled
106108
);
@@ -111,8 +113,6 @@ export class UiSettingsService
111113
permissionControlledUiSettingsWrapper.wrapperFactory
112114
);
113115

114-
this.register(getAIFeaturesSetting());
115-
116116
return {
117117
register: this.register.bind(this),
118118
};

src/plugins/advanced_settings/public/management_app/advanced_settings.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ export class AdvancedSettingsComponent extends Component<
202202
isCustom: config.isCustom(setting[0]),
203203
isOverridden: config.isOverridden(setting[0]),
204204
isPermissionControlled:
205-
all[setting[0]].scope === UiSettingScope.DASHBOARD_ADMIN && !isDashboardAdmin,
205+
((typeof all[setting[0]].scope === 'string' &&
206+
all[setting[0]].scope === UiSettingScope.DASHBOARD_ADMIN) ||
207+
(Array.isArray(all[setting[0]].scope) &&
208+
(all[setting[0]].scope || []).includes(UiSettingScope.DASHBOARD_ADMIN))) &&
209+
!isDashboardAdmin,
206210
userSettingsEnabled,
207211
});
208212
})

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { i18n } from '@osd/i18n';
77
import { ENABLE_AI_FEATURES, HttpSetup } from 'opensearch-dashboards/public';
88
import React, { useCallback, useEffect, useState } from 'react';
9-
import { BehaviorSubject, of } from 'rxjs';
9+
import { BehaviorSubject, of, combineLatest } from 'rxjs';
1010
import { useObservable } from 'react-use';
1111
import { distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
1212
import { DATA_STRUCTURE_META_TYPES, DEFAULT_DATA } from '../../../../data/common';
@@ -133,8 +133,8 @@ export const createQueryAssistExtension = (
133133
}
134134
},
135135
isEnabled$: () =>
136-
getAvailableLanguages$(http, data).pipe(
137-
map((languages) => languages.length > 0 && assistantEnabled$.value)
136+
combineLatest([getAvailableLanguages$(http, data), assistantEnabled$]).pipe(
137+
map(([languages, enabled]) => languages.length > 0 && enabled)
138138
),
139139
getComponent: (dependencies) => {
140140
// only show the component if user is on a supported language.

0 commit comments

Comments
 (0)