mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move cluster failed to list namespaces to injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
504d086bbf
commit
38de2edc50
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { ClusterId } from "../../../../common/cluster-types";
|
||||||
|
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
|
|
||||||
|
export const clusterFailedToListNamespacesChannel: MessageChannel<ClusterId> = {
|
||||||
|
id: "cluster-failed-to-list-namespaces",
|
||||||
|
};
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import type { MessageChannelSender } from "../../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
|
import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
|
import { clusterFailedToListNamespacesChannel } from "../common/channel";
|
||||||
|
|
||||||
|
export type EmitClusterFailedToListNamespaces = MessageChannelSender<typeof clusterFailedToListNamespacesChannel>;
|
||||||
|
|
||||||
|
const emitClusterFailedToListNamespacesInjectable = getInjectable({
|
||||||
|
id: "emit-cluster-failed-to-list-namespaces",
|
||||||
|
instantiate: (di): EmitClusterFailedToListNamespaces => {
|
||||||
|
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||||
|
|
||||||
|
return (clusterId) => sendMessageToChannel(clusterFailedToListNamespacesChannel, clusterId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default emitClusterFailedToListNamespacesInjectable;
|
||||||
@ -3,15 +3,13 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import navigateToEntitySettingsInjectable from "../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
import navigateToEntitySettingsInjectable from "../../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||||
import type { ListNamespaceForbiddenArgs } from "../../common/ipc/cluster";
|
import { Button } from "../../../../renderer/components/button";
|
||||||
import { Button } from "../components/button";
|
|
||||||
import type { IpcRendererEvent } from "electron";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable";
|
import { getMillisecondsFromUnixEpoch } from "../../../../common/utils/date/get-current-date-time";
|
||||||
import { getMillisecondsFromUnixEpoch } from "../../common/utils/date/get-current-date-time";
|
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||||
import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable";
|
import showSuccessNotificationInjectable from "../../../../renderer/components/notifications/show-success-notification.injectable";
|
||||||
import showSuccessNotificationInjectable from "../components/notifications/show-success-notification.injectable";
|
import type { ClusterId } from "../../../../common/cluster-types";
|
||||||
|
|
||||||
const intervalBetweenNotifications = 1000 * 60; // 60s
|
const intervalBetweenNotifications = 1000 * 60; // 60s
|
||||||
|
|
||||||
@ -20,15 +18,11 @@ const listNamespacesForbiddenHandlerInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const navigateToEntitySettings = di.inject(navigateToEntitySettingsInjectable);
|
const navigateToEntitySettings = di.inject(navigateToEntitySettingsInjectable);
|
||||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
|
||||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||||
const notificationLastDisplayedAt = new Map<string, number>();
|
const notificationLastDisplayedAt = new Map<string, number>();
|
||||||
const showSuccessNotification = di.inject(showSuccessNotificationInjectable);
|
const showSuccessNotification = di.inject(showSuccessNotificationInjectable);
|
||||||
|
|
||||||
return (
|
return (clusterId: ClusterId) => {
|
||||||
event: IpcRendererEvent,
|
|
||||||
...[clusterId]: ListNamespaceForbiddenArgs
|
|
||||||
): void => {
|
|
||||||
const lastDisplayedAt = notificationLastDisplayedAt.get(clusterId);
|
const lastDisplayedAt = notificationLastDisplayedAt.get(clusterId);
|
||||||
const now = getMillisecondsFromUnixEpoch();
|
const now = getMillisecondsFromUnixEpoch();
|
||||||
|
|
||||||
@ -42,14 +36,7 @@ const listNamespacesForbiddenHandlerInjectable = getInjectable({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationId = `list-namespaces-forbidden:${clusterId}`;
|
const closeNotification = showSuccessNotification(
|
||||||
|
|
||||||
if (notificationsStore.getById(notificationId)) {
|
|
||||||
// notification is still visible
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showSuccessNotification(
|
|
||||||
(
|
(
|
||||||
<div className="flex column gaps">
|
<div className="flex column gaps">
|
||||||
<b>Add Accessible Namespaces</b>
|
<b>Add Accessible Namespaces</b>
|
||||||
@ -65,18 +52,18 @@ const listNamespacesForbiddenHandlerInjectable = getInjectable({
|
|||||||
label="Go to Accessible Namespaces Settings"
|
label="Go to Accessible Namespaces Settings"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigateToEntitySettings(clusterId, "namespaces");
|
navigateToEntitySettings(clusterId, "namespaces");
|
||||||
notificationsStore.remove(notificationId);
|
closeNotification();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
id: notificationId,
|
id: `list-namespaces-forbidden:${clusterId}`,
|
||||||
/**
|
/**
|
||||||
* Set the time when the notification is closed as well so that there is at
|
* 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
|
* least a minute between closing the notification as seeing it again
|
||||||
*/
|
*/
|
||||||
onClose: () => notificationLastDisplayedAt.set(clusterId, getMillisecondsFromUnixEpoch()),
|
onClose: () => notificationLastDisplayedAt.set(clusterId, getMillisecondsFromUnixEpoch()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { noop } from "../../../../common/utils";
|
||||||
|
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
|
import currentlyInClusterFrameInjectable from "../../../../renderer/routes/currently-in-cluster-frame.injectable";
|
||||||
|
import { clusterFailedToListNamespacesChannel } from "../common/channel";
|
||||||
|
import listNamespacesForbiddenHandlerInjectable from "./list-namespaces-forbidden-handler.injectable";
|
||||||
|
|
||||||
|
const clusterFailedToListNamespacesListenerInjectable = getMessageChannelListenerInjectable({
|
||||||
|
channel: clusterFailedToListNamespacesChannel,
|
||||||
|
id: "main",
|
||||||
|
handler: (di) => {
|
||||||
|
const currentlyInClusterFrame = di.inject(currentlyInClusterFrameInjectable);
|
||||||
|
|
||||||
|
if (currentlyInClusterFrame) {
|
||||||
|
return noop;
|
||||||
|
}
|
||||||
|
|
||||||
|
return di.inject(listNamespacesForbiddenHandlerInjectable);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default clusterFailedToListNamespacesListenerInjectable;
|
||||||
@ -4,22 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { defaultHotbarCells } from "../../common/hotbars/types";
|
import { defaultHotbarCells } from "../../common/hotbars/types";
|
||||||
import { clusterListNamespaceForbiddenChannel } from "../../common/ipc/cluster";
|
|
||||||
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
||||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||||
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
||||||
import listNamespacesForbiddenHandlerInjectable from "./list-namespaces-forbidden-handler.injectable";
|
|
||||||
|
|
||||||
const registerIpcListenersInjectable = getInjectable({
|
const registerIpcListenersInjectable = getInjectable({
|
||||||
id: "register-ipc-listeners",
|
id: "register-ipc-listeners",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const listNamespacesForbiddenHandler = di.inject(listNamespacesForbiddenHandlerInjectable);
|
|
||||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
const ipcRenderer = di.inject(ipcRendererInjectable);
|
||||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
ipcRenderer.on(clusterListNamespaceForbiddenChannel, listNamespacesForbiddenHandler);
|
|
||||||
ipcRenderer.on(hotbarTooManyItemsChannel, () => {
|
ipcRenderer.on(hotbarTooManyItemsChannel, () => {
|
||||||
showErrorNotification(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
|
showErrorNotification(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user