added simple YAML validation on FE

This commit is contained in:
Davor 2022-08-05 20:22:05 +02:00
parent 94bd90486c
commit af4189e3b9
2 changed files with 11 additions and 4 deletions

View file

@ -3,11 +3,12 @@ import _ from 'lodash';
import Editor from 'react-simple-code-editor';
// import { Menu, Transition } from '@headlessui/react';
// import { ChevronDownIcon } from '@heroicons/react/solid';
import yaml from 'js-yaml';
import { highlight, languages } from 'prismjs';
import 'prismjs/components/prism-clike';
import 'prismjs/components/prism-yaml';
import 'prismjs/themes/prism.css';
import { showToast } from 'src/common/util/show-toast';
import { showToast, ToastType } from 'src/common/util/show-toast';
import { useApps } from 'src/services/apps';
import { initialEditorYaml } from '../../consts';
@ -21,8 +22,13 @@ export const AdvancedTab = () => {
};
const vertifyCode = () => {
// call yaml verification (only format)
// const result = validateSchema(code, {});
try {
yaml.load(code);
showToast('Configuration is valid!', ToastType.Success);
} catch (e: any) {
console.log('e', e);
showToast(`Configuration is not valid: ${e.message}`, ToastType.Error, Infinity);
}
};
const saveChanges = () => {