fix: Slow rendering of JSON and RAW response (#16971)
* fix:Slow rendering of JSON and RAW response * added debouncing for editor refresh
This commit is contained in:
parent
a560051d86
commit
02c8f6c2dd
|
|
@ -265,6 +265,7 @@ export const responseTabComponent = (
|
||||||
return {
|
return {
|
||||||
[API_RESPONSE_TYPE_OPTIONS.JSON]: (
|
[API_RESPONSE_TYPE_OPTIONS.JSON]: (
|
||||||
<ReadOnlyEditor
|
<ReadOnlyEditor
|
||||||
|
containerHeight={tableBodyHeight}
|
||||||
folding
|
folding
|
||||||
height={"100%"}
|
height={"100%"}
|
||||||
input={{
|
input={{
|
||||||
|
|
@ -278,6 +279,7 @@ export const responseTabComponent = (
|
||||||
),
|
),
|
||||||
[API_RESPONSE_TYPE_OPTIONS.RAW]: (
|
[API_RESPONSE_TYPE_OPTIONS.RAW]: (
|
||||||
<ReadOnlyEditor
|
<ReadOnlyEditor
|
||||||
|
containerHeight={tableBodyHeight}
|
||||||
folding
|
folding
|
||||||
height={"100%"}
|
height={"100%"}
|
||||||
input={{
|
input={{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import "codemirror/addon/lint/lint.css";
|
||||||
import { getDataTreeForAutocomplete } from "selectors/dataTreeSelectors";
|
import { getDataTreeForAutocomplete } from "selectors/dataTreeSelectors";
|
||||||
import EvaluatedValuePopup from "components/editorComponents/CodeEditor/EvaluatedValuePopup";
|
import EvaluatedValuePopup from "components/editorComponents/CodeEditor/EvaluatedValuePopup";
|
||||||
import { WrappedFieldInputProps } from "redux-form";
|
import { WrappedFieldInputProps } from "redux-form";
|
||||||
import _, { isString } from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import {
|
||||||
DataTree,
|
DataTree,
|
||||||
ENTITY_TYPE,
|
ENTITY_TYPE,
|
||||||
|
|
@ -179,6 +179,7 @@ export type EditorProps = EditorStyleProps &
|
||||||
isReadOnly?: boolean;
|
isReadOnly?: boolean;
|
||||||
isRawView?: boolean;
|
isRawView?: boolean;
|
||||||
isJSObject?: boolean;
|
isJSObject?: boolean;
|
||||||
|
containerHeight?: number;
|
||||||
// Custom gutter
|
// Custom gutter
|
||||||
customGutter?: CodeEditorGutter;
|
customGutter?: CodeEditorGutter;
|
||||||
};
|
};
|
||||||
|
|
@ -349,7 +350,20 @@ class CodeEditor extends Component<Props, State> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Debounce editor refresh request as container resizing triggers many change events.
|
||||||
|
debounceEditorRefresh = _.debounce(async () => {
|
||||||
|
this.editor.refresh();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props): void {
|
componentDidUpdate(prevProps: Props): void {
|
||||||
|
if (
|
||||||
|
prevProps.containerHeight &&
|
||||||
|
this.props.containerHeight &&
|
||||||
|
prevProps.containerHeight < this.props.containerHeight
|
||||||
|
) {
|
||||||
|
//Refresh editor when the container height is increased.
|
||||||
|
this.debounceEditorRefresh();
|
||||||
|
}
|
||||||
this.editor.operation(() => {
|
this.editor.operation(() => {
|
||||||
if (this.state.isFocused) return;
|
if (this.state.isFocused) return;
|
||||||
// const currentMode = this.editor.getOption("mode");
|
// const currentMode = this.editor.getOption("mode");
|
||||||
|
|
@ -359,7 +373,7 @@ class CodeEditor extends Component<Props, State> {
|
||||||
const previousInputValue = getInputValue(prevProps.input.value);
|
const previousInputValue = getInputValue(prevProps.input.value);
|
||||||
|
|
||||||
if (!!inputValue || inputValue === "") {
|
if (!!inputValue || inputValue === "") {
|
||||||
if (inputValue !== editorValue && isString(inputValue)) {
|
if (inputValue !== editorValue && _.isString(inputValue)) {
|
||||||
this.editor.setValue(inputValue);
|
this.editor.setValue(inputValue);
|
||||||
this.editor.clearHistory(); // when input gets updated on focus out clear undo/redo from codeMirror History
|
this.editor.clearHistory(); // when input gets updated on focus out clear undo/redo from codeMirror History
|
||||||
} else if (prevProps.isEditorHidden && !this.props.isEditorHidden) {
|
} else if (prevProps.isEditorHidden && !this.props.isEditorHidden) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ interface Props {
|
||||||
showLineNumbers?: boolean;
|
showLineNumbers?: boolean;
|
||||||
isReadOnly?: boolean;
|
isReadOnly?: boolean;
|
||||||
isRawView?: boolean;
|
isRawView?: boolean;
|
||||||
|
containerHeight?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReadOnlyEditor(props: Props) {
|
function ReadOnlyEditor(props: Props) {
|
||||||
|
|
@ -39,6 +40,7 @@ function ReadOnlyEditor(props: Props) {
|
||||||
folding: props.folding,
|
folding: props.folding,
|
||||||
isReadOnly: props.isReadOnly,
|
isReadOnly: props.isReadOnly,
|
||||||
isRawView: props.isRawView,
|
isRawView: props.isRawView,
|
||||||
|
containerHeight: props.containerHeight,
|
||||||
};
|
};
|
||||||
return <CodeEditor {...editorProps} />;
|
return <CodeEditor {...editorProps} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user