PATCH v1 no json patch
This commit is contained in:
@@ -10,8 +10,8 @@ import { Input } from '@grafana/ui/src/components/Input/Input';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
import { getQueryDisplayText } from 'app/core/utils/richHistory';
|
||||
import { useAddQueryTemplateMutation, useEditQueryTemplateMutation } from 'app/features/query-library';
|
||||
import { DataQuerySpec } from 'app/features/query-library/api/types';
|
||||
import { AddQueryTemplateCommand } from 'app/features/query-library/types';
|
||||
import { DataQueryFullSpec } from 'app/features/query-library/api/types';
|
||||
import { AddQueryTemplateCommand, EditQueryTemplateCommand } from 'app/features/query-library/types';
|
||||
|
||||
import { useDatasource } from '../QueryLibrary/utils/useDatasource';
|
||||
|
||||
@@ -77,8 +77,8 @@ export const QueryTemplateForm = ({ onCancel, onSave, queryToAdd, templateData }
|
||||
});
|
||||
};
|
||||
|
||||
const handleEditQueryTemplate = async (EditQueryTemplateCommand: DataQuerySpec) => {
|
||||
return editQueryTemplate(EditQueryTemplateCommand)
|
||||
const handleEditQueryTemplate = async (editQueryTemplateCommand: EditQueryTemplateCommand) => {
|
||||
return editQueryTemplate(editQueryTemplateCommand)
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
getAppEvents().publish({
|
||||
@@ -103,11 +103,8 @@ export const QueryTemplateForm = ({ onCancel, onSave, queryToAdd, templateData }
|
||||
const temporaryDefaultTitle =
|
||||
data.description || t('explore.query-library.default-description', 'Public', { timestamp: timestamp });
|
||||
|
||||
if (templateData?.fullSpec) {
|
||||
handleEditQueryTemplate({
|
||||
...templateData.fullSpec,
|
||||
spec: { ...templateData.fullSpec.spec, title: data.description },
|
||||
}).then((isSuccess) => {
|
||||
if (templateData?.uid) {
|
||||
handleEditQueryTemplate({ uid: templateData.uid, partialSpec: { title: data.description } }).then((isSuccess) => {
|
||||
onSave(isSuccess);
|
||||
});
|
||||
} else if (queryToAdd) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DataQuery, DataSourceRef } from '@grafana/schema';
|
||||
import { DataQuerySpec } from 'app/features/query-library/api/types';
|
||||
import { DataQueryFullSpec } from 'app/features/query-library/api/types';
|
||||
|
||||
export type QueryTemplateRow = {
|
||||
index: string;
|
||||
@@ -10,5 +10,5 @@ export type QueryTemplateRow = {
|
||||
createdAtTimestamp?: number;
|
||||
user?: string;
|
||||
uid?: string;
|
||||
fullSpec?: DataQuerySpec;
|
||||
fullSpec?: DataQueryFullSpec;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { AddQueryTemplateCommand, DeleteQueryTemplateCommand, QueryTemplate } from '../types';
|
||||
import { AddQueryTemplateCommand, DeleteQueryTemplateCommand, EditQueryTemplateCommand, QueryTemplate } from '../types';
|
||||
|
||||
import { convertAddQueryTemplateCommandToDataQuerySpec, convertDataQueryResponseToQueryTemplates } from './mappers';
|
||||
import { baseQuery } from './query';
|
||||
import { DataQuerySpec } from './types';
|
||||
import { DataQueryFullSpec, DataQueryPartialSpec } from './types';
|
||||
|
||||
export const queryLibraryApi = createApi({
|
||||
baseQuery,
|
||||
@@ -29,11 +29,11 @@ export const queryLibraryApi = createApi({
|
||||
}),
|
||||
invalidatesTags: ['QueryTemplatesList'],
|
||||
}),
|
||||
editQueryTemplate: builder.mutation<void, DataQuerySpec>({
|
||||
editQueryTemplate: builder.mutation<void, EditQueryTemplateCommand>({
|
||||
query: (editQueryTemplateCommand) => ({
|
||||
url: `${editQueryTemplateCommand.metadata.name}`,
|
||||
method: 'PUT',
|
||||
data: editQueryTemplateCommand,
|
||||
url: `${editQueryTemplateCommand.uid}`,
|
||||
method: 'PATCH',
|
||||
data: [{ op: 'replace', path: '/spec/title', value: editQueryTemplateCommand.partialSpec.title }],
|
||||
}),
|
||||
invalidatesTags: ['QueryTemplatesList'],
|
||||
}),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AddQueryTemplateCommand, QueryTemplate } from '../types';
|
||||
|
||||
import { API_VERSION, QueryTemplateKinds } from './query';
|
||||
import { CREATED_BY_KEY, DataQuerySpec, DataQuerySpecResponse, DataQueryTarget } from './types';
|
||||
import { CREATED_BY_KEY, DataQueryFullSpec, DataQuerySpecResponse, DataQueryTarget } from './types';
|
||||
|
||||
export const parseCreatedByValue = (value?: string) => {
|
||||
// https://github.com/grafana/grafana/blob/main/pkg/services/user/identity.go#L194
|
||||
@@ -43,7 +43,7 @@ export const convertDataQueryResponseToQueryTemplates = (result: DataQuerySpecRe
|
||||
|
||||
export const convertAddQueryTemplateCommandToDataQuerySpec = (
|
||||
addQueryTemplateCommand: AddQueryTemplateCommand
|
||||
): DataQuerySpec => {
|
||||
): DataQueryFullSpec => {
|
||||
const { title, targets } = addQueryTemplateCommand;
|
||||
return {
|
||||
apiVersion: API_VERSION,
|
||||
|
||||
@@ -6,6 +6,14 @@ export type DataQueryTarget = {
|
||||
};
|
||||
|
||||
export type DataQuerySpec = {
|
||||
title: string;
|
||||
vars: object[]; // TODO: Detect variables in #86838
|
||||
targets: DataQueryTarget[];
|
||||
};
|
||||
|
||||
// TODO : change put in API to PATCH and use DataQuerySpec instead of the full spec to try to not have shenanigans
|
||||
|
||||
export type DataQueryFullSpec = {
|
||||
apiVersion: string;
|
||||
kind: string;
|
||||
metadata: {
|
||||
@@ -14,16 +22,14 @@ export type DataQuerySpec = {
|
||||
creationTimestamp?: string;
|
||||
annotations?: { [key: string]: string };
|
||||
};
|
||||
spec: {
|
||||
title: string;
|
||||
vars: object[]; // TODO: Detect variables in #86838
|
||||
targets: DataQueryTarget[];
|
||||
};
|
||||
spec: DataQuerySpec;
|
||||
};
|
||||
|
||||
export type DataQueryPartialSpec = Partial<DataQuerySpec>;
|
||||
|
||||
export type DataQuerySpecResponse = {
|
||||
apiVersion: string;
|
||||
items: DataQuerySpec[];
|
||||
items: DataQueryFullSpec[];
|
||||
};
|
||||
|
||||
export const CREATED_BY_KEY = 'grafana.app/createdBy';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
|
||||
import { DataQuerySpec } from './api/types';
|
||||
import { DataQueryFullSpec, DataQueryPartialSpec } from './api/types';
|
||||
|
||||
export type QueryTemplate = {
|
||||
uid: string;
|
||||
@@ -8,7 +8,7 @@ export type QueryTemplate = {
|
||||
targets: DataQuery[];
|
||||
createdAtTimestamp: number;
|
||||
user?: string;
|
||||
fullSpec: DataQuerySpec;
|
||||
fullSpec: DataQueryFullSpec;
|
||||
};
|
||||
|
||||
export type AddQueryTemplateCommand = {
|
||||
@@ -16,6 +16,11 @@ export type AddQueryTemplateCommand = {
|
||||
targets: DataQuery[];
|
||||
};
|
||||
|
||||
export type EditQueryTemplateCommand = {
|
||||
uid: string;
|
||||
partialSpec: DataQueryPartialSpec;
|
||||
};
|
||||
|
||||
export type DeleteQueryTemplateCommand = {
|
||||
uid: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user