Skip to content

Commit

Permalink
Implement evt of clusterEventsMonitor usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Mar 27, 2024
1 parent 942e11d commit 94580cd
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 130 deletions.
29 changes: 0 additions & 29 deletions web/src/core/usecases/clusterEvents/evt.ts

This file was deleted.

100 changes: 0 additions & 100 deletions web/src/core/usecases/clusterEvents/selectors.ts

This file was deleted.

31 changes: 31 additions & 0 deletions web/src/core/usecases/clusterEventsMonitor/evt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { CreateEvt } from "core/bootstrap";
import { Evt } from "evt";

export const createEvt = (({ evtAction }) => {
const evtOut = Evt.create<{
actionName: "display notification";
severity: "warning" | "error";
message: string;
}>();

evtAction.$attach(
action =>
action.usecaseName === "clusterEventsMonitor" &&
action.actionName === "clusterEventReceived"
? [action.payload]
: null,
({ clusterEvent }) => {
if (clusterEvent.severity === "info") {
return;
}

evtOut.post({
"actionName": "display notification",
"message": clusterEvent.message,
"severity": clusterEvent.severity
});
}
);

return evtOut;
}) satisfies CreateEvt;
45 changes: 45 additions & 0 deletions web/src/core/usecases/clusterEventsMonitor/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { State as RootState } from "core/bootstrap";
import * as projectManagement from "core/usecases/projectManagement";
import { createSelector } from "clean-architecture";
import { name } from "./state";

const state = (rootState: RootState) => rootState[name];

const scopedState = createSelector(
state,
projectManagement.selectors.currentProject,
(state, currentProject) => {
const scopedState = state.clusterEventsByProjectId[currentProject.id];

if (scopedState === undefined) {
return {
"clusterEvents": [],
"notificationCheckoutTime": 0
};
}

return scopedState;
}
);

const clusterEvents = createSelector(scopedState, scopedState => {
const { clusterEvents, notificationCheckoutTime } = scopedState;

return clusterEvents.map(clusterEvent => ({
...clusterEvent,
"isHighlighted":
clusterEvent.severity !== "info" &&
clusterEvent.timestamp > notificationCheckoutTime
}));
});

const notificationsCount = createSelector(
clusterEvents,
clusterEvents =>
clusterEvents.filter(clusterEvent => clusterEvent.isHighlighted).length
);

export const selectors = {
clusterEvents,
notificationsCount
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type State = {
>;
};

export const name = "custerEvents";
export const name = "clusterEventsMonitor";

export const { reducer, actions } = createUsecaseActions({
name,
Expand Down
2 changes: 2 additions & 0 deletions web/src/core/usecases/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as autoLogoutCountdown from "./autoLogoutCountdown";
import * as catalog from "./catalog";
import * as clusterEventsMonitor from "./clusterEventsMonitor";
import * as deploymentRegionManagement from "./deploymentRegionManagement";
import * as fileExplorer from "./fileExplorer";
import * as secretExplorer from "./secretExplorer";
Expand All @@ -23,6 +24,7 @@ import * as viewQuotas from "./viewQuotas";
export const usecases = {
autoLogoutCountdown,
catalog,
clusterEventsMonitor,
deploymentRegionManagement,
fileExplorer,
secretExplorer,
Expand Down

0 comments on commit 94580cd

Please sign in to comment.