Skip to content

Commit 2b2a627

Browse files
authored
fix(compass-schema-validation): rules generated message COMPASS-9252 (#6843)
1 parent 41dec97 commit 2b2a627

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async function renderValidationEditor(
3636
validation={validation}
3737
generateValidationRules={() => {}}
3838
isRulesGenerationInProgress={false}
39+
isValidatorGenerated={false}
3940
isSavingInProgress={false}
4041
isEditable
4142
isEditingEnabled

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ const modifiedMessageStyles = css({
8484
flex: 1,
8585
});
8686

87+
const generatedMessageStyles = css({
88+
color: palette.green.dark2,
89+
display: 'flex',
90+
alignItems: 'center',
91+
gap: spacing[200],
92+
flex: 1,
93+
});
94+
95+
const generatedMessageDarkStyles = css({
96+
color: palette.green.light2,
97+
});
98+
8799
const modifiedMessageDarkStyles = css({
88100
color: palette.yellow.light2,
89101
});
@@ -150,6 +162,7 @@ type ValidationEditorProps = {
150162
isEditingEnabled: boolean;
151163
isRulesGenerationInProgress: boolean;
152164
isSavingInProgress: boolean;
165+
isValidatorGenerated: boolean;
153166
};
154167

155168
/**
@@ -173,6 +186,7 @@ export const ValidationEditor: React.FunctionComponent<
173186
isEditingEnabled,
174187
isRulesGenerationInProgress,
175188
isSavingInProgress,
189+
isValidatorGenerated,
176190
}) => {
177191
const enableExportSchema = usePreference('enableExportSchema');
178192
const track = useTelemetry();
@@ -315,7 +329,7 @@ export const ValidationEditor: React.FunctionComponent<
315329
<div className={actionsStyles}>
316330
{isEditingEnabled ? (
317331
<>
318-
{isChanged && (
332+
{isChanged && !isValidatorGenerated && (
319333
<Body
320334
className={cx(
321335
modifiedMessageStyles,
@@ -327,6 +341,18 @@ export const ValidationEditor: React.FunctionComponent<
327341
applied. Please review before applying.
328342
</Body>
329343
)}
344+
{isValidatorGenerated && (
345+
<Body
346+
className={cx(
347+
generatedMessageStyles,
348+
darkMode && generatedMessageDarkStyles
349+
)}
350+
data-testid="validation-action-message"
351+
>
352+
<Icon glyph="Checkmark" /> Rules generated. Please review
353+
before applying.
354+
</Body>
355+
)}
330356
<Button
331357
type="button"
332358
className={buttonStyles}
@@ -376,6 +402,7 @@ const mapStateToProps = (state: RootState) => ({
376402
validation: state.validation,
377403
namespace: state.namespace.ns,
378404
isRulesGenerationInProgress: state.rulesGeneration.isInProgress,
405+
isValidatorGenerated: state.rulesGeneration.isGenerated,
379406
isSavingInProgress: state.validation.isSaving,
380407
});
381408

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { zeroStateChanged } from './zero-state';
33
import { enableEditRules } from './edit-mode';
44
import type { MongoError } from 'mongodb';
55
import type { Action, Reducer } from 'redux';
6-
import { validationLevelChanged, validatorChanged } from './validation';
6+
import {
7+
ValidationActions,
8+
validationLevelChanged,
9+
validatorChanged,
10+
} from './validation';
711
import {
812
type analyzeSchema as analyzeSchemaType,
913
calculateSchemaMetadata,
@@ -48,6 +52,7 @@ export type RulesGenerationError = {
4852

4953
export interface RulesGenerationState {
5054
isInProgress: boolean;
55+
isGenerated: boolean;
5156
error?: RulesGenerationError;
5257
}
5358

@@ -56,6 +61,7 @@ export interface RulesGenerationState {
5661
*/
5762
export const INITIAL_STATE: RulesGenerationState = {
5863
isInProgress: false,
64+
isGenerated: false,
5965
};
6066

6167
function getErrorDetails(error: Error): RulesGenerationError {
@@ -103,6 +109,7 @@ export const rulesGenerationReducer: Reducer<RulesGenerationState, Action> = (
103109
return {
104110
...state,
105111
isInProgress: false,
112+
isGenerated: true,
106113
};
107114
}
108115

@@ -119,6 +126,26 @@ export const rulesGenerationReducer: Reducer<RulesGenerationState, Action> = (
119126
};
120127
}
121128

129+
if (
130+
isAction(action, ValidationActions.ValidatorChanged) &&
131+
state.isGenerated
132+
) {
133+
return {
134+
...state,
135+
isGenerated: false, // the generated validator has been changed
136+
};
137+
}
138+
139+
if (
140+
isAction(action, ValidationActions.ValidationSaveEnded) &&
141+
state.isGenerated
142+
) {
143+
return {
144+
...state,
145+
isGenerated: false, // the generated validator has been saved
146+
};
147+
}
148+
122149
if (
123150
isAction<RulesGenerationErrorCleared>(
124151
action,

0 commit comments

Comments
 (0)