mirror of https://github.com/apache/nifi.git
[NIFI-3035] disable deep linking when URL .searchParams and URL .search properties are unsupported by browser. This closes #1687
This commit is contained in:
parent
0b95ccb90a
commit
57ccf97c58
|
@ -301,20 +301,36 @@
|
||||||
|
|
||||||
// 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();
|
||||||
var componentIds = [];
|
|
||||||
|
|
||||||
if (urlSearchParams.get('processGroupId')) {
|
// if the `urlSearchParams` are still `undefined` then the browser does not support
|
||||||
groupId = urlSearchParams.get('processGroupId');
|
// the URL object's `.search` property. In this case we cannot support deep links.
|
||||||
}
|
if (nf.Common.isDefinedAndNotNull(urlSearchParams)) {
|
||||||
if (urlSearchParams.get('componentIds')) {
|
var componentIds = [];
|
||||||
componentIds = urlSearchParams.get('componentIds').split(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
// load the graph but do not update the browser history
|
if (urlSearchParams.get('processGroupId')) {
|
||||||
if (componentIds.length >= 1) {
|
groupId = urlSearchParams.get('processGroupId');
|
||||||
return nfCanvasUtils.showComponents(groupId, componentIds, forceCanvasLoad);
|
}
|
||||||
|
if (urlSearchParams.get('componentIds')) {
|
||||||
|
componentIds = urlSearchParams.get('componentIds').split(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
// load the graph but do not update the browser history
|
||||||
|
if (componentIds.length >= 1) {
|
||||||
|
return nfCanvasUtils.showComponents(groupId, componentIds, forceCanvasLoad);
|
||||||
|
} else {
|
||||||
|
return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId);
|
return nfCanvasUtils.getComponentByType('ProcessGroup').enterGroup(groupId);
|
||||||
}
|
}
|
||||||
|
@ -406,29 +422,44 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// get all URL parameters
|
// get all URL parameters
|
||||||
var params = new URL(window.location).searchParams;
|
|
||||||
params.set('processGroupId', groupId);
|
|
||||||
params.set('componentIds', selectedComponentIds.sort());
|
|
||||||
|
|
||||||
var url = new URL(window.location);
|
var url = new URL(window.location);
|
||||||
var newUrl = url.origin + url.pathname;
|
|
||||||
|
|
||||||
if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId()) || selectedComponentIds.length > 0) {
|
// get the `params` from the URL
|
||||||
if (!nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId())) {
|
var params = new URL(window.location).searchParams;
|
||||||
// we are in the root group so set processGroupId param value to 'root' alias
|
// if the `params` are undefined then the browser does not support
|
||||||
params.set('processGroupId', 'root');
|
// the URL object's `.searchParams` property
|
||||||
}
|
if (!nf.Common.isDefinedAndNotNull(params)) {
|
||||||
|
// attempt to get the `params` using the URLSearchParams constructor and
|
||||||
if ((url.origin + url.pathname + '?' + params.toString()).length <= nfCanvasUtils.MAX_URL_LENGTH) {
|
// the URL object's `.search` property
|
||||||
newUrl = url.origin + url.pathname + '?' + params.toString();
|
params = new URLSearchParams(url.search);
|
||||||
} else if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId())) {
|
|
||||||
// silently remove all component ids
|
|
||||||
params.set('componentIds', '');
|
|
||||||
newUrl = url.origin + url.pathname + '?' + params.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.history.replaceState({'previous_url': url.href}, window.document.title, newUrl);
|
// 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('componentIds', selectedComponentIds.sort());
|
||||||
|
|
||||||
|
var newUrl = url.origin + url.pathname;
|
||||||
|
|
||||||
|
if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId()) || selectedComponentIds.length > 0) {
|
||||||
|
if (!nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId())) {
|
||||||
|
// we are in the root group so set processGroupId param value to 'root' alias
|
||||||
|
params.set('processGroupId', 'root');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((url.origin + url.pathname + '?' + params.toString()).length <= nfCanvasUtils.MAX_URL_LENGTH) {
|
||||||
|
newUrl = url.origin + url.pathname + '?' + params.toString();
|
||||||
|
} else if (nfCommon.isDefinedAndNotNull(nfCanvasUtils.getParentGroupId())) {
|
||||||
|
// silently remove all component ids
|
||||||
|
params.set('componentIds', '');
|
||||||
|
newUrl = url.origin + url.pathname + '?' + params.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.history.replaceState({'previous_url': url.href}, window.document.title, newUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue