Skip to content

Commit

Permalink
fix(geomappanel.tsx): fix erroneous handling of data links
Browse files Browse the repository at this point in the history
Data links can now also be provided as relative paths, not only as fully valid URL. Also localhost
aliases are provided.
  • Loading branch information
felix-mu committed May 29, 2024
1 parent 0191d85 commit 59fa3af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion provisioning/dashboards/dashboard_e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"links": [
{
"title": "",
"url": "http://localhost:3000/d/bdjtpgo45296ob/dashboard-e2e-copy?var-datalink_test=${__data.fields.name}"
"url": "http://localhost:3000/d/bdjtpgo45296ob/dashboard-e2e?var-datalink_test=${__data.fields.name}"
}
],
"mappings": [],
Expand Down
18 changes: 13 additions & 5 deletions src/GeomapPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,24 @@ export class GeomapPanel extends Component<Props, State> {

for (const [key, value] of url.searchParams) {
updateVars[key] = value;
}
}

const localhostAliases = [
"localhost",
"127.0.0.1"
]

if (location.origin === url.origin && this.props.fieldConfig.defaults.links![0].targetBlank === false) {
if ((location.origin === url.origin || (localhostAliases.includes(url.hostname) && localhostAliases.includes(location.hostname) && url.port === location.port)) &&
(this.props.fieldConfig.defaults.links![0].targetBlank === undefined ||
this.props.fieldConfig.defaults.links![0].targetBlank === false)) {
// Update url with query parameters
locationService.partial({ ...updateVars }, false);
locationService.partial({ ...updateVars }, true);
} else {
if (this.props.fieldConfig.defaults.links![0].targetBlank === false) {
if (this.props.fieldConfig.defaults.links![0].targetBlank === undefined ||
this.props.fieldConfig.defaults.links![0].targetBlank === false) {
location.replace(url);
} else {
window.open(url, "_blank")?.focus();
open(url, "_blank");
}

}
Expand Down

0 comments on commit 59fa3af

Please sign in to comment.