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

[APM] Add validations to general settings #175874

Merged
Merged
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
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 { useApmFeatureFlag } from '../../../../hooks/use_apm_feature_flag';
import { ApmFeatureFlagName } from '../../../../../common/apm_feature_flags';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
Expand Down Expand Up @@ -66,7 +65,7 @@ function getApmSettingsKeys(isProfilingIntegrationEnabled: boolean) {

export function GeneralSettings() {
const trackApmEvent = useUiTracker({ app: 'apm' });
const { docLinks, notifications } = useApmPluginContext().core;
const { docLinks, notifications, settings } = useApmPluginContext().core;
const isProfilingIntegrationEnabled = useApmFeatureFlag(
ApmFeatureFlagName.ProfilingIntegrationAvailable
);
Expand Down Expand Up @@ -101,11 +100,9 @@ export function GeneralSettings() {
}
}

// We don't validate the user input on these settings
const settingsValidationResponse: ValueValidation = {
successfulValidation: true,
valid: true,
};
const hasInvalidChanges = Object.values(unsavedChanges).some(
({ isInvalid }) => isInvalid
);

return (
<>
Expand All @@ -118,7 +115,8 @@ export function GeneralSettings() {
links: docLinks.links.management,
showDanger: (message: string) =>
notifications.toasts.addDanger(message),
validateChange: async () => settingsValidationResponse,
validateChange: async (key: string, value: any) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need to add async here, settings.client.validateValue returns a promise already.

Suggested change
validateChange: async (key: string, value: any) =>
validateChange: (key: string, value: any) =>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Fixed in bd9b76c.

settings.client.validateValue(key, value),
}}
>
<FieldRow
Expand All @@ -140,6 +138,7 @@ export function GeneralSettings() {
})}
unsavedChangesCount={Object.keys(unsavedChanges).length}
appTestSubj="apm"
areChangesInvalid={hasInvalidChanges}
/>
)}
</>
Expand Down