-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdf-data-explorer.component.ts
More file actions
183 lines (166 loc) · 5.24 KB
/
df-data-explorer.component.ts
File metadata and controls
183 lines (166 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import {
Component,
OnInit,
OnDestroy,
AfterViewInit,
ElementRef,
HostBinding,
NgZone,
} from '@angular/core';
import { NgIf, AsyncPipe } from '@angular/common';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { TranslocoModule } from '@ngneat/transloco';
import { BehaviorSubject, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import {
DataExplorerService,
DatabaseService,
TableInfo,
} from './services/data-explorer.service';
import { DfDbSelectorComponent } from './df-db-selector.component';
import { DfSchemaTreeComponent } from './df-schema-tree.component';
import { DfDataGridComponent } from './df-data-grid.component';
import { DfThemeService } from '../shared/services/df-theme.service';
@Component({
selector: 'df-data-explorer',
templateUrl: './df-data-explorer.component.html',
styleUrls: ['./df-data-explorer.component.scss'],
standalone: true,
imports: [
NgIf,
AsyncPipe,
MatSidenavModule,
MatToolbarModule,
MatIconModule,
MatProgressSpinnerModule,
TranslocoModule,
FontAwesomeModule,
DfDbSelectorComponent,
DfSchemaTreeComponent,
DfDataGridComponent,
],
})
export class DfDataExplorerComponent
implements OnInit, OnDestroy, AfterViewInit
{
@HostBinding('style.height.px') hostHeight: number | null = null;
databases: DatabaseService[] = [];
tables: TableInfo[] = [];
selectedDb: DatabaseService | null = null;
selectedTable: TableInfo | null = null;
pendingFilter: string | undefined;
loadingDbs = false;
loadingSchema = false;
errorDbs: string | null = null;
errorSchema: string | null = null;
isDarkMode$ = this.themeService.darkMode$;
private destroy$ = new Subject<void>();
private resizeObserver: ResizeObserver | null = null;
private resizeListener = () => this.calculateHeight();
constructor(
private dataExplorerService: DataExplorerService,
private themeService: DfThemeService,
private elementRef: ElementRef,
private ngZone: NgZone
) {}
ngOnInit(): void {
this.loadDatabases();
}
ngAfterViewInit(): void {
// Measure actual available height from element position in viewport
this.calculateHeight();
window.addEventListener('resize', this.resizeListener);
// Watch for parent layout changes (e.g. sidebar collapse)
this.ngZone.runOutsideAngular(() => {
this.resizeObserver = new ResizeObserver(() => {
this.ngZone.run(() => this.calculateHeight());
});
const parent = this.elementRef.nativeElement.parentElement;
if (parent) {
this.resizeObserver.observe(parent);
}
});
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
window.removeEventListener('resize', this.resizeListener);
this.resizeObserver?.disconnect();
}
private calculateHeight(): void {
const el = this.elementRef.nativeElement as HTMLElement;
const rect = el.getBoundingClientRect();
// Available height = viewport bottom - element top - small margin for safety
this.hostHeight = Math.floor(window.innerHeight - rect.top);
}
loadDatabases(): void {
this.loadingDbs = true;
this.errorDbs = null;
this.dataExplorerService
.getDatabaseServices()
.pipe(takeUntil(this.destroy$))
.subscribe({
next: dbs => {
this.databases = dbs;
this.loadingDbs = false;
},
error: err => {
this.errorDbs =
err?.error?.error?.message || 'Failed to load databases';
this.loadingDbs = false;
},
});
}
onDatabaseSelected(db: DatabaseService): void {
this.selectedDb = db;
this.selectedTable = null;
this.tables = [];
this.loadSchema(db.name);
}
loadSchema(serviceName: string): void {
this.loadingSchema = true;
this.errorSchema = null;
this.dataExplorerService
.getSchema(serviceName)
.pipe(takeUntil(this.destroy$))
.subscribe({
next: tables => {
this.tables = tables;
this.loadingSchema = false;
},
error: err => {
this.errorSchema =
err?.error?.error?.message || 'Failed to load schema';
this.loadingSchema = false;
},
});
}
onTableSelected(table: TableInfo): void {
this.pendingFilter = undefined;
this.selectedTable = table;
}
onTableNavigated(event: { tableName: string; filter?: string }): void {
// Find the table in the current schema list
const table = this.tables.find(t => t.name === event.tableName);
if (table) {
this.pendingFilter = event.filter;
// If navigating to the same table, briefly null to force ngOnChanges
if (this.selectedTable?.name === table.name) {
this.selectedTable = null;
setTimeout(() => (this.selectedTable = table));
} else {
this.selectedTable = table;
}
}
}
onBackToDatabases(): void {
this.selectedDb = null;
this.selectedTable = null;
this.pendingFilter = undefined;
this.tables = [];
}
}