From 657f1bb7a4253b2c3596b8ba4bee3d8c31d1dafe Mon Sep 17 00:00:00 2001 From: gagik Date: Wed, 26 Mar 2025 16:52:03 +0100 Subject: [PATCH 1/3] feat(compass-schema-validator): add validationAction 'errorAndLog' COMPASS-8983 --- .../src/components/validation-editor.spec.tsx | 34 +++++++++++++++++++ .../src/components/validation-editor.tsx | 1 + .../src/components/validation-selectors.tsx | 11 ++++++ .../src/modules/validation.ts | 9 ++++- .../compass-telemetry/src/telemetry-events.ts | 2 +- 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/compass-schema-validation/src/components/validation-editor.spec.tsx b/packages/compass-schema-validation/src/components/validation-editor.spec.tsx index 43945859c61..20537246d2b 100644 --- a/packages/compass-schema-validation/src/components/validation-editor.spec.tsx +++ b/packages/compass-schema-validation/src/components/validation-editor.spec.tsx @@ -245,4 +245,38 @@ describe('ValidationEditor [Component]', function () { expect(applyBtn).to.have.attribute('aria-disabled', 'true'); }); }); + + context('with errorAndLog', function () { + it('should be hidden for server version <8.1', async function () { + await renderValidationEditor({ + serverVersion: '6.0.0', + }); + + expect( + screen.queryByTestId('validation-action-error-and-log-option') + ).is.null; + + screen.getByTestId('validation-action-selector').click(); + + expect( + screen.queryByTestId('validation-action-option-error-and-log') + ).is.null; + }); + + it('should be visible for server version >=8.1', async function () { + await renderValidationEditor({ + serverVersion: '8.1.0', + }); + + expect( + screen.queryByTestId('validation-action-error-and-log-option') + ).is.null; + + screen.getByTestId('validation-action-selector').click(); + + expect( + screen.queryByTestId('validation-action-option-error-and-log') + ).is.not.null; + }); + }); }); diff --git a/packages/compass-schema-validation/src/components/validation-editor.tsx b/packages/compass-schema-validation/src/components/validation-editor.tsx index 613e9ca472a..b60347026d4 100644 --- a/packages/compass-schema-validation/src/components/validation-editor.tsx +++ b/packages/compass-schema-validation/src/components/validation-editor.tsx @@ -284,6 +284,7 @@ export const ValidationEditor: React.FunctionComponent< isEditable={isEditable && isEditingEnabled} validationActionChanged={validationActionChanged} validationAction={validationAction} + serverVersion={serverVersion} /> void; validationAction: ValidationServerAction; + serverVersion: string; }; export function ActionSelector({ isEditable, validationActionChanged, validationAction, + serverVersion, }: ActionSelectorProps) { const labelId = useId(); const controlId = useId(); @@ -67,6 +70,14 @@ export function ActionSelector({ > + {hasErrorAndLogValidationActionSupport(serverVersion) && ( + + )} ); diff --git a/packages/compass-schema-validation/src/modules/validation.ts b/packages/compass-schema-validation/src/modules/validation.ts index ac00b17670b..ee0df1aa93e 100644 --- a/packages/compass-schema-validation/src/modules/validation.ts +++ b/packages/compass-schema-validation/src/modules/validation.ts @@ -11,8 +11,9 @@ import { IS_ZERO_STATE_CHANGED, type IsZeroStateChangedAction, } from './zero-state'; +import semver from 'semver'; -export type ValidationServerAction = 'error' | 'warn'; +export type ValidationServerAction = 'error' | 'warn' | 'errorAndLog'; export type ValidationLevel = 'off' | 'moderate' | 'strict'; export const enum ValidationActions { @@ -534,3 +535,9 @@ export const activateValidation = (): SchemaValidationThunkAction => { void dispatch(fetchValidation(namespace)); }; }; + +export const hasErrorAndLogValidationActionSupport = ( + serverVersion: string +) => { + return semver.gte(serverVersion, '8.1.0'); +}; diff --git a/packages/compass-telemetry/src/telemetry-events.ts b/packages/compass-telemetry/src/telemetry-events.ts index 0086a8681a4..c669db82c73 100644 --- a/packages/compass-telemetry/src/telemetry-events.ts +++ b/packages/compass-telemetry/src/telemetry-events.ts @@ -1897,7 +1897,7 @@ type SchemaValidationUpdatedEvent = ConnectionScopedEvent<{ /** * The validation action passed to the driver. */ - validation_action: 'error' | 'warn'; + validation_action: 'error' | 'warn' | 'errorAndLog'; /** * The level of schema validation passed to the driver. From bc40db5345b4203939a802ba96c42de90b09f215 Mon Sep 17 00:00:00 2001 From: gagik Date: Thu, 27 Mar 2025 14:02:23 +0100 Subject: [PATCH 2/3] fix: include rc.0 and default to false with invalid semver --- .../compass-schema-validation/src/modules/validation.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/compass-schema-validation/src/modules/validation.ts b/packages/compass-schema-validation/src/modules/validation.ts index ee0df1aa93e..55df3d2dadc 100644 --- a/packages/compass-schema-validation/src/modules/validation.ts +++ b/packages/compass-schema-validation/src/modules/validation.ts @@ -539,5 +539,9 @@ export const activateValidation = (): SchemaValidationThunkAction => { export const hasErrorAndLogValidationActionSupport = ( serverVersion: string ) => { - return semver.gte(serverVersion, '8.1.0'); + try { + return semver.gte(serverVersion, '8.1.0-rc.0'); + } catch (err) { + return false; + } }; From 33d61bc42eced6b262db0e00e728cdaca797fcb9 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 28 Mar 2025 16:27:37 +0100 Subject: [PATCH 3/3] refactor: use userEvent.click --- .../src/components/validation-editor.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compass-schema-validation/src/components/validation-editor.spec.tsx b/packages/compass-schema-validation/src/components/validation-editor.spec.tsx index 20537246d2b..aef80c3e17b 100644 --- a/packages/compass-schema-validation/src/components/validation-editor.spec.tsx +++ b/packages/compass-schema-validation/src/components/validation-editor.spec.tsx @@ -256,7 +256,7 @@ describe('ValidationEditor [Component]', function () { screen.queryByTestId('validation-action-error-and-log-option') ).is.null; - screen.getByTestId('validation-action-selector').click(); + userEvent.click(screen.getByTestId('validation-action-selector')); expect( screen.queryByTestId('validation-action-option-error-and-log') @@ -272,7 +272,7 @@ describe('ValidationEditor [Component]', function () { screen.queryByTestId('validation-action-error-and-log-option') ).is.null; - screen.getByTestId('validation-action-selector').click(); + userEvent.click(screen.getByTestId('validation-action-selector')); expect( screen.queryByTestId('validation-action-option-error-and-log')