Skip to content

fix(compass-schema-validation): rules generated message COMPASS-9252 #6843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(compass-schema-validation): rules generated message COMPASS-9252
  • Loading branch information
paula-stacho committed Apr 8, 2025
commit e4def04a01ae6c0857a7af6d5f2cb9c742e1afe5
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function renderValidationEditor(
validation={validation}
generateValidationRules={() => {}}
isRulesGenerationInProgress={false}
isValidatorGenerated={false}
isSavingInProgress={false}
isEditable
isEditingEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ const modifiedMessageStyles = css({
flex: 1,
});

const generatedMessageStyles = css({
color: palette.green.dark2,
display: 'flex',
alignItems: 'center',
gap: spacing[200],
flex: 1,
});

const generatedMessageDarkStyles = css({
color: palette.green.light2,
});

const modifiedMessageDarkStyles = css({
color: palette.yellow.light2,
});
Expand Down Expand Up @@ -150,6 +162,7 @@ type ValidationEditorProps = {
isEditingEnabled: boolean;
isRulesGenerationInProgress: boolean;
isSavingInProgress: boolean;
isValidatorGenerated: boolean;
};

/**
Expand All @@ -173,6 +186,7 @@ export const ValidationEditor: React.FunctionComponent<
isEditingEnabled,
isRulesGenerationInProgress,
isSavingInProgress,
isValidatorGenerated,
}) => {
const enableExportSchema = usePreference('enableExportSchema');
const track = useTelemetry();
Expand Down Expand Up @@ -315,7 +329,7 @@ export const ValidationEditor: React.FunctionComponent<
<div className={actionsStyles}>
{isEditingEnabled ? (
<>
{isChanged && (
{isChanged && !isValidatorGenerated && (
<Body
className={cx(
modifiedMessageStyles,
Expand All @@ -327,6 +341,18 @@ export const ValidationEditor: React.FunctionComponent<
applied. Please review before applying.
</Body>
)}
{isValidatorGenerated && (
<Body
className={cx(
generatedMessageStyles,
darkMode && generatedMessageDarkStyles
)}
data-testid="validation-action-message"
>
<Icon glyph="Checkmark" /> Rules generated. Please review
before applying.
</Body>
)}
<Button
type="button"
className={buttonStyles}
Expand Down Expand Up @@ -376,6 +402,7 @@ const mapStateToProps = (state: RootState) => ({
validation: state.validation,
namespace: state.namespace.ns,
isRulesGenerationInProgress: state.rulesGeneration.isInProgress,
isValidatorGenerated: state.rulesGeneration.isGenerated,
isSavingInProgress: state.validation.isSaving,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { zeroStateChanged } from './zero-state';
import { enableEditRules } from './edit-mode';
import type { MongoError } from 'mongodb';
import type { Action, Reducer } from 'redux';
import { validationLevelChanged, validatorChanged } from './validation';
import {
ValidationActions,
validationLevelChanged,
validatorChanged,
} from './validation';
import {
type analyzeSchema as analyzeSchemaType,
calculateSchemaMetadata,
Expand Down Expand Up @@ -48,6 +52,7 @@ export type RulesGenerationError = {

export interface RulesGenerationState {
isInProgress: boolean;
isGenerated: boolean;
error?: RulesGenerationError;
}

Expand All @@ -56,6 +61,7 @@ export interface RulesGenerationState {
*/
export const INITIAL_STATE: RulesGenerationState = {
isInProgress: false,
isGenerated: false,
};

function getErrorDetails(error: Error): RulesGenerationError {
Expand Down Expand Up @@ -103,6 +109,7 @@ export const rulesGenerationReducer: Reducer<RulesGenerationState, Action> = (
return {
...state,
isInProgress: false,
isGenerated: true,
};
}

Expand All @@ -119,6 +126,16 @@ export const rulesGenerationReducer: Reducer<RulesGenerationState, Action> = (
};
}

if (
isAction(action, ValidationActions.ValidatorChanged) &&
state.isGenerated
) {
return {
...state,
isGenerated: false, // the generated validator has been changed
};
}

if (
isAction<RulesGenerationErrorCleared>(
action,
Expand Down
Loading