Skip to content

Commit

Permalink
[Advanced Settings] Replace old settings components in Observability …
Browse files Browse the repository at this point in the history
…apps (elastic#174712)

Addresses elastic#172922

## Summary

The `src/plugins/advanced_settings` plugin will soon be removed and
completely replaced by the new settings packages:
`packages/kbn-management/settings`. This PR replaces the usages of the
old Advanced settings component across the Observability apps **APM,
Infrastructure, and Universal Profiling**.


<img width="1609" alt="Screenshot 2024-01-11 at 16 40 35"
src="https://github.com/elastic/kibana/assets/59341489/7123fb63-f21a-4d8e-98e2-75374241f49a">

<img width="1609" alt="Screenshot 2024-01-11 at 16 38 12"
src="https://github.com/elastic/kibana/assets/59341489/8477c3ee-18f3-4401-bc3a-433f544528e6">


<!---

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
--->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and CoenWarmer committed Feb 15, 2024
1 parent a11ffdd commit a1cffdd
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 126 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pageLoadAssetSize:
observabilityAIAssistant: 25000
observabilityLogExplorer: 46650
observabilityOnboarding: 19573
observabilityShared: 52256
observabilityShared: 72039
osquery: 107090
painlessLab: 179748
presentationPanel: 55463
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"profilingDataAccess"
],
"requiredBundles": [
"advancedSettings",
"fleet",
"kibanaReact",
"kibanaUtils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { EuiSpacer } from '@elastic/eui';
import { LazyField } from '@kbn/advanced-settings-plugin/public';
import { withSuspense } from '@kbn/shared-ux-utility';
import { i18n } from '@kbn/i18n';
import {
apmLabsButton,
Expand All @@ -28,9 +28,18 @@ import {
useEditableSettings,
useUiTracker,
} from '@kbn/observability-shared-plugin/public';
import { FieldRowProvider } from '@kbn/management-settings-components-field-row';
import { ValueValidation } from '@kbn/core-ui-settings-browser/src/types';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { BottomBarActions } from '../bottom_bar_actions';

const LazyFieldRow = React.lazy(async () => ({
default: (await import('@kbn/management-settings-components-field-row'))
.FieldRow,
}));

const FieldRow = withSuspense(LazyFieldRow);

const apmSettingsKeys = [
enableComparisonByDefault,
defaultApmServiceEnvironment,
Expand All @@ -50,8 +59,8 @@ export function GeneralSettings() {
const trackApmEvent = useUiTracker({ app: 'apm' });
const { docLinks, notifications } = useApmPluginContext().core;
const {
fields,
handleFieldChange,
settingsEditableConfig,
unsavedChanges,
saveAll,
isSaving,
Expand All @@ -61,7 +70,7 @@ export function GeneralSettings() {
async function handleSave() {
try {
const reloadPage = Object.keys(unsavedChanges).some((key) => {
return settingsEditableConfig[key].requiresPageReload;
return fields[key].requiresPageReload;
});
await saveAll();
trackApmEvent({ metric: 'general_settings_save' });
Expand All @@ -79,21 +88,33 @@ export function GeneralSettings() {
}
}

// We don't validate the user input on these settings
const settingsValidationResponse: ValueValidation = {
successfulValidation: true,
valid: true,
};

return (
<>
<EuiSpacer />
{apmSettingsKeys.map((settingKey) => {
const editableConfig = settingsEditableConfig[settingKey];
const field = fields[settingKey];
return (
<LazyField
key={settingKey}
setting={editableConfig}
handleChange={handleFieldChange}
enableSaving
docLinks={docLinks.links}
toasts={notifications.toasts}
unsavedChanges={unsavedChanges[settingKey]}
/>
<FieldRowProvider
{...{
links: docLinks.links.management,
showDanger: (message: string) =>
notifications.toasts.addDanger(message),
validateChange: async () => settingsValidationResponse,
}}
>
<FieldRow
field={field}
isSavingEnabled={true}
onFieldChange={handleFieldChange}
unsavedChange={unsavedChanges[settingKey]}
/>
</FieldRowProvider>
);
})}
{!isEmpty(unsavedChanges) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import { LazyField } from '@kbn/advanced-settings-plugin/public';
import { withSuspense } from '@kbn/shared-ux-utility';
import { i18n } from '@kbn/i18n';
import React from 'react';
import {
useEditableSettings,
useUiTracker,
} from '@kbn/observability-shared-plugin/public';
import { FieldRowProvider } from '@kbn/management-settings-components-field-row';
import { ValueValidation } from '@kbn/core-ui-settings-browser/src/types';
import { useApmPluginContext } from '../../../../../context/apm_plugin/use_apm_plugin_context';
import { useFetcher, isPending } from '../../../../../hooks/use_fetcher';

const LazyFieldRow = React.lazy(async () => ({
default: (await import('@kbn/management-settings-components-field-row'))
.FieldRow,
}));

const FieldRow = withSuspense(LazyFieldRow);

interface Props {
onClose: () => void;
}
Expand All @@ -46,8 +55,8 @@ export function LabsFlyout({ onClose }: Props) {
const labsItems = data?.labsItems || [];

const {
fields,
handleFieldChange,
settingsEditableConfig,
unsavedChanges,
saveAll,
isSaving,
Expand All @@ -57,7 +66,7 @@ export function LabsFlyout({ onClose }: Props) {
async function handleSave() {
try {
const reloadPage = Object.keys(unsavedChanges).some((key) => {
return settingsEditableConfig[key].requiresPageReload;
return fields[key].requiresPageReload;
});

await saveAll();
Expand Down Expand Up @@ -86,6 +95,12 @@ export function LabsFlyout({ onClose }: Props) {

const isLoading = isPending(status);

// We don't validate the user input on these settings
const settingsValidationResponse: ValueValidation = {
successfulValidation: true,
valid: true,
};

return (
<EuiFlyout onClose={onClose}>
<EuiFlyoutHeader hasBorder>
Expand Down Expand Up @@ -138,19 +153,25 @@ export function LabsFlyout({ onClose }: Props) {
) : (
<>
<EuiFlyoutBody>
{labsItems.map((settingKey, i) => {
const editableConfig = settingsEditableConfig[settingKey];
{labsItems.map((settingKey) => {
const field = fields[settingKey];
return (
<>
<LazyField
key={settingKey}
setting={editableConfig}
handleChange={handleFieldChange}
enableSaving
docLinks={docLinks.links}
toasts={notifications.toasts}
unsavedChanges={unsavedChanges[settingKey]}
/>
<FieldRowProvider
{...{
links: docLinks.links.management,
showDanger: (message: string) =>
notifications.toasts.addDanger(message),
validateChange: async () => settingsValidationResponse,
}}
>
<FieldRow
field={field}
isSavingEnabled={true}
onFieldChange={handleFieldChange}
unsavedChange={unsavedChanges[settingKey]}
/>
</FieldRowProvider>
<EuiHorizontalRule />
</>
);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@kbn/charts-plugin",
"@kbn/field-formats-plugin",
"@kbn/typed-react-router-config",
"@kbn/advanced-settings-plugin",
"@kbn/core-http-browser",
"@kbn/server-route-repository",
"@kbn/datemath",
Expand Down Expand Up @@ -110,6 +109,8 @@
"@kbn/core-ui-settings-browser",
"@kbn/code-editor",
"@kbn/shared-svg",
"@kbn/shared-ux-utility",
"@kbn/management-settings-components-field-row",
],
"exclude": ["target/**/*"]
}
1 change: 0 additions & 1 deletion x-pack/plugins/infra/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"ml",
"embeddable",
"controls",
"advancedSettings"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,42 @@ import {
enableInfrastructureProfilingIntegration,
} from '@kbn/observability-plugin/common';
import { useEditableSettings } from '@kbn/observability-shared-plugin/public';
import { LazyField } from '@kbn/advanced-settings-plugin/public';
import { usePluginConfig } from '../../../containers/plugin_config_context';
import { withSuspense } from '@kbn/shared-ux-utility';
import { FieldRowProvider } from '@kbn/management-settings-components-field-row';
import { ValueValidation } from '@kbn/core-ui-settings-browser/src/types';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { usePluginConfig } from '../../../containers/plugin_config_context';

const LazyFieldRow = React.lazy(async () => ({
default: (await import('@kbn/management-settings-components-field-row')).FieldRow,
}));

const FieldRow = withSuspense(LazyFieldRow);

type Props = Pick<
ReturnType<typeof useEditableSettings>,
'handleFieldChange' | 'settingsEditableConfig' | 'unsavedChanges'
'handleFieldChange' | 'fields' | 'unsavedChanges'
> & {
readOnly: boolean;
};

export function FeaturesConfigurationPanel({
readOnly,
handleFieldChange,
settingsEditableConfig,
fields,
unsavedChanges,
}: Props) {
const {
services: { docLinks, notifications },
} = useKibanaContextForPlugin();
const { featureFlags } = usePluginConfig();

// We don't validate the user input on these settings
const settingsValidationResponse: ValueValidation = {
successfulValidation: true,
valid: true,
};

return (
<EuiForm>
<EuiTitle size="s" data-test-subj="sourceConfigurationFeaturesSectionTitle">
Expand All @@ -48,26 +62,28 @@ export function FeaturesConfigurationPanel({
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<LazyField
key={enableInfrastructureHostsView}
setting={settingsEditableConfig[enableInfrastructureHostsView]}
handleChange={handleFieldChange}
enableSaving={!readOnly}
docLinks={docLinks.links}
toasts={notifications.toasts}
unsavedChanges={unsavedChanges[enableInfrastructureHostsView]}
/>
{featureFlags.profilingEnabled && (
<LazyField
key={enableInfrastructureProfilingIntegration}
setting={settingsEditableConfig[enableInfrastructureProfilingIntegration]}
handleChange={handleFieldChange}
enableSaving={!readOnly}
docLinks={docLinks.links}
toasts={notifications.toasts}
unsavedChanges={unsavedChanges[enableInfrastructureProfilingIntegration]}
<FieldRowProvider
{...{
links: docLinks.links.management,
showDanger: (message: string) => notifications.toasts.addDanger(message),
validateChange: async () => settingsValidationResponse,
}}
>
<FieldRow
field={fields[enableInfrastructureHostsView]}
isSavingEnabled={true}
onFieldChange={handleFieldChange}
unsavedChange={unsavedChanges[enableInfrastructureHostsView]}
/>
)}
{featureFlags.profilingEnabled && (
<FieldRow
field={fields[enableInfrastructureProfilingIntegration]}
isSavingEnabled={true}
onFieldChange={handleFieldChange}
unsavedChange={unsavedChanges[enableInfrastructureProfilingIntegration]}
/>
)}
</FieldRowProvider>
</EuiForm>
);
}
6 changes: 4 additions & 2 deletions x-pack/plugins/infra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@
"@kbn/metrics-data-access-plugin",
"@kbn/expressions-plugin",
"@kbn/chart-icons",
"@kbn/advanced-settings-plugin",
"@kbn/cloud-plugin",
"@kbn/custom-icons",
"@kbn/profiling-utils",
"@kbn/profiling-data-access-plugin",
"@kbn/core-http-request-handler-context-server",
"@kbn/observability-get-padded-alert-time-range-util",
"@kbn/ebt-tools"
"@kbn/ebt-tools",
"@kbn/shared-ux-utility",
"@kbn/management-settings-components-field-row",
"@kbn/core-ui-settings-browser"
],
"exclude": ["target/**/*"]
}
2 changes: 1 addition & 1 deletion x-pack/plugins/observability_shared/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"configPath": ["xpack", "observability_shared"],
"requiredPlugins": ["cases", "uiActions", "embeddable", "share"],
"optionalPlugins": ["guidedOnboarding"],
"requiredBundles": ["data", "inspector", "kibanaReact", "kibanaUtils", "advancedSettings"],
"requiredBundles": ["data", "inspector", "kibanaReact", "kibanaUtils"],
"extraPublicDirs": ["common"]
}
}
Loading

0 comments on commit a1cffdd

Please sign in to comment.