Skip to content

Commit 2a8ef10

Browse files
committed
fix: improve error messaging and clarify tree node consistency
1. **store.ts - loadRootEntities**: Enhance version info error handling - Add more informative warning message when version info fetch fails - Explain impact to users: "Server will be shown with generic name" - Clarify that version info may be incomplete but UI remains functional - Maintains existing fallback behavior with better user communication 2. **store.ts - toTreeNode**: Add documentation for hasChildren logic - Clarify relationship between hasChildren and children: undefined - hasChildren controls whether expand button is shown - children: undefined means "not loaded yet" (lazy loading) - Document all three hasChildren determination paths: * Explicit metadata from API (preferred) * Children array length check (if provided) * Type-based heuristic fallback (areas/components have children, apps don't) - Prevents confusion about apparent inconsistency between flags
1 parent eec6203 commit 2a8ef10

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/lib/store.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,31 @@ function toTreeNode(entity: SovdEntity, parentPath: string = ''): EntityTreeNode
132132
const path = parentPath ? `${parentPath}/${entity.id}` : `/${entity.id}`;
133133
const entityType = entity.type.toLowerCase();
134134

135-
// Prefer explicit metadata / existing children if available; fall back to type heuristic.
135+
// Determine hasChildren based on explicit metadata or type heuristic
136+
// Note: hasChildren controls whether expand button is shown
137+
// children: undefined means "not loaded yet" (lazy loading on expand)
136138
let hasChildren: boolean;
137139
const entityAny = entity as unknown as Record<string, unknown>;
138140
if (Object.prototype.hasOwnProperty.call(entityAny, 'hasChildren') && typeof entityAny.hasChildren === 'boolean') {
141+
// Explicit hasChildren metadata from API - use as-is
139142
hasChildren = entityAny.hasChildren as boolean;
140143
} else if (Array.isArray(entityAny.children)) {
144+
// Children array provided - check if non-empty
141145
hasChildren = (entityAny.children as unknown[]).length > 0;
142146
} else {
143-
// Areas and components typically have children (loaded on expand)
144-
// Apps are usually leaf nodes - their resources are shown in the detail panel
147+
// No explicit metadata - use type-based heuristic:
148+
// Areas and components typically have children (components, apps, subareas)
149+
// Apps are leaf nodes - their resources shown in detail panel, not tree
145150
hasChildren = entityType !== 'app';
146151
}
147152

148153
return {
149154
...entity,
150155
path,
151-
children: undefined, // Children loaded lazily on expand
156+
children: undefined, // Children always loaded lazily on expand
152157
isLoading: false,
153158
isExpanded: false,
154-
hasChildren,
159+
hasChildren, // Controls whether expand button is shown
155160
};
156161
}
157162

@@ -574,14 +579,17 @@ export const useAppStore = create<AppState>()(
574579
if (!client) return;
575580

576581
try {
577-
// Fetch version info
582+
// Fetch version info - critical for server identification and feature detection
578583
const versionInfo = await client.getVersionInfo().catch((error: unknown) => {
579584
const message = error instanceof Error ? error.message : 'Unknown error';
580-
toast.warn(`Failed to fetch server version info: ${message}`);
585+
toast.warn(
586+
`Failed to fetch server version info: ${message}. ` +
587+
'Server will be shown with generic name and version info may be incomplete.'
588+
);
581589
return null as VersionInfo | null;
582590
});
583591

584-
// Extract server info from version-info response
592+
// Extract server info from version-info response (fallback to generic values if unavailable)
585593
const sovdInfo = versionInfo?.sovd_info?.[0];
586594
const serverName = sovdInfo?.vendor_info?.name || 'SOVD Server';
587595
const serverVersion = sovdInfo?.vendor_info?.version || '';

0 commit comments

Comments
 (0)