Skip to content

Commit c38f029

Browse files
committed
fixup: hide cursor in code mirror readonly mode, update error banner variant, enable apply on non-syntax error
1 parent 21b25f7 commit c38f029

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

packages/compass-editor/src/editor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ const disabledContainerDarkModeStyles = css({
9595
boxShadow: `0 0 0 1px ${palette.gray.dark2}`,
9696
});
9797

98+
const readOnlyStyle = css({
99+
// We hide the blinking cursor in read only mode
100+
// as it can appear to users like the editor is editable.
101+
'& .cm-cursor': {
102+
display: 'none !important',
103+
},
104+
});
105+
98106
const hiddenScrollStyle = css({
99107
'& .cm-scroller': {
100108
overflow: '-moz-scrollbars-none',
@@ -1204,6 +1212,7 @@ const BaseEditor = React.forwardRef<EditorRef, EditorProps>(function BaseEditor(
12041212
className={cx(
12051213
disabled && disabledContainerStyles,
12061214
disabled && darkMode && disabledContainerDarkModeStyles,
1215+
readOnly && readOnlyStyle,
12071216
className
12081217
)}
12091218
style={{

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
22
import { debounce } from 'lodash';
33
import { connect } from 'react-redux';
44
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
5-
import type { BannerVariant } from '@mongodb-js/compass-components';
65
import {
76
css,
87
cx,
@@ -112,6 +111,7 @@ const ValidationCodeEditor = ({
112111
text={text}
113112
onChangeText={onChangeText}
114113
readOnly={readOnly}
114+
formattable={!readOnly}
115115
completer={completer}
116116
/>
117117
);
@@ -214,19 +214,6 @@ export const ValidationEditor: React.FunctionComponent<
214214
const { validationAction, validationLevel, error, syntaxError, isChanged } =
215215
validation;
216216

217-
const hasErrors = !!(error || syntaxError);
218-
219-
let message = '';
220-
let variant: BannerVariant = 'info';
221-
222-
if (syntaxError) {
223-
message = syntaxError.message;
224-
variant = 'danger';
225-
} else if (error) {
226-
message = error.message;
227-
variant = 'warning';
228-
}
229-
230217
const onClickApplyValidation = useCallback(async () => {
231218
const confirmed = await showConfirmation({
232219
title: 'Are you sure you want to apply these validation rules?',
@@ -273,7 +260,10 @@ export const ValidationEditor: React.FunctionComponent<
273260
serverVersion={serverVersion}
274261
/>
275262
</div>
276-
{variant && message && <Banner variant={variant}>{message}</Banner>}
263+
{syntaxError && <Banner variant="danger">{syntaxError.message}</Banner>}
264+
{!syntaxError && error && (
265+
<Banner variant="danger">{error.message}</Banner>
266+
)}
277267
{isEditable && (
278268
<div className={actionsStyles}>
279269
{isEditingEnabled ? (
@@ -308,7 +298,7 @@ export const ValidationEditor: React.FunctionComponent<
308298
onClick={() => {
309299
void onClickApplyValidation();
310300
}}
311-
disabled={hasErrors}
301+
disabled={!!syntaxError}
312302
>
313303
Apply
314304
</Button>
@@ -322,7 +312,7 @@ export const ValidationEditor: React.FunctionComponent<
322312
data-testid="enable-edit-validation-button"
323313
onClick={onClickEnableEditRules}
324314
>
325-
Edit Rules
315+
Edit rules
326316
</Button>
327317
)}
328318
</div>

0 commit comments

Comments
 (0)