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..aef80c3e17b 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; + + userEvent.click(screen.getByTestId('validation-action-selector')); + + 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; + + userEvent.click(screen.getByTestId('validation-action-selector')); + + 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..55df3d2dadc 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,13 @@ export const activateValidation = (): SchemaValidationThunkAction => { void dispatch(fetchValidation(namespace)); }; }; + +export const hasErrorAndLogValidationActionSupport = ( + serverVersion: string +) => { + try { + return semver.gte(serverVersion, '8.1.0-rc.0'); + } catch (err) { + return false; + } +}; 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.