mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add context menu entry for deleting local clusters (#2923)
This commit is contained in:
1 parent
e47d26e1ce
commit
eb45f45a7a
30 files changed
+348
-377
No files matched your search
@@ -26,28 +26,18 @@ import { Drawer, DrawerItem, DrawerItemLabels } from "../drawer";
|
||||
import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity";
|
||||
import type { CatalogCategory } from "../../../common/catalog";
|
||||
import { Icon } from "../icon";
|
||||
import { KubeObject } from "../../api/kube-object";
|
||||
import { CatalogEntityDrawerMenu } from "./catalog-entity-drawer-menu";
|
||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||
import type { CatalogEntityItem } from "./catalog-entity.store";
|
||||
|
||||
interface Props {
|
||||
entity: CatalogEntity;
|
||||
interface Props<T extends CatalogEntity> {
|
||||
item: CatalogEntityItem<T> | null | undefined;
|
||||
hideDetails(): void;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CatalogEntityDetails extends Component<Props> {
|
||||
private abortController?: AbortController;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.abortController?.abort();
|
||||
}
|
||||
|
||||
export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Props<T>> {
|
||||
categoryIcon(category: CatalogCategory) {
|
||||
if (category.metadata.icon.includes("<svg")) {
|
||||
return <Icon svg={category.metadata.icon} smallest />;
|
||||
@@ -56,16 +46,10 @@ export class CatalogEntityDetails extends Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
openEntity() {
|
||||
this.props.entity.onRun(catalogEntityRunContext);
|
||||
}
|
||||
|
||||
renderContent() {
|
||||
const { entity } = this.props;
|
||||
const labels = KubeObject.stringifyLabels(entity.metadata.labels);
|
||||
const detailItems = CatalogEntityDetailRegistry.getInstance().getItemsForKind(entity.kind, entity.apiVersion);
|
||||
const details = detailItems.map((item, index) => {
|
||||
return <item.components.Details entity={entity} key={index}/>;
|
||||
renderContent(item: CatalogEntityItem<T>) {
|
||||
const detailItems = CatalogEntityDetailRegistry.getInstance().getItemsForKind(item.kind, item.apiVersion);
|
||||
const details = detailItems.map(({ components }, index) => {
|
||||
return <components.Details entity={item.entity} key={index}/>;
|
||||
});
|
||||
|
||||
const showDetails = detailItems.find((item) => item.priority > 999) === undefined;
|
||||
@@ -76,29 +60,35 @@ export class CatalogEntityDetails extends Component<Props> {
|
||||
<div className="flex CatalogEntityDetails">
|
||||
<div className="EntityIcon box top left">
|
||||
<HotbarIcon
|
||||
uid={entity.metadata.uid}
|
||||
title={entity.metadata.name}
|
||||
source={entity.metadata.source}
|
||||
icon={entity.spec.iconData}
|
||||
onClick={() => this.openEntity()}
|
||||
uid={item.id}
|
||||
title={item.name}
|
||||
source={item.source}
|
||||
icon={item.entity.spec.iconData}
|
||||
disabled={!item?.enabled}
|
||||
onClick={() => item.onRun(catalogEntityRunContext)}
|
||||
size={128} />
|
||||
<div className="IconHint">
|
||||
Click to open
|
||||
</div>
|
||||
{item?.enabled && (
|
||||
<div className="IconHint">
|
||||
Click to open
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="box grow EntityMetadata">
|
||||
<DrawerItem name="Name">
|
||||
{entity.metadata.name}
|
||||
{item.name}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Kind">
|
||||
{entity.kind}
|
||||
{item.kind}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Source">
|
||||
{entity.metadata.source}
|
||||
{item.source}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Status">
|
||||
{item.phase}
|
||||
</DrawerItem>
|
||||
<DrawerItemLabels
|
||||
name="Labels"
|
||||
labels={labels}
|
||||
labels={item.labels}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -111,8 +101,8 @@ export class CatalogEntityDetails extends Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { entity, hideDetails } = this.props;
|
||||
const title = `${entity.kind}: ${entity.metadata.name}`;
|
||||
const { item, hideDetails } = this.props;
|
||||
const title = `${item.kind}: ${item.name}`;
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
@@ -120,10 +110,10 @@ export class CatalogEntityDetails extends Component<Props> {
|
||||
usePortal={true}
|
||||
open={true}
|
||||
title={title}
|
||||
toolbar={<CatalogEntityDrawerMenu entity={entity} key={entity.getId()} />}
|
||||
toolbar={<CatalogEntityDrawerMenu item={item} key={item.getId()} />}
|
||||
onClose={hideDetails}
|
||||
>
|
||||
{this.renderContent()}
|
||||
{item && this.renderContent(item)}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,10 @@ import { MenuItem } from "../menu";
|
||||
import { ConfirmDialog } from "../confirm-dialog";
|
||||
import { HotbarStore } from "../../../common/hotbar-store";
|
||||
import { Icon } from "../icon";
|
||||
import type { CatalogEntityItem } from "./catalog-entity.store";
|
||||
|
||||
export interface CatalogEntityDrawerMenuProps<T extends CatalogEntity> extends MenuActionsProps {
|
||||
entity: T | null | undefined;
|
||||
item: CatalogEntityItem<T> | null | undefined;
|
||||
}
|
||||
|
||||
@observer
|
||||
@@ -47,9 +48,9 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
|
||||
componentDidMount() {
|
||||
this.contextMenu = {
|
||||
menuItems: [],
|
||||
navigate: (url: string) => navigate(url)
|
||||
navigate: (url: string) => navigate(url),
|
||||
};
|
||||
this.props.entity?.onContextMenuOpen(this.contextMenu);
|
||||
this.props.item?.onContextMenuOpen(this.contextMenu);
|
||||
}
|
||||
|
||||
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
||||
@@ -107,19 +108,19 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.contextMenu) {
|
||||
const { className, item: entity, ...menuProps } = this.props;
|
||||
|
||||
if (!this.contextMenu || !entity.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { className, entity, ...menuProps } = this.props;
|
||||
|
||||
return (
|
||||
<MenuActions
|
||||
className={cssNames("CatalogEntityDrawerMenu", className)}
|
||||
toolbar
|
||||
{...menuProps}
|
||||
>
|
||||
{this.getMenuItems(entity)}
|
||||
{this.getMenuItems(entity.entity)}
|
||||
</MenuActions>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,17 @@ import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalo
|
||||
import { ItemObject, ItemStore } from "../../item.store";
|
||||
import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog";
|
||||
import { autoBind } from "../../../common/utils";
|
||||
export class CatalogEntityItem implements ItemObject {
|
||||
constructor(public entity: CatalogEntity) {}
|
||||
export class CatalogEntityItem<T extends CatalogEntity> implements ItemObject {
|
||||
constructor(public entity: T) {}
|
||||
|
||||
get kind() {
|
||||
return this.entity.kind;
|
||||
}
|
||||
|
||||
get apiVersion() {
|
||||
return this.entity.apiVersion;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.entity.metadata.name;
|
||||
}
|
||||
@@ -52,6 +56,10 @@ export class CatalogEntityItem implements ItemObject {
|
||||
return this.entity.status.phase;
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
return this.entity.status.enabled ?? true;
|
||||
}
|
||||
|
||||
get labels() {
|
||||
const labels: string[] = [];
|
||||
|
||||
@@ -87,7 +95,7 @@ export class CatalogEntityItem implements ItemObject {
|
||||
}
|
||||
}
|
||||
|
||||
export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
||||
export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntity>> {
|
||||
constructor() {
|
||||
super();
|
||||
makeObservable(this);
|
||||
@@ -95,6 +103,7 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
||||
}
|
||||
|
||||
@observable activeCategory?: CatalogCategory;
|
||||
@observable selectedItemId?: string;
|
||||
|
||||
@computed get entities() {
|
||||
if (!this.activeCategory) {
|
||||
@@ -104,6 +113,10 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
||||
return catalogEntityRegistry.getItemsForCategory(this.activeCategory).map(entity => new CatalogEntityItem(entity));
|
||||
}
|
||||
|
||||
@computed get selectedItem() {
|
||||
return this.entities.find(e => e.getId() === this.selectedItemId);
|
||||
}
|
||||
|
||||
watch() {
|
||||
const disposers: IReactionDisposer[] = [
|
||||
reaction(() => this.entities, () => this.loadAll()),
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
color: var(--colorSuccess);
|
||||
}
|
||||
|
||||
.disconnected {
|
||||
.disconnected, .deleting {
|
||||
color: var(--halfGray);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import type { CatalogEntityContextMenu, CatalogEntityContextMenuContext } from "
|
||||
import { Badge } from "../badge";
|
||||
import { HotbarStore } from "../../../common/hotbar-store";
|
||||
import { ConfirmDialog } from "../confirm-dialog";
|
||||
import { catalogCategoryRegistry } from "../../../common/catalog";
|
||||
import { catalogCategoryRegistry, CatalogEntity } from "../../../common/catalog";
|
||||
import { CatalogAddButton } from "./catalog-add-button";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { Notifications } from "../notifications";
|
||||
@@ -59,7 +59,6 @@ export class Catalog extends React.Component<Props> {
|
||||
@observable private catalogEntityStore?: CatalogEntityStore;
|
||||
@observable private contextMenu: CatalogEntityContextMenuContext;
|
||||
@observable activeTab?: string;
|
||||
@observable selectedItem?: CatalogEntityItem;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
@@ -79,7 +78,7 @@ export class Catalog extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
this.contextMenu = {
|
||||
menuItems: observable.array([]),
|
||||
navigate: (url: string) => navigate(url)
|
||||
navigate: (url: string) => navigate(url),
|
||||
};
|
||||
this.catalogEntityStore = new CatalogEntityStore();
|
||||
disposeOnUnmount(this, [
|
||||
@@ -103,13 +102,13 @@ export class Catalog extends React.Component<Props> {
|
||||
]);
|
||||
}
|
||||
|
||||
addToHotbar(item: CatalogEntityItem): void {
|
||||
addToHotbar(item: CatalogEntityItem<CatalogEntity>): void {
|
||||
HotbarStore.getInstance().addToHotbar(item.entity);
|
||||
}
|
||||
|
||||
onDetails(item: CatalogEntityItem) {
|
||||
this.selectedItem = item;
|
||||
}
|
||||
onDetails = (item: CatalogEntityItem<CatalogEntity>) => {
|
||||
this.catalogEntityStore.selectedItemId = item.getId();
|
||||
};
|
||||
|
||||
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
||||
if (menuItem.confirm) {
|
||||
@@ -144,7 +143,7 @@ export class Catalog extends React.Component<Props> {
|
||||
return <CatalogMenu activeItem={this.activeTab} onItemClick={this.onTabChange}/>;
|
||||
}
|
||||
|
||||
renderItemMenu = (item: CatalogEntityItem) => {
|
||||
renderItemMenu = (item: CatalogEntityItem<CatalogEntity>) => {
|
||||
const onOpen = () => {
|
||||
this.contextMenu.menuItems = [];
|
||||
|
||||
@@ -167,7 +166,7 @@ export class Catalog extends React.Component<Props> {
|
||||
);
|
||||
};
|
||||
|
||||
renderIcon(item: CatalogEntityItem) {
|
||||
renderIcon(item: CatalogEntityItem<CatalogEntity>) {
|
||||
return (
|
||||
<HotbarIcon
|
||||
uid={item.getId()}
|
||||
@@ -188,12 +187,12 @@ export class Catalog extends React.Component<Props> {
|
||||
store={this.catalogEntityStore}
|
||||
tableId="catalog-items"
|
||||
sortingCallbacks={{
|
||||
[sortBy.name]: (item: CatalogEntityItem) => item.name,
|
||||
[sortBy.source]: (item: CatalogEntityItem) => item.source,
|
||||
[sortBy.status]: (item: CatalogEntityItem) => item.phase,
|
||||
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
||||
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
||||
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
||||
}}
|
||||
searchFilters={[
|
||||
(entity: CatalogEntityItem) => entity.searchFields,
|
||||
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
||||
]}
|
||||
renderTableHeader={[
|
||||
{ title: "", className: css.iconCell },
|
||||
@@ -202,14 +201,17 @@ export class Catalog extends React.Component<Props> {
|
||||
{ title: "Labels", className: css.labelsCell },
|
||||
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
||||
]}
|
||||
renderTableContents={(item: CatalogEntityItem) => [
|
||||
customizeTableRowProps={(item: CatalogEntityItem<CatalogEntity>) => ({
|
||||
disabled: !item.enabled,
|
||||
})}
|
||||
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
||||
this.renderIcon(item),
|
||||
item.name,
|
||||
item.source,
|
||||
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
||||
]}
|
||||
onDetails={(item: CatalogEntityItem) => this.onDetails(item) }
|
||||
onDetails={this.onDetails}
|
||||
renderItemMenu={this.renderItemMenu}
|
||||
/>
|
||||
);
|
||||
@@ -224,13 +226,13 @@ export class Catalog extends React.Component<Props> {
|
||||
store={this.catalogEntityStore}
|
||||
tableId="catalog-items"
|
||||
sortingCallbacks={{
|
||||
[sortBy.name]: (item: CatalogEntityItem) => item.name,
|
||||
[sortBy.kind]: (item: CatalogEntityItem) => item.kind,
|
||||
[sortBy.source]: (item: CatalogEntityItem) => item.source,
|
||||
[sortBy.status]: (item: CatalogEntityItem) => item.phase,
|
||||
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
||||
[sortBy.kind]: (item: CatalogEntityItem<CatalogEntity>) => item.kind,
|
||||
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
||||
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
||||
}}
|
||||
searchFilters={[
|
||||
(entity: CatalogEntityItem) => entity.searchFields,
|
||||
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
||||
]}
|
||||
renderTableHeader={[
|
||||
{ title: "", className: css.iconCell },
|
||||
@@ -240,7 +242,10 @@ export class Catalog extends React.Component<Props> {
|
||||
{ title: "Labels", className: css.labelsCell },
|
||||
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
||||
]}
|
||||
renderTableContents={(item: CatalogEntityItem) => [
|
||||
customizeTableRowProps={(item: CatalogEntityItem<CatalogEntity>) => ({
|
||||
disabled: !item.enabled,
|
||||
})}
|
||||
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
||||
this.renderIcon(item),
|
||||
item.name,
|
||||
item.kind,
|
||||
@@ -248,8 +253,8 @@ export class Catalog extends React.Component<Props> {
|
||||
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
||||
]}
|
||||
detailsItem={this.selectedItem}
|
||||
onDetails={(item: CatalogEntityItem) => this.onDetails(item) }
|
||||
detailsItem={this.catalogEntityStore.selectedItem}
|
||||
onDetails={this.onDetails}
|
||||
renderItemMenu={this.renderItemMenu}
|
||||
/>
|
||||
);
|
||||
@@ -265,15 +270,18 @@ export class Catalog extends React.Component<Props> {
|
||||
<div className="p-6 h-full">
|
||||
{ this.catalogEntityStore.activeCategory ? this.renderSingleCategoryList() : this.renderAllCategoriesList() }
|
||||
</div>
|
||||
{ !this.selectedItem && (
|
||||
<CatalogAddButton category={this.catalogEntityStore.activeCategory} />
|
||||
)}
|
||||
{ this.selectedItem && (
|
||||
<CatalogEntityDetails
|
||||
entity={this.selectedItem.entity}
|
||||
hideDetails={() => this.selectedItem = null}
|
||||
/>
|
||||
)}
|
||||
{
|
||||
this.catalogEntityStore.selectedItem
|
||||
? (
|
||||
<CatalogEntityDetails
|
||||
item={this.catalogEntityStore.selectedItem}
|
||||
hideDetails={() => this.catalogEntityStore.selectedItemId = null}
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<CatalogAddButton category = {this.catalogEntityStore.activeCategory} />
|
||||
)
|
||||
}
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
this.contextMenu = {
|
||||
menuItems: [],
|
||||
navigate: (url: string) => navigate(url)
|
||||
navigate: (url: string) => navigate(url),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ function onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
||||
}
|
||||
|
||||
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
|
||||
const { uid, title, icon, active, className, source, disabled, onMenuOpen, children, ...rest } = props;
|
||||
const { uid, title, icon, active, className, source, disabled, onMenuOpen, onClick, children, ...rest } = props;
|
||||
const id = `hotbarIcon-${uid}`;
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
|
||||
@@ -77,7 +77,13 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
||||
src={icon}
|
||||
className={active ? "active" : "default"}
|
||||
width={size}
|
||||
height={size} />;
|
||||
height={size}
|
||||
onClick={(event) => {
|
||||
if (!disabled) {
|
||||
onClick?.(event);
|
||||
}
|
||||
}}
|
||||
/>;
|
||||
} else {
|
||||
return <Avatar
|
||||
{...rest}
|
||||
@@ -86,6 +92,11 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
||||
className={active ? "active" : "default"}
|
||||
width={size}
|
||||
height={size}
|
||||
onClick={(event) => {
|
||||
if (!disabled) {
|
||||
onClick?.(event);
|
||||
}
|
||||
}}
|
||||
/>;
|
||||
}
|
||||
};
|
||||
@@ -106,8 +117,10 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
||||
toggleEvent="contextmenu"
|
||||
position={{right: true, bottom: true }} // FIXME: position does not work
|
||||
open={() => {
|
||||
onMenuOpen?.();
|
||||
toggleMenu();
|
||||
if (!disabled) {
|
||||
onMenuOpen?.();
|
||||
toggleMenu();
|
||||
}
|
||||
}}
|
||||
close={() => toggleMenu()}>
|
||||
{ menuItems.map((menuItem) => {
|
||||
|
||||
@@ -25,7 +25,6 @@ import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, Upda
|
||||
import { Notifications, notificationsStore } from "../components/notifications";
|
||||
import { Button } from "../components/button";
|
||||
import { isMac } from "../../common/vars";
|
||||
import { invalidKubeconfigHandler } from "./invalid-kubeconfig-handler";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import { navigate } from "../navigation";
|
||||
import { entitySettingsURL } from "../../common/routes";
|
||||
@@ -87,7 +86,7 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
|
||||
|
||||
if (!wasDisplayed || (now - lastDisplayedAt) > intervalBetweenNotifications) {
|
||||
listNamespacesForbiddenHandlerDisplayedAt.set(clusterId, now);
|
||||
} else {
|
||||
} else {
|
||||
// don't bother the user too often
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +99,7 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
|
||||
<b>Add Accessible Namespaces</b>
|
||||
<p>Cluster <b>{ClusterStore.getInstance().getById(clusterId).name}</b> does not have permissions to list namespaces. Please add the namespaces you have access to.</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button active outlined label="Go to Accessible Namespaces Settings" onClick={()=> {
|
||||
<Button active outlined label="Go to Accessible Namespaces Settings" onClick={() => {
|
||||
navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "accessible-namespaces" }));
|
||||
notificationsStore.remove(notificationId);
|
||||
}} />
|
||||
@@ -120,7 +119,6 @@ export function registerIpcHandlers() {
|
||||
listener: UpdateAvailableHandler,
|
||||
verifier: areArgsUpdateAvailableFromMain,
|
||||
});
|
||||
onCorrect(invalidKubeconfigHandler);
|
||||
onCorrect({
|
||||
source: ipcRenderer,
|
||||
channel: ClusterListNamespaceForbiddenChannel,
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* 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 React from "react";
|
||||
import { ipcRenderer, IpcRendererEvent, shell } from "electron";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import { InvalidKubeConfigArgs, InvalidKubeconfigChannel } from "../../common/ipc/invalid-kubeconfig";
|
||||
import { Notifications, notificationsStore } from "../components/notifications";
|
||||
import { Button } from "../components/button";
|
||||
import { productName } from "../../common/vars";
|
||||
|
||||
export const invalidKubeconfigHandler = {
|
||||
source: ipcRenderer,
|
||||
channel: InvalidKubeconfigChannel,
|
||||
listener: InvalidKubeconfigListener,
|
||||
verifier: (args: [unknown]): args is InvalidKubeConfigArgs => {
|
||||
return args.length === 1 && typeof args[0] === "string" && !!ClusterStore.getInstance().getById(args[0]);
|
||||
},
|
||||
};
|
||||
|
||||
function InvalidKubeconfigListener(event: IpcRendererEvent, ...[clusterId]: InvalidKubeConfigArgs): void {
|
||||
const notificationId = `invalid-kubeconfig:${clusterId}`;
|
||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||
const contextName = cluster.name !== cluster.contextName ? `(context: ${cluster.contextName})` : "";
|
||||
|
||||
Notifications.error(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Cluster with Invalid Kubeconfig Detected!</b>
|
||||
<p>Cluster <b>{cluster.name}</b> has invalid kubeconfig {contextName} and cannot be displayed.
|
||||
Please fix the <a href="#" onClick={(e) => { e.preventDefault(); shell.showItemInFolder(cluster.kubeConfigPath); }}>kubeconfig</a> manually and restart {productName}
|
||||
or remove the cluster.</p>
|
||||
<p>Do you want to remove the cluster now?</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button active outlined label="Remove" onClick={()=> {
|
||||
ClusterStore.getInstance().removeById(clusterId);
|
||||
notificationsStore.remove(notificationId);
|
||||
}} />
|
||||
<Button active outlined label="Cancel" onClick={() => notificationsStore.remove(notificationId)} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: notificationId,
|
||||
timeout: 0
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user