VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

Payload is serialized JSON? #461

Closed jacksongoode closed 3 months ago

jacksongoode commented 3 months ago
image

I'm guessing this is some bug unless the code has to be serialized that way? Here's the code for that panel.

    {
      "datasource": {
        "type": "grafana-postgresql-datasource",
        "uid": "Timescale"
      },
      "description": "",
      "gridPos": {
        "h": 2,
        "w": 12,
        "x": 12,
        "y": 40
      },
      "id": 15,
      "options": {
        "buttonGroup": {
          "orientation": "center",
          "size": "md"
        },
        "confirmModal": {
          "body": "Please confirm to delete",
          "cancel": "Cancel",
          "columns": {
            "include": [],
            "name": "Label",
            "newValue": "New Value",
            "oldValue": "Old Value"
          },
          "confirm": "Delete",
          "elementDisplayMode": "modified",
          "title": "Confirm deletion"
        },
        "elementValueChanged": "",
        "elements": [],
        "initial": {
          "code": "const id = \"$note_id\";\nconst notes = context.panel.data.series[0].fields[0].values;\n\nif (notes.includes(parseInt(id))) {\n  context.panel.options.submit.text = `Delete note ${note_id}`;\n  context.panel.enableSubmit();\n} else {\n  context.panel.options.submit.text = \"No note selected\";\n  context.panel.disableSubmit();\n}\n\nreturn;",
          "contentType": "application/json",
          "datasource": "Timescale",
          "getPayload": "",
          "highlight": false,
          "highlightColor": "red",
          "method": "datasource",
          "payload": {}
        },
        "layout": {
          "orientation": "horizontal",
          "padding": 10,
          "sectionVariant": "default",
          "variant": "none"
        },
        "reset": {
          "backgroundColor": "purple",
          "foregroundColor": "yellow",
          "icon": "trash-alt",
          "text": "Delete",
          "variant": "hidden"
        },
        "resetAction": {
          "code": "",
          "confirm": false,
          "getPayload": "return {\n  rawSql: '',\n  format: 'table',\n}",
          "mode": "custom",
          "payload": {}
        },
        "saveDefault": {
          "icon": "save",
          "text": "Save Default",
          "variant": "hidden"
        },
        "submit": {
          "backgroundColor": "purple",
          "foregroundColor": "yellow",
          "icon": "trash-alt",
          "text": "No note selected",
          "variant": "destructive"
        },
        "sync": true,
        "update": {
          "code": "const id = \"$note_id\";\nconst notes = context.panel.data.series[0].fields[0].values;\n\nif (!notes.includes(parseInt(id))) {\n  context.grafana.notifyWarning(['Warning', 'No note selected or note ID doesn\\'t exist']);\n} else if (context.panel.response) {\n  context.grafana.notifySuccess(['Update', 'Values deleted successfully']);\n  context.grafana.refresh();\n} else {\n  context.grafana.notifyError(['Failed', 'An error occurred deleting values']);\n}",
          "confirm": true,
          "contentType": "application/json",
          "datasource": "Timescale",
          "getPayload": "return \"$note_id\";",
          "method": "datasource",
          "payload": {
            "0": "c",
            "1": "o",
            "2": "n",
            "3": "s",
            "4": "t",
            "5": " ",
            "6": "p",
            "7": "a",
            "8": "y",
            "9": "l",
            "10": "o",
            "11": "a",
            "12": "d",
            "13": " ",
            "14": "=",
            "15": " ",
            "16": "{",
            "17": "}",
            "18": ";",
            "19": "\n",
            "20": "\n",
            "21": "c",
            "22": "o",
            "23": "n",
            "24": "t",
            "25": "e",
            "26": "x",
            "27": "t",
            "28": ".",
            "29": "p",
            "30": "a",
            "31": "n",
            "32": "e",
            "33": "l",
            "34": ".",
            "35": "e",
            "36": "l",
            "37": "e",
            "38": "m",
            "39": "e",
            "40": "n",
            "41": "t",
            "42": "s",
            "43": ".",
            "44": "f",
            "45": "o",
            "46": "r",
            "47": "E",
            "48": "a",
            "49": "c",
            "50": "h",
            "51": "(",
            "52": "(",
            "53": "e",
            "54": "l",
            "55": "e",
            "56": "m",
            "57": "e",
            "58": "n",
            "59": "t",
            "60": ")",
            "61": " ",
            "62": "=",
            "63": ">",
            "64": " ",
            "65": "{",
            "66": "\n",
            "67": " ",
            "68": " ",
            "69": "i",
            "70": "f",
            "71": " ",
            "72": "(",
            "73": "!",
            "74": "e",
            "75": "l",
            "76": "e",
            "77": "m",
            "78": "e",
            "79": "n",
            "80": "t",
            "81": ".",
            "82": "v",
            "83": "a",
            "84": "l",
            "85": "u",
            "86": "e",
            "87": ")",
            "88": " ",
            "89": "{",
            "90": "\n",
            "91": " ",
            "92": " ",
            "93": " ",
            "94": " ",
            "95": "r",
            "96": "e",
            "97": "t",
            "98": "u",
            "99": "r",
            "100": "n",
            "101": ";",
            "102": "\n",
            "103": " ",
            "104": " ",
            "105": "}",
            "106": "\n",
            "107": "\n",
            "108": " ",
            "109": " ",
            "110": "p",
            "111": "a",
            "112": "y",
            "113": "l",
            "114": "o",
            "115": "a",
            "116": "d",
            "117": "[",
            "118": "e",
            "119": "l",
            "120": "e",
            "121": "m",
            "122": "e",
            "123": "n",
            "124": "t",
            "125": ".",
            "126": "i",
            "127": "d",
            "128": "]",
            "129": " ",
            "130": "=",
            "131": " ",
            "132": "e",
            "133": "l",
            "134": "e",
            "135": "m",
            "136": "e",
            "137": "n",
            "138": "t",
            "139": ".",
            "140": "v",
            "141": "a",
            "142": "l",
            "143": "u",
            "144": "e",
            "145": ";",
            "146": "\n",
            "147": "}",
            "148": ")",
            "149": "\n",
            "150": "\n",
            "151": "r",
            "152": "e",
            "153": "t",
            "154": "u",
            "155": "r",
            "156": "n",
            "157": " ",
            "158": "p",
            "159": "a",
            "160": "y",
            "161": "l",
            "162": "o",
            "163": "a",
            "164": "d",
            "165": ";",
            "editorMode": "code",
            "format": "table",
            "rawQuery": true,
            "rawSql": "delete from field_notes where id in (${payload});",
            "refId": "A",
            "sql": {
              "columns": [
                {
                  "parameters": [],
                  "type": "function"
                }
              ],
              "groupBy": [
                {
                  "property": {
                    "type": "string"
                  },
                  "type": "groupBy"
                }
              ],
              "limit": 50
            }
          },
          "payloadMode": "custom"
        },
        "updateEnabled": "manual"
      },
      "pluginVersion": "4.2.0",
mikhail-vl commented 3 months ago

@jacksongoode Thank you for letting us know. We will add migration logic to remove old serialized code in the upcoming release.

It's not required as we moved to using Data Source editor in 4.0.0.

jacksongoode commented 3 months ago

I'm using 4.2.0, how would I go about replacing this?

mikhail-vl commented 3 months ago

@jacksongoode You can remove it manually from the dashboard JSON or wait for 4.3.0 for migration scripts to clean it up.