Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds PUT/PATCH #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<!-- ALL-CONTRIBUTORS-BADGE:END -->

It provides a simple Grafana 7.x panel that shows only one button - to integrate with any kind of HTTP/REST API:
* Support `GET` and `POST` HTTP verb
* Support `GET`, `POST`, `PUT`, `PATCH` and `DELETE` HTTP verb
* Adds no new javascript dependencies
* Uses standard browser APIs and respects CORS
* Optional text payload for `POST` requests via syntax-highlighiting editor
* Support for custom header parameter or query parameter
* Variable support via `$variableName` in
* URL
* Header/Query parameter name & value
* POST body payload
* POST/PUT/PATCH body payload
* Button label
* Support for HTTP Basic Auth
* Custom label text & Grafana template design
Expand All @@ -38,7 +38,7 @@ Due to the Grafana API & security restrictions in modern browsers the following
* Neither username nor password are stored encryted in Grafana.
The password is there to everyone with access to the dashboard in Grafana!
* The *server* at the URL _must_ provide proper resposne to the [CORS pre-flight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request). That is:
* Provide a proper response to the `OPTIONS` request performed by the browser before the actual `GET`/`POST` requiest is issued
* Provide a proper response to the `OPTIONS` request performed by the browser before the actual `GET`/`POST`/`PUT`/`PATCH`/`DELETE` request is issued
* Provide a [`Access-Control-Allow-Credentials: true`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials) header
* Provide a proper [`Access-Control-Allow-Origin`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin) header.
_No wildcards_ are allowed if credentials are used!
Expand Down
2 changes: 1 addition & 1 deletion src/ButtonPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ButtonPanel extends PureComponent<Props, ButtonPanelState> {
//referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
};

if (options.method === 'POST') {
if (options.method === 'POST' || options.method == 'PUT' || options.method == 'PATCH') {
requestHeaders.set('Content-Type', options.contentType);
if (options.payload) {
fetchOpts.body = this.interpolateVariables(options.payload);
Expand Down
12 changes: 10 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
value: 'POST',
label: 'POST',
},
{
value: 'PUT',
label: 'PUT',
},
{
value: 'PATCH',
label: 'PATCH',
},
{
value: 'DELETE',
label: 'DELETE',
Expand Down Expand Up @@ -82,7 +90,7 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
{ label: 'text/plain', value: 'text/plain' },
],
},
showIf: (config) => config.method === 'POST',
showIf: (config) => (config.method === 'POST' || config.method == 'PUT' || config.method == 'PATCH'),
})
.addCustomEditor({
id: 'payload',
Expand All @@ -103,7 +111,7 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
}
},
},
showIf: (config) => config.method === 'POST',
showIf: (config) => (config.method === 'POST' || config.method == 'PUT' || config.method == 'PATCH'),
editor: ButtonPayloadEditor,
})
.addSelect({
Expand Down