diff --git a/src/extensions/renderer-api/components.ts b/src/extensions/renderer-api/components.ts index c5e48d29fe283..7173b592b38c4 100644 --- a/src/extensions/renderer-api/components.ts +++ b/src/extensions/renderer-api/components.ts @@ -62,6 +62,7 @@ export * from "../../renderer/components/chart/bar-chart"; export * from "../../renderer/components/chart/pie-chart"; // kube helpers +export * from "../../renderer/components/kube-detail-params"; export * from "../../renderer/components/kube-object-details"; export * from "../../renderer/components/kube-object-list-layout"; export * from "../../renderer/components/kube-object-menu"; diff --git a/src/extensions/renderer-api/navigation.ts b/src/extensions/renderer-api/navigation.ts index 0ec155cc3f64e..6c821b0e42b2c 100644 --- a/src/extensions/renderer-api/navigation.ts +++ b/src/extensions/renderer-api/navigation.ts @@ -23,7 +23,7 @@ import { navigation, PageParam, PageParamInit } from "../../renderer/navigation" export type { PageParamInit, PageParam } from "../../renderer/navigation/page-param"; export { navigate, isActiveRoute } from "../../renderer/navigation/helpers"; -export { hideDetails, showDetails, getDetailsUrl } from "../../renderer/components/kube-object-details"; +export { hideDetails, showDetails, getDetailsUrl } from "../../renderer/components/kube-detail-params"; export type { URLParams } from "../../common/utils/buildUrl"; export function createPageParam(init: PageParamInit) { diff --git a/src/renderer/components/+apps-releases/release-menu.tsx b/src/renderer/components/+apps-releases/release-menu.tsx index 30f048c8cb2e4..d74ffcc6ebb89 100644 --- a/src/renderer/components/+apps-releases/release-menu.tsx +++ b/src/renderer/components/+apps-releases/release-menu.tsx @@ -45,7 +45,7 @@ export class HelmReleaseMenu extends React.Component { const { release, hideDetails } = this.props; createUpgradeChartTab(release); - hideDetails && hideDetails(); + hideDetails?.(); } @boundMethod diff --git a/src/renderer/components/+storage-volume-claims/volume-claims.tsx b/src/renderer/components/+storage-volume-claims/volume-claims.tsx index aef558be823ff..e1f8e38527fbd 100644 --- a/src/renderer/components/+storage-volume-claims/volume-claims.tsx +++ b/src/renderer/components/+storage-volume-claims/volume-claims.tsx @@ -32,7 +32,7 @@ import { stopPropagation } from "../../utils"; import { storageClassApi } from "../../api/endpoints"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import type { VolumeClaimsRouteParams } from "../../../common/routes"; -import { getDetailsUrl } from "../kube-object-details"; +import { getDetailsUrl } from "../kube-detail-params"; enum columnId { name = "name", diff --git a/src/renderer/components/+storage-volumes/volume-details.tsx b/src/renderer/components/+storage-volumes/volume-details.tsx index 03bc4b4da7401..f8958414a3536 100644 --- a/src/renderer/components/+storage-volumes/volume-details.tsx +++ b/src/renderer/components/+storage-volumes/volume-details.tsx @@ -28,8 +28,9 @@ import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { PersistentVolume, pvcApi } from "../../api/endpoints"; -import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object-details"; +import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectMeta } from "../kube-object-meta/kube-object-meta"; +import { getDetailsUrl } from "../kube-detail-params"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+storage-volumes/volumes.tsx b/src/renderer/components/+storage-volumes/volumes.tsx index 54728c3da6b63..0d7cafd1b2f2c 100644 --- a/src/renderer/components/+storage-volumes/volumes.tsx +++ b/src/renderer/components/+storage-volumes/volumes.tsx @@ -25,7 +25,7 @@ import React from "react"; import { observer } from "mobx-react"; import { Link, RouteComponentProps } from "react-router-dom"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import { getDetailsUrl} from "../kube-object-details"; +import { getDetailsUrl } from "../kube-detail-params"; import { stopPropagation } from "../../utils"; import { volumesStore } from "./volumes.store"; import { pvcApi, storageClassApi } from "../../api/endpoints"; diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx index 635487d0cc546..6755edfa74299 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx +++ b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx @@ -30,7 +30,7 @@ import { ClusterRole, ClusterRoleBinding, ClusterRoleBindingSubject, ServiceAcco import { Dialog, DialogProps } from "../../dialog"; import { EditableList } from "../../editable-list"; import { Icon } from "../../icon"; -import { showDetails } from "../../kube-object-details"; +import { showDetails } from "../../kube-detail-params"; import { SubTitle } from "../../layout/sub-title"; import { Notifications } from "../../notifications"; import { Select, SelectOption } from "../../select"; diff --git a/src/renderer/components/+user-management/+role-bindings/dialog.tsx b/src/renderer/components/+user-management/+role-bindings/dialog.tsx index 62c32c0165bf4..6353145cc9ac7 100644 --- a/src/renderer/components/+user-management/+role-bindings/dialog.tsx +++ b/src/renderer/components/+user-management/+role-bindings/dialog.tsx @@ -32,7 +32,7 @@ import { ClusterRole, Role, roleApi, RoleBinding, RoleBindingSubject, ServiceAcc import { Dialog, DialogProps } from "../../dialog"; import { EditableList } from "../../editable-list"; import { Icon } from "../../icon"; -import { showDetails } from "../../kube-object-details"; +import { showDetails } from "../../kube-detail-params"; import { SubTitle } from "../../layout/sub-title"; import { Notifications } from "../../notifications"; import { Select, SelectOption } from "../../select"; diff --git a/src/renderer/components/+user-management/+service-accounts/create-dialog.tsx b/src/renderer/components/+user-management/+service-accounts/create-dialog.tsx index 457965c292201..5665835ff46cd 100644 --- a/src/renderer/components/+user-management/+service-accounts/create-dialog.tsx +++ b/src/renderer/components/+user-management/+service-accounts/create-dialog.tsx @@ -29,7 +29,7 @@ import { NamespaceSelect } from "../../+namespaces/namespace-select"; import { Dialog, DialogProps } from "../../dialog"; import { Input } from "../../input"; import { systemName } from "../../input/input_validators"; -import { showDetails } from "../../kube-object-details"; +import { showDetails } from "../../kube-detail-params"; import { SubTitle } from "../../layout/sub-title"; import { Notifications } from "../../notifications"; import { Wizard, WizardStep } from "../../wizard"; diff --git a/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx b/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx index 4e20dd4815b7d..195d254829764 100644 --- a/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx +++ b/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx @@ -29,9 +29,10 @@ import { Badge } from "../badge/badge"; import { jobStore } from "../+workloads-jobs/job.store"; import { Link } from "react-router-dom"; import { cronJobStore } from "./cronjob.store"; -import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object-details"; +import type { KubeObjectDetailsProps } from "../kube-object-details"; import type { CronJob, Job } from "../../api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta/kube-object-meta"; +import { getDetailsUrl } from "../kube-detail-params"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx b/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx index f977d713a0c4b..d48dc5bf27ef3 100644 --- a/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx +++ b/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx @@ -31,7 +31,7 @@ import { DrawerTitle } from "../drawer"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { replicaSetStore } from "../+workloads-replicasets/replicasets.store"; -import { showDetails } from "../kube-object-details"; +import { showDetails } from "../kube-detail-params"; enum sortBy { diff --git a/src/renderer/components/+workloads-pods/pod-details-list.tsx b/src/renderer/components/+workloads-pods/pod-details-list.tsx index 302105bb2d4a0..2ea299f5d07a7 100644 --- a/src/renderer/components/+workloads-pods/pod-details-list.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-list.tsx @@ -34,7 +34,7 @@ import { Table, TableCell, TableHead, TableRow } from "../table"; import { Spinner } from "../spinner"; import { DrawerTitle } from "../drawer"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; -import { showDetails } from "../kube-object-details"; +import { showDetails } from "../kube-detail-params"; enum sortBy { name = "name", diff --git a/src/renderer/components/+workloads-pods/pod-details.tsx b/src/renderer/components/+workloads-pods/pod-details.tsx index 308ff1216bc7a..530d60e159dcb 100644 --- a/src/renderer/components/+workloads-pods/pod-details.tsx +++ b/src/renderer/components/+workloads-pods/pod-details.tsx @@ -36,12 +36,13 @@ import { PodDetailsTolerations } from "./pod-details-tolerations"; import { Icon } from "../icon"; import { PodDetailsSecrets } from "./pod-details-secrets"; import { ResourceMetrics } from "../resource-metrics"; -import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object-details"; +import type { KubeObjectDetailsProps } from "../kube-object-details"; import { getItemMetrics } from "../../api/endpoints/metrics.api"; import { PodCharts, podMetricTabs } from "./pod-charts"; import { KubeObjectMeta } from "../kube-object-meta/kube-object-meta"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; +import { getDetailsUrl } from "../kube-detail-params"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+workloads-pods/pods.tsx b/src/renderer/components/+workloads-pods/pods.tsx index f04a4506f73a3..a3de5764fdf68 100644 --- a/src/renderer/components/+workloads-pods/pods.tsx +++ b/src/renderer/components/+workloads-pods/pods.tsx @@ -39,7 +39,7 @@ import { lookupApiLink } from "../../api/kube-api"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { Badge } from "../badge"; import type { PodsRouteParams } from "../../../common/routes"; -import { getDetailsUrl } from "../kube-object-details"; +import { getDetailsUrl } from "../kube-detail-params"; enum columnId { name = "name", diff --git a/src/renderer/components/kube-detail-params/index.ts b/src/renderer/components/kube-detail-params/index.ts new file mode 100644 index 0000000000000..146e52e6dd29c --- /dev/null +++ b/src/renderer/components/kube-detail-params/index.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +export * from "./params"; diff --git a/src/renderer/components/kube-detail-params/params.ts b/src/renderer/components/kube-detail-params/params.ts new file mode 100644 index 0000000000000..09256077d0631 --- /dev/null +++ b/src/renderer/components/kube-detail-params/params.ts @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import { createPageParam, navigation } from "../../navigation"; + +/** + * Used to store `object.selfLink` to show more info about resource in the details panel. + */ +export const kubeDetailsUrlParam = createPageParam({ + name: "kube-details", +}); + +/** + * Used to highlight last active/selected table row with the resource. + * + * @example + * If we go to "Nodes (page) -> Node (details) -> Pod (details)", + * last clicked Node should be "active" while Pod details are shown). + */ +export const kubeSelectedUrlParam = createPageParam({ + name: "kube-selected", + get defaultValue() { + return kubeDetailsUrlParam.get(); + } +}); + +export function showDetails(selfLink = "", resetSelected = true) { + const detailsUrl = getDetailsUrl(selfLink, resetSelected); + + navigation.merge({ search: detailsUrl }); +} + +export function hideDetails() { + showDetails(); +} + +export function getDetailsUrl(selfLink: string, resetSelected = false, mergeGlobals = true) { + console.debug("getDetailsUrl", { selfLink, resetSelected, mergeGlobals }); + const params = new URLSearchParams(mergeGlobals ? navigation.searchParams : ""); + + params.set(kubeDetailsUrlParam.name, selfLink); + + if (resetSelected) { + params.delete(kubeSelectedUrlParam.name); + } else { + params.set(kubeSelectedUrlParam.name, kubeSelectedUrlParam.get()); + } + + return `?${params}`; +} diff --git a/src/renderer/components/kube-object-details/kube-object-details.tsx b/src/renderer/components/kube-object-details/kube-object-details.tsx index fca0c2d67af21..5ef442ee333eb 100644 --- a/src/renderer/components/kube-object-details/kube-object-details.tsx +++ b/src/renderer/components/kube-object-details/kube-object-details.tsx @@ -24,7 +24,6 @@ import "./kube-object-details.scss"; import React from "react"; import { disposeOnUnmount, observer } from "mobx-react"; import { computed, observable, reaction, makeObservable } from "mobx"; -import { createPageParam, navigation } from "../../navigation"; import { Drawer } from "../drawer"; import type { KubeObject } from "../../api/kube-object"; import { Spinner } from "../spinner"; @@ -33,52 +32,8 @@ import { crdStore } from "../+custom-resources/crd.store"; import { KubeObjectMenu } from "../kube-object-menu"; import { KubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import logger from "../../../main/logger"; +import { hideDetails, kubeDetailsUrlParam } from "../kube-detail-params"; -/** - * Used to store `object.selfLink` to show more info about resource in the details panel. - */ -export const kubeDetailsUrlParam = createPageParam({ - name: "kube-details", -}); - -/** - * Used to highlight last active/selected table row with the resource. - * - * @example - * If we go to "Nodes (page) -> Node (details) -> Pod (details)", - * last clicked Node should be "active" while Pod details are shown). - */ -export const kubeSelectedUrlParam = createPageParam({ - name: "kube-selected", - get defaultValue() { - return kubeDetailsUrlParam.get(); - } -}); - -export function showDetails(selfLink = "", resetSelected = true) { - const detailsUrl = getDetailsUrl(selfLink, resetSelected); - - navigation.merge({ search: detailsUrl }); -} - -export function hideDetails() { - showDetails(); -} - -export function getDetailsUrl(selfLink: string, resetSelected = false, mergeGlobals = true) { - logger.debug("getDetailsUrl", { selfLink, resetSelected, mergeGlobals }); - const params = new URLSearchParams(mergeGlobals ? navigation.searchParams : ""); - - params.set(kubeDetailsUrlParam.name, selfLink); - - if (resetSelected) { - params.delete(kubeSelectedUrlParam.name); - } else { - params.set(kubeSelectedUrlParam.name, kubeSelectedUrlParam.get()); - } - - return `?${params}`; -} export interface KubeObjectDetailsProps { className?: string; diff --git a/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx b/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx index cd19c98bb4da7..07e3584cee7fb 100644 --- a/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx +++ b/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx @@ -31,7 +31,7 @@ import { kubeWatchApi } from "../../api/kube-watch-api"; import { clusterContext } from "../context"; import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter"; import { ResourceKindMap, ResourceNames } from "../../utils/rbac"; -import { kubeSelectedUrlParam, showDetails } from "../kube-object-details"; +import { kubeSelectedUrlParam, showDetails } from "../kube-detail-params"; export interface KubeObjectListLayoutProps extends ItemListLayoutProps { store: KubeObjectStore; diff --git a/src/renderer/components/kube-object-menu/kube-object-menu.tsx b/src/renderer/components/kube-object-menu/kube-object-menu.tsx index 56954dd27b82f..5da4427778c4b 100644 --- a/src/renderer/components/kube-object-menu/kube-object-menu.tsx +++ b/src/renderer/components/kube-object-menu/kube-object-menu.tsx @@ -24,7 +24,7 @@ import { boundMethod, cssNames } from "../../utils"; import type { KubeObject } from "../../api/kube-object"; import { editResourceTab } from "../dock/edit-resource.store"; import { MenuActions, MenuActionsProps } from "../menu/menu-actions"; -import { hideDetails } from "../kube-object-details"; +import { hideDetails } from "../kube-detail-params"; import { apiManager } from "../../api/api-manager"; import { KubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry";