mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Simplify requestPatchKubeResource impl
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b90e04e02d
commit
bc149f0627
@ -227,7 +227,7 @@ metadata:
|
|||||||
|
|
||||||
it("calls for save with just the adding version label", () => {
|
it("calls for save with just the adding version label", () => {
|
||||||
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
||||||
someNamespace,
|
"/apis/some-api-version/namespaces/some-uid",
|
||||||
[{
|
[{
|
||||||
op: "add",
|
op: "add",
|
||||||
path: "/metadata/labels",
|
path: "/metadata/labels",
|
||||||
@ -527,7 +527,7 @@ metadata:
|
|||||||
|
|
||||||
it("calls for save with changed configuration", () => {
|
it("calls for save with changed configuration", () => {
|
||||||
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
||||||
someNamespace,
|
"/apis/some-api-version/namespaces/some-uid",
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
op: "remove",
|
op: "remove",
|
||||||
@ -594,7 +594,7 @@ metadata:
|
|||||||
fireEvent.click(saveButton);
|
fireEvent.click(saveButton);
|
||||||
|
|
||||||
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
||||||
someNamespace,
|
"/apis/some-api-version/namespaces/some-uid",
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
op: "add",
|
op: "add",
|
||||||
@ -782,7 +782,7 @@ metadata:
|
|||||||
fireEvent.click(saveButton);
|
fireEvent.click(saveButton);
|
||||||
|
|
||||||
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
||||||
someOtherNamespace,
|
"/apis/some-api-version/namespaces/some-other-uid",
|
||||||
[{
|
[{
|
||||||
op: "add",
|
op: "add",
|
||||||
path: "/metadata/labels",
|
path: "/metadata/labels",
|
||||||
@ -855,7 +855,7 @@ metadata:
|
|||||||
fireEvent.click(saveButton);
|
fireEvent.click(saveButton);
|
||||||
|
|
||||||
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
|
||||||
someNamespace,
|
"/apis/some-api-version/namespaces/some-uid",
|
||||||
[ {
|
[ {
|
||||||
op: "add",
|
op: "add",
|
||||||
path: "/metadata/labels",
|
path: "/metadata/labels",
|
||||||
|
|||||||
@ -205,7 +205,7 @@ export class EditResourceModel {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.dependencies.callForPatchResource(this.resource, patches);
|
const result = await this.dependencies.callForPatchResource(selfLink, patches);
|
||||||
|
|
||||||
if (!result.callWasSuccessful) {
|
if (!result.callWasSuccessful) {
|
||||||
this.dependencies.showErrorNotification((
|
this.dependencies.showErrorNotification((
|
||||||
|
|||||||
@ -4,42 +4,36 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { AsyncResult } from "@k8slens/utilities";
|
import type { AsyncResult } from "@k8slens/utilities";
|
||||||
import apiManagerInjectable from "../../../../../common/k8s-api/api-manager/manager.injectable";
|
|
||||||
import type { JsonPatch } from "../../../../../common/k8s-api/kube-object.store";
|
import type { JsonPatch } from "../../../../../common/k8s-api/kube-object.store";
|
||||||
import type { KubeObject } from "../../../../../common/k8s-api/kube-object";
|
|
||||||
import assert from "assert";
|
|
||||||
import { getErrorMessage } from "../../../../../common/utils/get-error-message";
|
import { getErrorMessage } from "../../../../../common/utils/get-error-message";
|
||||||
|
import apiKubeInjectable from "../../../../k8s/api-kube.injectable";
|
||||||
|
import { patchTypeHeaders } from "../../../../../common/k8s-api/kube-api";
|
||||||
|
|
||||||
export type RequestPatchKubeResource = (
|
export type RequestPatchKubeResource = (selfLink: string, patch: JsonPatch) => AsyncResult<{ name: string; kind: string }>;
|
||||||
item: KubeObject,
|
|
||||||
patch: JsonPatch
|
|
||||||
) => AsyncResult<{ name: string; kind: string }>;
|
|
||||||
|
|
||||||
const requestPatchKubeResourceInjectable = getInjectable({
|
const requestPatchKubeResourceInjectable = getInjectable({
|
||||||
id: "request-patch-kube-resource",
|
id: "request-patch-kube-resource",
|
||||||
instantiate: (di): RequestPatchKubeResource => {
|
instantiate: (di): RequestPatchKubeResource => {
|
||||||
const apiManager = di.inject(apiManagerInjectable);
|
const apiKube = di.inject(apiKubeInjectable);
|
||||||
|
|
||||||
return async (item, patch) => {
|
|
||||||
const store = apiManager.getStore(item.selfLink);
|
|
||||||
|
|
||||||
assert(store);
|
|
||||||
|
|
||||||
let kubeObject: KubeObject;
|
|
||||||
|
|
||||||
|
return async (selfLink, patch) => {
|
||||||
try {
|
try {
|
||||||
kubeObject = await store.patch(item, patch);
|
const kubeObject = await apiKube.patch(selfLink, { data: patch }, {
|
||||||
} catch (e: any) {
|
headers: {
|
||||||
|
"content-type": patchTypeHeaders.json,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
callWasSuccessful: true,
|
||||||
|
response: { name: kubeObject.metadata.name, kind: kubeObject.kind },
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: getErrorMessage(e),
|
error: getErrorMessage(e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
callWasSuccessful: true,
|
|
||||||
response: { name: kubeObject.getName(), kind: kubeObject.kind },
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user