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