Skip to content

Commit

Permalink
Split out kube-detail URL params
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <[email protected]>
  • Loading branch information
Nokel81 committed Jul 29, 2021
1 parent 9c44411 commit 90da9da
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 61 deletions.
1 change: 1 addition & 0 deletions src/extensions/renderer-api/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/renderer-api/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<V>(init: PageParamInit<V>) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/+apps-releases/release-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class HelmReleaseMenu extends React.Component<Props> {
const { release, hideDetails } = this.props;

createUpgradeChartTab(release);
hideDetails && hideDetails();
hideDetails?.();
}

@boundMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/+storage-volumes/volume-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersistentVolume> {
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/+storage-volumes/volumes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CronJob> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/+workloads-pods/pod-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pod> {
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/+workloads-pods/pods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/components/kube-detail-params/index.ts
Original file line number Diff line number Diff line change
@@ -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";
67 changes: 67 additions & 0 deletions src/renderer/components/kube-detail-params/params.ts
Original file line number Diff line number Diff line change
@@ -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}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<T extends KubeObject = KubeObject> {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<K extends KubeObject> extends ItemListLayoutProps<K> {
store: KubeObjectStore<K>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 90da9da

Please sign in to comment.