import * as plugins from '../plugins.js'; import { apiService, type IDatabaseStats } from '../services/index.js'; import { formatSize, formatCount } from '../utilities/index.js'; import { themeStyles } from '../styles/index.js'; const { html, css, cssManager, customElement, property, state, DeesElement } = plugins; @customElement('tsview-mongo-db-overview') export class TsviewMongoDbOverview extends DeesElement { @property({ type: String }) public accessor databaseName: string = ''; @state() private accessor stats: IDatabaseStats | null = null; @state() private accessor loading: boolean = false; @state() private accessor error: string = ''; public static styles = [ cssManager.defaultStyles, themeStyles, css` :host { display: block; height: 100%; } .overview-container { display: flex; flex-direction: column; height: 100%; padding: 24px; box-sizing: border-box; overflow: auto; } .header { margin-bottom: 24px; } .header-title { font-size: 24px; font-weight: 600; color: #fff; margin: 0 0 8px 0; display: flex; align-items: center; gap: 12px; } .header-title svg { width: 28px; height: 28px; color: #888; } .header-subtitle { color: #888; font-size: 14px; } .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; } .stat-card { background: rgba(255, 255, 255, 0.03); border: 1px solid #333; border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 8px; } .stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #888; } .stat-value { font-size: 24px; font-weight: 600; color: #e0e0e0; } .stat-value.small { font-size: 18px; } .stat-description { font-size: 11px; color: #666; } .section { margin-bottom: 24px; } .section-title { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: #666; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid #333; } .loading-state { display: flex; align-items: center; justify-content: center; height: 100%; color: #888; font-size: 14px; } .error-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #f87171; text-align: center; } .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #666; text-align: center; } .empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; } `, ]; updated(changedProperties: Map) { if (changedProperties.has('databaseName') && this.databaseName) { this.loadStats(); } } async connectedCallback() { super.connectedCallback(); if (this.databaseName) { await this.loadStats(); } } private async loadStats() { if (!this.databaseName) return; this.loading = true; this.error = ''; try { this.stats = await apiService.getDatabaseStats(this.databaseName); } catch (err) { console.error('Error loading database stats:', err); this.error = 'Failed to load database statistics'; } this.loading = false; } render() { if (!this.databaseName) { return html`

Select a database to view overview

`; } if (this.loading) { return html`
Loading database statistics...
`; } if (this.error) { return html`
${this.error}
`; } if (!this.stats) { return html`

No statistics available

`; } return html`

${this.databaseName}

Database Overview

Storage
Collections ${this.stats.collections} Total collections in database
Documents ${formatCount(this.stats.objects) || this.stats.objects} Total documents stored
Avg Document Size ${formatSize(this.stats.avgObjSize)} Average size per document
Data Size ${formatSize(this.stats.dataSize)} Uncompressed data size
Storage Size ${formatSize(this.stats.storageSize)} Allocated storage
Indexes
Index Count ${this.stats.indexes} Total indexes in database
Index Size ${formatSize(this.stats.indexSize)} Total index storage
`; } }