MCPcopy Create free account
hub / github.com/bytebase/bytebase / mapGroupNode

Function mapGroupNode

frontend/src/react/stores/sqlEditor/tree-utils.ts:94–122  ·  view source on GitHub ↗
(
  factor: Factor,
  value: string,
  parent: TreeNode | undefined
)

Source from the content-addressed store, hash-verified

92): TreeNode[] => buildSubTree(databaseList, undefined, factorList, 0);
93
94const 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
124export const mapTreeNodeByType = <T extends NodeType>(
125 type: T,

Callers 1

buildSubTreeFunction · 0.85

Calls 2

unknownInstanceFunction · 0.90
mapTreeNodeByTypeFunction · 0.70

Tested by

no test coverage detected