Mustafa Dikici
08/23/2024, 9:35 AMMustafa Dikici
08/23/2024, 10:04 AMMustafa Dikici
08/23/2024, 12:46 PMuseEffect(() => {
emitter.subscribe((value: any) => {
if(value.type === 'GDC.DASH/EVT.FILTER_CONTEXT.DATE_FILTER.SELECTION_CHANGED') {
const {filter} = value;
if(filter.type === 'relative') {
const { from, to, granularity } = filter;
setFilters(newRelativeDateFilter(Md.DateDatasets.CreatedAt, granularity, from, to));
}
return
}
const ff = filterContextItemsToDashboardFiltersByDateDataSet(value.filters, Md.DateDatasets.CreatedAt);
const { relativeDateFilter } = ff[0] as any;
const { from, to, granularity } = relativeDateFilter;
setFilters(newRelativeDateFilter(Md.DateDatasets.CreatedAt, granularity, from, to));
});
pluginReeady.emit(true);
}, []);
inside plugin register function added event handlers:
handlers.addEventHandler("GDC.DASH/EVT.INITIALIZED", (evt) => {
pluginReeady.subscribe((value: any) => {
emitter.emit(evt.payload.dashboard.filterContext);
});
});
handlers.addEventHandler("GDC.DASH/EVT.FILTER_CONTEXT.DATE_FILTER.SELECTION_CHANGED", (evt) => {
emitter.emit({filter: evt.payload.filter.dateFilter, type: evt.type});
});
one thing to is that, dashboard init is called before plugin is rendered so you need a way to tell dashboard that plugin is ready