Skip to content

Commit

Permalink
Merge pull request #74 from andymchugh/sametab
Browse files Browse the repository at this point in the history
same tab links
  • Loading branch information
andymchugh authored Jun 11, 2024
2 parents ffaaaf1 + 8c01043 commit 754e3e3
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## 1.x.0

Link in the Same Tab
--------------------
This adds the ability to configure links to open in the same tab rather than a new tab.
It can be set at the cell, panel or site level. New config terms in siteConfig and panelConfig:
- siteConfig:linkWindow
- panelConfig:linkWindow
- panelConfig:cells.cell-name.link.sameTab

Link Variables
---------------
This adds the ability to define link url substitutions to simplify oft-repeated base urls
Expand Down
2 changes: 1 addition & 1 deletion provisioning/dashboardData/links.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions provisioning/dashboardData/linksSameTab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions provisioning/dashboardData/linksSameTabPanel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

#------------------------------------------------------------------------------
# Panel Config

cellIdPreamble: "cell-"

cells:
website:
link:
url: "https://github.com/andymchugh/andrewbmchugh-flow-panel"
params: null
13 changes: 13 additions & 0 deletions provisioning/dashboardData/linksSameTabPanelCellSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

#------------------------------------------------------------------------------
# Panel Config

cellIdPreamble: "cell-"

cells:
website:
link:
url: "https://github.com/andymchugh/andrewbmchugh-flow-panel"
params: null
sameTab: true
15 changes: 15 additions & 0 deletions provisioning/dashboardData/linksSameTabPanelSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

#------------------------------------------------------------------------------
# Panel Config

cellIdPreamble: "cell-"

linkWindow:
sameTab: true

cells:
website:
link:
url: "https://github.com/andymchugh/andrewbmchugh-flow-panel"
params: null
7 changes: 7 additions & 0 deletions provisioning/dashboardData/linksSameTabSiteSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

#------------------------------------------------------------------------------
# Site Config

linkWindow:
sameTab: true
101 changes: 99 additions & 2 deletions provisioning/dashboards/links.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/components/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type Threshold = {
export type Link = {
url: string;
params: LinkUrlParams;
sameTab: boolean | undefined;
};

export type Background = {
Expand Down Expand Up @@ -128,9 +129,14 @@ export type ZoomPanPinch = {
wheelActivationKeys: string[] | undefined;
};

type LinkWindow = {
sameTab: boolean;
};

export type SiteConfig = {
zoomPanPinch: ZoomPanPinch;
variableThresholdScalars: Map<string, VariableThresholdScalars[]>;
linkWindow: LinkWindow,
linkVariables: Map<string, string>;
links: Map<string, Link>;
colors: Map<string, string>;
Expand All @@ -141,6 +147,7 @@ export type SiteConfig = {
export type PanelConfig = {
test: TestConfig;
zoomPanPinch: ZoomPanPinch;
linkWindow: LinkWindow,
linkVariables: Map<string, string>;
background: Background;
animationsPresent: boolean;
Expand Down Expand Up @@ -183,6 +190,7 @@ export function panelConfigFactory(config: any) {
return {
test: config.test || {},
zoomPanPinch: config.zoomPanPinch || {},
linkWindow: config.linkWindow,
linkVariables: new Map<string, string>(Object.entries(config.linkVariables || {})),
background: config.background || {},
variableThresholdScalars: new Map<string, VariableThresholdScalars[]>(Object.entries(config.variableThresholdScalars || {})),
Expand All @@ -200,6 +208,7 @@ export function siteConfigFactory(config: any) {
config = config || {};
return {
zoomPanPinch: config.zoomPanPinch || {},
linkWindow: config.linkWindow,
linkVariables: new Map<string, string>(Object.entries(config.linkVariables || {})),
links: new Map<string, Link>(Object.entries(config.links || {})),
colors: new Map<string, string>(Object.entries(config.colors || {})),
Expand Down Expand Up @@ -255,9 +264,15 @@ function panelConfigDereference(siteConfig: SiteConfig, panelConfig: PanelConfig
colorBlend(cell, 'strokeColor', cell.strokeColorCompound);
colorBlend(cell, 'fillColor', cell.fillColorCompound);

// Links
if (!cell.link && cell.linkRef) {
cell.link = siteConfig.links.get(cell.linkRef);
}
if (cell.link) {
cell.link.sameTab = typeof cell.link.sameTab === 'boolean' ? cell.link.sameTab :
typeof panelConfig.linkWindow?.sameTab === 'boolean' ? panelConfig.linkWindow.sameTab :
typeof siteConfig.linkWindow?.sameTab === 'boolean' ? siteConfig.linkWindow.sameTab : false;
}

if (cell.label) {
if (typeof cell.label.decimalPoints === 'undefined') {
Expand Down
3 changes: 2 additions & 1 deletion src/components/FlowPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ function clickHandlerFactory(elementAttribs: Map<string, SvgElementAttribs>, lin
if (link) {
const url = constructUrl(link, attribs, linkVariables);
if (url) {
window.open(getTemplateSrv().replace(url));
const sameTarget = link.sameTab && !event.ctrlKey && !event.shiftKey;
window.open(getTemplateSrv().replace(url), (sameTarget ? '_self' : undefined));
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion yaml_defs/panelConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ zoomPanPinch:
wheelActivationKeys: ["Alt"]

#------------------------------------------------------------------------------
# Version 1.14.0 onwards: This section defines panel level defaults for the link window
linkWindow:
# Default for '<cell>.link.sameTab'.
sameTab: true

# Version 1.14.0 onwards: Link variables will be substituted in urls prior to passing through
# grafana variable substitution. Variables should be defined in the same format as grafana variables.
# i.e. ${urlBasePlugin}. These variables can be defined in siteConfig or panelConfig.
Expand Down Expand Up @@ -408,7 +413,12 @@ cells:
# aren't available as grafana-variables.
# 'all': all params will be appended
params: "time"


# Version 1.14.0 onwards: When set the url will be opened in the same tab unless the
# <CTRL> or <SHFT> overrides are depressed. When undefined the setting falls back to
# the panel level 'linkWindow.sameTab' and then to the site level 'linkWindow.sameTab'.
sameTab: true

# This defines an ID to a link defined in the siteConfig. If you want to share a
# link just within the panelConfig you should instead use a yaml anchor/alias.
# The above 'link' field takes precedence. Only if undefined will linkRef be
Expand Down
5 changes: 5 additions & 0 deletions yaml_defs/siteConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ variableThresholdScalars:
environment:
- {variableValuePattern: "dev", thresholdScalar: 0.2, cellIdPatternScope: ["inbox_depth"]}

# Version 1.14.0 onwards: This section defines site level defaults for the link window
linkWindow:
# Default for '<cell>.link.sameTab'.
sameTab: true

# Version 1.14.0 onwards: Link variables will be substituted in urls prior to passing through
# grafana variable substitution. Variables should be defined in the same format as grafana variables.
# i.e. ${urlBasePlugin}. These variables can be defined in siteConfig or panelConfig.
Expand Down

0 comments on commit 754e3e3

Please sign in to comment.