mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 19:37:38 -02:30
fix empty CodeMirror bug in modals
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { oneOf, bool, number, string, func } from 'prop-types';
|
import { oneOf, bool, number, string, func } from 'prop-types';
|
||||||
import { Controlled as ReactCodeMirror } from 'react-codemirror2';
|
import { Controlled as ReactCodeMirror } from 'react-codemirror2';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
@@ -67,6 +67,20 @@ function CodeMirrorInput({
|
|||||||
fullHeight,
|
fullHeight,
|
||||||
className,
|
className,
|
||||||
}) {
|
}) {
|
||||||
|
// Workaround for CodeMirror bug: If CodeMirror renders in a modal on the
|
||||||
|
// modal's initial render, it appears as an empty box due to mis-calculated
|
||||||
|
// element height. Forcing an initial render before mounting <CodeMirror>
|
||||||
|
// fixes this.
|
||||||
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isInitialized) {
|
||||||
|
setIsInitialized(true);
|
||||||
|
}
|
||||||
|
}, [isInitialized]);
|
||||||
|
if (!isInitialized) {
|
||||||
|
return <div />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
className={`pf-c-form-control ${className}`}
|
className={`pf-c-form-control ${className}`}
|
||||||
|
|||||||
@@ -58,9 +58,14 @@ function SurveyStep({ template, i18n }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a nested Formik form to perform validation on individual
|
||||||
|
// survey questions. When changes to the inner form occur (onBlur), the
|
||||||
|
// values for all questions are added to the outer form's `survey` field
|
||||||
|
// as a single object.
|
||||||
function SurveySubForm({ survey, initialValues, i18n }) {
|
function SurveySubForm({ survey, initialValues, i18n }) {
|
||||||
const [, , surveyFieldHelpers] = useField('survey');
|
const [, , surveyFieldHelpers] = useField('survey');
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// set survey initial values to parent form
|
||||||
surveyFieldHelpers.setValue(initialValues);
|
surveyFieldHelpers.setValue(initialValues);
|
||||||
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
||||||
}, []);
|
}, []);
|
||||||
@@ -74,10 +79,6 @@ function SurveySubForm({ survey, initialValues, i18n }) {
|
|||||||
integer: NumberField,
|
integer: NumberField,
|
||||||
float: NumberField,
|
float: NumberField,
|
||||||
};
|
};
|
||||||
// This is a nested Formik form to perform validation on individual
|
|
||||||
// survey questions. When changes to the inner form occur (onBlur), the
|
|
||||||
// values for all questions are added to the outer form's `survey` field
|
|
||||||
// as a single object.
|
|
||||||
return (
|
return (
|
||||||
<Formik initialValues={initialValues}>
|
<Formik initialValues={initialValues}>
|
||||||
{({ values }) => (
|
{({ values }) => (
|
||||||
|
|||||||
@@ -322,7 +322,6 @@ exports[`<DeleteRoleConfirmationModal /> should render initially 1`] = `
|
|||||||
className="pf-c-backdrop"
|
className="pf-c-backdrop"
|
||||||
>
|
>
|
||||||
<FocusTrap
|
<FocusTrap
|
||||||
_createFocusTrap={[Function]}
|
|
||||||
active={true}
|
active={true}
|
||||||
className="pf-l-bullseye"
|
className="pf-l-bullseye"
|
||||||
focusTrapOptions={
|
focusTrapOptions={
|
||||||
@@ -331,7 +330,6 @@ exports[`<DeleteRoleConfirmationModal /> should render initially 1`] = `
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
paused={false}
|
paused={false}
|
||||||
tag="div"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="pf-l-bullseye"
|
className="pf-l-bullseye"
|
||||||
|
|||||||
Reference in New Issue
Block a user