Stijn Habekotté
09/22/2023, 8:34 AM@Component({
selector: 'insight-component',
templateUrl: './insight.component.html',
styleUrls: ['./insight.component.css'],
})
export class InsightComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
constructor(private goodData: GoodDataService) {}
@Input() config: IChartConfig = {
chart: {
verticalAlignment: "middle"
},
colors: ["rgb(195, 49, 73)", "rgb(168, 194, 86)"]
}
@Input() dateFilter: DateFilterOption;
@Input() drillableItems?: ExplicitDrill[];
// Otherwise, filters are applied from most specific to least specific
@Input() zoneCode: string;
@Input() establishmentCode;
// These are filter properties
// @Input() filters: IFilter[]; // A array of filters takes precedence over all other parameters
private hasViewLoaded = false;
@Input() heightFactor = 10;
@Input() heightMultiplier = 1;
@Input() insight: string;
@Input() onError?: any;
@Input() onLoadingChanged?: any;
@Input() props: IInsightViewProps;
private reactEl: React.ComponentElement<IInsightViewProps, InsightView>;
@Input() repoId: number;
public rootDomID: string;
@ViewChild('placeHolder', { read: ElementRef }) spanEl: ElementRef<HTMLElement>;
@Input() workspace: string;
protected getProps(): IInsightViewProps {
const { workspace, insight } = this;
let filters: IFilter[] = [];
if (this.establishmentCode) { // first filter criteria
filters = [this.goodData.filters.EstablishmentCodeFilter(this.establishmentCode)];
}
if (this.zoneCode) { // if establishment is already set it will still be overwritten by Zone, to limit the amount of filter criteria
filters = [this.goodData.filters.ZoneCodeFilter(this.zoneCode)];
}
return {
workspace,
filters,
insight,
config: {
chart: {
verticalAlignment: "middle"
},
colors: ["rgb(195, 49, 73)", "rgb(168, 194, 86)"]
},
drillableItems: this.drillableItems,
backend: this.goodData.backend,
...this.props,
};
}
ngAfterViewInit() {
this.hasViewLoaded = true;
clearInsightViewCaches();
this.render();
const childView: HTMLElement = this.spanEl.nativeElement.querySelector('.insight-view-container');
childView.style.height = `${this.heightMultiplier * this.heightFactor}px`;
}
ngOnChanges() {
this.render();
}
ngOnDestroy() {
// Uncomment if Angular issue that ngOnDestroy is called AFTER DOM node removal is resolved
ReactDOM.unmountComponentAtNode(this.spanEl.nativeElement);
}
ngOnInit() {
this.rootDomID = uuidv4();
}
protected render() {
if (!this.hasViewLoaded) {
return;
}
this.reactEl = React.createElement(InsightView, this.getProps());
ReactDOM.render(this.reactEl, this.spanEl.nativeElement);
}
}
Please note: This is the situation before I made any attempt at implementing the export on my own.
Best regards,
StijnRadek Novacek
09/25/2023, 7:40 AMStijn Habekotté
09/26/2023, 7:53 AMRadek Novacek
09/26/2023, 2:41 PMStijn Habekotté
09/28/2023, 9:56 AMprivate onExportReady(getExportedData){
console.log("onExportReady is called: " + getExportedData);
this.getExportedData = getExportedData;
}
private async doExport() {
try {
const result = await this.getExportedData({
format: "csv",
includeFilterContext: true,
mergeHeaders: true,
title: "henkie"
});
console.log("Export successfully: ", result.uri);
} catch (error) {
console.log("Export error: ", error);
}
}
And this is what the props returned in getProps looks like right now
return {
workspace,
filters,
insight,
config: {
chart: {
verticalAlignment: "middle"
},
colors: ["rgb(195, 49, 73)", "rgb(168, 194, 86)"]
},
drillableItems: this.drillableItems,
backend: this.goodData.backend,
onExportReady: exportFunction => {
this.onExportReady.bind(this);
},
...this.props,
};
Thank you for your time,
StijnRadek Novacek
10/02/2023, 12:23 PMStijn Habekotté
10/16/2023, 9:04 AMRadek Novacek
10/16/2023, 9:08 AM