Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export const ValidationEditor: React.FunctionComponent<
isEditable={isEditable && isEditingEnabled}
validationActionChanged={validationActionChanged}
validationAction={validationAction}
serverVersion={serverVersion}
/>
<LevelSelector
isEditable={isEditable && isEditingEnabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
css,
spacing,
} from '@mongodb-js/compass-components';
import { hasErrorAndLogValidationActionSupport } from '../modules/validation';
import type {
ValidationLevel,
ValidationServerAction,
Expand All @@ -35,12 +36,14 @@ type ActionSelectorProps = {
isEditable: boolean;
validationActionChanged: (value: ValidationServerAction) => void;
validationAction: ValidationServerAction;
serverVersion: string;
};

export function ActionSelector({
isEditable,
validationActionChanged,
validationAction,
serverVersion,
}: ActionSelectorProps) {
const labelId = useId();
const controlId = useId();
Expand All @@ -67,6 +70,14 @@ export function ActionSelector({
>
<Option value="warn">Warning</Option>
<Option value="error">Error</Option>
{hasErrorAndLogValidationActionSupport(serverVersion) && (
<Option
value="errorAndLog"
data-testid="validation-action-option-error-and-log"
>
Error and Log
</Option>
)}
</Select>
</div>
);
Expand Down
13 changes: 12 additions & 1 deletion packages/compass-schema-validation/src/modules/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -534,3 +535,13 @@ export const activateValidation = (): SchemaValidationThunkAction<void> => {
void dispatch(fetchValidation(namespace));
};
};

export const hasErrorAndLogValidationActionSupport = (
serverVersion: string
) => {
try {
return semver.gte(serverVersion, '8.1.0-rc.0');
Copy link
Contributor Author

@gagik gagik Mar 27, 2025

Choose a reason for hiding this comment

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

seems worthwhile to do this if someone is trying the RC version for whatever reason.

not sure if we'd rather make it stricter and let it just be 8.1.0 as semver is strict about pre-releases otherwise; alternatively we can also semver.coerce(serverVersion)

} catch (err) {
return false;
}
};
2 changes: 1 addition & 1 deletion packages/compass-telemetry/src/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading