You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/02/07 12:10:26 UTC
[GitHub] garrensmith closed pull request #1053: Throttle fetch requests triggered by key press events
garrensmith closed pull request #1053: Throttle fetch requests triggered by key press events
URL: https://github.com/apache/couchdb-fauxton/pull/1053
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/app/addons/components/components/throttledreacselect.js b/app/addons/components/components/throttledreacselect.js
new file mode 100644
index 000000000..c39f63f5a
--- /dev/null
+++ b/app/addons/components/components/throttledreacselect.js
@@ -0,0 +1,49 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactSelect from "react-select";
+
+export class ThrottledReactSelectAsync extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.lastCall = undefined;
+ const { loadOptions } = props;
+ this.throttledLoadOptions = this.wrapThrottler(loadOptions).bind(this);
+ }
+
+ wrapThrottler(loadOptions) {
+ if (!loadOptions) {
+ return () => {};
+ }
+ return (id, callback) => {
+ if (this.lastCall) {
+ clearTimeout(this.lastCall);
+ }
+ this.lastCall = setTimeout(() => {
+ loadOptions(id, callback);
+ }, 400);
+ };
+ }
+
+ render() {
+ const newProps = {
+ ...this.props,
+ loadOptions: this.throttledLoadOptions
+ };
+ return (
+ <ReactSelect.Async {...newProps} />
+ );
+ }
+}
diff --git a/app/addons/components/react-components.js b/app/addons/components/react-components.js
index 6bad879a8..bd8abb42e 100644
--- a/app/addons/components/react-components.js
+++ b/app/addons/components/react-components.js
@@ -31,6 +31,7 @@ import {TabElement, TabElementWrapper} from './components/tabelement';
import {Polling, RefreshBtn} from './components/polling';
import {Copy} from './components/copy';
import {TabWindowWrapper} from './components/tabwindowwrapper';
+import {ThrottledReactSelectAsync} from './components/throttledreacselect';
export default {
BadgeList,
@@ -58,5 +59,6 @@ export default {
TabElementWrapper,
RefreshBtn,
Copy,
- TabWindowWrapper
+ TabWindowWrapper,
+ ThrottledReactSelectAsync
};
diff --git a/app/addons/databases/components.js b/app/addons/databases/components.js
index 21242308f..fc14d2a7f 100644
--- a/app/addons/databases/components.js
+++ b/app/addons/databases/components.js
@@ -23,7 +23,6 @@ import FauxtonComponentsReact from "..//fauxton/components";
import Stores from "./stores";
import Actions from "./actions";
-import ReactSelect from "react-select";
import {Tooltip, OverlayTrigger} from 'react-bootstrap';
const databasesStore = Stores.databasesStore;
@@ -272,12 +271,13 @@ class AddDatabaseWidget extends React.Component {
}
}
+
const JumpToDatabaseWidget = ({loadOptions}) => {
return (
<div data-name="jump-to-db" className="faux-header__searchboxwrapper">
<div className="faux-header__searchboxcontainer">
- <ReactSelect.Async
+ <Components.ThrottledReactSelectAsync
placeholder="Database name"
loadOptions={loadOptions}
clearable={false}
diff --git a/app/addons/documents/components/jumptodoc.js b/app/addons/documents/components/jumptodoc.js
index cbe753ad9..58dc45ebf 100644
--- a/app/addons/documents/components/jumptodoc.js
+++ b/app/addons/documents/components/jumptodoc.js
@@ -14,15 +14,15 @@ import FauxtonAPI from "../../../core/api";
// the License.
import PropTypes from 'prop-types';
-
import React from "react";
import ReactDOM from "react-dom";
-import ReactSelect from "react-select";
+import Components from "../../components/react-components";
+
const JumpToDoc = ({database, loadOptions}) => {
return (
<div>
- <ReactSelect.Async
+ <Components.ThrottledReactSelectAsync
className="jump-to-doc"
name="jump-to-doc"
placeholder="Document ID"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services