Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advanced Settings] Integrate new Settings application into stateful Kibana #175255

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8ae69c
[Advanced Settings] Integrate new Settings application into stateful …
ElenaStoeva Jan 22, 2024
f18d463
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 22, 2024
43424d9
Fix type errors, mocks, and functional test helper functions
ElenaStoeva Jan 23, 2024
135aa1e
Merge branch 'main' into advanced-settings/integration-into-stateful
ElenaStoeva Jan 23, 2024
dd5ad1c
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 23, 2024
9209197
Fix application story and security solution tests
ElenaStoeva Jan 23, 2024
5b05a8f
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jan 23, 2024
6d69ee7
Fix a few more tests
ElenaStoeva Jan 23, 2024
28be6f4
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Jan 23, 2024
24db6e2
Merge branch 'main' into advanced-settings/integration-into-stateful
ElenaStoeva Jan 24, 2024
15df30f
Update limits file
ElenaStoeva Jan 24, 2024
a5e9232
Remove old translations
ElenaStoeva Jan 24, 2024
fc8297b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 24, 2024
6914c1a
Fix failing tests
ElenaStoeva Jan 24, 2024
1e1085a
Merge branch 'advanced-settings/integration-into-stateful' of https:/…
ElenaStoeva Jan 24, 2024
9487b54
Refactor changes
ElenaStoeva Jan 26, 2024
d76258c
Fix lint errors
ElenaStoeva Jan 26, 2024
05bd391
Merge branch 'main' into advanced-settings/integration-into-stateful
ElenaStoeva Jan 26, 2024
c255fe1
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 26, 2024
67168c5
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Jan 26, 2024
41cab4a
Fix translation labels
ElenaStoeva Jan 26, 2024
3a0dbe7
Fix type check error
ElenaStoeva Jan 26, 2024
65d43bf
Merge branch 'main' into advanced-settings/integration-into-stateful
ElenaStoeva Jan 26, 2024
4302ca2
Merge branch 'main' into advanced-settings/integration-into-stateful
ElenaStoeva Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ guided_onboarding.enabled: false
# Other disabled plugins
xpack.canvas.enabled: false
data.search.sessions.enabled: false
advanced_settings.enabled: false
advanced_settings.globalSettingsEnabled: false

# Disable the browser-side functionality that depends on SecurityCheckupGetStateRoutes
xpack.security.showInsecureClusterWarning: false
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NOTE:


|{kib-repo}blob/{branch}/src/plugins/advanced_settings/README.md[advancedSettings]
|This plugin contains the advanced settings management section
|This plugin registers the management settings application
allowing users to configure their advanced settings, also known
as uiSettings within the code.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getSettingsMock,
} from '@kbn/management-settings-utilities/mocks/settings.mock';
import { UiSettingsScope } from '@kbn/core-ui-settings-common';
import { getSettingsCapabilitiesMock } from '@kbn/management-settings-utilities/mocks/capabilities.mock';
import { SettingsApplication as Component } from '../application';
import { SettingsApplicationProvider } from '../services';

