Skip to content

Commit 3fb5f2f

Browse files
authored
feat(compass-schema-validator): add validation action option for 'errorAndLog' with 8.1 COMPASS-8983 (#6820)
8.1 supports a new 'errorAndLog' validation action. This adds it to the schema validator UI.
1 parent 5ef2fb8 commit 3fb5f2f

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

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

+34
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,38 @@ describe('ValidationEditor [Component]', function () {
245245
expect(applyBtn).to.have.attribute('aria-disabled', 'true');
246246
});
247247
});
248+
249+
context('with errorAndLog', function () {
250+
it('should be hidden for server version <8.1', async function () {
251+
await renderValidationEditor({
252+
serverVersion: '6.0.0',
253+
});
254+
255+
expect(
256+
screen.queryByTestId('validation-action-error-and-log-option')
257+
).is.null;
258+
259+
userEvent.click(screen.getByTestId('validation-action-selector'));
260+
261+
expect(
262+
screen.queryByTestId('validation-action-option-error-and-log')
263+
).is.null;
264+
});
265+
266+
it('should be visible for server version >=8.1', async function () {
267+
await renderValidationEditor({
268+
serverVersion: '8.1.0',
269+
});
270+
271+
expect(
272+
screen.queryByTestId('validation-action-error-and-log-option')
273+
).is.null;
274+
275+
userEvent.click(screen.getByTestId('validation-action-selector'));
276+
277+
expect(
278+
screen.queryByTestId('validation-action-option-error-and-log')
279+
).is.not.null;
280+
});
281+
});
248282
});

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

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export const ValidationEditor: React.FunctionComponent<
284284
isEditable={isEditable && isEditingEnabled}
285285
validationActionChanged={validationActionChanged}
286286
validationAction={validationAction}
287+
serverVersion={serverVersion}
287288
/>
288289
<LevelSelector
289290
isEditable={isEditable && isEditingEnabled}

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

+11
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

+12-1
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 {
@@ -534,3 +535,13 @@ export const activateValidation = (): SchemaValidationThunkAction<void> => {
534535
void dispatch(fetchValidation(namespace));
535536
};
536537
};
538+
539+
export const hasErrorAndLogValidationActionSupport = (
540+
serverVersion: string
541+
) => {
542+
try {
543+
return semver.gte(serverVersion, '8.1.0-rc.0');
544+
} catch (err) {
545+
return false;
546+
}
547+
};

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

+1-1
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)