[NIFI-3035] disable deep linking when URL .searchParams and URL .search properties are unsupported by browser. This closes #1687

This commit is contained in:
Scott Aslan 2017-04-21 13:24:01 -04:00 committed by Matt Gilman
parent 0b95ccb90a
commit 57ccf97c58
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
1 changed files with 60 additions and 29 deletions

View File

@ -301,8 +301,21 @@
// Feature detection and browser support for URLSearchParams // Feature detection and browser support for URLSearchParams
if ('URLSearchParams' in window) { if ('URLSearchParams' in window) {
// get the `urlSearchParams` from the URL
var urlSearchParams = new URL(window.location).searchParams; var urlSearchParams = new URL(window.location).searchParams;
// if the `urlSearchParams` are `undefined` then the browser does not support
// the URL object's `.searchParams` property
if (!nf.Common.isDefinedAndNotNull(urlSearchParams)) {
// attempt to get the `urlSearchParams` using the URLSearchParams constructor and
// the URL object's `.search` property
urlSearchParams = new URLSearchParams(new URL(window.location).search);
}
var groupId = nfCanvasUtils.getGroupId(); var groupId = nfCanvasUtils.getGroupId();
// if the `urlSearchParams` are still `undefined` then the browser does not support
// the URL object's `.search` property. In this case we cannot support deep links.
if (nf.Common.isDefinedAndNotNull(urlSearchParams)) {
var componentIds = []; var componentIds = [];
if (urlSearchParams.get('processGroupId')) { if (urlSearchParams.get('processGroupId')) {
@ -318,6 +331,9 @@
} else { } else {
return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId); return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId);
} }
} else {
return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId);
}
} }
}, },
@ -406,11 +422,25 @@
}); });
// get all URL parameters // get all URL parameters
var url = new URL(window.location);
// get the `params` from the URL
var params = new URL(window.location).searchParams; var params = new URL(window.location).searchParams;
// if the `params` are undefined then the browser does not support
// the URL object's `.searchParams` property
if (!nf.Common.isDefinedAndNotNull(params)) {
// attempt to get the `params` using the URLSearchParams constructor and
// the URL object's `.search` property
params = new URLSearchParams(url.search);
}
// if the `params` are still `undefined` then the browser does not support
// the URL object's `.search` property. In this case we cannot support deep links.
if (nf.Common.isDefinedAndNotNull(params)) {
var params = new URLSearchParams(url.search);
params.set('processGroupId', groupId); params.set('processGroupId', groupId);
params.set('componentIds', selectedComponentIds.sort()); params.set('componentIds', selectedComponentIds.sort());
var url = new URL(window.location);
var newUrl = url.origin + url.pathname; var newUrl = url.origin + url.pathname;
if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId()) || selectedComponentIds.length > 0) { if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId()) || selectedComponentIds.length > 0) {
@ -430,6 +460,7 @@
window.history.replaceState({'previous_url': url.href}, window.document.title, newUrl); window.history.replaceState({'previous_url': url.href}, window.document.title, newUrl);
} }
}
}, },
/** /**