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

Add backend service to custom code #331

Closed asimonok closed 10 months ago

asimonok commented 10 months ago

Resolve #320

Run datasource request with base64 in custom code

const uploadFiles = async () => {
  const file = elements[0].value[0];
  const fileBase64 = await context.utils.fileToBase64(file);

  return context.grafana.backendService.post('/api/ds/query', {
    queries: [{
      datasource: {
        type: 'postgres',
        uid: 'PCC52D03280B7034C'
      },
      format: 'table',
      rawSql: `
      INSERT INTO records
      VALUES ('${file.path}', '${fileBase64}');
      `
    }]
  })
}

return uploadFiles();

Get datasource query payload with base64

const getPayload = async () => {
  const file = elements[0].value[0];
  const fileBase64 = await context.utils.fileToBase64(file);

  return {
    format: 'table',
    rawSql: `
      INSERT INTO records
      VALUES ('${file.path}', '${fileBase64}');
      `
  }
}

return getPayload();
codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (c26e2ee) 97.98% compared to head (6f8bdb0) 97.98%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #331 +/- ## ======================================= Coverage 97.98% 97.98% ======================================= Files 66 66 Lines 1140 1144 +4 Branches 210 210 ======================================= + Hits 1117 1121 +4 Misses 13 13 Partials 10 10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.