1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix cluster-role-bindings/__tests__/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-04-11 11:11:18 -04:00
parent 2d3aab2179
commit 668cac691e
41 changed files with 1547 additions and 1556 deletions

View File

@ -129,6 +129,9 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-restricted-imports": ["error", {
"paths": ["."],
}],
"@typescript-eslint/member-delimiter-style": ["error", {
"multiline": {
"delimiter": "semi",

View File

@ -286,7 +286,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@sentry/types": "^6.19.3",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.4",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.5.0",
"@types/byline": "^4.2.33",
"@types/chart.js": "^2.9.36",
@ -315,9 +315,9 @@
"@types/npm": "^2.0.32",
"@types/proper-lockfile": "^4.1.2",
"@types/randomcolor": "^0.5.6",
"@types/react": "^17.0.44",
"@types/react": "^18.0.1",
"@types/react-beautiful-dnd": "^13.1.2",
"@types/react-dom": "^17.0.14",
"@types/react-dom": "^18.0.0",
"@types/react-router-dom": "^5.3.3",
"@types/react-table": "^7.7.11",
"@types/react-virtualized-auto-sizer": "^1.0.1",

View File

@ -0,0 +1,28 @@
/**
* 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 assert from "assert";
import { apiKubePrefix, isDevelopment } from "../vars";
import { createStoresAndApisInjectionToken } from "./create-stores-apis.token";
import { KubeJsonApi } from "./kube-json-api";
const apiKubeInjectable = getInjectable({
id: "api-kube",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "apiKube is only available in certain environments");
return new KubeJsonApi({
serverAddress: `http://127.0.0.1:${window.location.port}`,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": window.location.host,
},
});
},
});
export default apiKubeInjectable;

View File

@ -3,18 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { isClusterPageContext } from "../utils";
import { KubeJsonApi } from "./kube-json-api";
import { apiKubePrefix, isDevelopment } from "../vars";
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import apiKubeInjectable from "./api-kube.injectable";
export const apiKube = isClusterPageContext()
? new KubeJsonApi({
serverAddress: `http://127.0.0.1:${window.location.port}`,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": window.location.host,
},
})
: undefined as never;
export const apiKube = asLegacyGlobalForExtensionApi(apiKubeInjectable);

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
export const createStoresAndApisInjectionToken = getInjectionToken<boolean>({
id: "create-stores-and-apis-token",
});

View File

@ -0,0 +1,19 @@
/**
* 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 assert from "assert";
import { createStoresAndApisInjectionToken } from "../create-stores-apis.token";
import { ClusterRoleBindingApi } from "./cluster-role-binding.api";
const clusterRoleBindingApiInjectable = getInjectable({
id: "cluster-role-binding-api",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "clusterRoleBindingApi is only accessible in certain environments");
return new ClusterRoleBindingApi();
},
});
export default clusterRoleBindingApiInjectable;

View File

@ -2,7 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -51,7 +50,3 @@ export class ClusterRoleBindingApi extends KubeApi<ClusterRoleBinding, ClusterRo
});
}
}
export const clusterRoleBindingApi = isClusterPageContext()
? new ClusterRoleBindingApi()
: undefined as never;

View File

@ -0,0 +1,19 @@
/**
* 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 assert from "assert";
import { createStoresAndApisInjectionToken } from "../create-stores-apis.token";
import { ClusterRoleApi } from "./cluster-role.api";
const clusterRoleApiInjectable = getInjectable({
id: "cluster-role-api",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "clusterRoleApi is only available in certain environments");
return new ClusterRoleApi();
},
});
export default clusterRoleApiInjectable;

View File

@ -3,7 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -44,7 +43,3 @@ export class ClusterRoleApi extends KubeApi<ClusterRole, ClusterRoleData> {
});
}
}
export const clusterRoleApi = isClusterPageContext()
? new ClusterRoleApi()
: undefined as never;

View File

@ -36,6 +36,7 @@ export * from "./role-binding.api";
export * from "./secret.api";
export * from "./selfsubjectrulesreviews.api";
export * from "./service.api";
export * from "./service-accounts.api";
export * from "./service-account.api";
export * from "./stateful-set.api";
export * from "./storage-class.api";
export * from "./legacy-globals";

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import clusterRoleBindingApiInjectable from "./cluster-role-binding.api.injectable";
import clusterRoleApiInjectable from "./cluster-role.api.injectable";
import serviceAccountApiInjectable from "./service-account.api.injectable";
/**
* @deprecated use `di.inject(clusterRoleBindingApiInjectable)` instead
*/
export const clusterRoleBindingApi = asLegacyGlobalForExtensionApi(clusterRoleBindingApiInjectable);
/**
* @deprecated use `di.inject(clusterRoleApiInjectable)` instead
*/
export const clusterRoleApi = asLegacyGlobalForExtensionApi(clusterRoleApiInjectable);
/**
* @deprecated use `di.inject(serviceAccountApiInjectable)` instead
*/
export const serviceAccountApi = asLegacyGlobalForExtensionApi(serviceAccountApiInjectable);

View File

@ -0,0 +1,19 @@
/**
* 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 assert from "assert";
import { createStoresAndApisInjectionToken } from "../create-stores-apis.token";
import { ServiceAccountApi } from "./service-account.api";
const serviceAccountApiInjectable = getInjectable({
id: "service-account-api",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "serviceAccountApi is only available in certain environments");
return new ServiceAccountApi();
},
});
export default serviceAccountApiInjectable;

View File

@ -8,7 +8,6 @@ import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
export interface ServiceAccountData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
automountServiceAccountToken?: boolean;
@ -54,7 +53,3 @@ export class ServiceAccountApi extends KubeApi<ServiceAccount, ServiceAccountDat
});
}
}
export const serviceAccountApi = isClusterPageContext()
? new ServiceAccountApi()
: undefined as never;

View File

@ -3,6 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import clusterRoleBindingApiInjectable from "../../common/k8s-api/endpoints/cluster-role-binding.api.injectable";
import clusterRoleApiInjectable from "../../common/k8s-api/endpoints/cluster-role.api.injectable";
import serviceAccountApiInjectable from "../../common/k8s-api/endpoints/service-account.api.injectable";
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
/**
* @deprecated This function never works
* @returns false
@ -11,6 +16,10 @@ export function isAllowedResource(...args: any[]) {
return Boolean(void args);
}
export const serviceAccountsApi = asLegacyGlobalForExtensionApi(serviceAccountApiInjectable);
export const clusterRoleApi = asLegacyGlobalForExtensionApi(clusterRoleApiInjectable);
export const clusterRoleBindingApi = asLegacyGlobalForExtensionApi(clusterRoleBindingApiInjectable);
export { ResourceStack } from "../../common/k8s/resource-stack";
export { apiManager } from "../../common/k8s-api/api-manager";
export { KubeApi, forCluster, forRemoteCluster } from "../../common/k8s-api/kube-api";
@ -39,11 +48,11 @@ export { PersistentVolumeClaim, persistentVolumeClaimApi as pvcApi, PersistentVo
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints/storage-class.api";
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints/namespaces.api";
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints/events.api";
export { ServiceAccount, serviceAccountApi as serviceAccountsApi } from "../../common/k8s-api/endpoints/service-accounts.api";
export { ServiceAccount } from "../../common/k8s-api/endpoints/service-account.api";
export { Role, roleApi } from "../../common/k8s-api/endpoints/role.api";
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints/role-binding.api";
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints/cluster-role.api";
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints/cluster-role-binding.api";
export { ClusterRole } from "../../common/k8s-api/endpoints/cluster-role.api";
export { ClusterRoleBinding } from "../../common/k8s-api/endpoints/cluster-role-binding.api";
export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints/crd.api";
// types

View File

@ -7,6 +7,10 @@ import isAllowedResourceInjectable from "../../common/utils/is-allowed-resource.
import { castArray } from "lodash/fp";
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import type { BaseKubeJsonApiObjectMetadata } from "../../common/k8s-api/kube-object";
import clusterRoleBindingApiInjectable from "../../common/k8s-api/endpoints/cluster-role-binding.api.injectable";
import clusterRoleApiInjectable from "../../common/k8s-api/endpoints/cluster-role.api.injectable";
import serviceAccountApiInjectable from "../../common/k8s-api/endpoints/service-account.api.injectable";
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
export function isAllowedResource(resource: KubeResource | KubeResource[]) {
const resources = castArray(resource);
@ -21,6 +25,10 @@ export function isAllowedResource(resource: KubeResource | KubeResource[]) {
});
}
export const serviceAccountsApi = asLegacyGlobalForExtensionApi(serviceAccountApiInjectable);
export const clusterRoleApi = asLegacyGlobalForExtensionApi(clusterRoleApiInjectable);
export const clusterRoleBindingApi = asLegacyGlobalForExtensionApi(clusterRoleBindingApiInjectable);
export {
BaseKubeJsonApiObjectMetadata,
};
@ -52,11 +60,11 @@ export { PersistentVolumeClaim, persistentVolumeClaimApi as pvcApi, PersistentVo
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints";
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints";
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints";
export { ServiceAccount, serviceAccountApi as serviceAccountsApi } from "../../common/k8s-api/endpoints";
export { ServiceAccount } from "../../common/k8s-api/endpoints";
export { Role, roleApi } from "../../common/k8s-api/endpoints";
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints";
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints";
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints";
export { ClusterRole } from "../../common/k8s-api/endpoints";
export { ClusterRoleBinding } from "../../common/k8s-api/endpoints";
export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints";
export { KubeObjectStatusLevel } from "./kube-object-status";
export { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
@ -93,7 +101,7 @@ export type { PersistentVolumesStore } from "../../renderer/components/+storage-
export type { PersistentVolumeClaimStore as VolumeClaimStore } from "../../renderer/components/+storage-volume-claims/volume-claim.store";
export type { StorageClassStore } from "../../renderer/components/+storage-classes/storage-class.store";
export type { NamespaceStore } from "../../renderer/components/+namespaces/namespace-store/namespace.store";
export type { ServiceAccountsStore } from "../../renderer/components/+user-management/+service-accounts/store";
export type { ServiceAccountStore as ServiceAccountsStore } from "../../renderer/components/+user-management/+service-accounts/store";
export type { RolesStore } from "../../renderer/components/+user-management/+roles/store";
export type { RoleBindingStore as RoleBindingsStore } from "../../renderer/components/+user-management/+role-bindings/store";
export type { CRDStore } from "../../renderer/components/+custom-resources/crd.store";

View File

@ -0,0 +1,14 @@
/**
* 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 { createStoresAndApisInjectionToken } from "../common/k8s-api/create-stores-apis.token";
const createStoresAndApisInjectable = getInjectable({
id: "create-stores-and-apis",
instantiate: () => false,
injectionToken: createStoresAndApisInjectionToken,
});
export default createStoresAndApisInjectable;

View File

@ -3,22 +3,4 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { JsonApiErrorParsed } from "../../common/k8s-api/json-api";
import type { Response } from "node-fetch";
import { Notifications } from "../components/notifications";
import { apiBase, apiKube } from "../../common/k8s-api";
export { apiBase, apiKube } from "../../common/k8s-api";
// Common handler for HTTP api errors
export function onApiError(error: JsonApiErrorParsed, res: Response) {
switch (res.status) {
case 403:
error.isUsedForNotification = true;
Notifications.error(error);
break;
}
}
if (apiBase) apiBase.onError.addListener(onApiError);
if (apiKube) apiKube.onError.addListener(onApiError);

View File

@ -0,0 +1,17 @@
/**
* 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;
}
}

View File

@ -0,0 +1,21 @@
/**
* 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 apiKubeInjectable from "../../common/k8s-api/api-kube.injectable";
import { onApiError } from "./on-api-error";
const setupOnApiErrorListenersInjectable = getInjectable({
id: "setup-on-api-error-listeners",
setup: async (di) => {
const apiKube = await di.inject(apiKubeInjectable);
apiBase?.onError.addListener(onApiError);
apiKube?.onError.addListener(onApiError);
},
instantiate: () => undefined,
});
export default setupOnApiErrorListenersInjectable;

View File

@ -5,14 +5,13 @@
import React from "react";
import { ClusterRoleBindingDialog } from "../dialog";
import { clusterRolesStore } from "../../+cluster-roles/store";
import { ClusterRole } from "../../../../../common/k8s-api/endpoints";
import userEvent from "@testing-library/user-event";
import { getDiForUnitTesting } from "../../../../getDiForUnitTesting";
import type { DiRender } from "../../../test-utils/renderFor";
import { renderFor } from "../../../test-utils/renderFor";
jest.mock("../../+cluster-roles/store");
import clusterRoleStoreInjectable from "../../+cluster-roles/store.injectable";
import createStoresAndApisInjectable from "../../../../create-stores-apis.injectable";
describe("ClusterRoleBindingDialog tests", () => {
let render: DiRender;
@ -20,11 +19,15 @@ describe("ClusterRoleBindingDialog tests", () => {
beforeEach(async () => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
di.override(createStoresAndApisInjectable, () => true);
await di.runSetups();
render = renderFor(di);
clusterRolesStore.items.replace([
const store = di.inject(clusterRoleStoreInjectable);
store.items.replace([
new ClusterRole({
apiVersion: "rbac.authorization.k8s.io/v1",
kind: "ClusterRole",

View File

@ -18,7 +18,7 @@ import type { KubeObjectDetailsProps } from "../../kube-object-details";
import { KubeObjectMeta } from "../../kube-object-meta";
import { Table, TableCell, TableHead, TableRow } from "../../table";
import { ClusterRoleBindingDialog } from "./dialog";
import { clusterRoleBindingStore } from "./store";
import { clusterRoleBindingStore } from "./legacy-store";
import { hashSubject } from "../hashers";
export interface ClusterRoleBindingDetailsProps extends KubeObjectDetailsProps<ClusterRoleBinding> {

View File

@ -9,7 +9,7 @@ import { action, computed, makeObservable, observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import React from "react";
import { serviceAccountsStore } from "../+service-accounts/store";
import { serviceAccountStore } from "../+service-accounts/legacy-store";
import type { ClusterRole, ClusterRoleBinding, ServiceAccount } from "../../../../common/k8s-api/endpoints";
import type { DialogProps } from "../../dialog";
import { Dialog } from "../../dialog";
@ -20,8 +20,8 @@ import { SubTitle } from "../../layout/sub-title";
import { Notifications } from "../../notifications";
import { Select } from "../../select";
import { Wizard, WizardStep } from "../../wizard";
import { clusterRoleBindingStore } from "./store";
import { clusterRolesStore } from "../+cluster-roles/store";
import { clusterRoleBindingStore } from "./legacy-store";
import { clusterRolesStore } from "../+cluster-roles/legacy-store";
import { ObservableHashSet, nFircate } from "../../../utils";
import { Input } from "../../input";
import { TooltipPosition } from "../../tooltip";
@ -115,7 +115,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
const accountNames = new Set(saSubjects.map(acc => acc.name));
this.selectedAccounts.replace(
serviceAccountsStore.items
serviceAccountStore.items
.filter(sa => accountNames.has(sa.getName())),
);
this.selectedUsers.replace(uSubjects.map(user => user.name));
@ -223,7 +223,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
isMulti
themeName="light"
placeholder="Select service accounts ..."
options={serviceAccountsStore.items.slice()}
options={serviceAccountStore.items.slice()}
formatOptionLabel={value => (
<>
<Icon small material="account_box" />
@ -257,9 +257,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
<Wizard
header={(
<h5>
{action}
{" "}
ClusterRoleBinding
{`${action} ClusterRoleBinding`}
</h5>
)}
done={ClusterRoleBindingDialog.close}

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { asLegacyGlobalForExtensionApi } from "../../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import clusterRoleBindingStoreInjectable from "./store.injectable";
/**
* @deprecated use `di.inject(clusterRoleBindingStoreInjectable)` instead
*/
export const clusterRoleBindingStore = asLegacyGlobalForExtensionApi(clusterRoleBindingStoreInjectable);

View File

@ -0,0 +1,27 @@
/**
* 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 assert from "assert";
import { createStoresAndApisInjectionToken } from "../../../../common/k8s-api/create-stores-apis.token";
import clusterRoleBindingApiInjectable from "../../../../common/k8s-api/endpoints/cluster-role-binding.api.injectable";
import apiManagerInjectable from "../../kube-object-menu/dependencies/api-manager.injectable";
import { ClusterRoleBindingStore } from "./store";
const clusterRoleBindingStoreInjectable = getInjectable({
id: "cluster-role-binding-store",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "clusterRoleBindingStore is only accessible in certain environments");
const api = di.inject(clusterRoleBindingApiInjectable);
const apiManager = di.inject(apiManagerInjectable);
const store = new ClusterRoleBindingStore(api);
apiManager.registerStore(store);
return store;
},
});
export default clusterRoleBindingStoreInjectable;

View File

@ -3,12 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { apiManager } from "../../../../common/k8s-api/api-manager";
import type { ClusterRoleBinding, ClusterRoleBindingApi, ClusterRoleBindingData } from "../../../../common/k8s-api/endpoints";
import { clusterRoleBindingApi } from "../../../../common/k8s-api/endpoints";
import type { Subject } from "../../../../common/k8s-api/endpoints/types/subject";
import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
import { HashSet, isClusterPageContext } from "../../../utils";
import { HashSet } from "../../../utils";
import { hashSubject } from "../hashers";
export class ClusterRoleBindingStore extends KubeObjectStore<ClusterRoleBinding, ClusterRoleBindingApi, ClusterRoleBindingData> {
@ -37,11 +35,3 @@ export class ClusterRoleBindingStore extends KubeObjectStore<ClusterRoleBinding,
}
}
export const clusterRoleBindingStore = isClusterPageContext()
? new ClusterRoleBindingStore(clusterRoleBindingApi)
: undefined as never;
if (isClusterPageContext()) {
apiManager.registerStore(clusterRoleBindingStore);
}

View File

@ -10,7 +10,7 @@ import React from "react";
import { KubeObjectListLayout } from "../../kube-object-list-layout";
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
import { ClusterRoleBindingDialog } from "./dialog";
import { clusterRoleBindingStore } from "./store";
import { clusterRoleBindingStore } from "./legacy-store";
import { clusterRolesStore } from "../+cluster-roles/store";
import { serviceAccountsStore } from "../+service-accounts/store";
import { SiblingsInTabLayout } from "../../layout/siblings-in-tab-layout";

View File

@ -15,7 +15,7 @@ import { showDetails } from "../../kube-detail-params";
import { SubTitle } from "../../layout/sub-title";
import { Notifications } from "../../notifications";
import { Wizard, WizardStep } from "../../wizard";
import { clusterRolesStore } from "./store";
import { clusterRolesStore } from "./legacy-store";
export interface AddClusterRoleDialogProps extends Partial<DialogProps> {
}

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { asLegacyGlobalForExtensionApi } from "../../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import clusterRoleStoreInjectable from "./store.injectable";
/**
* @deprecated use `di.inject(clusterRoleStoreInjectable)` instead
*/
export const clusterRolesStore = asLegacyGlobalForExtensionApi(clusterRoleStoreInjectable);

View File

@ -0,0 +1,27 @@
/**
* 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 assert from "assert";
import { createStoresAndApisInjectionToken } from "../../../../common/k8s-api/create-stores-apis.token";
import clusterRoleApiInjectable from "../../../../common/k8s-api/endpoints/cluster-role.api.injectable";
import apiManagerInjectable from "../../kube-object-menu/dependencies/api-manager.injectable";
import { ClusterRolesStore } from "./store";
const clusterRoleStoreInjectable = getInjectable({
id: "cluster-role-store",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectionToken), "clusterRoleStore is only available in certain environments");
const api = di.inject(clusterRoleApiInjectable);
const apiManager = di.inject(apiManagerInjectable);
const store = new ClusterRolesStore(api);
apiManager.registerStore(store);
return store;
},
});
export default clusterRoleStoreInjectable;

View File

@ -2,11 +2,8 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { apiManager } from "../../../../common/k8s-api/api-manager";
import type { ClusterRole, ClusterRoleApi, ClusterRoleData } from "../../../../common/k8s-api/endpoints";
import { clusterRoleApi } from "../../../../common/k8s-api/endpoints";
import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
import { isClusterPageContext } from "../../../utils";
export class ClusterRolesStore extends KubeObjectStore<ClusterRole, ClusterRoleApi, ClusterRoleData> {
protected sortItems(items: ClusterRole[]) {
@ -16,11 +13,3 @@ export class ClusterRolesStore extends KubeObjectStore<ClusterRole, ClusterRoleA
]);
}
}
export const clusterRolesStore = isClusterPageContext()
? new ClusterRolesStore(clusterRoleApi)
: undefined as never;
if (isClusterPageContext()) {
apiManager.registerStore(clusterRolesStore);
}

View File

@ -10,7 +10,7 @@ import React from "react";
import { KubeObjectListLayout } from "../../kube-object-list-layout";
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
import { AddClusterRoleDialog } from "./add-dialog";
import { clusterRolesStore } from "./store";
import { clusterRolesStore } from "./legacy-store";
import { SiblingsInTabLayout } from "../../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../../kube-object/age";

View File

@ -18,7 +18,7 @@ import { showDetails } from "../../kube-detail-params";
import { SubTitle } from "../../layout/sub-title";
import { Notifications } from "../../notifications";
import { Wizard, WizardStep } from "../../wizard";
import { serviceAccountsStore } from "./store";
import { serviceAccountStore } from "./legacy-store";
export interface CreateServiceAccountDialogProps extends Partial<DialogProps> {
}
@ -47,7 +47,7 @@ export class CreateServiceAccountDialog extends React.Component<CreateServiceAcc
const { name, namespace } = this;
try {
const serviceAccount = await serviceAccountsStore.create({ namespace, name });
const serviceAccount = await serviceAccountStore.create({ namespace, name });
this.name = "";
showDetails(serviceAccount.selfLink);

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { asLegacyGlobalForExtensionApi } from "../../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import serviceAccountStoreInjectable from "./store.injectable";
/**
* @deprecated use `di.inject(serviceAccountStoreInjectable)` instead
*/
export const serviceAccountStore = asLegacyGlobalForExtensionApi(serviceAccountStoreInjectable);

View File

@ -0,0 +1,27 @@
/**
* 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 assert from "assert";
import serviceAccountApiInjectable from "../../../../common/k8s-api/endpoints/service-account.api.injectable";
import createStoresAndApisInjectable from "../../../create-stores-apis.injectable";
import apiManagerInjectable from "../../kube-object-menu/dependencies/api-manager.injectable";
import { ServiceAccountStore } from "./store";
const serviceAccountStoreInjectable = getInjectable({
id: "service-account-store",
instantiate: (di) => {
assert(di.inject(createStoresAndApisInjectable), "serviceAccountStore is only available in certain environments");
const api = di.inject(serviceAccountApiInjectable);
const apiManager = di.inject(apiManagerInjectable);
const store = new ServiceAccountStore(api);
apiManager.registerStore(store);
return store;
},
});
export default serviceAccountStoreInjectable;

View File

@ -3,24 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { apiManager } from "../../../../common/k8s-api/api-manager";
import type { ServiceAccount, ServiceAccountApi, ServiceAccountData } from "../../../../common/k8s-api/endpoints";
import { serviceAccountApi } from "../../../../common/k8s-api/endpoints";
import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
import { isClusterPageContext } from "../../../utils";
export class ServiceAccountsStore extends KubeObjectStore<ServiceAccount, ServiceAccountApi, ServiceAccountData> {
export class ServiceAccountStore extends KubeObjectStore<ServiceAccount, ServiceAccountApi, ServiceAccountData> {
protected async createItem(params: { name: string; namespace?: string }) {
await super.createItem(params);
return this.api.get(params); // hackfix: load freshly created account, cause it doesn't have "secrets" field yet
}
}
export const serviceAccountsStore = isClusterPageContext()
? new ServiceAccountsStore(serviceAccountApi)
: undefined as never;
if (isClusterPageContext()) {
apiManager.registerStore(serviceAccountsStore);
}

View File

@ -10,7 +10,7 @@ import React from "react";
import { KubeObjectListLayout } from "../../kube-object-list-layout";
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
import { CreateServiceAccountDialog } from "./create-dialog";
import { serviceAccountsStore } from "./store";
import { serviceAccountStore } from "./legacy-store";
import { SiblingsInTabLayout } from "../../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../../kube-object/age";
@ -29,7 +29,7 @@ export class ServiceAccounts extends React.Component {
isConfigurable
tableId="access_service_accounts"
className="ServiceAccounts"
store={serviceAccountsStore}
store={serviceAccountStore}
sortingCallbacks={{
[columnId.name]: account => account.getName(),
[columnId.namespace]: account => account.getNs(),

View File

@ -26,6 +26,7 @@ export interface DialogProps {
pinned?: boolean;
animated?: boolean;
"data-testid"?: string;
children?: React.ReactNode | React.ReactNode[];
}
interface DialogState {
@ -164,6 +165,6 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
return null;
}
return createPortal(dialog, document.body) as React.ReactPortal;
return createPortal(dialog, document.body);
}
}

View File

@ -14,7 +14,14 @@ type DiRenderFor = (di: DiContainer) => DiRender;
export const renderFor: DiRenderFor = (di) => (ui) => {
const result = testingLibraryRender(
<DiContextProvider value={{ di }}>{ui}</DiContextProvider>,
(
<DiContextProvider value={{ di }}>
{ui}
</DiContextProvider>
),
{
legacyRoot: true,
},
);
return {

View File

@ -18,6 +18,7 @@ export interface WizardCommonProps<D> {
reset?: () => void;
done?: () => void;
hideSteps?: boolean;
children?: React.ReactElement<WizardStepProps<D>>[] | React.ReactElement<WizardStepProps<D>>;
}
export interface WizardProps<D> extends WizardCommonProps<D> {
@ -26,7 +27,6 @@ export interface WizardProps<D> extends WizardCommonProps<D> {
title?: string;
header?: React.ReactNode;
onChange?: (step: number) => void;
children?: React.ReactElement<WizardStepProps<D>>[] | React.ReactElement<WizardStepProps<D>>;
}
interface State {

View File

@ -0,0 +1,16 @@
/**
* 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 { createStoresAndApisInjectionToken } from "../common/k8s-api/create-stores-apis.token";
import { isClusterPageContext } from "./utils";
const createStoresAndApisInjectable = getInjectable({
id: "create-stores-and-apis",
instantiate: () => isClusterPageContext(),
injectionToken: createStoresAndApisInjectionToken,
causesSideEffects: true,
});
export default createStoresAndApisInjectable;

2615
yarn.lock

File diff suppressed because it is too large Load Diff