Expand Down Expand Up @@ -43,6 +44,11 @@ const getSettingsApplicationStory = ({ hasGlobalSettings }: StoryProps) => (
getAllowlistedSettings={(scope: UiSettingsScope) =>
scope === 'namespace' ? getSettingsMock() : hasGlobalSettings ? getGlobalSettingsMock() : {}
}
getSections={() => []}
// @ts-ignore
getToastsService={() => null}
getCapabilities={getSettingsCapabilitiesMock}
setBadge={() => {}}
isCustomSetting={() => false}
isOverriddenSetting={() => false}
saveChanges={action('saveChanges')}
Expand Down
57 changes: 45 additions & 12 deletions packages/kbn-management/settings/application/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SettingsTabs } from '@kbn/management-settings-types/tab';
import { EmptyState } from './empty_state';
import { i18nTexts } from './i18n_texts';
import { Tab } from './tab';
import { readOnlyBadge } from './read_only_badge';
import { useScopeFields } from './hooks/use_scope_fields';
import { QueryInput, QueryInputProps } from './query_input';
import { useServices } from './services';
Expand Down Expand Up @@ -53,7 +54,8 @@ function getQueryParam(url: string) {
* Component for displaying the {@link SettingsApplication} component.
*/
export const SettingsApplication = () => {
const { addUrlToHistory } = useServices();
const { addUrlToHistory, getSections, getToastsService, getCapabilities, setBadge } =
useServices();

const queryParam = getQueryParam(window.location.href);
const [query, setQuery] = useState<Query>(Query.parse(queryParam));
Expand All @@ -68,7 +70,17 @@ export const SettingsApplication = () => {
const [spaceAllFields, globalAllFields] = useScopeFields();
const [spaceFilteredFields, globalFilteredFields] = useScopeFields(query);

const globalSettingsEnabled = globalAllFields.length > 0;
const {
spaceSettings: { save: canSaveSpaceSettings },
globalSettings: { save: canSaveGlobalSettings, show: canShowGlobalSettings },
} = getCapabilities();
if (!canSaveSpaceSettings || (!canSaveGlobalSettings && canShowGlobalSettings)) {
setBadge(readOnlyBadge);
}

// Only enabled the Global settings tab if there are any global settings
// and if global settings can be shown
const globalTabEnabled = globalAllFields.length > 0 && canShowGlobalSettings;

const tabs: SettingsTabs = {
[SPACE_SETTINGS_TAB_ID]: {
Expand All @@ -77,16 +89,19 @@ export const SettingsApplication = () => {
categoryCounts: getCategoryCounts(spaceAllFields),
callOutTitle: i18nTexts.spaceCalloutTitle,
callOutText: i18nTexts.spaceCalloutText,
sections: getSections('namespace'),
isSavingEnabled: canSaveSpaceSettings,
},
};
// Only add a Global settings tab if there are any global settings
if (globalSettingsEnabled) {
if (globalTabEnabled) {
tabs[GLOBAL_SETTINGS_TAB_ID] = {
name: i18nTexts.globalTabTitle,
fields: globalFilteredFields,
categoryCounts: getCategoryCounts(globalAllFields),
callOutTitle: i18nTexts.globalCalloutTitle,
callOutText: i18nTexts.globalCalloutText,
sections: getSections('global'),
isSavingEnabled: canSaveGlobalSettings,
};
}

Expand All @@ -110,7 +125,7 @@ export const SettingsApplication = () => {
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
{globalSettingsEnabled && (
{globalTabEnabled && (
<>
<EuiTabs>
{Object.keys(tabs).map((id) => (
Expand All @@ -130,13 +145,31 @@ export const SettingsApplication = () => {
)}
<EuiSpacer size="xl" />
{selectedTab.fields.length ? (
<Form
fields={selectedTab.fields}
categoryCounts={selectedTab.categoryCounts}
isSavingEnabled={true}
onClearQuery={() => onQueryChange()}
scope={selectedTabId === SPACE_SETTINGS_TAB_ID ? 'namespace' : 'global'}
/>
<>
<Form
fields={selectedTab.fields}
categoryCounts={selectedTab.categoryCounts}
isSavingEnabled={selectedTab.isSavingEnabled}
onClearQuery={() => onQueryChange()}
scope={selectedTabId === SPACE_SETTINGS_TAB_ID ? 'namespace' : 'global'}
/>
<EuiSpacer size="l" />
{selectedTab.sections.length > 0 &&
selectedTab.sections.map(({ Component, queryMatch }, index) => {
if (queryMatch(query.text)) {
return (
<Component
key={`component-${index}`}
toasts={getToastsService()}
enableSaving={{
global: canSaveGlobalSettings,
namespace: canSaveSpaceSettings,
}}
/>
);
}
})}
</>
) : (
<EmptyState {...{ queryText: query?.text, onClearQuery: () => onQueryChange() }} />
)}
Expand Down
15 changes: 14 additions & 1 deletion packages/kbn-management/settings/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,22 @@ export const KibanaSettingsApplication = ({
settings,
theme,
history,
sectionRegistry,
application,
chrome,
}: SettingsApplicationKibanaDependencies) => (
<SettingsApplicationKibanaProvider
{...{ settings, theme, i18n, notifications, docLinks, history }}
{...{
settings,
theme,
i18n,
notifications,
docLinks,
history,
sectionRegistry,
application,
chrome,
}}
>
<SettingsApplication />
</SettingsApplicationKibanaProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getSettingsMock,
} from '@kbn/management-settings-utilities/mocks/settings.mock';
import { UiSettingsScope } from '@kbn/core-ui-settings-common';
import { getSettingsCapabilitiesMock } from '@kbn/management-settings-utilities/mocks/capabilities.mock';
import { SettingsApplicationProvider, SettingsApplicationServices } from '../services';

const createRootMock = () => {
Expand All @@ -42,10 +43,14 @@ export const createSettingsApplicationServicesMock = (
...createFormServicesMock(),
getAllowlistedSettings: (scope: UiSettingsScope) =>
scope === 'namespace' ? getSettingsMock() : hasGlobalSettings ? getGlobalSettingsMock() : {},
getSections: () => [],
getCapabilities: getSettingsCapabilitiesMock,
setBadge: jest.fn(),
isCustomSetting: () => false,
isOverriddenSetting: () => false,
subscribeToUpdates: () => new Subscription(),
addUrlToHistory: jest.fn(),
getToastsService: jest.fn(),
});

export const TestWrapper = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
* Side Public License, v 1.
*/

import React from 'react';
import { shallow } from 'enzyme';
import { i18n } from '@kbn/i18n';

import { CallOuts } from './call_outs';

describe('CallOuts', () => {
it('should render normally', async () => {
const component = shallow(<CallOuts />);

expect(component).toMatchSnapshot();
});
});
export const readOnlyBadge = {
text: i18n.translate('management.settings.badge.readOnly.text', {
defaultMessage: 'Read only',
}),
tooltip: i18n.translate('management.settings.badge.readOnly.tooltip', {
defaultMessage: 'Unable to save advanced settings',
}),
iconType: 'glasses',
};
61 changes: 58 additions & 3 deletions packages/kbn-management/settings/application/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ import {
type FormKibanaDependencies,
type FormServices,
} from '@kbn/management-settings-components-form';
import { UiSettingMetadata } from '@kbn/management-settings-types';
import { SettingsCapabilities, UiSettingMetadata } from '@kbn/management-settings-types';
import { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { normalizeSettings } from '@kbn/management-settings-utilities';
import { Subscription } from 'rxjs';
import { ScopedHistory } from '@kbn/core-application-browser';
import { ApplicationStart, ScopedHistory } from '@kbn/core-application-browser';
import { UiSettingsScope } from '@kbn/core-ui-settings-common';
import { RegistryEntry, SectionRegistryStart } from '@kbn/management-settings-section-registry';
import { ToastsStart } from '@kbn/core-notifications-browser';
import { ChromeBadge, ChromeStart } from '@kbn/core-chrome-browser';

export interface Services {
getAllowlistedSettings: (scope: UiSettingsScope) => Record<string, UiSettingMetadata>;
getSections: (scope: UiSettingsScope) => RegistryEntry[];
getToastsService: () => ToastsStart;
getCapabilities: () => SettingsCapabilities;
setBadge: (badge: ChromeBadge) => void;
subscribeToUpdates: (fn: () => void, scope: UiSettingsScope) => Subscription;
isCustomSetting: (key: string, scope: UiSettingsScope) => boolean;
isOverriddenSetting: (key: string, scope: UiSettingsScope) => boolean;
Expand All @@ -43,6 +50,12 @@ export interface KibanaDependencies {
>;
};
history: ScopedHistory;
sectionRegistry: SectionRegistryStart;
notifications: {
toasts: ToastsStart;
};
application: Pick<ApplicationStart, 'capabilities'>;
chrome: Pick<ChromeStart, 'setBadge'>;
}

export type SettingsApplicationKibanaDependencies = KibanaDependencies & FormKibanaDependencies;
Expand All @@ -65,6 +78,10 @@ export const SettingsApplicationProvider: FC<SettingsApplicationServices> = ({
links,
showDanger,
getAllowlistedSettings,
getSections,
getCapabilities,
setBadge,
getToastsService,
subscribeToUpdates,
isCustomSetting,
isOverriddenSetting,
Expand All @@ -75,6 +92,10 @@ export const SettingsApplicationProvider: FC<SettingsApplicationServices> = ({
<SettingsApplicationContext.Provider
value={{
getAllowlistedSettings,
getSections,
getToastsService,
getCapabilities,
setBadge,
subscribeToUpdates,
isCustomSetting,
isOverriddenSetting,
Expand All @@ -97,7 +118,17 @@ export const SettingsApplicationKibanaProvider: FC<SettingsApplicationKibanaDepe
children,
...dependencies
}) => {
const { docLinks, notifications, theme, i18n, settings, history } = dependencies;
const {
docLinks,
notifications,
theme,
i18n,
settings,
history,
sectionRegistry,
application,
chrome,
} = dependencies;
const { client, globalClient } = settings;

const getScopeClient = (scope: UiSettingsScope) => {
Expand All @@ -114,6 +145,26 @@ export const SettingsApplicationKibanaProvider: FC<SettingsApplicationKibanaDepe
return normalizeSettings(rawSettings);
};

const getSections = (scope: UiSettingsScope) => {
return scope === 'namespace'
? sectionRegistry.getSpacesSections()
: sectionRegistry.getGlobalSections();
};

const getCapabilities = () => {
const { advancedSettings, globalSettings } = application.capabilities;
return {
spaceSettings: {
show: advancedSettings.show as boolean,
save: advancedSettings.save as boolean,
},
globalSettings: {
show: globalSettings.show as boolean,
save: globalSettings.save as boolean,
},
};
};

const isCustomSetting = (key: string, scope: UiSettingsScope) => {
const scopeClient = getScopeClient(scope);
return scopeClient.isCustom(key);
Expand All @@ -131,6 +182,10 @@ export const SettingsApplicationKibanaProvider: FC<SettingsApplicationKibanaDepe

const services: Services = {
getAllowlistedSettings,
getSections,
getToastsService: () => notifications.toasts,
getCapabilities,
setBadge: (badge: ChromeBadge) => chrome.setBadge(badge),
isCustomSetting,
isOverriddenSetting,
subscribeToUpdates,
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-management/settings/application/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"@kbn/core-i18n-browser",
"@kbn/core-analytics-browser-mocks",
"@kbn/core-ui-settings-common",
"@kbn/management-settings-section-registry",
"@kbn/core-notifications-browser",
"@kbn/core-chrome-browser",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
* Side Public License, v 1.
*/

export { Field, getEditableValue } from './field';
export interface SettingsCapabilities {
spaceSettings: SettingCapability;
globalSettings: SettingCapability;
}

// eslint-disable-next-line import/no-default-export
export { Field as default } from './field';
interface SettingCapability {
show: boolean;
save: boolean;
}
2 changes: 2 additions & 0 deletions packages/kbn-management/settings/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export type {
} from './setting_type';

export type { CategorizedFields, CategoryCounts } from './category';
export type { SettingsTabs } from './tab';
export type { SettingsCapabilities } from './capabilities';

/**
* A React `ref` that indicates an input can be reset using an
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-management/settings/types/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { RegistryEntry } from '@kbn/management-settings-section-registry';
import { CategoryCounts } from './category';
import { FieldDefinition } from '.';

Expand All @@ -16,5 +17,7 @@ export interface SettingsTabs {
categoryCounts: CategoryCounts;
callOutTitle: string;
callOutText: string;
sections: RegistryEntry[];
isSavingEnabled: boolean;
};
}
1 change: 1 addition & 0 deletions packages/kbn-management/settings/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"@kbn/analytics",
"@kbn/core",
"@kbn/core-ui-settings-common",
"@kbn/management-settings-section-registry",
]
}
Loading