Skip to content

Commit c55f332

Browse files
committed
feat(compass-schema-validator): add validationAction 'errorAndLog' COMPASS-8983
1 parent e7633d7 commit c55f332

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

packages/compass-schema-validation/src/components/validation-editor.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,38 @@ describe('ValidationEditor [Component]', function () {
179179
expect(generateBtn).to.have.attribute('aria-disabled', 'true');
180180
});
181181
});
182+
183+
context('with errorAndLog', function () {
184+
it('should be hidden for server version <8.1', async function () {
185+
await renderValidationEditor({
186+
serverVersion: '6.0.0',
187+
});
188+
189+
expect(
190+
screen.queryByTestId('validation-action-error-and-log-option')
191+
).is.null;
192+
193+
screen.getByTestId('validation-action-selector').click();
194+
195+
expect(
196+
screen.queryByTestId('validation-action-option-error-and-log')
197+
).is.null;
198+
});
199+
200+
it('should be visible for server version >=8.1', async function () {
201+
await renderValidationEditor({
202+
serverVersion: '8.1.0',
203+
});
204+
205+
expect(
206+
screen.queryByTestId('validation-action-error-and-log-option')
207+
).is.null;
208+
209+
screen.getByTestId('validation-action-selector').click();
210+
211+
expect(
212+
screen.queryByTestId('validation-action-option-error-and-log')
213+
).is.not.null;
214+
});
215+
});
182216
});

packages/compass-schema-validation/src/components/validation-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export const ValidationEditor: React.FunctionComponent<
282282
isEditable={isEditable && isEditingEnabled}
283283
validationActionChanged={validationActionChanged}
284284
validationAction={validationAction}
285+
serverVersion={serverVersion}
285286
/>
286287
<LevelSelector
287288
isEditable={isEditable && isEditingEnabled}

packages/compass-schema-validation/src/components/validation-selectors.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
css,
1111
spacing,
1212
} from '@mongodb-js/compass-components';
13+
import { hasErrorAndLogValidationActionSupport } from '../modules/validation';
1314
import type {
1415
ValidationLevel,
1516
ValidationServerAction,
@@ -35,12 +36,14 @@ type ActionSelectorProps = {
3536
isEditable: boolean;
3637
validationActionChanged: (value: ValidationServerAction) => void;
3738
validationAction: ValidationServerAction;
39+
serverVersion: string;
3840
};
3941

4042
export function ActionSelector({
4143
isEditable,
4244
validationActionChanged,
4345
validationAction,
46+
serverVersion,
4447
}: ActionSelectorProps) {
4548
const labelId = useId();
4649
const controlId = useId();
@@ -67,6 +70,14 @@ export function ActionSelector({
6770
>
6871
<Option value="warn">Warning</Option>
6972
<Option value="error">Error</Option>
73+
{hasErrorAndLogValidationActionSupport(serverVersion) && (
74+
<Option
75+
value="errorAndLog"
76+
data-testid="validation-action-option-error-and-log"
77+
>
78+
Error and Log
79+
</Option>
80+
)}
7081
</Select>
7182
</div>
7283
);

packages/compass-schema-validation/src/modules/validation.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {
1111
IS_ZERO_STATE_CHANGED,
1212
type IsZeroStateChangedAction,
1313
} from './zero-state';
14+
import semver from 'semver';
1415

15-
export type ValidationServerAction = 'error' | 'warn';
16+
export type ValidationServerAction = 'error' | 'warn' | 'errorAndLog';
1617
export type ValidationLevel = 'off' | 'moderate' | 'strict';
1718

1819
export const enum ValidationActions {
@@ -484,3 +485,9 @@ export const activateValidation = (): SchemaValidationThunkAction<void> => {
484485
void dispatch(fetchValidation(namespace));
485486
};
486487
};
488+
489+
export const hasErrorAndLogValidationActionSupport = (
490+
serverVersion: string
491+
) => {
492+
return semver.gte(serverVersion, '8.1.0');
493+
};

packages/compass-telemetry/src/telemetry-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ type SchemaValidationUpdatedEvent = ConnectionScopedEvent<{
18971897
/**
18981898
* The validation action passed to the driver.
18991899
*/
1900-
validation_action: 'error' | 'warn';
1900+
validation_action: 'error' | 'warn' | 'errorAndLog';
19011901

19021902
/**
19031903
* The level of schema validation passed to the driver.

0 commit comments

Comments
 (0)