${(['dashboard', 'collections', 'oplog', 'revert'] as TTab[]).map(
(tab) => html`
this.switchTab(tab)}
>
${tab === 'dashboard'
? 'Dashboard'
: tab === 'collections'
? 'Collections'
: tab === 'oplog'
? 'OpLog'
: 'Revert'}
`,
)}
${this.activeTab === 'dashboard' ? this.renderDashboard() : ''}
${this.activeTab === 'collections' ? this.renderCollections() : ''}
${this.activeTab === 'oplog' ? this.renderOplog() : ''}
${this.activeTab === 'revert' ? this.renderRevert() : ''}
`;
}
private renderDashboard() {
return html`
Databases
${this.metrics?.databases ?? '-'}
Collections
${this.metrics?.collections ?? '-'}
OpLog Entries
${this.oplogStats?.totalEntries ?? '-'}
Current Seq
${this.oplogStats?.currentSeq ?? '-'}
Uptime
${this.metrics ? this.formatUptime(this.metrics.uptimeSeconds) : '-'}
${this.oplogStats
? html`
${this.selectedCollection
? html`
${this.selectedCollection.db}.${this.selectedCollection.name}
(${this.documentsTotal} total)
${this.documents.length === 0
? html`
`
: this.documents.map(
(doc) => html`
${JSON.stringify(doc, null, 2)}
`,
)}
`
: html`
Select a collection
Choose a collection from the sidebar to browse its documents
`}
`;
}
private renderOplog() {
const filtered = this.getFilteredOplog();
return html`
${isExpanded
? html`
${entry.op === 'insert'
? html`
Inserted Document
${JSON.stringify(entry.document, null, 2)}
`
: entry.op === 'delete'
? html`
Deleted Document
${JSON.stringify(entry.previousDocument, null, 2)}
`
: html`
Changes
${diffs.length > 0
? diffs.map((d) => this.renderDiffRow(d))
: html`
No field-level changes
`}
Before
${JSON.stringify(entry.previousDocument, null, 2)}
After
${JSON.stringify(entry.document, null, 2)}
`}
`
: ''}
`;
}
private renderDiffRow(diff: IDiffEntry) {
return html`
Point-in-Time Revert
Revert the database to a specific oplog sequence number. All operations after that
point will be undone in reverse order.
Current sequence: ${currentSeq}
Target seq:
{
this.revertTargetSeq = parseInt((e.target as HTMLInputElement).value) || 0;
this.revertPreview = null;
}}
/>
currentSeq}
@click=${this.handlePreviewRevert}
>
Preview
${this.revertPreview
? html`
Revert Preview: ${this.revertPreview.reverted} operations to undo
${this.revertPreview.entries?.map(
(e: any) => html`
#${e.seq} ${e.op} ${e.db}.${e.collection} (${e.documentId})
`,
)}
${this.revertInProgress ? 'Reverting...' : 'Execute Revert'}
`
: ''}
Recent Operations (newest first)
${this.oplogEntries.length === 0
? html`
No operations recorded yet
`
: [...this.oplogEntries]
.reverse()
.slice(0, 20)
.map(
(entry) => html`
#${entry.seq}
${entry.op}
${entry.db}.${entry.collection}
${entry.documentId.substring(0, 12)}
`,
)}
`;
}
}