Add context menu into sidebar (#4044)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-19 09:19:25 -04:00
1 parent e21888c62c
commit 125a073007
8 files changed
+243 -197

No files matched your search

+2
View File
@@ -72,6 +72,7 @@ import type { ClusterId } from "../../common/cluster-types";
import { watchHistoryState } from "../remote-helpers/history-updater";
import { unmountComponentAtNode } from "react-dom";
import { PortForwardDialog } from "../port-forward";
import { DeleteClusterDialog } from "./delete-cluster-dialog";
@observer
export class App extends React.Component {
@@ -230,6 +231,7 @@ export class App extends React.Component {
<ReplicaSetScaleDialog/>
<CronJobTriggerDialog/>
<PortForwardDialog/>
<DeleteClusterDialog/>
<CommandContainer clusterId={App.clusterId}/>
</ErrorBoundary>
</Router>
@@ -44,20 +44,16 @@ interface Props extends DOMAttributes<HTMLElement> {
@observer
export class HotbarEntityIcon extends React.Component<Props> {
@observable private contextMenu: CatalogEntityContextMenuContext;
@observable private contextMenu: CatalogEntityContextMenuContext = {
menuItems: [],
navigate: (url: string) => navigate(url),
};
constructor(props: Props) {
super(props);
makeObservable(this);
}
componentDidMount() {
this.contextMenu = {
menuItems: [],
navigate: (url: string) => navigate(url),
};
}
get kindIcon() {
const className = "badge";
const category = catalogCategoryRegistry.getCategoryForEntity(this.props.entity);
@@ -42,6 +42,9 @@ import * as routes from "../../../common/routes";
import { Config } from "../+config";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { HotbarIcon } from "../hotbar/hotbar-icon";
import { makeObservable, observable } from "mobx";
import type { CatalogEntityContextMenuContext } from "../../../common/catalog";
import { HotbarStore } from "../../../common/hotbar-store";
interface Props {
className?: string;
@@ -50,6 +53,15 @@ interface Props {
@observer
export class Sidebar extends React.Component<Props> {
static displayName = "Sidebar";
@observable private contextMenu: CatalogEntityContextMenuContext = {
menuItems: [],
navigate,
};
constructor(props: Props) {
super(props);
makeObservable(this);
}
async componentDidMount() {
crdStore.reloadAll();
@@ -194,6 +206,20 @@ export class Sidebar extends React.Component<Props> {
src={spec.icon?.src}
className="mr-5"
onClick={() => navigate("/")}
menuItems={this.contextMenu.menuItems}
onMenuOpen={() => {
const hotbarStore = HotbarStore.getInstance();
const isAddedToActive = HotbarStore.getInstance().isAddedToActive(this.clusterEntity);
const title = isAddedToActive
? "Remove from Hotbar"
: "Add to Hotbar";
const onClick = isAddedToActive
? () => hotbarStore.removeFromHotbar(metadata.uid)
: () => hotbarStore.addToHotbar(this.clusterEntity);
this.contextMenu.menuItems = [{ title, onClick }];
this.clusterEntity.onContextMenuOpen(this.contextMenu);
}}
/>
<div className={styles.clusterName}>
{metadata.name}
+1
View File
@@ -63,6 +63,7 @@ function bindClusterManagerRouteEvents() {
ipcRendererOn(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
logger.info(`[IPC]: navigate to ${url}`, { currentLocation: location.href });
navigate(url);
window.focus(); // make sure that the main frame is focused
});
}