-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement evt of clusterEventsMonitor usecase
- Loading branch information
Showing
8 changed files
with
79 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters