mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove legacy apiBase global
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2478136635
commit
2909674beb
@ -5,13 +5,7 @@
|
||||
|
||||
import type { JsonApi } from "./json-api";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
|
||||
export const apiBaseInjectionToken = getInjectionToken<JsonApi>({
|
||||
id: "api-base-token",
|
||||
});
|
||||
|
||||
/**
|
||||
* @deprecated switch to using apiBaseInjectionToken instead
|
||||
*/
|
||||
export const apiBase = asLegacyGlobalForExtensionApi(apiBaseInjectionToken);
|
||||
|
||||
@ -3,5 +3,4 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export { apiBase } from "./api-base";
|
||||
export { apiKube } from "./api-kube";
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { Response } from "node-fetch";
|
||||
import type { JsonApiErrorParsed } from "../../common/k8s-api/json-api";
|
||||
import { Notifications } from "../components/notifications";
|
||||
|
||||
export function onApiError(error: JsonApiErrorParsed, res: Response) {
|
||||
switch (res.status) {
|
||||
case 403:
|
||||
error.isUsedForNotification = true;
|
||||
Notifications.error(error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBase } from "../../common/k8s-api";
|
||||
import { onApiError } from "./on-api-error";
|
||||
import { beforeFrameStartsInjectionToken } from "../before-frame-starts/before-frame-starts-injection-token";
|
||||
|
||||
const setupOnApiErrorListenersInjectable = getInjectable({
|
||||
id: "setup-on-api-error-listeners",
|
||||
|
||||
instantiate: () => ({
|
||||
id: "setup-on-api-error-listeners",
|
||||
run: () => {
|
||||
apiBase?.onError.addListener(onApiError);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default setupOnApiErrorListenersInjectable;
|
||||
@ -32,7 +32,6 @@ import { ApiManager } from "../common/k8s-api/api-manager";
|
||||
import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable";
|
||||
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
|
||||
import apiManagerInjectable from "../common/k8s-api/api-manager/manager.injectable";
|
||||
import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.injectable";
|
||||
import { observable, computed, runInAction } from "mobx";
|
||||
import defaultShellInjectable from "./components/+preferences/default-shell.injectable";
|
||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||
@ -109,7 +108,6 @@ export const getDiForUnitTesting = (
|
||||
[
|
||||
startTopbarStateSyncInjectable,
|
||||
setupSystemCaInjectable,
|
||||
setupOnApiErrorListenersInjectable,
|
||||
].forEach((injectable) => {
|
||||
di.override(injectable, () => ({
|
||||
id: injectable.id,
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { onApiError } from "../api/on-api-error";
|
||||
import { apiKubePrefix } from "../../common/vars";
|
||||
import { apiKubeInjectionToken } from "../../common/k8s-api/api-kube";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token";
|
||||
import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable";
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||
|
||||
const apiKubeInjectable = getInjectable({
|
||||
id: "api-kube",
|
||||
@ -17,6 +17,7 @@ const apiKubeInjectable = getInjectable({
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "apiKube is only available in certain environments");
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
|
||||
const apiKube = createKubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||
@ -28,7 +29,14 @@ const apiKubeInjectable = getInjectable({
|
||||
},
|
||||
});
|
||||
|
||||
apiKube.onError.addListener(onApiError);
|
||||
apiKube.onError.addListener((error, res) => {
|
||||
switch (res.status) {
|
||||
case 403:
|
||||
error.isUsedForNotification = true;
|
||||
showErrorNotification(error);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return apiKube;
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user