mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Implement a lot of technical requirements for behavioural unit tests
Note: the crux of this was to make routing env-agnostic, and not based on URLs as magic strings, but instead something type-enforced. Note: extension-based routes comply to same exact interface by "late-registering" their routes when installed. Routes are just injectables. Note: another chunk of global shared state is no more. Note: a lot of explicit side effects have been cornered to injectables. Note: a lot of stuff has become reactive as part if this. Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
086604630a
commit
5c8ca2c038
523 files changed
+11727
-5541
No files matched your search
+21
@@ -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 { NetworkPolicies } from "./network-policies";
|
||||
import networkPoliciesRouteInjectable from "../../../common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable";
|
||||
import { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
|
||||
|
||||
const networkPoliciesRouteComponentInjectable = getInjectable({
|
||||
id: "network-policies-route-component",
|
||||
|
||||
instantiate: (di) => ({
|
||||
route: di.inject(networkPoliciesRouteInjectable),
|
||||
Component: NetworkPolicies,
|
||||
}),
|
||||
|
||||
injectionToken: routeSpecificComponentInjectionToken,
|
||||
});
|
||||
|
||||
export default networkPoliciesRouteComponentInjectable;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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 { computed } from "mobx";
|
||||
|
||||
import networkPoliciesRouteInjectable from "../../../common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable";
|
||||
import { networkSidebarItemId } from "../+network/network-sidebar-items.injectable";
|
||||
import { sidebarItemsInjectionToken } from "../layout/sidebar-items.injectable";
|
||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||
import navigateToNetworkPoliciesInjectable from "../../../common/front-end-routing/routes/cluster/network/network-policies/navigate-to-network-policies.injectable";
|
||||
|
||||
const networkPoliciesSidebarItemsInjectable = getInjectable({
|
||||
id: "network-policies-sidebar-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const route = di.inject(networkPoliciesRouteInjectable);
|
||||
const navigateToNetworkPolicies = di.inject(navigateToNetworkPoliciesInjectable);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
||||
|
||||
return computed(() => [
|
||||
{
|
||||
id: "network-policies",
|
||||
parentId: networkSidebarItemId,
|
||||
title: "Network Policies",
|
||||
onClick: navigateToNetworkPolicies,
|
||||
isActive: routeIsActive,
|
||||
isVisible: route.isEnabled,
|
||||
orderNumber: 40,
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
injectionToken: sidebarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default networkPoliciesSidebarItemsInjectable;
|
||||
@@ -7,11 +7,10 @@ import "./network-policies.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router-dom";
|
||||
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
||||
import { networkPolicyStore } from "./network-policy.store";
|
||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||
import type { NetworkPoliciesRouteParams } from "../../../common/routes";
|
||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||
import { KubeObjectAge } from "../kube-object/age";
|
||||
|
||||
enum columnId {
|
||||
@@ -21,42 +20,41 @@ enum columnId {
|
||||
age = "age",
|
||||
}
|
||||
|
||||
export interface NetworkPoliciesProps extends RouteComponentProps<NetworkPoliciesRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class NetworkPolicies extends React.Component<NetworkPoliciesProps> {
|
||||
export class NetworkPolicies extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="network_policies"
|
||||
className="NetworkPolicies"
|
||||
store={networkPolicyStore}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: networkPolicy => networkPolicy.getName(),
|
||||
[columnId.namespace]: networkPolicy => networkPolicy.getNs(),
|
||||
[columnId.age]: networkPolicy => -networkPolicy.getCreationTimestamp(),
|
||||
}}
|
||||
searchFilters={[
|
||||
networkPolicy => networkPolicy.getSearchFields(),
|
||||
]}
|
||||
renderHeaderTitle="Network Policies"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
|
||||
{ className: "warning", showWithColumn: columnId.name },
|
||||
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
|
||||
{ title: "Policy Types", className: "type", id: columnId.types },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={networkPolicy => [
|
||||
networkPolicy.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={networkPolicy} />,
|
||||
networkPolicy.getNs(),
|
||||
networkPolicy.getTypes().join(", "),
|
||||
<KubeObjectAge key="age" object={networkPolicy} />,
|
||||
]}
|
||||
/>
|
||||
<SiblingsInTabLayout>
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="network_policies"
|
||||
className="NetworkPolicies"
|
||||
store={networkPolicyStore}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: networkPolicy => networkPolicy.getName(),
|
||||
[columnId.namespace]: networkPolicy => networkPolicy.getNs(),
|
||||
[columnId.age]: networkPolicy => -networkPolicy.getCreationTimestamp(),
|
||||
}}
|
||||
searchFilters={[
|
||||
networkPolicy => networkPolicy.getSearchFields(),
|
||||
]}
|
||||
renderHeaderTitle="Network Policies"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
|
||||
{ className: "warning", showWithColumn: columnId.name },
|
||||
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
|
||||
{ title: "Policy Types", className: "type", id: columnId.types },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={networkPolicy => [
|
||||
networkPolicy.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={networkPolicy} />,
|
||||
networkPolicy.getNs(),
|
||||
networkPolicy.getTypes().join(", "),
|
||||
<KubeObjectAge key="age" object={networkPolicy} />,
|
||||
]}
|
||||
/>
|
||||
</SiblingsInTabLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user