Input code json (#9291)

* remove language selection for input code type JSON

* lint as json when type is json

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Azri Kahar
2021-11-02 02:35:59 +08:00
committed by GitHub
parent 90bb9d4879
commit c53a539fdd
2 changed files with 52 additions and 37 deletions

View File

@@ -1,3 +1,4 @@
import { ExtensionsOptionsContext } from '@directus/shared/types';
import { defineInterface } from '@directus/shared/utils';
import CodeMirror from 'codemirror';
import 'codemirror/mode/meta';
@@ -37,43 +38,57 @@ export default defineInterface({
types: ['string', 'json', 'text', 'geometry'],
group: 'standard',
preview: PreviewSVG,
options: [
{
field: 'language',
name: '$t:language',
type: 'string',
meta: {
width: 'half',
interface: 'select-dropdown',
options: { choices },
},
},
{
field: 'lineNumber',
name: '$t:interfaces.input-code.line_number',
type: 'boolean',
meta: {
width: 'half',
interface: 'boolean',
},
schema: {
default_value: false,
},
},
{
field: 'template',
name: '$t:template',
type: 'text',
meta: {
width: 'full',
interface: 'input-code',
options: {
placeholder: '$t:interfaces.input-code.placeholder',
options: ({ field }: ExtensionsOptionsContext) => {
const sharedOptions = [
{
field: 'lineNumber',
name: '$t:interfaces.input-code.line_number',
type: 'boolean',
meta: {
width: 'half',
interface: 'boolean',
},
schema: {
default_value: false,
},
},
schema: {
default_value: null,
{
field: 'template',
name: '$t:template',
type: 'text',
meta: {
width: 'full',
interface: 'input-code',
options: {
placeholder: '$t:interfaces.input-code.placeholder',
},
},
schema: {
default_value: null,
},
},
},
],
];
const defaultOptions = [
{
field: 'language',
name: '$t:language',
type: 'string',
meta: {
width: 'half',
interface: 'select-dropdown',
options: { choices },
},
},
...sharedOptions,
];
const jsonOptions = [...sharedOptions];
if (field?.type === 'json') {
return jsonOptions;
}
return defaultOptions;
},
});

View File

@@ -135,7 +135,7 @@ export default defineComponent({
if (codemirror) {
const lang = props.language.toLowerCase();
if (lang === 'json') {
if (props.type === 'json' || lang === 'json') {
// @ts-ignore
await import('codemirror/mode/javascript/javascript.js');