Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CreateCsvDownloaderService #2367

Merged
merged 15 commits into from
Sep 15, 2023
4 changes: 4 additions & 0 deletions projects/components/src/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ export class TableComponent
@Output()
public readonly columnConfigsChange: EventEmitter<TableColumnConfig[]> = new EventEmitter<TableColumnConfig[]>();

@Output()
public readonly visibleColumnsChange: EventEmitter<TableColumnConfig[]> = new EventEmitter<TableColumnConfig[]>();

@Output()
public readonly sortChange: EventEmitter<SortedColumn<TableColumnConfig>> = new EventEmitter<
SortedColumn<TableColumnConfig>
Expand Down Expand Up @@ -731,6 +734,7 @@ export class TableComponent
private updateVisibleColumns(visibleColumnConfigs: TableColumnConfigExtended[]): void {
this.visibleColumnConfigs = visibleColumnConfigs;
this.visibleColumnIds = this.visibleColumnConfigs.map(column => column.id);
this.visibleColumnsChange.next(this.visibleColumnConfigs.filter(column => column.id !== '$$expanded'));
palbizu marked this conversation as resolved.
Show resolved Hide resolved
}

private initializeData(): void {
Expand Down
3 changes: 3 additions & 0 deletions projects/observability/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,6 @@ export * from './shared/components/bar-gauge/bar-gauge.module';

// Time Range utils
export * from './shared/utils/time-range';

// CSV Downloader Service
export * from './shared/services/global-csv-download/global-csv-download.service';
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { SpecificationBackedTableColumnDef } from './table-widget-column.model';
import { TableWidgetControlSelectOptionModel } from './table-widget-control-select-option.model';
import { TableWidgetViewToggleModel } from './table-widget-view-toggle.model';
import { TableWidgetModel } from './table-widget.model';
import { GlobalCsvDownloadService } from '../../../services/global-csv-download/global-csv-download.service';

@Renderer({ modelClass: TableWidgetModel })
@Renderer({ modelClass: TableWidgetViewToggleModel })
Expand Down Expand Up @@ -110,6 +111,7 @@ import { TableWidgetModel } from './table-widget.model';
(rowClicked)="this.onRowClicked($event)"
(selectionsChange)="this.onRowSelection($event)"
(columnConfigsChange)="this.onColumnsChange($event)"
(visibleColumnsChange)="this.onVisibleColumnsChange($event)"
>
</ht-table>
</div>
Expand Down Expand Up @@ -154,7 +156,8 @@ export class TableWidgetRendererComponent
@Inject(RENDERER_API) api: RendererApi<TableWidgetModel>,
changeDetectorRef: ChangeDetectorRef,
private readonly metadataService: MetadataService,
private readonly preferenceService: PreferenceService
private readonly preferenceService: PreferenceService,
private readonly globalCsvDownloadService: GlobalCsvDownloadService
) {
super(api, changeDetectorRef);
}
Expand Down Expand Up @@ -498,6 +501,13 @@ export class TableWidgetRendererComponent
this.columnConfigs$ = this.getColumnConfigs();
}

public onVisibleColumnsChange(columns: TableColumnConfig[]): void {
this.globalCsvDownloadService.registerDataSource('table-widget-renderer', {
palbizu marked this conversation as resolved.
Show resolved Hide resolved
columns: columns,
getData: this.model.getData()
});
}

public onColumnsChange(columns: TableColumnConfig[]): void {
if (isNonEmptyString(this.model.getId())) {
this.getLocalPreferences().subscribe(preferences =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Injectable } from '@angular/core';
import { TableColumnConfig, TableDataSource, TableRow } from '@hypertrace/components';
import { Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class GlobalCsvDownloadService {
// Note: This service should be use to connect and donwload data from two unrelated components. The component's data to be downloaded should be register and can be executed from a different component.

private readonly csvDataSourceMap: Map<string, GlobalCsvDownloadData> = new Map();

public registerDataSource(key: string, source: GlobalCsvDownloadData): void {
if (this.csvDataSourceMap.has(key)) {
this.csvDataSourceMap.delete(key);
}
palbizu marked this conversation as resolved.
Show resolved Hide resolved

this.csvDataSourceMap.set(key, source);
palbizu marked this conversation as resolved.
Show resolved Hide resolved
}

public getRegisteredDataSource(key: string): GlobalCsvDownloadData | undefined {
return this.csvDataSourceMap.get(key);
}

public hasRegisteredDataSource(key: string): boolean {
return this.csvDataSourceMap.has(key);
}

public deleteRegisteredDataSource(key: string): void {
if (this.csvDataSourceMap.has(key)) {
this.csvDataSourceMap.delete(key);
}
palbizu marked this conversation as resolved.
Show resolved Hide resolved
}

public clearAllDataSource(): void {
this.csvDataSourceMap.clear();
}
}

export interface GlobalCsvDownloadData {
palbizu marked this conversation as resolved.
Show resolved Hide resolved
columns: TableColumnConfig[];
palbizu marked this conversation as resolved.
Show resolved Hide resolved
getData: Observable<TableDataSource<TableRow>>;
palbizu marked this conversation as resolved.
Show resolved Hide resolved
palbizu marked this conversation as resolved.
Show resolved Hide resolved
}