mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
This works!
This commit is contained in:
parent
0c49d0c30d
commit
d57ffcbc4b
@ -74,7 +74,10 @@ export const isContentTypeApplicationJson = (headers: Headers) => {
|
||||
}
|
||||
|
||||
const contentType = headers.get('content-type');
|
||||
if (contentType && contentType.toLowerCase() === 'application/json') {
|
||||
if (
|
||||
contentType &&
|
||||
(contentType.toLowerCase() === 'application/json' || contentType.toLowerCase() === 'application/json-patch+json')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Observer, deepClone, generate, observe } from 'fast-json-patch';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useAsync } from 'react-use';
|
||||
|
||||
@ -103,8 +104,12 @@ export const QueryTemplateForm = ({ onCancel, onSave, queryToAdd, templateData }
|
||||
const temporaryDefaultTitle =
|
||||
data.description || t('explore.query-library.default-description', 'Public', { timestamp: timestamp });
|
||||
|
||||
if (templateData?.uid) {
|
||||
handleEditQueryTemplate({ uid: templateData.uid, partialSpec: { title: data.description } }).then((isSuccess) => {
|
||||
if (templateData?.fullSpec && templateData.uid) {
|
||||
const docCopy: DataQueryFullSpec = deepClone(templateData.fullSpec);
|
||||
const observer: Observer<DataQueryFullSpec> = observe(docCopy);
|
||||
docCopy.spec.title = data.description;
|
||||
const patch = generate(observer);
|
||||
handleEditQueryTemplate({ uid: templateData.uid, jsonPatch: patch }).then((isSuccess) => {
|
||||
onSave(isSuccess);
|
||||
});
|
||||
} else if (queryToAdd) {
|
||||
|
@ -33,7 +33,7 @@ export const queryLibraryApi = createApi({
|
||||
query: (editQueryTemplateCommand) => ({
|
||||
url: `${editQueryTemplateCommand.uid}`,
|
||||
method: 'PATCH',
|
||||
data: [{ op: 'replace', path: '/spec/title', value: editQueryTemplateCommand.partialSpec.title }],
|
||||
data: editQueryTemplateCommand.jsonPatch,
|
||||
}),
|
||||
invalidatesTags: ['QueryTemplatesList'],
|
||||
}),
|
||||
|
@ -27,6 +27,7 @@ export const BASE_URL = `/apis/${API_VERSION}/namespaces/default/querytemplates/
|
||||
// URL is optional for these requests
|
||||
interface QueryLibraryBackendRequest extends Pick<BackendSrvRequest, 'data' | 'method'> {
|
||||
url?: string;
|
||||
jsonFormat?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,6 +42,9 @@ export const baseQuery: BaseQueryFn<QueryLibraryBackendRequest, DataQuerySpecRes
|
||||
showErrorAlert: true,
|
||||
method: requestOptions.method || 'GET',
|
||||
data: requestOptions.data,
|
||||
headers: {
|
||||
'Content-type': 'application/json-patch+json',
|
||||
},
|
||||
});
|
||||
return await lastValueFrom(responseObservable);
|
||||
} catch (error) {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { Operation, ReplaceOperation } from 'fast-json-patch';
|
||||
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
|
||||
import { DataQueryFullSpec, DataQueryPartialSpec } from './api/types';
|
||||
@ -18,7 +20,7 @@ export type AddQueryTemplateCommand = {
|
||||
|
||||
export type EditQueryTemplateCommand = {
|
||||
uid: string;
|
||||
partialSpec: DataQueryPartialSpec;
|
||||
jsonPatch: Operation[];
|
||||
};
|
||||
|
||||
export type DeleteQueryTemplateCommand = {
|
||||
|
Loading…
Reference in New Issue
Block a user