fix(dashboard): initialize TabManager with proper dashboard structure

- Add dashboard.tabs array and defaultTab to DashboardManager state
- Create default 'main' tab on initialization
- Pass dashboard object to TabManager instead of event handlers
- Register tab change listeners using onChange pattern
- Fix applyDashboardConfig to directly manipulate tabs array
- Fix getDashboardConfig to include all tab properties and defaultTab
- Remove non-existent deleteAllTabs() call
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-10-23 11:37:51 +11:00
parent e5e3c3592f
commit e32a008f0b
+51 -13
View File
@@ -62,6 +62,12 @@ export class DashboardManager {
this.widgets = new Map(); // widgetId => { widget data, element, tab } this.widgets = new Map(); // widgetId => { widget data, element, tab }
this.defaultLayout = null; this.defaultLayout = null;
// Dashboard data structure (for TabManager)
this.dashboard = {
tabs: [],
defaultTab: null
};
// System instances // System instances
this.gridEngine = null; this.gridEngine = null;
this.registry = null; this.registry = null;
@@ -100,13 +106,29 @@ export class DashboardManager {
// Initialize Widget Registry // Initialize Widget Registry
this.registry = new WidgetRegistry(); this.registry = new WidgetRegistry();
// Initialize Tab Manager // Initialize Tab Manager with dashboard data structure
this.tabManager = new TabManager({ // Create default tab if no tabs exist
onTabChange: (tabId) => this.onTabChange(tabId), if (this.dashboard.tabs.length === 0) {
onTabCreate: (tab) => this.onTabCreate(tab), this.dashboard.tabs.push({
onTabDelete: (tabId) => this.onTabDelete(tabId), id: 'main',
onTabRename: (tabId, newName) => this.onTabRename(tabId, newName), name: 'Main',
onTabReorder: (fromIndex, toIndex) => this.onTabReorder(fromIndex, toIndex) icon: '🏠',
order: 0,
widgets: []
});
this.dashboard.defaultTab = 'main';
}
this.tabManager = new TabManager(this.dashboard);
// Set current tab to active tab from TabManager
this.currentTabId = this.tabManager.getActiveTabId();
// Register tab change listener
this.tabManager.onChange((event, data) => {
if (event === 'tabChanged') {
this.onTabChange(data.tabId);
}
}); });
// Initialize Drag & Drop // Initialize Drag & Drop
@@ -610,8 +632,11 @@ export class DashboardManager {
tabs: this.tabManager.getTabs().map(tab => ({ tabs: this.tabManager.getTabs().map(tab => ({
id: tab.id, id: tab.id,
name: tab.name, name: tab.name,
icon: tab.icon,
order: tab.order,
widgets: tab.widgets || [] widgets: tab.widgets || []
})) })),
defaultTab: this.dashboard.defaultTab
}; };
} }
@@ -624,15 +649,28 @@ export class DashboardManager {
// Clear existing // Clear existing
this.clearGrid(); this.clearGrid();
this.tabManager.deleteAllTabs();
// Create tabs // Clear tabs directly (we have access to shared dashboard object)
this.dashboard.tabs = [];
// Recreate tabs from config (preserve IDs and widgets)
config.tabs.forEach(tabConfig => { config.tabs.forEach(tabConfig => {
this.tabManager.createTab(tabConfig.name, tabConfig.id); this.dashboard.tabs.push({
const tab = this.tabManager.getTab(tabConfig.id); id: tabConfig.id,
tab.widgets = tabConfig.widgets || []; name: tabConfig.name,
icon: tabConfig.icon || '📄',
order: tabConfig.order || 0,
widgets: tabConfig.widgets || []
});
}); });
// Update default tab
if (config.defaultTab) {
this.dashboard.defaultTab = config.defaultTab;
} else if (this.dashboard.tabs.length > 0) {
this.dashboard.defaultTab = this.dashboard.tabs[0].id;
}
// Switch to first tab // Switch to first tab
if (config.tabs.length > 0) { if (config.tabs.length > 0) {
this.switchTab(config.tabs[0].id); this.switchTab(config.tabs[0].id);