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

Update defaults code to use context #436

Closed mikhail-vl closed 4 months ago

mikhail-vl commented 4 months ago

Please validate if there is more to update.

/**
 * Initial Request
 */
export const INITIAL_CODE_DEFAULT = `console.log(data, response, initial, elements);

return;

/**
 * Data Source
 * Requires form elements to be defined
 */
const dataQuery = toDataQueryResponse(response);
console.log(dataQuery);`;

/**
 * Update Request
 */
export const UPDATE_CODE_DEFAULT = `if (response && response.ok) {
  notifySuccess(['Update', 'Values updated successfully.']);
  locationService.reload();
} else {
  notifyError(['Update', 'An error occured updating values.']);
}`;

/**
 * Reset Request
 */
export const RESET_CODE_DEFAULT = `console.log(data, response, initial, elements);`;

/**
 * Initial Payload
 */
export const INITIAL_PAYLOAD_DEFAULT = `return {
  rawSql: '',
  format: 'table',
}`;

/**
 * Update Payload
 */
export const UPDATE_PAYLOAD_DEFAULT = `const payload = {};

elements.forEach((element) => {
  if (!element.value) {
    return;
  }

  payload[element.id] = element.value;
})

return payload;

/**
 * Data Source payload
 */ 
return {
  rawSql: '',
  format: 'table',
};`;