Skip to content

Commit b881c14

Browse files
author
Íñigo Marquínez
committed
fix: ajax was not working
1 parent 0d5ff78 commit b881c14

File tree

5 files changed

+49
-65
lines changed

5 files changed

+49
-65
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ node_modules/
1919
.coverage
2020

2121
# Build
22-
build/*
23-
!/build/index.html
22+
build

build/index.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@contentful/forma-36-fcss": "^0.0.20",
3333
"@contentful/forma-36-react-components": "^3.11.3",
3434
"@contentful/forma-36-tokens": "^0.3.0",
35-
"@json-editor/json-editor": "^2.0.0-alpha.0",
35+
"@json-editor/json-editor": "^2.1.0",
3636
"contentful-ui-extensions-sdk": "3.9.0",
3737
"lodash": "^4.17.15",
3838
"prop-types": "^15.7.2",

src/Extension.js

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ const Extension = ({ sdk }) => {
1919
sdk.window.updateHeight();
2020
validateAndSave();
2121
};
22-
22+
2323
Object.keys(editorRef.editors).forEach(key => {
2424
if (Object.prototype.hasOwnProperty.call(editorRef.editors, key) && key !== 'root') {
2525
editorRef.watch(key, watcherCallback.bind(editorRef, key));
2626
}
2727
});
28-
28+
2929
const validateAndSave = _debounce(() => {
3030
const errors = editorRef.validate();
3131
if (errors.length === 0) {
@@ -42,45 +42,48 @@ const Extension = ({ sdk }) => {
4242
const schemaPath = sdk.parameters.instance.overridenSchemaPath || defaultSchemaPath;
4343
const schemaName = sdk.parameters.instance.schemaName;
4444

45-
const editorRef = new JSONEditor(ref.current, { // eslint-disable-line no-undef
46-
ajax: true,
47-
ajaxBase: schemaPath,
48-
compact: false,
49-
disable_array_add: false,
50-
disable_array_delete: false,
51-
disable_array_reorder: false,
52-
enable_array_copy: false,
53-
disable_collapse: true,
54-
disable_edit_json: true,
55-
disable_properties: true,
56-
array_controls_top: true,
57-
form_name_root: 'root',
58-
iconlib: null,
59-
remove_button_labels: false,
60-
no_additional_properties: true,
61-
// refs: {} // An object containing schema definitions for URLs. Allows you to pre-define external schemas.
62-
required_by_default: true,
63-
keep_oneof_values: true,
64-
schema: {
65-
$ref: schemaName,
66-
},
67-
show_errors: 'never', // interaction | change | always | never
68-
startval: value,
69-
template: 'default',
70-
display_required_only: false,
71-
show_opt_in: true,
72-
prompt_before_delete: false,
73-
object_layout: 'table',
74-
plugin: {
75-
selectize: true,
76-
},
77-
});
78-
79-
editorRef.on('ready', () => {
80-
initializeEditor(editorRef);
81-
});
82-
83-
return editorRef;
45+
fetch(`${schemaPath}${schemaName}`)
46+
.then(response => response.text())
47+
.then(data => {
48+
try {
49+
const editorRef = new JSONEditor(ref.current, { // eslint-disable-line no-undef
50+
compact: false,
51+
disable_array_add: false,
52+
disable_array_delete: false,
53+
disable_array_reorder: false,
54+
enable_array_copy: false,
55+
disable_collapse: true,
56+
disable_edit_json: true,
57+
disable_properties: true,
58+
array_controls_top: true,
59+
form_name_root: 'root',
60+
iconlib: null,
61+
remove_button_labels: false,
62+
no_additional_properties: true,
63+
required_by_default: true,
64+
keep_oneof_values: true,
65+
schema: JSON.parse(data),
66+
show_errors: 'never', // interaction | change | always | never
67+
startval: value,
68+
template: 'default',
69+
display_required_only: false,
70+
show_opt_in: true,
71+
prompt_before_delete: false,
72+
object_layout: 'table',
73+
plugin: {
74+
selectize: true,
75+
},
76+
});
77+
78+
editorRef.on('ready', () => {
79+
initializeEditor(editorRef);
80+
});
81+
82+
return editorRef;
83+
} catch (error) {
84+
console.error(error.message);
85+
}
86+
});
8487
};
8588

8689
sdk.window.startAutoResizer();

0 commit comments

Comments
 (0)