( factor: Factor, value: string, parent: TreeNode | undefined )
| 92 | ): TreeNode[] => buildSubTree(databaseList, undefined, factorList, 0); |
| 93 | |
| 94 | const mapGroupNode = ( |
| 95 | factor: Factor, |
| 96 | value: string, |
| 97 | parent: TreeNode | undefined |
| 98 | ) => { |
| 99 | if (factor === "environment") { |
| 100 | const environment = useAppStore |
| 101 | .getState() |
| 102 | .getEnvironmentByName(value || ""); |
| 103 | return mapTreeNodeByType("environment", environment, parent); |
| 104 | } |
| 105 | if (factor === "instance") { |
| 106 | const appStore = useAppStore.getState(); |
| 107 | // Best-effort: trigger a background fetch and render the cached |
| 108 | // instance (or an `unknownInstance` placeholder until the fetch |
| 109 | // resolves). Matches the legacy Pinia `useInstanceResourceByName` |
| 110 | // behavior — synchronous read with an async hydrate. |
| 111 | void appStore.fetchInstance(value); |
| 112 | const instance = appStore.instancesByName[value] ?? unknownInstance(); |
| 113 | return mapTreeNodeByType("instance", instance, parent); |
| 114 | } |
| 115 | const key = extractLabelFactor(factor); |
| 116 | if (key) { |
| 117 | return mapTreeNodeByType("label", { key, value }, parent); |
| 118 | } |
| 119 | throw new Error( |
| 120 | `mapGroupNode: should never reach this line. factor=${factor}, factorValue=${value}` |
| 121 | ); |
| 122 | }; |
| 123 | |
| 124 | export const mapTreeNodeByType = <T extends NodeType>( |
| 125 | type: T, |
no test coverage detected