Skip to content

Commit 76b72f2

Browse files
Merge pull request #2230 from appbaseio/http-request-timeout
feat(web-vue): add request timeout prop
2 parents d582b10 + b6a7dac commit 76b72f2

File tree

5 files changed

+10859
-377
lines changed

5 files changed

+10859
-377
lines changed

packages/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@appbaseio/vue-emotion": "0.6.0-alpha.6",
4040
"@emotion/css": "^11.10.5",
4141
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
42-
"appbase-js": "^5.2.0",
42+
"appbase-js": "^5.3.3",
4343
"compute-scroll-into-view": "^1.0.11",
4444
"emotion": "11.0.0",
4545
"hotkeys-js": "^3.8.7",

packages/vue/src/components/ReactiveBase/index.jsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const ReactiveBase = {
4848
mongodb: types.mongodb,
4949
endpoint: types.endpointConfig,
5050
preferences: VueTypes.object,
51+
httpRequestTimeout: VueTypes.number.def(30),
5152
},
5253
provide() {
5354
let createCacheFn = createCache;
@@ -94,6 +95,9 @@ const ReactiveBase = {
9495
mongodb() {
9596
this.updateState(this.$props);
9697
},
98+
httpRequestTimeout() {
99+
this.updateState(this.$props);
100+
},
97101
},
98102
computed: {
99103
getHeaders() {
@@ -105,10 +109,10 @@ const ReactiveBase = {
105109
...(enableTelemetry === false && { 'X-Enable-Telemetry': false }),
106110
}),
107111
...headers,
108-
...(endpoint
109-
&& endpoint.headers && {
110-
...endpoint.headers,
111-
}),
112+
...(endpoint &&
113+
endpoint.headers && {
114+
...endpoint.headers,
115+
}),
112116
};
113117
},
114118
},
@@ -118,8 +122,8 @@ const ReactiveBase = {
118122
this.key = `${this.state.key}-0`;
119123
},
120124
setStore(props) {
121-
const credentials
122-
= props.url && props.url.trim() !== '' && !props.credentials
125+
const credentials =
126+
props.url && props.url.trim() !== '' && !props.credentials
123127
? null
124128
: props.credentials;
125129
let url = props.url && props.url.trim() !== '' ? props.url : '';
@@ -147,6 +151,7 @@ const ReactiveBase = {
147151
analyticsConfig: props.reactivesearchAPIConfig,
148152
mongodb: props.mongodb,
149153
endpoint: props.endpoint,
154+
httpRequestTimeout: (props.httpRequestTimeout || 0) * 1000 || 30000,
150155
};
151156
let queryParams = '';
152157

@@ -203,8 +208,8 @@ const ReactiveBase = {
203208
// When endpoint prop is used index is not defined, so we use _default
204209
index: appbaseRef.app || '_default',
205210
globalCustomEvents:
206-
this.$props.reactivesearchAPIConfig
207-
&& this.$props.reactivesearchAPIConfig.customEvents,
211+
this.$props.reactivesearchAPIConfig &&
212+
this.$props.reactivesearchAPIConfig.customEvents,
208213
};
209214

210215
try {
@@ -214,13 +219,13 @@ const ReactiveBase = {
214219
/\/\/(.*?)\/.*/,
215220
'//$1',
216221
);
217-
const headerCredentials
218-
= this.$props.endpoint.headers && this.$props.endpoint.headers.Authorization;
219-
analyticsInitConfig.credentials
220-
= headerCredentials && headerCredentials.replace('Basic ', '');
222+
const headerCredentials =
223+
this.$props.endpoint.headers && this.$props.endpoint.headers.Authorization;
224+
analyticsInitConfig.credentials =
225+
headerCredentials && headerCredentials.replace('Basic ', '');
221226
// Decode the credentials
222-
analyticsInitConfig.credentials
223-
= analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
227+
analyticsInitConfig.credentials =
228+
analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
224229
}
225230
} catch (e) {
226231
console.error('Endpoint not set correctly for analytics');

packages/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@appbaseio/rheostat": "^1.0.0-alpha.15",
4343
"@emotion/core": "^10.0.28",
4444
"@emotion/styled": "^10.0.27",
45-
"appbase-js": "^5.2.0",
45+
"appbase-js": "^5.3.3",
4646
"cross-env": "^5.2.0",
4747
"dayjs": "^1.11.7",
4848
"downshift": "^1.31.2",

packages/web/src/components/basic/ReactiveBase.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ReactiveBase extends Component {
5353
],
5454
() => {
5555
this.setStore(this.props);
56-
this.setState(state => ({
56+
this.setState((state) => ({
5757
key: `${state.key}-0`,
5858
}));
5959
},
@@ -78,28 +78,26 @@ class ReactiveBase extends Component {
7878
}
7979

8080
get headers() {
81-
const {
82-
headers, reactivesearchAPIConfig, mongodb, endpoint,
83-
} = this.props;
81+
const { headers, reactivesearchAPIConfig, mongodb, endpoint } = this.props;
8482
const { enableTelemetry } = reactivesearchAPIConfig || {};
8583
return {
8684
...(!mongodb && {
8785
'X-Search-Client': X_SEARCH_CLIENT,
8886
...(enableTelemetry === false && { 'X-Enable-Telemetry': false }),
8987
}),
9088
...headers,
91-
...(endpoint
92-
&& endpoint.headers && {
93-
...endpoint.headers,
94-
}),
89+
...(endpoint &&
90+
endpoint.headers && {
91+
...endpoint.headers,
92+
}),
9593
};
9694
}
9795

9896
setStore = (props) => {
9997
this.type = props.type ? props.type : '*';
10098

101-
const credentials
102-
= props.url && props.url.trim() !== '' && !props.credentials ? null : props.credentials;
99+
const credentials =
100+
props.url && props.url.trim() !== '' && !props.credentials ? null : props.credentials;
103101

104102
let url = props.url && props.url.trim() !== '' ? props.url : '';
105103
if (props.endpoint instanceof Object) {
@@ -125,6 +123,7 @@ class ReactiveBase extends Component {
125123
transformResponse: props.transformResponse,
126124
mongodb: props.mongodb,
127125
...(props.endpoint instanceof Object && { endpoint: props.endpoint }),
126+
httpRequestTimeout: props.httpRequestTimeout * 1000,
128127
};
129128

130129
let queryParams = '';
@@ -184,13 +183,13 @@ class ReactiveBase extends Component {
184183
if (this.props.endpoint && this.props.endpoint.url) {
185184
// Remove parts between '//' and first '/' in the url
186185
analyticsInitConfig.url = this.props.endpoint.url.replace(/\/\/(.*?)\/.*/, '//$1');
187-
const headerCredentials
188-
= this.props.endpoint.headers && this.props.endpoint.headers.Authorization;
189-
analyticsInitConfig.credentials
190-
= headerCredentials && headerCredentials.replace('Basic ', '');
186+
const headerCredentials =
187+
this.props.endpoint.headers && this.props.endpoint.headers.Authorization;
188+
analyticsInitConfig.credentials =
189+
headerCredentials && headerCredentials.replace('Basic ', '');
191190
// Decode the credentials
192-
analyticsInitConfig.credentials
193-
= analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
191+
analyticsInitConfig.credentials =
192+
analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
194193
}
195194
} catch (e) {
196195
console.error('Endpoint not set correctly for analytics');
@@ -223,9 +222,9 @@ class ReactiveBase extends Component {
223222

224223
// server side rendered app to collect context
225224
if (
226-
typeof window === 'undefined'
227-
&& props.contextCollector
228-
&& !this.calledContextCollector
225+
typeof window === 'undefined' &&
226+
props.contextCollector &&
227+
!this.calledContextCollector
229228
) {
230229
this.calledContextCollector = true;
231230
const res = props.contextCollector({
@@ -271,6 +270,7 @@ ReactiveBase.defaultProps = {
271270
graphQLUrl: '',
272271
as: 'div',
273272
endpoint: null,
273+
httpRequestTimeout: 30,
274274
};
275275

276276
ReactiveBase.propTypes = {
@@ -301,6 +301,7 @@ ReactiveBase.propTypes = {
301301
preferences: types.preferences,
302302
endpoint: types.endpoint,
303303
contextCollector: types.func,
304+
httpRequestTimeout: types.number,
304305
};
305306

306307
export default ReactiveBase;

0 commit comments

Comments
 (0)