Skip to content

Commit c404e9f

Browse files
committed
fixup: only add isChanged when creating a new rule
1 parent ed8e462 commit c404e9f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { openToast } from '@mongodb-js/compass-components';
66
import { isEqual, pick } from 'lodash';
77
import { disableEditRules } from './edit-mode';
88
import { isAction } from '../util';
9+
import { IS_ZERO_STATE_CHANGED, IsZeroStateChangedAction } from './zero-state';
910

1011
export type ValidationServerAction = 'error' | 'warn';
1112
export type ValidationLevel = 'off' | 'moderate' | 'strict';
@@ -91,17 +92,17 @@ export const VALIDATION_TEMPLATE = `/**
9192
* More information on schema validation rules can be found at:
9293
* https://www.mongodb.com/docs/manual/core/schema-validation/
9394
*/
94-
{
95+
{
9596
$jsonSchema: {
96-
title: "Library.books",
97-
bsonType: "object",
97+
title: "Library.books",
98+
bsonType: "object",
9899
required: ["fieldname1", "fieldname2"],
99100
properties: {
100-
fieldname1: {
101+
fieldname1: {
101102
bsonType: "string",
102103
description: "Fieldname1 must be a string",
103104
},
104-
fieldname2: {
105+
fieldname2: {
105106
bsonType: "int",
106107
description: "Fieldname2 must be an integer",
107108
},
@@ -210,7 +211,7 @@ export default function reducer(
210211
) {
211212
return {
212213
...state,
213-
isChanged: true,
214+
isChanged: false,
214215
error: null,
215216
syntaxError: null,
216217
...DEFAULT_VALIDATION,
@@ -285,6 +286,13 @@ export default function reducer(
285286
};
286287
}
287288

289+
if (isAction<IsZeroStateChangedAction>(action, IS_ZERO_STATE_CHANGED)) {
290+
return {
291+
...state,
292+
isChanged: true,
293+
};
294+
}
295+
288296
if (
289297
isAction<ValidationLevelChangedAction>(
290298
action,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
*/
1414
export const IS_ZERO_STATE_CHANGED =
1515
'validation/namespace/IS_ZERO_STATE_CHANGED' as const;
16-
interface IsZeroStateChangedAction {
16+
export interface IsZeroStateChangedAction {
1717
type: typeof IS_ZERO_STATE_CHANGED;
1818
isZeroState: boolean;
1919
}

0 commit comments

Comments
 (0)