This commit is contained in:
Carl-Gerhard Lindesvärd
2026-01-07 10:04:21 +01:00
parent ba93924d20
commit ca15717885
33 changed files with 2375 additions and 148 deletions

View File

@@ -22,11 +22,10 @@ import {
getSelectPropertyKey,
getSettingsForProject,
onlyReportEvents,
sankeyService,
} from '@openpanel/db';
import {
type IChartEvent,
zChartEvent,
zChartEventFilter,
zChartInput,
zChartSeries,
zCriteria,
@@ -379,6 +378,38 @@ export const chartRouter = createTRPCRouter({
};
}),
sankey: protectedProcedure.input(zChartInput).query(async ({ input }) => {
const { timezone } = await getSettingsForProject(input.projectId);
const currentPeriod = getChartStartEndDate(input, timezone);
// Extract sankey options
const options = input.options;
if (!options || options.type !== 'sankey') {
throw new Error('Sankey options are required');
}
// Extract start/end events from series based on mode
const eventSeries = onlyReportEvents(input.series);
if (!eventSeries[0]) {
throw new Error('Start and end events are required');
}
return sankeyService.getSankey({
projectId: input.projectId,
startDate: currentPeriod.startDate,
endDate: currentPeriod.endDate,
steps: options.steps,
mode: options.mode,
startEvent: eventSeries[0],
endEvent: eventSeries[1],
exclude: options.exclude || [],
include: options.include,
timezone,
});
}),
chart: publicProcedure
// .use(cacher)
.input(zChartInput)

View File

@@ -59,6 +59,7 @@ export const reportRouter = createTRPCRouter({
metric: report.metric === 'count' ? 'sum' : report.metric,
funnelGroup: report.funnelGroup,
funnelWindow: report.funnelWindow,
options: report.options,
},
});
}),
@@ -104,6 +105,7 @@ export const reportRouter = createTRPCRouter({
metric: report.metric === 'count' ? 'sum' : report.metric,
funnelGroup: report.funnelGroup,
funnelWindow: report.funnelWindow,
options: report.options,
},
});
}),
@@ -175,6 +177,7 @@ export const reportRouter = createTRPCRouter({
metric: report.metric,
funnelGroup: report.funnelGroup,
funnelWindow: report.funnelWindow,
options: report.options,
},
});
}),