-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): implement resource running state indicators (#6643)
Closes #6622.
- Loading branch information
Showing
35 changed files
with
660 additions
and
378 deletions.
There are no files selected for viewing
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
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
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
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
47 changes: 47 additions & 0 deletions
47
apps/wing-console/console/server/src/router/app.get-hierarchichal-running-state.ts
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,47 @@ | ||
import type { ConstructTreeNodeMap } from "../utils/constructTreeNodeMap.js"; | ||
|
||
type RunningState = "starting" | "started" | "stopping" | "stopped" | "error"; | ||
|
||
const RunningStateOrder = { | ||
started: 0, | ||
stopped: 1, | ||
starting: 2, | ||
stopping: 3, | ||
error: 4, | ||
} as const; | ||
|
||
export const getHierarchichalRunningState = ( | ||
path: string, | ||
nodeMap: ConstructTreeNodeMap, | ||
): RunningState => { | ||
const node = nodeMap.get(path); | ||
if (!node) { | ||
return "stopped"; | ||
} | ||
|
||
const runningState = (node?.resourceConfig?.attrs?.["runningState"] ?? | ||
"started") as RunningState; | ||
|
||
if (node.children?.length > 0) { | ||
const childrenRunningStates = node.children.map((child) => | ||
getHierarchichalRunningState(child, nodeMap), | ||
); | ||
|
||
// eslint-disable-next-line unicorn/no-array-reduce | ||
const highestRunningState = childrenRunningStates.reduce<RunningState>( | ||
(highest, current) => { | ||
return RunningStateOrder[current] > RunningStateOrder[highest] | ||
? current | ||
: highest; | ||
}, | ||
"started", | ||
); | ||
|
||
return RunningStateOrder[highestRunningState] > | ||
RunningStateOrder[runningState] | ||
? highestRunningState | ||
: runningState; | ||
} | ||
|
||
return runningState; | ||
}; |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export type { Trace } from "@winglang/sdk/lib/std/test-runner.js"; | ||
export type { ResourceLifecycleEvent } from "@winglang/sdk/lib/simulator/simulator.js"; | ||
|
||
export type State = "compiling" | "loadingSimulator" | "success" | "error"; |
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
Oops, something went wrong.