Add notification to user to add accessible namespaces (#2173)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-03-23 13:21:47 -04:00
1 parent 0b99377feb
commit ee4d434d35
9 files changed
+85 -18

No files matched your search

+48 -2
View File
@@ -1,10 +1,13 @@
import React from "react";
import { ipcRenderer, IpcRendererEvent } from "electron";
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg } from "../../common/ipc";
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs } from "../../common/ipc";
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 { clusterSettingsURL } from "../components/+cluster-settings";
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
notificationsStore.remove(notificationId);
@@ -42,7 +45,8 @@ function UpdateAvailableHandler(event: IpcRendererEvent, ...[backchannel, update
<Button active outlined label="No" onClick={() => sendToBackchannel(backchannel, notificationId, { doUpdate: false })} />
</div>
</div>
), {
),
{
id: notificationId,
onClose() {
sendToBackchannel(backchannel, notificationId, { doUpdate: false });
@@ -51,6 +55,42 @@ function UpdateAvailableHandler(event: IpcRendererEvent, ...[backchannel, update
);
}
const listNamespacesForbiddenHandlerDisplayedAt = new Map<string, number>();
const intervalBetweenNotifications = 1000 * 60; // 60s
function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]: ListNamespaceForbiddenArgs): void {
const lastDisplayedAt = listNamespacesForbiddenHandlerDisplayedAt.get(clusterId);
const wasDisplayed = Boolean(lastDisplayedAt);
const now = Date.now();
if (!wasDisplayed || (now - lastDisplayedAt) > intervalBetweenNotifications) {
listNamespacesForbiddenHandlerDisplayedAt.set(clusterId, now);
} else {
// don't bother the user too often
return;
}
const notificationId = `list-namespaces-forbidden:${clusterId}`;
Notifications.info(
(
<div className="flex column gaps">
<b>Add Accessible Namespaces</b>
<p>Cluster <b>{clusterStore.active.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={()=> {
navigate(clusterSettingsURL({ params: { clusterId }, fragment: "accessible-namespaces" }));
notificationsStore.remove(notificationId);
}} />
</div>
</div>
),
{
id: notificationId,
}
);
}
export function registerIpcHandlers() {
onCorrect({
source: ipcRenderer,
@@ -59,4 +99,10 @@ export function registerIpcHandlers() {
verifier: areArgsUpdateAvailableFromMain,
});
onCorrect(invalidKubeconfigHandler);
onCorrect({
source: ipcRenderer,
channel: ClusterListNamespaceForbiddenChannel,
listener: ListNamespacesForbiddenHandler,
verifier: isListNamespaceForbiddenArgs,
});
}