Skip to content
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
22 changes: 21 additions & 1 deletion table/schemas/migrate/migrate.cue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ _getLastKey: {
output: [for k, _ in #map {k}][len(#map) - 1]
}

// Function to return the last value of a map
_getLastValue: {
#map: struct.MinFields(1)
output: [for _, v in #map {v}][len(#map) - 1]
}

kind: "Table"
spec: {
if (*#panel.type | null) == "table" {
Expand Down Expand Up @@ -89,6 +95,17 @@ spec: {
// Same principle for width
"\({_reuseMatchingName & {#var: override.matcher.options}}.output)": widths: (*"\(property.value)" | "auto"): true
}
if property.id == "links" {
for link in property.value {
"\({_reuseMatchingName & {#var: override.matcher.options}}.output)": dataLinks: "\(link.url)": {
url: link.url
openNewTab: *link.targetBlank | false
if link.title != _|_ {
title: link.title
}
}
}
}
// NB: enrich this part when this is done https://github.com/perses/perses/issues/2852
}
}
Expand All @@ -109,6 +126,9 @@ spec: {
strconv.Atoi(_width),
][0]
}
if settings.dataLinks != _|_ {
dataLink: {_getLastValue & {#map: settings.dataLinks}}.output
}
}
}
for name, settings in _columnSettingsFromTansform {
Expand Down Expand Up @@ -143,7 +163,7 @@ spec: {
settings
}]
])

// Using flatten to get rid of the nested array for "value" mappings
// (https://cuelang.org/docs/howto/use-list-flattenn-to-flatten-lists/)
#cellSettings: list.FlattenN([
Expand Down
30 changes: 30 additions & 0 deletions table/schemas/migrate/tests/link-missing-values/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"kind": "Table",
"spec": {
"columnSettings": [
{
"name": "instance",
"dataLink": {
"url": "/graph?instance=${__data.fields[\"instance\"]}",
"openNewTab": false,
"title": "View Instance"
}
},
{
"name": "job",
"dataLink": {
"url": "/graph?instance=${__data.fields[\"job\"]}",
"openNewTab": true,
"title": "Job"
}
},
{
"name": "value",
"dataLink": {
"url": "/graph?instance=${__data.fields[\"value\"]}",
"openNewTab": false
}
}
]
}
}
104 changes: 104 additions & 0 deletions table/schemas/migrate/tests/link-missing-values/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DATASOURCE}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"displayMode": "auto"
},
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "instance"
},
"properties": [
{
"id": "links",
"value": [
{
"title": "View Instance",
"url": "/graph?instance=${__data.fields[\"instance\"]}"
}
]
}
]
},
{
"matcher": {
"id": "byName",
"options": "job"
},
"properties": [
{
"id": "links",
"value": [
{
"title": "Job",
"targetBlank": true,
"url": "/graph?instance=${__data.fields[\"job\"]}"
}
]
}
]
},
{
"matcher": {
"id": "byName",
"options": "value"
},
"properties": [
{
"id": "links",
"value": [
{
"url": "/graph?instance=${__data.fields[\"value\"]}"
}
]
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"showHeader": true
},
"pluginVersion": "10.1.8",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DATASOURCE}"
},
"expr": "up",
"format": "table",
"instant": true,
"refId": "A"
}
],
"title": "Table with Link Without TargetBlank",
"type": "table"
}
23 changes: 23 additions & 0 deletions table/schemas/migrate/tests/link/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"kind": "Table",
"spec": {
"columnSettings": [
{
"name": "instance",
"dataLink": {
"url": "/graph?instance=${__data.fields[\"instance\"]}",
"openNewTab": true,
"title": "View Instance"
}
},
{
"name": "job",
"dataLink": {
"url": "/d/job-dashboard?job=${__data.fields[\"job\"]}",
"openNewTab": false,
"title": ""
}
}
]
}
}
89 changes: 89 additions & 0 deletions table/schemas/migrate/tests/link/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DATASOURCE}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"displayMode": "auto"
},
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "instance"
},
"properties": [
{
"id": "links",
"value": [
{
"targetBlank": true,
"title": "View Instance",
"url": "/graph?instance=${__data.fields[\"instance\"]}"
}
]
}
]
},
{
"matcher": {
"id": "byName",
"options": "job"
},
"properties": [
{
"id": "links",
"value": [
{
"targetBlank": false,
"title": "",
"url": "/d/job-dashboard?job=${__data.fields[\"job\"]}"
}
]
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"showHeader": true
},
"pluginVersion": "10.1.8",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DATASOURCE}"
},
"expr": "up",
"format": "table",
"instant": true,
"refId": "A"
}
],
"title": "Table with Links",
"type": "table"
}
29 changes: 29 additions & 0 deletions table/schemas/migrate/tests/links-combined/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"kind": "Table",
"spec": {
"columnSettings": [
{
"name": "instance",
"dataLink": {
"url": "/graph?instance=${__data.fields[\"instance\"]}",
"openNewTab": true,
"title": "View Instance"
}
},
{
"name": "job",
"dataLink": {
"url": "/d/job-dashboard?job=${__data.fields[\"job\"]}",
"openNewTab": false
}
},
{
"name": "value",
"dataLink": {
"url": "http://example.com/second",
"openNewTab": true
}
}
]
}
}
Loading