mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
fix formatting JSON on initialize
This commit is contained in:
@@ -49,6 +49,9 @@ function VariablesDetail({
|
||||
}
|
||||
const modeMatches = isJsonString(value) === (mode === JSON_MODE);
|
||||
if (modeMatches) {
|
||||
if (mode === JSON_MODE) {
|
||||
return JSON.stringify(JSON.parse(value), null, 2);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return mode === YAML_MODE ? jsonToYaml(value) : yamlToJson(value);
|
||||
|
||||
@@ -57,11 +57,12 @@ function VariablesField({
|
||||
);
|
||||
const [field, meta, helpers] = useField({ name, validate });
|
||||
|
||||
// mode's useState above couldn't be initialized to JSON_MODE because
|
||||
// the field value had to be defined below it
|
||||
useEffect(function initializeMode() {
|
||||
useEffect(function initializeJSON() {
|
||||
if (isJsonString(field.value)) {
|
||||
// mode's useState above couldn't be initialized to JSON_MODE because
|
||||
// the field value had to be defined below it
|
||||
setMode(JSON_MODE);
|
||||
helpers.setValue(JSON.stringify(JSON.parse(field.value), null, 2));
|
||||
}
|
||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ describe('VariablesField', () => {
|
||||
</Formik>
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
|
||||
expect(wrapper.find('CodeEditor').prop('mode')).toEqual('javascript');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user