Skip to content

fix: Add debounce to textarea component to improve performance #10345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/components/layout-utils.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import PropTypes from "prop-types"
import DebounceInput from "react-debounce-input"

function xclass(...args) {
return args.filter(a => !!a).join(" ").trim()
Expand Down Expand Up @@ -124,9 +125,10 @@ export class Button extends React.Component {

}


export const TextArea = (props) => <textarea {...props} />

export const DebounceTextArea = (props) => <DebounceInput element={TextArea} debounceTimeout={350} forceNotifyByEnter={false} {...props} />

export const Input = (props) => <input {...props} />

export class Select extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/param-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class ParamBody extends PureComponent {
} = this.props

const Button = getComponent("Button")
const TextArea = getComponent("TextArea")
const TextArea = getComponent("DebounceTextArea")
const HighlightCode = getComponent("HighlightCode", true)
const ContentType = getComponent("contentType")
// for domains where specSelectors not passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export class JsonSchema_object extends PureComponent {
disabled
} = this.props

const TextArea = getComponent("TextArea")
const TextArea = getComponent("DebounceTextArea")
errors = errors.toJS ? errors.toJS() : Array.isArray(errors) ? errors : []

return (
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/components/request-body-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class RequestBodyEditor extends PureComponent {
} = this.state

let isInvalid = errors.size > 0 ? true : false
const TextArea = getComponent("TextArea")
const TextArea = getComponent("DebounceTextArea")

return (
<div className="body-param">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
)
.should("not.have.class", "invalid")
.clear()
.blur()
// Execute
.get(".execute.opblock-control__btn")
.click()
Expand All @@ -104,6 +105,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
)
.clear()
.type(" ")
.blur()
// Execute
.get(".execute.opblock-control__btn")
.click()
Expand Down Expand Up @@ -197,6 +199,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
)
.should("not.have.class", "invalid")
.clear()
.blur()
// Execute
.get(".execute.opblock-control__btn")
.click()
Expand Down
1 change: 1 addition & 0 deletions test/e2e-cypress/e2e/features/schema-form.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
}
]`
)
.blur()
.should("contain.text", "Jane")
.should("contain.text", "201")
// Execute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { mount, render } from "enzyme"
import * as JsonSchemaComponents from "core/plugins/json-schema-5/components/json-schema-components"
import { foldType } from "core/plugins/json-schema-2020-12-samples/fn/index"
import { makeIsFileUploadIntended } from "core/plugins/oas3/fn"
import { DebounceTextArea } from "core/components/layout-utils"

const components = {...JsonSchemaComponents, Select, Input, TextArea}
const components = {...JsonSchemaComponents, Select, Input, TextArea, DebounceTextArea}

const getComponentStub = (name) => {
if(components[name]) return components[name]
Expand Down