Skip to content
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

feat(web-vue): add request timeout prop #2230

Merged
merged 5 commits into from
Jul 12, 2023
Merged
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
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@appbaseio/vue-emotion": "0.6.0-alpha.6",
"@emotion/css": "^11.10.5",
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
"appbase-js": "^5.2.0",
"appbase-js": "^5.3.3",
"compute-scroll-into-view": "^1.0.11",
"emotion": "11.0.0",
"hotkeys-js": "^3.8.7",
Expand Down
33 changes: 19 additions & 14 deletions packages/vue/src/components/ReactiveBase/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ReactiveBase = {
mongodb: types.mongodb,
endpoint: types.endpointConfig,
preferences: VueTypes.object,
httpRequestTimeout: VueTypes.number.def(30),
},
provide() {
let createCacheFn = createCache;
Expand Down Expand Up @@ -94,6 +95,9 @@ const ReactiveBase = {
mongodb() {
this.updateState(this.$props);
},
httpRequestTimeout() {
this.updateState(this.$props);
},
},
computed: {
getHeaders() {
Expand All @@ -105,10 +109,10 @@ const ReactiveBase = {
...(enableTelemetry === false && { 'X-Enable-Telemetry': false }),
}),
...headers,
...(endpoint
&& endpoint.headers && {
...endpoint.headers,
}),
...(endpoint &&
endpoint.headers && {
...endpoint.headers,
}),
};
},
},
Expand All @@ -118,8 +122,8 @@ const ReactiveBase = {
this.key = `${this.state.key}-0`;
},
setStore(props) {
const credentials
= props.url && props.url.trim() !== '' && !props.credentials
const credentials =
props.url && props.url.trim() !== '' && !props.credentials
? null
: props.credentials;
let url = props.url && props.url.trim() !== '' ? props.url : '';
Expand Down Expand Up @@ -147,6 +151,7 @@ const ReactiveBase = {
analyticsConfig: props.reactivesearchAPIConfig,
mongodb: props.mongodb,
endpoint: props.endpoint,
httpRequestTimeout: (props.httpRequestTimeout || 0) * 1000 || 30000,
};
let queryParams = '';

Expand Down Expand Up @@ -203,8 +208,8 @@ const ReactiveBase = {
// When endpoint prop is used index is not defined, so we use _default
index: appbaseRef.app || '_default',
globalCustomEvents:
this.$props.reactivesearchAPIConfig
&& this.$props.reactivesearchAPIConfig.customEvents,
this.$props.reactivesearchAPIConfig &&
this.$props.reactivesearchAPIConfig.customEvents,
};

try {
Expand All @@ -214,13 +219,13 @@ const ReactiveBase = {
/\/\/(.*?)\/.*/,
'//$1',
);
const headerCredentials
= this.$props.endpoint.headers && this.$props.endpoint.headers.Authorization;
analyticsInitConfig.credentials
= headerCredentials && headerCredentials.replace('Basic ', '');
const headerCredentials =
this.$props.endpoint.headers && this.$props.endpoint.headers.Authorization;
analyticsInitConfig.credentials =
headerCredentials && headerCredentials.replace('Basic ', '');
// Decode the credentials
analyticsInitConfig.credentials
= analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
analyticsInitConfig.credentials =
analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
}
} catch (e) {
console.error('Endpoint not set correctly for analytics');
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@appbaseio/rheostat": "^1.0.0-alpha.15",
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"appbase-js": "^5.2.0",
"appbase-js": "^5.3.3",
"cross-env": "^5.2.0",
"dayjs": "^1.11.7",
"downshift": "^1.31.2",
Expand Down
39 changes: 20 additions & 19 deletions packages/web/src/components/basic/ReactiveBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ReactiveBase extends Component {
],
() => {
this.setStore(this.props);
this.setState(state => ({
this.setState((state) => ({
key: `${state.key}-0`,
}));
},
Expand All @@ -78,28 +78,26 @@ class ReactiveBase extends Component {
}

get headers() {
const {
headers, reactivesearchAPIConfig, mongodb, endpoint,
} = this.props;
const { headers, reactivesearchAPIConfig, mongodb, endpoint } = this.props;
const { enableTelemetry } = reactivesearchAPIConfig || {};
return {
...(!mongodb && {
'X-Search-Client': X_SEARCH_CLIENT,
...(enableTelemetry === false && { 'X-Enable-Telemetry': false }),
}),
...headers,
...(endpoint
&& endpoint.headers && {
...endpoint.headers,
}),
...(endpoint &&
endpoint.headers && {
...endpoint.headers,
}),
};
}

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

const credentials
= props.url && props.url.trim() !== '' && !props.credentials ? null : props.credentials;
const credentials =
props.url && props.url.trim() !== '' && !props.credentials ? null : props.credentials;

let url = props.url && props.url.trim() !== '' ? props.url : '';
if (props.endpoint instanceof Object) {
Expand All @@ -125,6 +123,7 @@ class ReactiveBase extends Component {
transformResponse: props.transformResponse,
mongodb: props.mongodb,
...(props.endpoint instanceof Object && { endpoint: props.endpoint }),
httpRequestTimeout: props.httpRequestTimeout * 1000,
};

let queryParams = '';
Expand Down Expand Up @@ -184,13 +183,13 @@ class ReactiveBase extends Component {
if (this.props.endpoint && this.props.endpoint.url) {
// Remove parts between '//' and first '/' in the url
analyticsInitConfig.url = this.props.endpoint.url.replace(/\/\/(.*?)\/.*/, '//$1');
const headerCredentials
= this.props.endpoint.headers && this.props.endpoint.headers.Authorization;
analyticsInitConfig.credentials
= headerCredentials && headerCredentials.replace('Basic ', '');
const headerCredentials =
this.props.endpoint.headers && this.props.endpoint.headers.Authorization;
analyticsInitConfig.credentials =
headerCredentials && headerCredentials.replace('Basic ', '');
// Decode the credentials
analyticsInitConfig.credentials
= analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
analyticsInitConfig.credentials =
analyticsInitConfig.credentials && atob(analyticsInitConfig.credentials);
}
} catch (e) {
console.error('Endpoint not set correctly for analytics');
Expand Down Expand Up @@ -223,9 +222,9 @@ class ReactiveBase extends Component {

// server side rendered app to collect context
if (
typeof window === 'undefined'
&& props.contextCollector
&& !this.calledContextCollector
typeof window === 'undefined' &&
props.contextCollector &&
!this.calledContextCollector
) {
this.calledContextCollector = true;
const res = props.contextCollector({
Expand Down Expand Up @@ -271,6 +270,7 @@ ReactiveBase.defaultProps = {
graphQLUrl: '',
as: 'div',
endpoint: null,
httpRequestTimeout: 30,
};

ReactiveBase.propTypes = {
Expand Down Expand Up @@ -301,6 +301,7 @@ ReactiveBase.propTypes = {
preferences: types.preferences,
endpoint: types.endpoint,
contextCollector: types.func,
httpRequestTimeout: types.number,
};

export default ReactiveBase;
Loading