Skip to content

Commit

Permalink
fix: validation in the yaml editor (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrasEszes authored Dec 5, 2024
1 parent 29bd3d9 commit 4bd9cf9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"jquery": "^3.7.1",
"json-schema-to-ts": "^3.1.1",
"launchdarkly-js-client-sdk": "^3.5.0",
"monaco-editor": "^0.52.0",
"monaco-editor": "0.51.0",
"monaco-yaml": "^5.2.3",
"ng-showdown": "^1.1.0",
"prop-types": "^15.8.1",
Expand Down
36 changes: 21 additions & 15 deletions source/javascripts/components/YmlEditor/YmlEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
import { useEffect, useState } from 'react';

import Editor from '@monaco-editor/react';
import { configureMonacoYaml } from 'monaco-yaml';
import { configureMonacoYaml, MonacoYaml } from 'monaco-yaml';

type YmlEditorProps = {
isLoading?: boolean;
readonly: boolean;
yml: string;
onChange: (changedText?: string) => void;
};

const YmlEditor = ({ isLoading, readonly, yml, onChange }: YmlEditorProps) => {
const defaultSchema = {
uri: 'https://json.schemastore.org/bitrise.json',
fileMatch: ['*'],
};
const [monacoYaml, setMonacoYaml] = useState<MonacoYaml>();

useEffect(() => {
return monacoYaml?.dispose;
}, [monacoYaml]);

return (
<Editor
language="yaml"
value={isLoading ? 'Loading...' : yml}
theme="vs-dark"
options={{
readOnly: readonly || isLoading,
roundedSelection: false,
scrollBeyondLastLine: false,
readOnly: readonly || isLoading,
stickyScroll: {
enabled: true,
},
}}
onMount={(_, monaco) => {
configureMonacoYaml(monaco, {
validate: true,
enableSchemaRequest: true,
format: true,
hover: true,
completion: true,
schemas: [defaultSchema],
});
beforeMount={(monaco) => {
setMonacoYaml(
configureMonacoYaml(monaco, {
hover: true,
format: true,
validate: true,
completion: true,
enableSchemaRequest: true,
schemas: [{ uri: 'https://json.schemastore.org/bitrise.json', fileMatch: ['*'] }],
}),
);
}}
onChange={onChange}
/>
Expand Down

0 comments on commit 4bd9cf9

Please sign in to comment.