mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix accessible namespaces notification not navigating to correct settings (#4048)
This commit is contained in:
1 parent
c5de0b1e00
commit
246305cd63
6 files changed
+81
-82
No files matched your search
+27
-10
@@ -77,16 +77,15 @@ function UpdateAvailableHandler(event: IpcRendererEvent, ...[backchannel, update
|
||||
);
|
||||
}
|
||||
|
||||
const listNamespacesForbiddenHandlerDisplayedAt = new Map<string, number>();
|
||||
const notificationLastDisplayedAt = 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 lastDisplayedAt = notificationLastDisplayedAt.get(clusterId);
|
||||
const now = Date.now();
|
||||
|
||||
if (!wasDisplayed || (now - lastDisplayedAt) > intervalBetweenNotifications) {
|
||||
listNamespacesForbiddenHandlerDisplayedAt.set(clusterId, now);
|
||||
if (!notificationLastDisplayedAt.has(clusterId) || (now - lastDisplayedAt) > intervalBetweenNotifications) {
|
||||
notificationLastDisplayedAt.set(clusterId, now);
|
||||
} else {
|
||||
// don't bother the user too often
|
||||
return;
|
||||
@@ -94,21 +93,39 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
|
||||
|
||||
const notificationId = `list-namespaces-forbidden:${clusterId}`;
|
||||
|
||||
if (notificationsStore.getById(notificationId)) {
|
||||
// notification is still visible
|
||||
return;
|
||||
}
|
||||
|
||||
Notifications.info(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<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>
|
||||
<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={() => {
|
||||
navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "accessible-namespaces" }));
|
||||
notificationsStore.remove(notificationId);
|
||||
}} />
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Go to Accessible Namespaces Settings"
|
||||
onClick={() => {
|
||||
navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "namespaces" }));
|
||||
notificationsStore.remove(notificationId);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: notificationId,
|
||||
/**
|
||||
* Set the time when the notification is closed as well so that there is at
|
||||
* least a minute between closing the notification as seeing it again
|
||||
*/
|
||||
onClose: () => notificationLastDisplayedAt.set(clusterId, Date.now()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user