diff --git a/src/plugins/telemetry_management_section/public/components/__snapshots__/telemetry_management_section.test.tsx.snap b/src/plugins/telemetry_management_section/public/components/__snapshots__/telemetry_management_section.test.tsx.snap index 430cf538779b6..55c9a27ce0df9 100644 --- a/src/plugins/telemetry_management_section/public/components/__snapshots__/telemetry_management_section.test.tsx.snap +++ b/src/plugins/telemetry_management_section/public/components/__snapshots__/telemetry_management_section.test.tsx.snap @@ -44,97 +44,99 @@ exports[`TelemetryManagementSectionComponent renders as expected 1`] = ` - -

- - - , + + +

+ + + , + } } - } - /> -

-

- - - , - "securityData": - - , + /> +

+

+ + + , + "securityData": + + , + } } - } - /> -

- , - "displayName": "Share usage with Elastic", - "isCustom": true, - "isOverridden": false, - "name": "Usage collection", - "requiresPageReload": false, - "type": "boolean", - "value": true, - } - } - toasts={ - Object { - "add": [MockFunction], - "addDanger": [MockFunction], - "addError": [MockFunction], - "addInfo": [MockFunction], - "addSuccess": [MockFunction], - "addWarning": [MockFunction], - "get$": [MockFunction], - "remove": [MockFunction], + /> +

+ , + "displayName": "Share usage with Elastic", + "groupId": "Share usage with Elastic-group", + "id": "Usage collection", + "isCustom": true, + "isDefaultValue": true, + "isOverridden": false, + "isReadOnly": false, + "metric": undefined, + "name": "Share usage with Elastic", + "options": Object { + "labels": Object {}, + "values": Array [], + }, + "order": undefined, + "requiresPageReload": false, + "savedValue": true, + "type": "boolean", + "unsavedFieldId": "Usage collection-unsaved", + } } - } - /> + isSavingEnabled={true} + onFieldChange={[Function]} + /> + diff --git a/src/plugins/telemetry_management_section/public/components/telemetry_management_section.test.tsx b/src/plugins/telemetry_management_section/public/components/telemetry_management_section.test.tsx index aa57485ce6049..14fd9abd2ab81 100644 --- a/src/plugins/telemetry_management_section/public/components/telemetry_management_section.test.tsx +++ b/src/plugins/telemetry_management_section/public/components/telemetry_management_section.test.tsx @@ -243,19 +243,19 @@ describe('TelemetryManagementSectionComponent', () => { /> ); try { - const toggleOptInComponent = component.find('Field'); + const toggleOptInComponent = component.find('FieldRow'); await expect( - toggleOptInComponent.prop('handleChange')() + toggleOptInComponent.prop('onFieldChange')() ).resolves.toBe(true); // TODO: Fix `mountWithIntl` types in @kbn/test-jest-helpers to make testing easier expect((component.state() as { enabled: boolean }).enabled).toBe(true); await expect( - toggleOptInComponent.prop('handleChange')() + toggleOptInComponent.prop('onFieldChange')() ).resolves.toBe(true); expect((component.state() as { enabled: boolean }).enabled).toBe(false); telemetryService.setOptIn = jest.fn().mockRejectedValue(Error('test-error')); await expect( - toggleOptInComponent.prop('handleChange')() + toggleOptInComponent.prop('onFieldChange')() ).rejects.toStrictEqual(Error('test-error')); } finally { component.unmount(); diff --git a/src/plugins/telemetry_management_section/public/components/telemetry_management_section.tsx b/src/plugins/telemetry_management_section/public/components/telemetry_management_section.tsx index 6c3fe94256941..1448e8dc6b41d 100644 --- a/src/plugins/telemetry_management_section/public/components/telemetry_management_section.tsx +++ b/src/plugins/telemetry_management_section/public/components/telemetry_management_section.tsx @@ -21,8 +21,12 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import type { TelemetryPluginSetup } from '@kbn/telemetry-plugin/public'; import type { DocLinksStart, ToastsStart } from '@kbn/core/public'; -import { LazyField } from '@kbn/advanced-settings-plugin/public'; +import { withSuspense } from '@kbn/shared-ux-utility'; import { TrackApplicationView } from '@kbn/usage-collection-plugin/public'; +import { getFieldDefinition } from '@kbn/management-settings-field-definition'; +import { UiSettingMetadata } from '@kbn/management-settings-types'; +import { FieldRowProvider } from '@kbn/management-settings-components-field-row'; +import { ValueValidation } from '@kbn/core-ui-settings-browser/src/types'; import { OptInExampleFlyout } from './opt_in_example_flyout'; type TelemetryService = TelemetryPluginSetup['telemetryService']; @@ -42,6 +46,12 @@ interface State { enabled: boolean; } +const LazyFieldRow = React.lazy(async () => ({ + default: (await import('@kbn/management-settings-components-field-row')).FieldRow, +})); + +const FieldRow = withSuspense(LazyFieldRow); + export class TelemetryManagementSection extends Component { constructor(props: Props) { super(props); @@ -62,6 +72,24 @@ export class TelemetryManagementSection extends Component { return null; } + const usageCollectionSetting: UiSettingMetadata = { + type: 'boolean', + value: true, + userValue: enabled, + name: i18n.translate('telemetry.provideUsageDataTitle', { + defaultMessage: 'Share usage with Elastic', + }), + // @ts-expect-error + description: this.renderDescription(), + requiresPageReload: false, + }; + + // We don't validate the user input on these settings + const settingsValidationResponse: ValueValidation = { + successfulValidation: true, + valid: true, + }; + return ( {showExample && ( @@ -90,30 +118,23 @@ export class TelemetryManagementSection extends Component { {this.maybeGetAppliesSettingMessage()} - this.props.toasts.addDanger(message), + validateChange: async () => settingsValidationResponse, }} - loading={processing} - docLinks={this.props.docLinks} - toasts={this.props.toasts} - handleChange={this.toggleOptIn} - enableSaving={this.props.enableSaving} - /> + > + + diff --git a/src/plugins/telemetry_management_section/tsconfig.json b/src/plugins/telemetry_management_section/tsconfig.json index 76e8beadc68b2..2441412ff912a 100644 --- a/src/plugins/telemetry_management_section/tsconfig.json +++ b/src/plugins/telemetry_management_section/tsconfig.json @@ -18,6 +18,11 @@ "@kbn/i18n-react", "@kbn/i18n", "@kbn/management-settings-section-registry", + "@kbn/shared-ux-utility", + "@kbn/management-settings-field-definition", + "@kbn/management-settings-types", + "@kbn/management-settings-components-field-row", + "@kbn/core-ui-settings-browser", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index fcbc20c1a8c79..0c01e6e827d32 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -5564,7 +5564,6 @@ "telemetry.optInNoticeSeenErrorToastText": "Une erreur s'est produite lors du rejet de l'avis.", "telemetry.optInSuccessOff": "Ne partage plus l’utilisation avec Elastic.", "telemetry.optInSuccessOn": "Le partage d’utilisation avec Elastic est activé.", - "telemetry.provideUsageDataAriaName": "Partager l’utilisation avec Elastic", "telemetry.provideUsageDataTitle": "Partager l’utilisation avec Elastic", "telemetry.readOurUsageDataPrivacyStatementLinkText": "Déclaration de confidentialité", "telemetry.securityData": "données de sécurité", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 62908af4bd9c1..4cbe5278ce358 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5579,7 +5579,6 @@ "telemetry.optInNoticeSeenErrorToastText": "通知の消去中にエラーが発生しました", "telemetry.optInSuccessOff": "Elasticと使用状況が共有されることはありません。", "telemetry.optInSuccessOn": "Elasticとの使用状況の共有は有効です。", - "telemetry.provideUsageDataAriaName": "Elasticと使用状況を共有", "telemetry.provideUsageDataTitle": "Elasticと使用状況を共有", "telemetry.readOurUsageDataPrivacyStatementLinkText": "プライバシーポリシー", "telemetry.securityData": "セキュリティデータ", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index c1550eab55885..e3e0ae5d42628 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5672,7 +5672,6 @@ "telemetry.optInNoticeSeenErrorToastText": "关闭声明时发生错误", "telemetry.optInSuccessOff": "不再与 Elastic 共享使用情况。", "telemetry.optInSuccessOn": "已启用与 Elastic 共享使用情况。", - "telemetry.provideUsageDataAriaName": "与 Elastic 共享使用情况", "telemetry.provideUsageDataTitle": "与 Elastic 共享使用情况", "telemetry.readOurUsageDataPrivacyStatementLinkText": "隐私声明", "telemetry.securityData": "安全数据",