Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

feat: share dashboard & reports, sankey report, new widgets

Carl-Gerhard Lindesvärded1c57dbb88b
diff --git a/apps/api/src/controllers/export.controller.ts b/apps/api/src/controllers/export.controller.ts
index ac6229083..294f59c8c 100644
--- a/apps/api/src/controllers/export.controller.ts
+++ b/apps/api/src/controllers/export.controller.ts
@@ -13,7 +13,7 @@ import {
getSettingsForProject,
} from '@openpanel/db';
import { ChartEngine } from '@openpanel/db';
-import { zChartEvent, zChartInputBase } from '@openpanel/validation';
+import { zChartEvent, zReport } from '@openpanel/validation';
import { omit } from 'ramda';
async function getProjectId(
@@ -139,7 +139,7 @@ export async function events(
});
}
-const chartSchemeFull = zChartInputBase
+const chartSchemeFull = zReport
.pick({
breakdowns: true,
interval: true,
diff --git a/apps/api/src/controllers/webhook.controller.ts b/apps/api/src/controllers/webhook.controller.ts
index ccd447a2d..788e2741a 100644
--- a/apps/api/src/controllers/webhook.controller.ts
+++ b/apps/api/src/controllers/webhook.controller.ts
@@ -191,7 +191,9 @@ export async function polarWebhook(
where: {
subscriptionCustomerId: event.data.customer.id,
subscriptionId: event.data.id,
- subscriptionStatus: 'active',
+ subscriptionStatus: {
+ in: ['active', 'past_due', 'unpaid'],
+ },
},
});
diff --git a/apps/api/src/utils/ai-tools.ts b/apps/api/src/utils/ai-tools.ts
index e261b551b..70f43d277 100644
--- a/apps/api/src/utils/ai-tools.ts
+++ b/apps/api/src/utils/ai-tools.ts
@@ -9,7 +9,7 @@ import {
} from '@openpanel/db';
import { ChartEngine } from '@openpanel/db';
import { getCache } from '@openpanel/redis';
-import { zChartInputAI } from '@openpanel/validation';
+import { zReportInput } from '@openpanel/validation';
import { tool } from 'ai';
import { z } from 'zod';
@@ -27,7 +27,10 @@ export function getReport({
- ${chartTypes.metric}
- ${chartTypes.bar}
`,
- parameters: zChartInputAI,
+ parameters: zReportInput.extend({
+ startDate: z.string().describe('The start date for the report'),
+ endDate: z.string().describe('The end date for the report'),
+ }),
execute: async (report) => {
return {
type: 'report',
@@ -72,7 +75,10 @@ export function getConversionReport({
return tool({
description:
'Generate a report (a chart) for conversions between two actions a unique user took.',
- parameters: zChartInputAI,
+ parameters: zReportInput.extend({
+ startDate: z.string().describe('The start date for the report'),
+ endDate: z.string().describe('The end date for the report'),
+ }),
execute: async (report) => {
return {
type: 'report',
@@ -94,7 +100,10 @@ export function getFunnelReport({
return tool({
description:
'Generate a report (a chart) for funnel between two or more actions a unique user (session_id or profile_id) took.',
- parameters: zChartInputAI,
+ parameters: zReportInput.extend({
+ startDate: z.string().describe('The start date for the report'),
+ endDate: z.string().describe('The end date for the report'),
+ }),
execute: async (report) => {
return {
type: 'report',
diff --git a/apps/justfuckinguseopenpanel/favicon.ico b/apps/justfuckinguseopenpanel/favicon.ico
new file mode 100644
index 000000000..d0979c25f
Binary files /dev/null and b/apps/justfuckinguseopenpanel/favicon.ico differ
diff --git a/apps/justfuckinguseopenpanel/index.html b/apps/justfuckinguseopenpanel/index.html
new file mode 100644
index 000000000..7c880bafa
--- /dev/null
+++ b/apps/justfuckinguseopenpanel/index.html
@@ -0,0 +1,505 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ <!-- Primary Meta Tags -->
+ <title>Just Fucking Use OpenPanel - Stop Overpaying for Analytics</title>
+ <meta name="title" content="Just Fucking Use OpenPanel - Stop Overpaying for Analytics">
+ <meta name="description" content="Mixpanel costs $2,300/month at scale. PostHog costs $1,982/month. Web-only tools tell you nothing about user behavior. OpenPanel gives you full product analytics for a fraction of the cost, or FREE self-hosted.">
+ <meta name="keywords" content="openpanel, analytics, mixpanel alternative, posthog alternative, product analytics, web analytics, open source analytics, self-hosted analytics">
+ <meta name="author" content="OpenPanel">
+ <meta name="robots" content="index, follow">
+ <link rel="canonical" href="https://justfuckinguseopenpanel.dev/">
+ <link rel="icon" type="image/x-icon" href="/favicon.ico">
+
+ <!-- Open Graph / Facebook -->
+ <meta property="og:type" content="website">
+ <meta property="og:url" content="https://justfuckinguseopenpanel.dev/">
+ <meta property="og:title" content="Just Fucking Use OpenPanel - Stop Overpaying for Analytics">
+ <meta property="og:description" content="Mixpanel costs $2,300/month at scale. PostHog costs $1,982/month. Web-only tools tell you nothing about user behavior. OpenPanel gives you full product analytics for a fraction of the cost, or FREE self-hosted.">
+ <meta property="og:image" content="/ogimage.png">
+ <meta property="og:image:width" content="1200">
+ <meta property="og:image:height" content="630">
+ <meta property="og:site_name" content="Just Fucking Use OpenPanel">
+
+ <!-- Twitter -->
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:url" content="https://justfuckinguseopenpanel.dev/">
+ <meta name="twitter:title" content="Just Fucking Use OpenPanel - Stop Overpaying for Analytics">
+ <meta name="twitter:description" content="Mixpanel costs $2,300/month at scale. PostHog costs $1,982/month. Web-only tools tell you nothing about user behavior. OpenPanel gives you full product analytics for a fraction of the cost, or FREE self-hosted.">
+ <meta name="twitter:image" content="/ogimage.png">
+
+ <!-- Additional Meta Tags -->
+ <meta name="theme-color" content="#0a0a0a">
+ <meta name="color-scheme" content="dark">
+ <style>
+ * {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ }
+
+ body {
+ background: #0a0a0a;
+ color: #e5e5e5;
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
+ font-size: 18px;
+ line-height: 1.75;
+ padding: 2rem 1.5rem;
+ }
+
+ .container {
+ max-width: 700px;
+ margin: 0 auto;
+ }
+
+ h1 {
+ font-size: 2rem;
+ font-weight: 700;
+ line-height: 1;
+ margin-bottom: 0.5rem;
+ color: #ffffff;
+ }
+
+ h2 {
+ font-size: 1.875rem;
+ font-weight: 800;
+ line-height: 1.3;
+ margin-top: 3rem;
+ margin-bottom: 1.5rem;
+ color: #ffffff;
+ }
+
+ h3 {
+ font-size: 1.5rem;
+ font-weight: 700;
+ line-height: 1.4;
+ margin-top: 2rem;
+ margin-bottom: 1rem;
+ color: #ffffff;
+ }
+
+ p {
+ margin-bottom: 1.25em;
+ }
+
+ strong {
+ font-weight: 700;
+ color: #ffffff;
+ }
+
+ a {
+ color: #3b82f6;
+ text-decoration: underline;
+ text-underline-offset: 2px;
+ }
+
+ a:hover {
+ color: #60a5fa;
+ }
+
+ ul, ol {
+ margin-left: 1.5rem;
+ margin-bottom: 1.25em;
+ }
+
+ li {
+ margin-bottom: 0.5em;
+ }
+
+ blockquote {
+ border-left: 4px solid #3b82f6;
+ padding-left: 1.5rem;
+ margin: 1.5rem 0;
+ font-style: italic;
+ color: #d1d5db;
+ }
+
+ table {
+ width: 100%;
+ border-collapse: collapse;
+ margin: 2rem 0;
+ }
+
+ th, td {
+ padding: 0.75rem;
+ text-align: left;
+ border-bottom: 1px solid #374151;
+ }
+
+ th {
+ font-weight: 700;
+ color: #ffffff;
+ background: #131313;
+ }
+
+ tr:hover {
+ background: #131313;
+ }
+
+ .screenshot {
+ margin: 0 -4rem 4rem;
+ position: relative;
+ z-index: 10;
+ }
+
+ @media (max-width: 840px) {
+ .screenshot {
+ margin: 0;
+ }
+ }
+
+ .screenshot-inner {
+ border-radius: 8px;
+ overflow: hidden;
+ padding: 0.5rem;
+ background: #1a1a1a;
+ border: 1px solid #2a2a2a;
+ }
+
+ .window-controls {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ margin-bottom: 0.5rem;
+ padding: 0 0.25rem;
+ }
+
+ .window-dot {
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+ }
+
+ .window-dot.red {
+ background: #ef4444;
+ }
+
+ .window-dot.yellow {
+ background: #eab308;
+ }
+
+ .window-dot.green {
+ background: #22c55e;
+ }
+
+ .screenshot-image-wrapper {
+ width: 100%;
+ border: 1px solid #2a2a2a;
+ border-radius: 6px;
+ overflow: hidden;
+ background: #0a0a0a;
+ }
+
+ .screenshot img {
+ width: 100%;
+ height: auto;
+ display: block;
+ }
+
+ .cta {
+ background: #131313;
+ border: 1px solid rgba(255, 255, 255, 0.1);
+ border-radius: 8px;
+ padding: 2rem;
+ margin: 3rem 0;
+ text-align: center;
+ margin: 0 -4rem 4rem;
+ }
+
+ @media (max-width: 840px) {
+ .cta {
+ margin: 0;
+ }
+ }
+
+ .cta h2 {
+ margin-top: 0;
+ }
+
+ .cta a {
+ display: inline-block;
+ background: #fff;
+ color: #000;
+ padding: 0.75rem 1.5rem;
+ border-radius: 6px;
+ text-decoration: none;
+ font-weight: 600;
+ margin: 0.5rem;
+ transition: background 0.2s;
+ }
+
+ .cta a:hover {
+ background: #fff;
+ color: #000;
+ }
+
+ footer {
+ margin-top: 4rem;
+ padding-top: 2rem;
+ border-top: 1px solid #374151;
+ text-align: center;
+ color: #9ca3af;
+ font-size: 0.875rem;
+ }
+
+ .hero {
+ text-align: left;
+ margin-top: 4rem;
+ line-height: 1.5;
+ }
+
+ .hero p {
+ font-size: 1.25rem;
+ color: #8f8f8f;
+ margin-top: 1rem;
+ }
+
+ figcaption {
+ margin-top: 1rem;
+ font-size: 0.875rem;
+ text-align: center;
+ color: #9ca3af;
+ max-width: 100%;
+ }
+ </style>
+</head>
+<body>
+ <div class="container">
+ <div class="hero">
+ <h1>Just Fucking Use OpenPanel</h1>
+ <p>Stop settling for basic metrics. Get real insights that actually help you build a better product.</p>
+ </div>
+
+ <figure class="screenshot">
+ <div class="screenshot-inner">
+ <div class="window-controls">
+ <div class="window-dot red"></div>
+ <div class="window-dot yellow"></div>
+ <div class="window-dot green"></div>
+ </div>
+ <div class="screenshot-image-wrapper">
+ <img src="screenshots/realtime-dark.webp" alt="OpenPanel Real-time Analytics" width="1400" height="800">
+ </div>
+ </div>
+ <figcaption>Real-time analytics - see events as they happen. No waiting, no delays.</figcaption>
+ </figure>
+
+ <h2>The PostHog/Mixpanel Problem (Volume Pricing Hell)</h2>
+
+ <p>Let's talk about what happens when you have a <strong>real product</strong> with <strong>real users</strong>.</p>
+
+ <p><strong>Real pricing at scale (20M+ events/month):</strong></p>
+ <ul>
+ <li><strong>Mixpanel</strong>: $2,300/month (and more with add-ons)</li>
+ <li><strong>PostHog</strong>: $1,982/month (and more with add-ons)</li>
+ </ul>
+
+ <p>"1 million free events!" they scream. Cute. Until you have an actual product with actual users doing actual things. Then suddenly you need to "talk to sales" and your wallet starts bleeding.</p>
+
+ <p>Add-ons, add-ons everywhere. Session replay? +$X. Feature flags? +$X. HIPAA compliance? +$250/month. A/B testing? That'll be extra. You're hemorrhaging money just to understand what your users are doing, you magnificent fool.</p>
+
+ <h2>The Web-Only Analytics Trap</h2>
+
+ <p>You built a great fucking product. You have real traffic. Thousands, tens of thousands of visitors. But you're flying blind.</p>
+
+ <blockquote>
+ "Congrats, 50,000 visitors from France this month. Why didn't a single one buy your baguette?"
+ </blockquote>
+
+ <p>You see the traffic. You see the bounce rate. You see the referrers. You see where they're from. You have <strong>NO FUCKING IDEA</strong> what users actually do.</p>
+
+ <p>Where do they drop off? Do they come back? What features do they use? Why didn't they convert? Who the fuck knows! You're using a glorified hit counter with a pretty dashboard that tells you everything about geography and nothing about behavior.</p>
+
+ <p>Plausible. Umami. Fathom. Simple Analytics. GoatCounter. Cabin. Pirsch. They're all the same story: simple analytics with some goals you can define. Page views, visitors, countries, basic funnels. That's it. No retention analysis. No user profiles. No event tracking. No cohorts. No revenue tracking. Just... basic web analytics.</p>
+
+ <p>And when you finally need to understand your users—when you need to see where they drop off in your signup flow, or which features drive retention, or why your conversion rate is shit—you end up paying for a <strong>SECOND tool</strong> on top. Now you're paying for two subscriptions, managing two dashboards, and your users' data is split across two platforms like a bad divorce.</p>
+
+ <h2>Counter One Dollar Stats</h2>
+
+ <p>"$1/month for page views. Adorable."</p>
+
+ <p>Look, I get it. A dollar is cheap. But you're getting exactly what you pay for: page views. That's it. No funnels. No retention. No user profiles. No event tracking. Just... page views.</p>
+
+ <p>Here's the thing: if you want to make <strong>good decisions</strong> about your product, you need to understand <strong>what your users are actually doing</strong>, not just where the fuck they're from.</p>
+
+ <p>OpenPanel gives you the full product analytics suite. Or self-host for <strong>FREE</strong> with <strong>UNLIMITED events</strong>.</p>
+
+ <p>You get:</p>
+ <ul>
+ <li>Funnels to see where users drop off</li>
+ <li>Retention analysis to see who comes back</li>
+ <li>Cohorts to segment your users</li>
+ <li>User profiles to understand individual behavior</li>
+ <li>Custom dashboards to see what matters to YOU</li>
+ <li>Revenue tracking to see what actually makes money</li>
+ <li>All the web analytics (page views, visitors, referrers) that the other tools give you</li>
+ </ul>
+
+ <p>One Dollar Stats tells you 50,000 people visited from France. OpenPanel tells you why they didn't buy your baguette. That's the difference between vanity metrics and actual insights.</p>
+
+ <h2>Why OpenPanel is the Answer</h2>
+
+ <p>You want analytics that actually help you build a better product. Not vanity metrics. Not enterprise pricing. Not two separate tools.</p>
+
+ <p>To make good decisions, you need to understand <strong>what your users are doing</strong>, not just where they're from. You need to see where they drop off. You need to know which features they use. You need to understand why they convert or why they don't.</p>
+
+ <ul>
+ <li><strong>Open Source & Self-Hostable</strong>: AGPL-3.0 - fork it, audit it, own it. Self-host for FREE with unlimited events, or use our cloud</li>
+ <li><strong>Price</strong>: Affordable pricing that scales, or FREE self-hosted (unlimited events, forever)</li>
+ <li><strong>SDK Size</strong>: 2.3KB (PostHog is 52KB+ - that's 22x bigger, you performance-obsessed maniac)</li>
+ <li><strong>Privacy</strong>: Cookie-free by default, EU-only hosting (or your own servers if you self-host)</li>
+ <li><strong>Full Suite</strong>: Web analytics + product analytics in one tool. No need for two subscriptions.</li>
+ </ul>
+
+ <figure class="screenshot">
+ <div class="screenshot-inner">
+ <div class="window-controls">
+ <div class="window-dot red"></div>
+ <div class="window-dot yellow"></div>
+ <div class="window-dot green"></div>
+ </div>
+ <div class="screenshot-image-wrapper">
+ <img src="screenshots/overview-dark.webp" alt="OpenPanel Overview Dashboard" width="1400" height="800">
+ </div>
+ </div>
+ <figcaption>OpenPanel overview showing web analytics and product analytics in one clean interface</figcaption>
+ </figure>
+
+ <h2>Open Source & Self-Hosting: The Ultimate Fuck You to Pricing Hell</h2>
+
+ <p>Tired of watching your analytics bill grow every month? Tired of "talk to sales" when you hit their arbitrary limits? Tired of paying $2,000+/month just to understand your users?</p>
+
+ <p><strong>OpenPanel is open source.</strong> AGPL-3.0 licensed. You can fork it. You can audit it. You can own it. And you can <strong>self-host it for FREE with UNLIMITED events</strong>.</p>
+
+ <p>That's right. Zero dollars. Unlimited events. All the features. Your data on your servers. No vendor lock-in. No surprise bills. No "enterprise sales" calls.</p>
+
+ <p>Mixpanel at 20M events? $2,300/month. PostHog? $1,982/month. OpenPanel self-hosted? <strong>$0/month</strong>. Forever.</p>
+
+ <p>Don't want to manage infrastructure? That's fine. Use our cloud. But if you want to escape the pricing hell entirely, self-hosting is a Docker command away. Your data, your rules, your wallet.</p>
+
+ <h2>The Comparison Table (The Brutal Truth)</h2>
+
+ <table>
+ <thead>
+ <tr>
+ <th>Tool</th>
+ <th>Price at 20M events</th>
+ <th>What You Get</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><strong>Mixpanel</strong></td>
+ <td>$2,300+/month</td>
+ <td>Not all feautres... since addons are extra</td>
+ </tr>
+ <tr>
+ <td><strong>PostHog</strong></td>
+ <td>$1,982+/month</td>
+ <td>Not all feautres... since addons are extra</td>
+ </tr>
+ <tr>
+ <td><strong>Plausible</strong></td>
+ <td>Various pricing</td>
+ <td>Simple analytics with basic goals. Page views and visitors. That's it.</td>
+ </tr>
+ <tr>
+ <td><strong>One Dollar Stats</strong></td>
+ <td>$1/month</td>
+ <td>Page views (but cheaper!)</td>
+ </tr>
+ <tr style="background: #131313; border: 2px solid #3b82f6;">
+ <td><strong>OpenPanel</strong></td>
+ <td><strong>~$530/mo or FREE (self-hosted)</strong></td>
+ <td><strong>Web + Product analytics. The full package. Open source. Your data.</strong></td>
+ </tr>
+ </tbody>
+ </table>
+
+ <figure class="screenshot">
+ <div class="screenshot-inner">
+ <div class="window-controls">
+ <div class="window-dot red"></div>
+ <div class="window-dot yellow"></div>
+ <div class="window-dot green"></div>
+ </div>
+ <div class="screenshot-image-wrapper">
+ <img src="screenshots/profile-dark.webp" alt="OpenPanel User Profiles" width="1400" height="800">
+ </div>
+ </div>
+ <figcaption>User profiles - see individual user journeys and behavior. Something web-only tools can't give you.</figcaption>
+ </figure>
+
+ <figure class="screenshot">
+ <div class="screenshot-inner">
+ <div class="window-controls">
+ <div class="window-dot red"></div>
+ <div class="window-dot yellow"></div>
+ <div class="window-dot green"></div>
+ </div>
+ <div class="screenshot-image-wrapper">
+ <img src="screenshots/report-dark.webp" alt="OpenPanel Reports and Funnels" width="1400" height="800">
+ </div>
+ </div>
+ <figcaption>Funnels, retention, and custom reports - the features you CAN'T get with web-only tools</figcaption>
+ </figure>
+
+ <h2>The Bottom Fucking Line</h2>
+
+ <p>If you want to make good decisions about your product, you need to understand what your users are actually doing. Not just where they're from. Not just how many page views you got. You need to see the full picture: funnels, retention, user behavior, conversion paths.</p>
+
+ <p>You have three choices:</p>
+
+ <ol>
+ <li>Keep using Google Analytics like a data-harvesting accomplice, adding cookie banners, annoying your users, and contributing to the dystopian surveillance economy</li>
+ <li>Pay $2,000+/month for Mixpanel or PostHog when you scale, or use simple web-only analytics that tell you nothing about user behavior—just where they're from</li>
+ <li>Use OpenPanel (affordable pricing or FREE self-hosted) and get the full analytics suite: web analytics AND product analytics in one tool, so you can actually understand what your users do</li>
+ </ol>
+
+ <p>If you picked option 1 or 2, I can't help you. You're beyond saving. Go enjoy your complicated, privacy-violating, overpriced analytics life where you know everything about where your users are from but nothing about what they actually do.</p>
+
+ <p>But if you have even one functioning brain cell, you'll realize that OpenPanel gives you everything you need—web analytics AND product analytics—for a fraction of what the enterprise tools cost. You'll finally understand what your users are doing, not just where the fuck they're from.</p>
+
+ <div class="cta">
+ <h2>Ready to understand what your users actually do?</h2>
+ <p>Stop settling for vanity metrics. Get the full analytics suite—web analytics AND product analytics—so you can make better decisions. Or self-host for free.</p>
+ <a href="https://openpanel.dev" target="_blank">Get Started with OpenPanel</a>
+ <a href="https://openpanel.dev/docs/self-hosting/self-hosting" target="_blank">Self-Host Guide</a>
+ </div>
+
+ <figure class="screenshot">
+ <div class="screenshot-inner">
+ <div class="window-controls">
+ <div class="window-dot red"></div>
+ <div class="window-dot yellow"></div>
+ <div class="window-dot green"></div>
+ </div>
+ <div class="screenshot-image-wrapper">
+ <img src="screenshots/dashboard-dark.webp" alt="OpenPanel Custom Dashboards" width="1400" height="800">
+ </div>
+ </div>
+ <figcaption>Custom dashboards - build exactly what you need to understand your product</figcaption>
+ </figure>
+
+ <footer>
+ <p><strong>Just Fucking Use OpenPanel</strong></p>
+ <p>Inspired by <a href="https://justfuckingusereact.com" target="_blank" rel="nofollow">justfuckingusereact.com</a>, <a href="https://justfuckingusehtml.com" target="_blank" rel="nofollow">justfuckingusehtml.com</a>, and <a href="https://justfuckinguseonedollarstats.com" target="_blank" rel="nofollow">justfuckinguseonedollarstats.com</a> and all other just fucking use sites.</p>
+ <p style="margin-top: 1rem;">This is affiliated with <a href="https://openpanel.dev" target="_blank" rel="nofollow">OpenPanel</a>. We still love all products mentioned in this website, and we're grateful for them and what they do 🫶</p>
+ </footer>
+ </div>
+
+ <script>
+ window.op=window.op||function(){var n=[];return new Proxy(function(){arguments.length&&n.push([].slice.call(arguments))},{get:function(t,r){return"q"===r?n:function(){n.push([r].concat([].slice.call(arguments)))}} ,has:function(t,r){return"q"===r}}) }();
+ window.op('init', {
+ clientId: '59d97757-9449-44cf-a8c1-8f213843b4f0',
+ trackScreenViews: true,
+ trackOutgoingLinks: true,
+ trackAttributes: true,
+ });
+ </script>
+ <script src="https://openpanel.dev/op1.js" defer async></script>
+</body>
+</html>
diff --git a/apps/justfuckinguseopenpanel/ogimage.png b/apps/justfuckinguseopenpanel/ogimage.png
new file mode 100644
index 000000000..3c78a117e
Binary files /dev/null and b/apps/justfuckinguseopenpanel/ogimage.png differ
diff --git a/apps/justfuckinguseopenpanel/screenshots/dashboard-dark.webp b/apps/justfuckinguseopenpanel/screenshots/dashboard-dark.webp
new file mode 100644
index 000000000..ff4d74aa2
Binary files /dev/null and b/apps/justfuckinguseopenpanel/screenshots/dashboard-dark.webp differ
diff --git a/apps/justfuckinguseopenpanel/screenshots/overview-dark.webp b/apps/justfuckinguseopenpanel/screenshots/overview-dark.webp
new file mode 100644
index 000000000..922b3b8d8
Binary files /dev/null and b/apps/justfuckinguseopenpanel/screenshots/overview-dark.webp differ
diff --git a/apps/justfuckinguseopenpanel/screenshots/profile-dark.webp b/apps/justfuckinguseopenpanel/screenshots/profile-dark.webp
new file mode 100644
index 000000000..8a022a8af
Binary files /dev/null and b/apps/justfuckinguseopenpanel/screenshots/profile-dark.webp differ
diff --git a/apps/justfuckinguseopenpanel/screenshots/realtime-dark.webp b/apps/justfuckinguseopenpanel/screenshots/realtime-dark.webp
new file mode 100644
index 000000000..5c1d5cc6e
Binary files /dev/null and b/apps/justfuckinguseopenpanel/screenshots/realtime-dark.webp differ
diff --git a/apps/justfuckinguseopenpanel/screenshots/report-dark.webp b/apps/justfuckinguseopenpanel/screenshots/report-dark.webp
new file mode 100644
index 000000000..7cc2f15e0
Binary files /dev/null and b/apps/justfuckinguseopenpanel/screenshots/report-dark.webp differ
diff --git a/apps/justfuckinguseopenpanel/wrangler.jsonc b/apps/justfuckinguseopenpanel/wrangler.jsonc
new file mode 100644
index 000000000..005d95fb1
--- /dev/null
+++ b/apps/justfuckinguseopenpanel/wrangler.jsonc
@@ -0,0 +1,7 @@
+{
+ "name": "justfuckinguseopenpanel",
+ "compatibility_date": "2025-12-19",
+ "assets": {
+ "directory": "."
+ }
+}
\ No newline at end of file
diff --git a/apps/start/package.json b/apps/start/package.json
index a3dbf91cb..98ec9948d 100644
--- a/apps/start/package.json
+++ b/apps/start/package.json
@@ -10,7 +10,6 @@
"cf-typegen": "wrangler types",
"build": "pnpm with-env vite build",
"serve": "vite preview",
- "test": "vitest run",
"format": "biome format",
"lint": "biome lint",
"check": "biome check",
@@ -26,7 +25,7 @@
"@hookform/resolvers": "^3.3.4",
"@hyperdx/node-opentelemetry": "^0.8.1",
"@nivo/sankey": "^0.99.0",
- "@number-flow/react": "0.3.5",
+ "@number-flow/react": "0.5.10",
"@openpanel/common": "workspace:^",
"@openpanel/constants": "workspace:^",
"@openpanel/integrations": "workspace:^",
@@ -150,7 +149,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
- "@cloudflare/vite-plugin": "^1.13.12",
+ "@cloudflare/vite-plugin": "1.20.3",
"@openpanel/db": "workspace:*",
"@openpanel/trpc": "workspace:*",
"@tanstack/devtools-event-client": "^0.3.3",
@@ -171,6 +170,6 @@
"vite": "^6.3.5",
"vitest": "^3.0.5",
"web-vitals": "^4.2.4",
- "wrangler": "^4.42.2"
+ "wrangler": "4.59.1"
}
}
\ No newline at end of file
diff --git a/apps/start/src/components/animated-number.tsx b/apps/start/src/components/animated-number.tsx
index 61f5e8b54..813a7979b 100644
--- a/apps/start/src/components/animated-number.tsx
+++ b/apps/start/src/components/animated-number.tsx
@@ -1,20 +1,6 @@
import type { NumberFlowProps } from '@number-flow/react';
-import { useEffect, useState } from 'react';
+import ReactAnimatedNumber from '@number-flow/react';
-// NumberFlow is breaking ssr and forces loaders to fetch twice
export function AnimatedNumber(props: NumberFlowProps) {
- const [Component, setComponent] =
- useState<React.ComponentType<NumberFlowProps> | null>(null);
-
- useEffect(() => {
- import('@number-flow/react').then(({ default: NumberFlow }) => {
- setComponent(NumberFlow);
- });
- }, []);
-
- if (!Component) {
- return <>{props.value}</>;
- }
-
- return <Component {...props} />;
+ return <ReactAnimatedNumber {...props} />;
}
diff --git a/apps/start/src/components/auth/share-enter-password.tsx b/apps/start/src/components/auth/share-enter-password.tsx
index a04759bb4..b25dae612 100644
--- a/apps/start/src/components/auth/share-enter-password.tsx
+++ b/apps/start/src/components/auth/share-enter-password.tsx
@@ -8,7 +8,13 @@ import { LogoSquare } from '../logo';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
-export function ShareEnterPassword({ shareId }: { shareId: string }) {
+export function ShareEnterPassword({
+ shareId,
+ shareType = 'overview',
+}: {
+ shareId: string;
+ shareType?: 'overview' | 'dashboard' | 'report';
+}) {
const trpc = useTRPC();
const mutation = useMutation(
trpc.auth.signInShare.mutationOptions({
@@ -25,6 +31,7 @@ export function ShareEnterPassword({ shareId }: { shareId: string }) {
defaultValues: {
password: '',
shareId,
+ shareType,
},
});
@@ -32,6 +39,7 @@ export function ShareEnterPassword({ shareId }: { shareId: string }) {
mutation.mutate({
password: data.password,
shareId,
+ shareType,
});
});
@@ -40,9 +48,20 @@ export function ShareEnterPassword({ shareId }: { shareId: string }) {
<div className="bg-background p-6 rounded-lg max-w-md w-full text-left">
<div className="col mt-1 flex-1 gap-2">
<LogoSquare className="size-12 mb-4" />
- <div className="text-xl font-semibold">Overview is locked</div>
+ <div className="text-xl font-semibold">
+ {shareType === 'dashboard'
+ ? 'Dashboard is locked'
+ : shareType === 'report'
+ ? 'Report is locked'
+ : 'Overview is locked'}
+ </div>
<div className="text-lg text-muted-foreground leading-normal">
- Please enter correct password to access this overview
+ Please enter correct password to access this{' '}
+ {shareType === 'dashboard'
+ ? 'dashboard'
+ : shareType === 'report'
+ ? 'report'
+ : 'overview'}
</div>
</div>
<form onSubmit={onSubmit} className="col gap-4 mt-6">
diff --git a/apps/start/src/components/chat/chat-message.tsx b/apps/start/src/components/chat/chat-message.tsx
index 5d08db9e5..e380c2472 100644
--- a/apps/start/src/components/chat/chat-message.tsx
+++ b/apps/start/src/components/chat/chat-message.tsx
@@ -1,6 +1,7 @@
import { Markdown } from '@/components/markdown';
import { cn } from '@/utils/cn';
-import { zChartInputAI } from '@openpanel/validation';
+import { zReport } from '@openpanel/validation';
+import { z } from 'zod';
import type { UIMessage } from 'ai';
import { Loader2Icon, UserIcon } from 'lucide-react';
import { Fragment, memo } from 'react';
@@ -77,7 +78,10 @@ export const ChatMessage = memo(
const { result } = p.toolInvocation;
if (result.type === 'report') {
- const report = zChartInputAI.safeParse(result.report);
+ const report = zReport.extend({
+ startDate: z.string(),
+ endDate: z.string(),
+ }).safeParse(result.report);
if (report.success) {
return (
<Fragment key={key}>
diff --git a/apps/start/src/components/chat/chat-report.tsx b/apps/start/src/components/chat/chat-report.tsx
index f8538ccda..bc967001f 100644
--- a/apps/start/src/components/chat/chat-report.tsx
+++ b/apps/start/src/components/chat/chat-report.tsx
@@ -1,6 +1,6 @@
import { pushModal } from '@/modals';
import type {
- IChartInputAi,
+ IReport,
IChartRange,
IChartType,
IInterval,
@@ -16,7 +16,7 @@ import { Button } from '../ui/button';
export function ChatReport({
lazy,
...props
-}: { report: IChartInputAi; lazy: boolean }) {
+}: { report: IReport & { startDate: string; endDate: string }; lazy: boolean }) {
const [chartType, setChartType] = useState<IChartType>(
props.report.chartType,
);
diff --git a/apps/start/src/components/grafana-grid.tsx b/apps/start/src/components/grafana-grid.tsx
new file mode 100644
index 000000000..4b4232ccd
--- /dev/null
+++ b/apps/start/src/components/grafana-grid.tsx
@@ -0,0 +1,95 @@
+import type { IServiceReport } from '@openpanel/db';
+import { useMemo } from 'react';
+import { Responsive, WidthProvider } from 'react-grid-layout';
+
+const ResponsiveGridLayout = WidthProvider(Responsive);
+
+export type Layout = ReactGridLayout.Layout;
+
+export const useReportLayouts = (
+ reports: NonNullable<IServiceReport>[],
+): ReactGridLayout.Layouts => {
+ return useMemo(() => {
+ const baseLayout = reports.map((report, index) => ({
+ i: report.id,
+ x: report.layout?.x ?? (index % 2) * 6,
+ y: report.layout?.y ?? Math.floor(index / 2) * 4,
+ w: report.layout?.w ?? 6,
+ h: report.layout?.h ?? 4,
+ minW: 3,
+ minH: 3,
+ }));
+
+ return {
+ lg: baseLayout,
+ md: baseLayout,
+ sm: baseLayout.map((item) => ({ ...item, w: Math.min(item.w, 6) })),
+ xs: baseLayout.map((item) => ({ ...item, w: 4, x: 0 })),
+ xxs: baseLayout.map((item) => ({ ...item, w: 2, x: 0 })),
+ };
+ }, [reports]);
+};
+
+export function GrafanaGrid({
+ layouts,
+ children,
+ transitions,
+ onLayoutChange,
+ onDragStop,
+ onResizeStop,
+ isDraggable,
+ isResizable,
+}: {
+ children: React.ReactNode;
+ transitions?: boolean;
+} & Pick<
+ ReactGridLayout.ResponsiveProps,
+ | 'layouts'
+ | 'onLayoutChange'
+ | 'onDragStop'
+ | 'onResizeStop'
+ | 'isDraggable'
+ | 'isResizable'
+>) {
+ return (
+ <>
+ <style>{`
+ .react-grid-item {
+ transition: ${transitions ? 'transform 200ms ease, width 200ms ease, height 200ms ease' : 'none'} !important;
+ }
+ .react-grid-item.react-grid-placeholder {
+ background: none !important;
+ opacity: 0.5;
+ transition-duration: 100ms;
+ border-radius: 0.5rem;
+ border: 1px dashed var(--primary);
+ }
+ .react-grid-item.resizing {
+ transition: none !important;
+ }
+ `}</style>
+ <div className="-m-4">
+ <ResponsiveGridLayout
+ className="layout"
+ layouts={layouts}
+ breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
+ cols={{ lg: 12, md: 12, sm: 6, xs: 4, xxs: 2 }}
+ rowHeight={100}
+ draggableHandle=".drag-handle"
+ compactType="vertical"
+ preventCollision={false}
+ margin={[16, 16]}
+ transformScale={1}
+ useCSSTransforms={true}
+ onLayoutChange={onLayoutChange}
+ onDragStop={onDragStop}
+ onResizeStop={onResizeStop}
+ isDraggable={isDraggable}
+ isResizable={isResizable}
+ >
+ {children}
+ </ResponsiveGridLayout>
+ </div>
+ </>
+ );
+}
diff --git a/apps/start/src/components/login-navbar.tsx b/apps/start/src/components/login-navbar.tsx
index e8cb47701..1c703abb1 100644
--- a/apps/start/src/components/login-navbar.tsx
+++ b/apps/start/src/components/login-navbar.tsx
@@ -33,7 +33,7 @@ export function LoginNavbar({ className }: { className?: string }) {
</a>
</li>
<li>
- <a href="https://openpanel.dev/compare/mixpanel-alternative">
+ <a href="https://openpanel.dev/compare/posthog-alternative">
Posthog alternative
</a>
</li>
diff --git a/apps/start/src/components/organization/prompt-card.tsx b/apps/start/src/components/organization/prompt-card.tsx
index 97a49d48e..8c9111a02 100644
--- a/apps/start/src/components/organization/prompt-card.tsx
+++ b/apps/start/src/components/organization/prompt-card.tsx
@@ -33,7 +33,7 @@ export function PromptCard({
}}
className="fixed bottom-0 right-0 z-50 p-4 max-w-sm"
>
- <div className="bg-card border rounded-lg shadow-[0_0_100px_50px_rgba(20,20,20,1)] col gap-6 py-6 overflow-hidden">
+ <div className="bg-card border rounded-lg shadow-[0_0_100px_50px_var(--color-background)] col gap-6 py-6 overflow-hidden">
<div className="relative px-6 col gap-1">
<div
className="absolute -bottom-10 -right-10 h-64 w-64 rounded-full opacity-30 blur-3xl pointer-events-none"
diff --git a/apps/start/src/components/overview/overview-top-events.tsx b/apps/start/src/components/overview/overview-top-events.tsx
index bd2fe3776..6b2fb678b 100644
--- a/apps/start/src/components/overview/overview-top-events.tsx
+++ b/apps/start/src/components/overview/overview-top-events.tsx
@@ -1,7 +1,7 @@
import { useEventQueryFilters } from '@/hooks/use-event-query-filters';
import { useMemo, useState } from 'react';
-import type { IChartInput } from '@openpanel/validation';
+import type { IReportInput } from '@openpanel/validation';
import { useTRPC } from '@/integrations/trpc/react';
import { useQuery } from '@tanstack/react-query';
@@ -74,7 +74,7 @@ export default function OverviewTopEvents({
},
});
- const report: IChartInput = useMemo(
+ const report: IReportInput = useMemo(
() => ({
limit: 1000,
projectId,
@@ -96,9 +96,7 @@ export default function OverviewTopEvents({
},
],
chartType: 'bar' as const,
- lineType: 'monotone' as const,
interval,
- name: widget.title,
range,
previous,
metric: 'sum' as const,
diff --git a/apps/start/src/components/overview/overview-top-geo.tsx b/apps/start/src/components/overview/overview-top-geo.tsx
index 1ce235520..2afaa58a3 100644
--- a/apps/start/src/components/overview/overview-top-geo.tsx
+++ b/apps/start/src/components/overview/overview-top-geo.tsx
@@ -11,6 +11,7 @@ import { useQuery } from '@tanstack/react-query';
import { ChevronRightIcon } from 'lucide-react';
import { ReportChart } from '../report-chart';
import { SerieIcon } from '../report-chart/common/serie-icon';
+import { ReportChartShortcut } from '../report-chart/shortcut';
import { Widget, WidgetBody } from '../widget';
import { OVERVIEW_COLUMNS_NAME } from './overview-constants';
import OverviewDetailsButton from './overview-details-button';
@@ -210,9 +211,8 @@ export default function OverviewTopGeo({ projectId }: OverviewTopGeoProps) {
<div className="title">Map</div>
</WidgetHead>
<WidgetBody>
- <ReportChart
- options={{ hideID: true }}
- report={{
+ <ReportChartShortcut
+ {...{
projectId,
startDate,
endDate,
@@ -232,12 +232,9 @@ export default function OverviewTopGeo({ projectId }: OverviewTopGeoProps) {
},
],
chartType: 'map',
- lineType: 'monotone',
interval: interval,
- name: 'Top sources',
range: range,
previous: previous,
- metric: 'sum',
}}
/>
</WidgetBody>
diff --git a/apps/start/src/components/profiles/profile-charts.tsx b/apps/start/src/components/profiles/profile-charts.tsx
index 41797dd9b..21428ea6d 100644
--- a/apps/start/src/components/profiles/profile-charts.tsx
+++ b/apps/start/src/components/profiles/profile-charts.tsx
@@ -2,7 +2,7 @@ import { ReportChart } from '@/components/report-chart';
import { Widget, WidgetBody } from '@/components/widget';
import { memo } from 'react';
-import type { IChartProps } from '@openpanel/validation';
+import type { IReport } from '@openpanel/validation';
import { WidgetHead } from '../overview/overview-widget';
type Props = {
@@ -12,7 +12,7 @@ type Props = {
export const ProfileCharts = memo(
({ profileId, projectId }: Props) => {
- const pageViewsChart: IChartProps = {
+ const pageViewsChart: IReport = {
projectId,
chartType: 'linear',
series: [
@@ -46,7 +46,7 @@ export const ProfileCharts = memo(
metric: 'sum',
};
- const eventsChart: IChartProps = {
+ const eventsChart: IReport = {
projectId,
chartType: 'linear',
series: [
diff --git a/apps/start/src/components/report-chart/area/index.tsx b/apps/start/src/components/report-chart/area/index.tsx
index c8d3f74a4..fea775870 100644
--- a/apps/start/src/components/report-chart/area/index.tsx
+++ b/apps/start/src/components/report-chart/area/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -9,15 +10,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportAreaChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.chart.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.chart.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/bar/index.tsx b/apps/start/src/components/report-chart/bar/index.tsx
index 877f104dd..38855bdea 100644
--- a/apps/start/src/components/report-chart/bar/index.tsx
+++ b/apps/start/src/components/report-chart/bar/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { cn } from '@/utils/cn';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
@@ -9,15 +10,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportBarChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.aggregate.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.aggregate.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/common/previous-diff-indicator.tsx b/apps/start/src/components/report-chart/common/previous-diff-indicator.tsx
index 38988963c..669af54b2 100644
--- a/apps/start/src/components/report-chart/common/previous-diff-indicator.tsx
+++ b/apps/start/src/components/report-chart/common/previous-diff-indicator.tsx
@@ -42,10 +42,10 @@ export function PreviousDiffIndicator({
className,
}: PreviousDiffIndicatorProps) {
const {
- report: { previousIndicatorInverted, previous },
+ report: { previous },
} = useReportChartContext();
const variant = getDiffIndicator(
- inverted ?? previousIndicatorInverted,
+ inverted,
state,
'bg-emerald-300',
'bg-rose-300',
diff --git a/apps/start/src/components/report-chart/context.tsx b/apps/start/src/components/report-chart/context.tsx
index 8dd603318..fc648623e 100644
--- a/apps/start/src/components/report-chart/context.tsx
+++ b/apps/start/src/components/report-chart/context.tsx
@@ -2,16 +2,11 @@ import isEqual from 'lodash.isequal';
import type { LucideIcon } from 'lucide-react';
import { createContext, useContext, useEffect, useState } from 'react';
-import type {
- IChartInput,
- IChartProps,
- IChartSerie,
-} from '@openpanel/validation';
+import type { IChartSerie, IReportInput } from '@openpanel/validation';
export type ReportChartContextType = {
options: Partial<{
columns: React.ReactNode[];
- hideID: boolean;
hideLegend: boolean;
hideXAxis: boolean;
hideYAxis: boolean;
@@ -28,9 +23,11 @@ export type ReportChartContextType = {
onClick: () => void;
}[];
}>;
- report: IChartProps;
+ report: IReportInput & { id?: string };
isLazyLoading: boolean;
isEditMode: boolean;
+ shareId?: string;
+ reportId?: string;
};
type ReportChartContextProviderProps = ReportChartContextType & {
@@ -38,7 +35,7 @@ type ReportChartContextProviderProps = ReportChartContextType & {
};
export type ReportChartProps = Partial<ReportChartContextType> & {
- report: IChartInput;
+ report: IReportInput & { id?: string };
lazy?: boolean;
};
@@ -54,20 +51,6 @@ export const useReportChartContext = () => {
return ctx;
};
-export const useSelectReportChartContext = <T,>(
- selector: (ctx: ReportChartContextType) => T,
-) => {
- const ctx = useReportChartContext();
- const [state, setState] = useState(selector(ctx));
- useEffect(() => {
- const newState = selector(ctx);
- if (!isEqual(newState, state)) {
- setState(newState);
- }
- }, [ctx]);
- return state;
-};
-
export const ReportChartProvider = ({
children,
...propsToContext
diff --git a/apps/start/src/components/report-chart/conversion/index.tsx b/apps/start/src/components/report-chart/conversion/index.tsx
index fc75527b5..a594b5cb6 100644
--- a/apps/start/src/components/report-chart/conversion/index.tsx
+++ b/apps/start/src/components/report-chart/conversion/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { cn } from '@/utils/cn';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
@@ -11,15 +12,27 @@ import { Chart } from './chart';
import { Summary } from './summary';
export function ReportConversionChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
console.log(report.limit);
const res = useQuery(
- trpc.chart.conversion.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.conversion.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/funnel/chart.tsx b/apps/start/src/components/report-chart/funnel/chart.tsx
index e48fce132..66506f0c7 100644
--- a/apps/start/src/components/report-chart/funnel/chart.tsx
+++ b/apps/start/src/components/report-chart/funnel/chart.tsx
@@ -131,34 +131,36 @@ export function Tables({
series: reportSeries,
breakdowns: reportBreakdowns,
previous,
- funnelWindow,
- funnelGroup,
+ options,
},
} = useReportChartContext();
+ const funnelOptions = options?.type === 'funnel' ? options : undefined;
+ const funnelWindow = funnelOptions?.funnelWindow;
+ const funnelGroup = funnelOptions?.funnelGroup;
+
const handleInspectStep = (step: (typeof steps)[0], stepIndex: number) => {
if (!projectId || !step.event.id) return;
// For funnels, we need to pass the step index so the modal can query
// users who completed at least that step in the funnel sequence
- pushModal('ViewChartUsers', {
- type: 'funnel',
- report: {
- projectId,
- series: reportSeries,
- breakdowns: reportBreakdowns || [],
- interval: interval || 'day',
- startDate,
- endDate,
- range,
- previous,
- chartType: 'funnel',
- metric: 'sum',
- funnelWindow,
- funnelGroup,
- },
- stepIndex, // Pass the step index for funnel queries
- });
+ pushModal('ViewChartUsers', {
+ type: 'funnel',
+ report: {
+ projectId,
+ series: reportSeries,
+ breakdowns: reportBreakdowns || [],
+ interval: interval || 'day',
+ startDate,
+ endDate,
+ range,
+ previous,
+ chartType: 'funnel',
+ metric: 'sum',
+ options: funnelOptions,
+ },
+ stepIndex, // Pass the step index for funnel queries
+ });
};
return (
<div className={cn('col @container divide-y divide-border card')}>
diff --git a/apps/start/src/components/report-chart/funnel/index.tsx b/apps/start/src/components/report-chart/funnel/index.tsx
index 5fdda9c28..9239eb341 100644
--- a/apps/start/src/components/report-chart/funnel/index.tsx
+++ b/apps/start/src/components/report-chart/funnel/index.tsx
@@ -2,7 +2,8 @@ import { useTRPC } from '@/integrations/trpc/react';
import type { RouterOutputs } from '@/trpc/client';
import { useQuery } from '@tanstack/react-query';
-import type { IChartInput } from '@openpanel/validation';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
+import type { IReportInput } from '@openpanel/validation';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
@@ -14,35 +15,39 @@ import { Chart, Summary, Tables } from './chart';
export function ReportFunnelChart() {
const {
report: {
+ id,
series,
range,
projectId,
- funnelWindow,
- funnelGroup,
+ options,
startDate,
endDate,
previous,
breakdowns,
+ interval,
},
isLazyLoading,
+ shareId,
} = useReportChartContext();
+ const { range: overviewRange, startDate: overviewStartDate, endDate: overviewEndDate, interval: overviewInterval } = useOverviewOptions();
- const input: IChartInput = {
+ const funnelOptions = options?.type === 'funnel' ? options : undefined;
+
+ const trpc = useTRPC();
+ const input: IReportInput = {
series,
- range,
+ range: overviewRange ?? range,
projectId,
- interval: 'day',
+ interval: overviewInterval ?? interval ?? 'day',
chartType: 'funnel',
breakdowns,
- funnelWindow,
- funnelGroup,
previous,
metric: 'sum',
- startDate,
- endDate,
+ startDate: overviewStartDate ?? startDate,
+ endDate: overviewEndDate ?? endDate,
limit: 20,
+ options: funnelOptions,
};
- const trpc = useTRPC();
const res = useQuery(
trpc.chart.funnel.queryOptions(input, {
enabled: !isLazyLoading && input.series.length > 0,
diff --git a/apps/start/src/components/report-chart/histogram/index.tsx b/apps/start/src/components/report-chart/histogram/index.tsx
index 1f6d01468..e3c2b384a 100644
--- a/apps/start/src/components/report-chart/histogram/index.tsx
+++ b/apps/start/src/components/report-chart/histogram/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -9,15 +10,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportHistogramChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.chart.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.chart.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/index.tsx b/apps/start/src/components/report-chart/index.tsx
index f116cf1f7..95567b51f 100644
--- a/apps/start/src/components/report-chart/index.tsx
+++ b/apps/start/src/components/report-chart/index.tsx
@@ -15,6 +15,7 @@ import { ReportMapChart } from './map';
import { ReportMetricChart } from './metric';
import { ReportPieChart } from './pie';
import { ReportRetentionChart } from './retention';
+import { ReportSankeyChart } from './sankey';
export const ReportChart = ({ lazy = true, ...props }: ReportChartProps) => {
const ref = useRef<HTMLDivElement>(null);
@@ -57,6 +58,8 @@ export const ReportChart = ({ lazy = true, ...props }: ReportChartProps) => {
return <ReportRetentionChart />;
case 'conversion':
return <ReportConversionChart />;
+ case 'sankey':
+ return <ReportSankeyChart />;
default:
return null;
}
diff --git a/apps/start/src/components/report-chart/line/index.tsx b/apps/start/src/components/report-chart/line/index.tsx
index 5c11c5d78..5b2c90a17 100644
--- a/apps/start/src/components/report-chart/line/index.tsx
+++ b/apps/start/src/components/report-chart/line/index.tsx
@@ -2,6 +2,7 @@ import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { cn } from '@/utils/cn';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -10,15 +11,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportLineChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.chart.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.chart.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/map/index.tsx b/apps/start/src/components/report-chart/map/index.tsx
index d6ca11c74..8dd256f75 100644
--- a/apps/start/src/components/report-chart/map/index.tsx
+++ b/apps/start/src/components/report-chart/map/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -9,15 +10,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportMapChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.chart.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.chart.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/metric/index.tsx b/apps/start/src/components/report-chart/metric/index.tsx
index 7d8e5829e..83447a7b2 100644
--- a/apps/start/src/components/report-chart/metric/index.tsx
+++ b/apps/start/src/components/report-chart/metric/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -8,15 +9,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportMetricChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.chart.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.chart.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/metric/metric-card.tsx b/apps/start/src/components/report-chart/metric/metric-card.tsx
index 7383889f8..334091bfc 100644
--- a/apps/start/src/components/report-chart/metric/metric-card.tsx
+++ b/apps/start/src/components/report-chart/metric/metric-card.tsx
@@ -54,10 +54,7 @@ export function MetricCard({
metric,
unit,
}: MetricCardProps) {
- const {
- report: { previousIndicatorInverted },
- isEditMode,
- } = useReportChartContext();
+ const { isEditMode } = useReportChartContext();
const number = useNumber();
const renderValue = (value: number | undefined, unitClassName?: string) => {
@@ -80,7 +77,7 @@ export function MetricCard({
const previous = serie.metrics.previous?.[metric];
const graphColors = getDiffIndicator(
- previousIndicatorInverted,
+ false,
previous?.state,
'#6ee7b7', // green
'#fda4af', // red
diff --git a/apps/start/src/components/report-chart/pie/index.tsx b/apps/start/src/components/report-chart/pie/index.tsx
index bf2589cc5..7420ac6d2 100644
--- a/apps/start/src/components/report-chart/pie/index.tsx
+++ b/apps/start/src/components/report-chart/pie/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -9,15 +10,27 @@ import { useReportChartContext } from '../context';
import { Chart } from './chart';
export function ReportPieChart() {
- const { isLazyLoading, report } = useReportChartContext();
+ const { isLazyLoading, report, shareId } = useReportChartContext();
const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
const res = useQuery(
- trpc.chart.aggregate.queryOptions(report, {
- placeholderData: keepPreviousData,
- staleTime: 1000 * 60 * 1,
- enabled: !isLazyLoading,
- }),
+ trpc.chart.aggregate.queryOptions(
+ {
+ ...report,
+ shareId,
+ reportId: 'id' in report ? report.id : undefined,
+ range: range ?? report.range,
+ startDate: startDate ?? report.startDate,
+ endDate: endDate ?? report.endDate,
+ interval: interval ?? report.interval,
+ },
+ {
+ placeholderData: keepPreviousData,
+ staleTime: 1000 * 60 * 1,
+ enabled: !isLazyLoading,
+ },
+ ),
);
if (
diff --git a/apps/start/src/components/report-chart/report-editor.tsx b/apps/start/src/components/report-chart/report-editor.tsx
index 28617064e..dc1a04a98 100644
--- a/apps/start/src/components/report-chart/report-editor.tsx
+++ b/apps/start/src/components/report-chart/report-editor.tsx
@@ -11,7 +11,6 @@ import {
changeStartDate,
ready,
reset,
- setName,
setReport,
} from '@/components/report/reportSlice';
import { ReportSidebar } from '@/components/report/sidebar/ReportSidebar';
@@ -19,9 +18,10 @@ import { TimeWindowPicker } from '@/components/time-window-picker';
import { Button } from '@/components/ui/button';
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet';
import { useAppParams } from '@/hooks/use-app-params';
+import { pushModal } from '@/modals';
import { useDispatch, useSelector } from '@/redux';
import { bind } from 'bind-event-listener';
-import { GanttChartSquareIcon } from 'lucide-react';
+import { GanttChartSquareIcon, ShareIcon } from 'lucide-react';
import { useEffect } from 'react';
import type { IServiceReport } from '@openpanel/db';
@@ -54,8 +54,19 @@ export default function ReportEditor({
return (
<Sheet>
<div>
- <div className="p-4">
+ <div className="p-4 flex items-center justify-between">
<EditReportName />
+ {initialReport?.id && (
+ <Button
+ variant="outline"
+ icon={ShareIcon}
+ onClick={() =>
+ pushModal('ShareReportModal', { reportId: initialReport.id })
+ }
+ >
+ Share
+ </Button>
+ )}
</div>
<div className="grid grid-cols-2 gap-2 p-4 pt-0 md:grid-cols-6">
<SheetTrigger asChild>
diff --git a/apps/start/src/components/report-chart/retention/index.tsx b/apps/start/src/components/report-chart/retention/index.tsx
index 58bbffff4..9619ab0e7 100644
--- a/apps/start/src/components/report-chart/retention/index.tsx
+++ b/apps/start/src/components/report-chart/retention/index.tsx
@@ -1,6 +1,7 @@
import { useTRPC } from '@/integrations/trpc/react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { AspectContainer } from '../aspect-container';
import { ReportChartEmpty } from '../common/empty';
import { ReportChartError } from '../common/error';
@@ -12,21 +13,33 @@ import CohortTable from './table';
export function ReportRetentionChart() {
const {
report: {
+ id,
series,
range,
projectId,
+ options,
startDate,
endDate,
- criteria,
interval,
},
isLazyLoading,
+ shareId,
} = useReportChartContext();
+ const {
+ range: overviewRange,
+ startDate: overviewStartDate,
+ endDate: overviewEndDate,
+ interval: overviewInterval,
+ } = useOverviewOptions();
const eventSeries = series.filter((item) => item.type === 'event');
const firstEvent = (eventSeries[0]?.filters?.[0]?.value ?? []).map(String);
const secondEvent = (eventSeries[1]?.filters?.[0]?.value ?? []).map(String);
const isEnabled =
firstEvent.length > 0 && secondEvent.length > 0 && !isLazyLoading;
+
+ const retentionOptions = options?.type === 'retention' ? options : undefined;
+ const criteria = retentionOptions?.criteria ?? 'on_or_after';
+
const trpc = useTRPC();
const res = useQuery(
trpc.chart.cohort.queryOptions(
@@ -34,11 +47,13 @@ export function ReportRetentionChart() {
firstEvent,
secondEvent,
projectId,
- range,
- startDate,
- endDate,
+ range: overviewRange ?? range,
+ startDate: overviewStartDate ?? startDate,
+ endDate: overviewEndDate ?? endDate,
criteria,
- interval,
+ interval: overviewInterval ?? interval,
+ shareId,
+ reportId: id,
},
{
placeholderData: keepPreviousData,
diff --git a/apps/start/src/components/report-chart/sankey/chart.tsx b/apps/start/src/components/report-chart/sankey/chart.tsx
new file mode 100644
index 000000000..57cd4a2d6
--- /dev/null
+++ b/apps/start/src/components/report-chart/sankey/chart.tsx
@@ -0,0 +1,302 @@
+import {
+ ChartTooltipContainer,
+ ChartTooltipHeader,
+ ChartTooltipItem,
+} from '@/components/charts/chart-tooltip';
+import { useNumber } from '@/hooks/use-numer-formatter';
+import { round } from '@/utils/math';
+import { ResponsiveSankey } from '@nivo/sankey';
+import {
+ type ReactNode,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+ useState,
+} from 'react';
+import { createPortal } from 'react-dom';
+
+import { useTheme } from '@/components/theme-provider';
+import { truncate } from '@/utils/truncate';
+import { ArrowRightIcon } from 'lucide-react';
+import { AspectContainer } from '../aspect-container';
+
+type PortalTooltipPosition = { left: number; top: number; ready: boolean };
+
+function SankeyPortalTooltip({
+ children,
+ offset = 12,
+ padding = 8,
+}: {
+ children: ReactNode;
+ offset?: number;
+ padding?: number;
+}) {
+ const anchorRef = useRef<HTMLSpanElement | null>(null);
+ const tooltipRef = useRef<HTMLDivElement | null>(null);
+ const [anchorRect, setAnchorRect] = useState<DOMRect | null>(null);
+ const [pos, setPos] = useState<PortalTooltipPosition>({
+ left: 0,
+ top: 0,
+ ready: false,
+ });
+ const [mounted, setMounted] = useState(false);
+
+ useLayoutEffect(() => {
+ setMounted(true);
+ }, []);
+
+ useLayoutEffect(() => {
+ const el = anchorRef.current;
+ if (!el) return;
+
+ const wrapper = el.parentElement;
+ if (!wrapper) return;
+
+ const update = () => {
+ setAnchorRect(wrapper.getBoundingClientRect());
+ };
+
+ update();
+
+ const ro = new ResizeObserver(update);
+ ro.observe(wrapper);
+
+ window.addEventListener('scroll', update, true);
+ window.addEventListener('resize', update);
+
+ return () => {
+ ro.disconnect();
+ window.removeEventListener('scroll', update, true);
+ window.removeEventListener('resize', update);
+ };
+ }, []);
+
+ useLayoutEffect(() => {
+ if (!mounted) return;
+ if (!anchorRect) return;
+ const tooltipEl = tooltipRef.current;
+ if (!tooltipEl) return;
+
+ const rect = tooltipEl.getBoundingClientRect();
+ const vw = window.innerWidth;
+ const vh = window.innerHeight;
+
+ let left = anchorRect.left + offset;
+ let top = anchorRect.top + offset;
+
+ left = Math.min(
+ Math.max(padding, left),
+ Math.max(padding, vw - rect.width - padding),
+ );
+ top = Math.min(
+ Math.max(padding, top),
+ Math.max(padding, vh - rect.height - padding),
+ );
+
+ setPos({ left, top, ready: true });
+ }, [mounted, anchorRect, children, offset, padding]);
+
+ if (typeof document === 'undefined') {
+ return <>{children}</>;
+ }
+
+ return (
+ <>
+ <span ref={anchorRef} className="sr-only" />
+ {mounted &&
+ createPortal(
+ <div
+ ref={tooltipRef}
+ className="pointer-events-none fixed z-[9999]"
+ style={{
+ left: pos.left,
+ top: pos.top,
+ visibility: pos.ready ? 'visible' : 'hidden',
+ }}
+ >
+ {children}
+ </div>,
+ document.body,
+ )}
+ </>
+ );
+}
+
+type SankeyData = {
+ nodes: Array<{
+ id: string;
+ label: string;
+ nodeColor: string;
+ percentage?: number;
+ value?: number;
+ step?: number;
+ }>;
+ links: Array<{ source: string; target: string; value: number }>;
+};
+
+export function Chart({ data }: { data: SankeyData }) {
+ const number = useNumber();
+ const containerRef = useRef<HTMLDivElement>(null);
+ const { appTheme } = useTheme();
+
+ // Process data for Sankey
+ const sankeyData = useMemo(() => {
+ if (!data) return { nodes: [], links: [] };
+
+ return {
+ nodes: data.nodes.map((node) => ({
+ ...node,
+ label: node.label || node.id,
+ data: {
+ percentage: node.percentage,
+ value: node.value,
+ step: node.step,
+ label: node.label || node.id,
+ },
+ })),
+ links: data.links,
+ };
+ }, [data]);
+
+ const totalSessions = useMemo(() => {
+ if (!sankeyData.nodes || sankeyData.nodes.length === 0) return 0;
+ const step1 = sankeyData.nodes.filter((n: any) => n.data?.step === 1);
+ const base = step1.length > 0 ? step1 : sankeyData.nodes;
+ return base.reduce((sum: number, n: any) => sum + (n.data?.value ?? 0), 0);
+ }, [sankeyData.nodes]);
+
+ return (
+ <AspectContainer>
+ <div
+ ref={containerRef}
+ className="w-full relative aspect-square md:aspect-[2]"
+ >
+ <ResponsiveSankey
+ margin={{ top: 20, right: 20, bottom: 20, left: 20 }}
+ data={sankeyData}
+ colors={(node: any) => node.nodeColor}
+ nodeBorderRadius={2}
+ animate={false}
+ nodeBorderWidth={0}
+ nodeOpacity={0.8}
+ linkContract={1}
+ linkOpacity={0.3}
+ linkBlendMode={'normal'}
+ nodeTooltip={({ node }: any) => {
+ const label = node?.data?.label ?? node?.label ?? node?.id;
+ const value = node?.data?.value ?? node?.value ?? 0;
+ const step = node?.data?.step;
+ const pct =
+ typeof node?.data?.percentage === 'number'
+ ? node.data.percentage
+ : totalSessions > 0
+ ? (value / totalSessions) * 100
+ : 0;
+ const color =
+ node?.color ??
+ node?.data?.nodeColor ??
+ node?.data?.color ??
+ node?.nodeColor ??
+ '#64748b';
+
+ return (
+ <SankeyPortalTooltip>
+ <ChartTooltipContainer className="min-w-[250px]">
+ <ChartTooltipHeader>
+ <div className="min-w-0 flex-1 font-medium break-words">
+ {label}
+ </div>
+ {typeof step === 'number' && (
+ <div className="shrink-0 text-muted-foreground">
+ Step {step}
+ </div>
+ )}
+ </ChartTooltipHeader>
+ <ChartTooltipItem color={color} innerClassName="gap-2">
+ <div className="flex items-center justify-between gap-8 font-mono font-medium">
+ <div className="text-muted-foreground">Sessions</div>
+ <div>{number.format(value)}</div>
+ </div>
+ <div className="flex items-center justify-between gap-8 font-mono font-medium">
+ <div className="text-muted-foreground">Share</div>
+ <div>{number.format(round(pct, 1))} %</div>
+ </div>
+ </ChartTooltipItem>
+ </ChartTooltipContainer>
+ </SankeyPortalTooltip>
+ );
+ }}
+ linkTooltip={({ link }: any) => {
+ const sourceLabel =
+ link?.source?.data?.label ??
+ link?.source?.label ??
+ link?.source?.id;
+ const targetLabel =
+ link?.target?.data?.label ??
+ link?.target?.label ??
+ link?.target?.id;
+
+ const value = link?.value ?? 0;
+ const sourceValue =
+ link?.source?.data?.value ?? link?.source?.value ?? 0;
+
+ const pctOfTotal =
+ totalSessions > 0 ? (value / totalSessions) * 100 : 0;
+ const pctOfSource =
+ sourceValue > 0 ? (value / sourceValue) * 100 : 0;
+
+ const sourceStep = link?.source?.data?.step;
+ const targetStep = link?.target?.data?.step;
+
+ const color =
+ link?.color ??
+ link?.source?.color ??
+ link?.source?.data?.nodeColor ??
+ '#64748b';
+
+ return (
+ <SankeyPortalTooltip>
+ <ChartTooltipContainer>
+ <ChartTooltipHeader>
+ <div className="min-w-0 flex-1 font-medium break-words">
+ {sourceLabel}
+ <ArrowRightIcon className="size-2 inline-block mx-3" />
+ {targetLabel}
+ </div>
+ {typeof sourceStep === 'number' &&
+ typeof targetStep === 'number' && (
+ <div className="shrink-0 text-muted-foreground">
+ {sourceStep} → {targetStep}
+ </div>
+ )}
+ </ChartTooltipHeader>
+
+ <ChartTooltipItem color={color} innerClassName="gap-2">
+ <div className="flex items-center justify-between gap-8 font-mono font-medium">
+ <div className="text-muted-foreground">Sessions</div>
+ <div>{number.format(value)}</div>
+ </div>
+ <div className="flex items-center justify-between gap-8 font-mono text-sm">
+ <div className="text-muted-foreground">% of total</div>
+ <div>{number.format(round(pctOfTotal, 1))} %</div>
+ </div>
+ <div className="flex items-center justify-between gap-8 font-mono text-sm">
+ <div className="text-muted-foreground">% of source</div>
+ <div>{number.format(round(pctOfSource, 1))} %</div>
+ </div>
+ </ChartTooltipItem>
+ </ChartTooltipContainer>
+ </SankeyPortalTooltip>
+ );
+ }}
+ label={(node: any) => {
+ const label = node.data?.label || node.label || node.id;
+ return truncate(label, 30, 'middle');
+ }}
+ labelTextColor={appTheme === 'dark' ? '#e2e8f0' : '#0f172a'}
+ nodeSpacing={10}
+ />
+ </div>
+ </AspectContainer>
+ );
+}
diff --git a/apps/start/src/components/report-chart/sankey/index.tsx b/apps/start/src/components/report-chart/sankey/index.tsx
new file mode 100644
index 000000000..879d90211
--- /dev/null
+++ b/apps/start/src/components/report-chart/sankey/index.tsx
@@ -0,0 +1,93 @@
+import { useTRPC } from '@/integrations/trpc/react';
+import { useQuery } from '@tanstack/react-query';
+
+import type { IReportInput } from '@openpanel/validation';
+
+import { AspectContainer } from '../aspect-container';
+import { ReportChartEmpty } from '../common/empty';
+import { ReportChartError } from '../common/error';
+import { ReportChartLoading } from '../common/loading';
+import { useReportChartContext } from '../context';
+import { Chart } from './chart';
+
+export function ReportSankeyChart() {
+ const {
+ report: {
+ series,
+ range,
+ projectId,
+ options,
+ startDate,
+ endDate,
+ breakdowns,
+ },
+ isLazyLoading,
+ } = useReportChartContext();
+
+ if (!options) {
+ return <Empty />;
+ }
+
+ const input: IReportInput = {
+ series,
+ range,
+ projectId,
+ interval: 'day',
+ chartType: 'sankey',
+ breakdowns,
+ options,
+ metric: 'sum',
+ startDate,
+ endDate,
+ limit: 20,
+ previous: false,
+ };
+ const trpc = useTRPC();
+ const res = useQuery(
+ trpc.chart.sankey.queryOptions(input, {
+ enabled: !isLazyLoading && input.series.length > 0,
+ }),
+ );
+
+ if (isLazyLoading || res.isLoading) {
+ return <Loading />;
+ }
+
+ if (res.isError) {
+ return <Error />;
+ }
+
+ if (!res.data || res.data.nodes.length === 0) {
+ return <Empty />;
+ }
+
+ return (
+ <div className="col gap-4">
+ <Chart data={res.data} />
+ </div>
+ );
+}
+
+function Loading() {
+ return (
+ <AspectContainer>
+ <ReportChartLoading />
+ </AspectContainer>
+ );
+}
+
+function Error() {
+ return (
+ <AspectContainer>
+ <ReportChartError />
+ </AspectContainer>
+ );
+}
+
+function Empty() {
+ return (
+ <AspectContainer>
+ <ReportChartEmpty />
+ </AspectContainer>
+ );
+}
diff --git a/apps/start/src/components/report-chart/shortcut.tsx b/apps/start/src/components/report-chart/shortcut.tsx
index c42e6aa4e..f53ddf711 100644
--- a/apps/start/src/components/report-chart/shortcut.tsx
+++ b/apps/start/src/components/report-chart/shortcut.tsx
@@ -26,7 +26,6 @@ export const ReportChartShortcut = ({
return (
<ReportChart
report={{
- name: 'Shortcut',
projectId,
range,
breakdowns: breakdowns ?? [],
diff --git a/apps/start/src/components/report/ReportChartType.tsx b/apps/start/src/components/report/ReportChartType.tsx
index ccc6f8220..4d6129e68 100644
--- a/apps/start/src/components/report/ReportChartType.tsx
+++ b/apps/start/src/components/report/ReportChartType.tsx
@@ -5,6 +5,7 @@ import {
ChartColumnIncreasingIcon,
ConeIcon,
GaugeIcon,
+ GitBranchIcon,
Globe2Icon,
LineChartIcon,
type LucideIcon,
@@ -58,6 +59,7 @@ export function ReportChartType({
retention: UsersIcon,
map: Globe2Icon,
conversion: TrendingUpIcon,
+ sankey: GitBranchIcon,
};
return (
diff --git a/apps/start/src/components/report/report-item.tsx b/apps/start/src/components/report/report-item.tsx
new file mode 100644
index 000000000..ca9cb6ba6
--- /dev/null
+++ b/apps/start/src/components/report/report-item.tsx
@@ -0,0 +1,255 @@
+import { ReportChart } from '@/components/report-chart';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu';
+import { cn } from '@/utils/cn';
+import { CopyIcon, MoreHorizontal, Trash } from 'lucide-react';
+
+import { timeWindows } from '@openpanel/constants';
+
+import { useRouter } from '@tanstack/react-router';
+
+export function ReportItemSkeleton() {
+ return (
+ <div className="card h-full flex flex-col animate-pulse">
+ <div className="flex items-center justify-between border-b border-border p-4">
+ <div className="flex-1">
+ <div className="h-5 w-32 bg-muted rounded mb-2" />
+ <div className="h-4 w-24 bg-muted/50 rounded" />
+ </div>
+ <div className="flex items-center gap-2">
+ <div className="w-8 h-8 bg-muted rounded" />
+ <div className="w-8 h-8 bg-muted rounded" />
+ </div>
+ </div>
+ <div className="p-4 flex-1 flex items-center justify-center aspect-video" />
+ </div>
+ );
+}
+
+export function ReportItem({
+ report,
+ organizationId,
+ projectId,
+ range,
+ startDate,
+ endDate,
+ interval,
+ onDelete,
+ onDuplicate,
+}: {
+ report: any;
+ organizationId: string;
+ projectId: string;
+ range: any;
+ startDate: any;
+ endDate: any;
+ interval: any;
+ onDelete: (reportId: string) => void;
+ onDuplicate: (reportId: string) => void;
+}) {
+ const router = useRouter();
+ const chartRange = report.range;
+
+ return (
+ <div className="card h-full flex flex-col">
+ <div className="flex items-center hover:bg-muted/50 justify-between border-b border-border p-4 leading-none [&_svg]:hover:opacity-100">
+ <div
+ className="flex-1 cursor-pointer -m-4 p-4"
+ onClick={(event) => {
+ if (event.metaKey) {
+ window.open(
+ `/${organizationId}/${projectId}/reports/${report.id}`,
+ '_blank',
+ );
+ return;
+ }
+ router.navigate({
+ to: '/$organizationId/$projectId/reports/$reportId',
+ params: {
+ organizationId,
+ projectId,
+ reportId: report.id,
+ },
+ });
+ }}
+ onKeyUp={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ router.navigate({
+ to: '/$organizationId/$projectId/reports/$reportId',
+ params: {
+ organizationId,
+ projectId,
+ reportId: report.id,
+ },
+ });
+ }
+ }}
+ role="button"
+ tabIndex={0}
+ >
+ <div className="font-medium">{report.name}</div>
+ {chartRange !== null && (
+ <div className="mt-2 flex gap-2 ">
+ <span
+ className={
+ (chartRange !== range && range !== null) ||
+ (startDate && endDate)
+ ? 'line-through'
+ : ''
+ }
+ >
+ {timeWindows[chartRange as keyof typeof timeWindows]?.label}
+ </span>
+ {startDate && endDate ? (
+ <span>Custom dates</span>
+ ) : (
+ range !== null &&
+ chartRange !== range && (
+ <span>
+ {timeWindows[range as keyof typeof timeWindows]?.label}
+ </span>
+ )
+ )}
+ </div>
+ )}
+ </div>
+ <div className="flex items-center gap-2">
+ <div className="drag-handle cursor-move p-2 hover:bg-muted rounded">
+ <svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="currentColor"
+ className="opacity-30 hover:opacity-100"
+ >
+ <circle cx="4" cy="4" r="1.5" />
+ <circle cx="4" cy="8" r="1.5" />
+ <circle cx="4" cy="12" r="1.5" />
+ <circle cx="12" cy="4" r="1.5" />
+ <circle cx="12" cy="8" r="1.5" />
+ <circle cx="12" cy="12" r="1.5" />
+ </svg>
+ </div>
+ <DropdownMenu>
+ <DropdownMenuTrigger className="flex h-8 w-8 items-center justify-center rounded hover:border">
+ <MoreHorizontal size={16} />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-[200px]">
+ <DropdownMenuItem
+ onClick={(event) => {
+ event.stopPropagation();
+ onDuplicate(report.id);
+ }}
+ >
+ <CopyIcon size={16} className="mr-2" />
+ Duplicate
+ </DropdownMenuItem>
+ <DropdownMenuGroup>
+ <DropdownMenuItem
+ className="text-destructive"
+ onClick={(event) => {
+ event.stopPropagation();
+ onDelete(report.id);
+ }}
+ >
+ <Trash size={16} className="mr-2" />
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </div>
+ <div
+ className={cn(
+ 'p-4 overflow-auto flex-1',
+ report.chartType === 'metric' && 'p-0',
+ )}
+ >
+ <ReportChart
+ report={{
+ ...report,
+ range: range ?? report.range,
+ startDate: startDate ?? null,
+ endDate: endDate ?? null,
+ interval: interval ?? report.interval,
+ }}
+ />
+ </div>
+ </div>
+ );
+}
+
+export function ReportItemReadOnly({
+ report,
+ shareId,
+ range,
+ startDate,
+ endDate,
+ interval,
+}: {
+ report: any;
+ shareId: string;
+ range: any;
+ startDate: any;
+ endDate: any;
+ interval: any;
+}) {
+ const chartRange = report.range;
+
+ return (
+ <div className="card h-full flex flex-col">
+ <div className="flex items-center justify-between border-b border-border p-4 leading-none">
+ <div className="flex-1">
+ <div className="font-medium">{report.name}</div>
+ {chartRange !== null && (
+ <div className="mt-2 flex gap-2 ">
+ <span
+ className={
+ (chartRange !== range && range !== null) ||
+ (startDate && endDate)
+ ? 'line-through'
+ : ''
+ }
+ >
+ {timeWindows[chartRange as keyof typeof timeWindows]?.label}
+ </span>
+ {startDate && endDate ? (
+ <span>Custom dates</span>
+ ) : (
+ range !== null &&
+ chartRange !== range && (
+ <span>
+ {timeWindows[range as keyof typeof timeWindows]?.label}
+ </span>
+ )
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ <div
+ className={cn(
+ 'p-4 overflow-auto flex-1',
+ report.chartType === 'metric' && 'p-0',
+ )}
+ >
+ <ReportChart
+ report={{
+ ...report,
+ range: range ?? report.range,
+ startDate: startDate ?? null,
+ endDate: endDate ?? null,
+ interval: interval ?? report.interval,
+ }}
+ shareId={shareId}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/start/src/components/report/reportSlice.ts b/apps/start/src/components/report/reportSlice.ts
index 9ec30e32b..243511765 100644
--- a/apps/start/src/components/report/reportSlice.ts
+++ b/apps/start/src/components/report/reportSlice.ts
@@ -1,6 +1,5 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
-import { endOfDay, format, isSameDay, isSameMonth, startOfDay } from 'date-fns';
import { shortId } from '@openpanel/common';
import {
@@ -12,18 +11,19 @@ import {
import type {
IChartBreakdown,
IChartEventItem,
- IChartFormula,
IChartLineType,
- IChartProps,
IChartRange,
IChartType,
IInterval,
+ IReport,
+ IReportOptions,
UnionOmit,
zCriteria,
} from '@openpanel/validation';
import type { z } from 'zod';
-type InitialState = IChartProps & {
+type InitialState = IReport & {
+ id?: string;
dirty: boolean;
ready: boolean;
startDate: string | null;
@@ -34,7 +34,6 @@ type InitialState = IChartProps & {
const initialState: InitialState = {
ready: false,
dirty: false,
- // TODO: remove this
projectId: '',
name: '',
chartType: 'linear',
@@ -50,9 +49,7 @@ const initialState: InitialState = {
unit: undefined,
metric: 'sum',
limit: 500,
- criteria: 'on_or_after',
- funnelGroup: undefined,
- funnelWindow: undefined,
+ options: undefined,
};
export const reportSlice = createSlice({
@@ -74,7 +71,7 @@ export const reportSlice = createSlice({
ready: true,
};
},
- setReport(state, action: PayloadAction<IChartProps>) {
+ setReport(state, action: PayloadAction<IReport>) {
return {
...state,
...action.payload,
@@ -187,6 +184,16 @@ export const reportSlice = createSlice({
state.dirty = true;
state.chartType = action.payload;
+ // Initialize sankey options if switching to sankey
+ if (action.payload === 'sankey' && !state.options) {
+ state.options = {
+ type: 'sankey',
+ mode: 'after',
+ steps: 5,
+ exclude: [],
+ };
+ }
+
if (
!isMinuteIntervalEnabledByRange(state.range) &&
state.interval === 'minute'
@@ -254,7 +261,14 @@ export const reportSlice = createSlice({
changeCriteria(state, action: PayloadAction<z.infer<typeof zCriteria>>) {
state.dirty = true;
- state.criteria = action.payload;
+ if (!state.options || state.options.type !== 'retention') {
+ state.options = {
+ type: 'retention',
+ criteria: action.payload,
+ };
+ } else {
+ state.options.criteria = action.payload;
+ }
},
changeUnit(state, action: PayloadAction<string | undefined>) {
@@ -264,12 +278,88 @@ export const reportSlice = createSlice({
changeFunnelGroup(state, action: PayloadAction<string | undefined>) {
state.dirty = true;
- state.funnelGroup = action.payload || undefined;
+ if (!state.options || state.options.type !== 'funnel') {
+ state.options = {
+ type: 'funnel',
+ funnelGroup: action.payload,
+ funnelWindow: undefined,
+ };
+ } else {
+ state.options.funnelGroup = action.payload;
+ }
},
changeFunnelWindow(state, action: PayloadAction<number | undefined>) {
state.dirty = true;
- state.funnelWindow = action.payload || undefined;
+ if (!state.options || state.options.type !== 'funnel') {
+ state.options = {
+ type: 'funnel',
+ funnelGroup: undefined,
+ funnelWindow: action.payload,
+ };
+ } else {
+ state.options.funnelWindow = action.payload;
+ }
+ },
+ changeOptions(state, action: PayloadAction<IReportOptions | undefined>) {
+ state.dirty = true;
+ state.options = action.payload || undefined;
+ },
+ changeSankeyMode(
+ state,
+ action: PayloadAction<'between' | 'after' | 'before'>,
+ ) {
+ state.dirty = true;
+ if (!state.options) {
+ state.options = {
+ type: 'sankey',
+ mode: action.payload,
+ steps: 5,
+ exclude: [],
+ };
+ } else if (state.options.type === 'sankey') {
+ state.options.mode = action.payload;
+ }
+ },
+ changeSankeySteps(state, action: PayloadAction<number>) {
+ state.dirty = true;
+ if (!state.options) {
+ state.options = {
+ type: 'sankey',
+ mode: 'after',
+ steps: action.payload,
+ exclude: [],
+ };
+ } else if (state.options.type === 'sankey') {
+ state.options.steps = action.payload;
+ }
+ },
+ changeSankeyExclude(state, action: PayloadAction<string[]>) {
+ state.dirty = true;
+ if (!state.options) {
+ state.options = {
+ type: 'sankey',
+ mode: 'after',
+ steps: 5,
+ exclude: action.payload,
+ };
+ } else if (state.options.type === 'sankey') {
+ state.options.exclude = action.payload;
+ }
+ },
+ changeSankeyInclude(state, action: PayloadAction<string[] | undefined>) {
+ state.dirty = true;
+ if (!state.options) {
+ state.options = {
+ type: 'sankey',
+ mode: 'after',
+ steps: 5,
+ exclude: [],
+ include: action.payload,
+ };
+ } else if (state.options.type === 'sankey') {
+ state.options.include = action.payload;
+ }
},
reorderEvents(
state,
@@ -311,6 +401,11 @@ export const {
changeUnit,
changeFunnelGroup,
changeFunnelWindow,
+ changeOptions,
+ changeSankeyMode,
+ changeSankeySteps,
+ changeSankeyExclude,
+ changeSankeyInclude,
reorderEvents,
} = reportSlice.actions;
diff --git a/apps/start/src/components/report/sidebar/ReportSeries.tsx b/apps/start/src/components/report/sidebar/ReportSeries.tsx
index 103cceecf..e7bd29555 100644
--- a/apps/start/src/components/report/sidebar/ReportSeries.tsx
+++ b/apps/start/src/components/report/sidebar/ReportSeries.tsx
@@ -23,15 +23,13 @@ import {
verticalListSortingStrategy,
} from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
-import { shortId } from '@openpanel/common';
import { alphabetIds } from '@openpanel/constants';
import type {
IChartEvent,
IChartEventItem,
IChartFormula,
} from '@openpanel/validation';
-import { FilterIcon, HandIcon, PiIcon } from 'lucide-react';
-import { ReportSegment } from '../ReportSegment';
+import { HandIcon, PiIcon, PlusIcon } from 'lucide-react';
import {
addSerie,
changeEvent,
@@ -39,27 +37,21 @@ import {
removeEvent,
reorderEvents,
} from '../reportSlice';
-import { EventPropertiesCombobox } from './EventPropertiesCombobox';
-import { PropertiesCombobox } from './PropertiesCombobox';
import type { ReportEventMoreProps } from './ReportEventMore';
import { ReportEventMore } from './ReportEventMore';
-import { FiltersList } from './filters/FiltersList';
+import {
+ ReportSeriesItem,
+ type ReportSeriesItemProps,
+} from './ReportSeriesItem';
-function SortableSeries({
+function SortableReportSeriesItem({
event,
index,
showSegment,
showAddFilter,
isSelectManyEvents,
...props
-}: {
- event: IChartEventItem | IChartEvent;
- index: number;
- showSegment: boolean;
- showAddFilter: boolean;
- isSelectManyEvents: boolean;
-} & React.HTMLAttributes<HTMLDivElement>) {
- const dispatch = useDispatch();
+}: Omit<ReportSeriesItemProps, 'renderDragHandle'>) {
const eventId = 'type' in event ? event.id : (event as IChartEvent).id;
const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({ id: eventId ?? '' });
@@ -69,85 +61,26 @@ function SortableSeries({
transition,
};
- // Normalize event to have type field
- const normalizedEvent: IChartEventItem =
- 'type' in event ? event : { ...event, type: 'event' as const };
-
- const isFormula = normalizedEvent.type === 'formula';
- const chartEvent = isFormula
- ? null
- : (normalizedEvent as IChartEventItem & { type: 'event' });
-
return (
- <div ref={setNodeRef} style={style} {...attributes} {...props}>
- <div className="flex items-center gap-2 p-2 group">
- <button className="cursor-grab active:cursor-grabbing" {...listeners}>
- <ColorSquare className="relative">
- <HandIcon className="size-3 opacity-0 scale-50 group-hover:opacity-100 group-hover:scale-100 transition-all absolute inset-1" />
- <span className="block group-hover:opacity-0 group-hover:scale-0 transition-all">
- {alphabetIds[index]}
- </span>
- </ColorSquare>
- </button>
- {props.children}
- </div>
-
- {/* Segment and Filter buttons - only for events */}
- {chartEvent && (showSegment || showAddFilter) && (
- <div className="flex gap-2 p-2 pt-0">
- {showSegment && (
- <ReportSegment
- value={chartEvent.segment}
- onChange={(segment) => {
- dispatch(
- changeEvent({
- ...chartEvent,
- segment,
- }),
- );
- }}
- />
- )}
- {showAddFilter && (
- <PropertiesCombobox
- event={chartEvent}
- onSelect={(action) => {
- dispatch(
- changeEvent({
- ...chartEvent,
- filters: [
- ...chartEvent.filters,
- {
- id: shortId(),
- name: action.value,
- operator: 'is',
- value: [],
- },
- ],
- }),
- );
- }}
- >
- {(setOpen) => (
- <button
- onClick={() => setOpen((p) => !p)}
- type="button"
- className="flex items-center gap-1 rounded-md border border-border bg-card p-1 px-2 text-sm font-medium leading-none"
- >
- <FilterIcon size={12} /> Add filter
- </button>
- )}
- </PropertiesCombobox>
- )}
-
- {showSegment && chartEvent.segment.startsWith('property_') && (
- <EventPropertiesCombobox event={chartEvent} />
- )}
- </div>
- )}
-
- {/* Filters - only for events */}
- {chartEvent && !isSelectManyEvents && <FiltersList event={chartEvent} />}
+ <div ref={setNodeRef} style={style} {...attributes}>
+ <ReportSeriesItem
+ event={event}
+ index={index}
+ showSegment={showSegment}
+ showAddFilter={showAddFilter}
+ isSelectManyEvents={isSelectManyEvents}
+ renderDragHandle={(index) => (
+ <button className="cursor-grab active:cursor-grabbing" {...listeners}>
+ <ColorSquare className="relative">
+ <HandIcon className="size-3 opacity-0 scale-50 group-hover:opacity-100 group-hover:scale-100 transition-all absolute inset-1" />
+ <span className="block group-hover:opacity-0 group-hover:scale-0 transition-all">
+ {alphabetIds[index]}
+ </span>
+ </ColorSquare>
+ </button>
+ )}
+ {...props}
+ />
</div>
);
}
@@ -161,12 +94,23 @@ export function ReportSeries() {
projectId,
});
- const showSegment = !['retention', 'funnel'].includes(chartType);
- const showAddFilter = !['retention'].includes(chartType);
- const showDisplayNameInput = !['retention'].includes(chartType);
+ const showSegment = !['retention', 'funnel', 'sankey'].includes(chartType);
+ const showAddFilter = !['retention', 'sankey'].includes(chartType);
+ const showDisplayNameInput = !['retention', 'sankey'].includes(chartType);
+ const options = useSelector((state) => state.report.options);
+ const isSankey = chartType === 'sankey';
const isAddEventDisabled =
(chartType === 'retention' || chartType === 'conversion') &&
selectedSeries.length >= 2;
+ const isSankeyEventLimitReached =
+ isSankey &&
+ options &&
+ ((options.type === 'sankey' &&
+ options.mode === 'between' &&
+ selectedSeries.length >= 2) ||
+ (options.type === 'sankey' &&
+ options.mode !== 'between' &&
+ selectedSeries.length >= 1));
const dispatchChangeEvent = useDebounceFn((event: IChartEventItem) => {
dispatch(changeEvent(event));
});
@@ -218,7 +162,8 @@ export function ReportSeries() {
const showFormula =
chartType !== 'conversion' &&
chartType !== 'funnel' &&
- chartType !== 'retention';
+ chartType !== 'retention' &&
+ chartType !== 'sankey';
return (
<div>
@@ -239,7 +184,7 @@ export function ReportSeries() {
const isFormula = event.type === 'formula';
return (
- <SortableSeries
+ <SortableReportSeriesItem
key={event.id}
event={event}
index={index}
@@ -348,13 +293,14 @@ export function ReportSeries() {
<ReportEventMore onClick={handleMore(event)} />
</>
)}
- </SortableSeries>
+ </SortableReportSeriesItem>
);
})}
<div className="flex gap-2">
<ComboboxEvents
- disabled={isAddEventDisabled}
+ className="flex-1"
+ disabled={isAddEventDisabled || isSankeyEventLimitReached}
value={''}
searchable
onChange={(value) => {
@@ -386,13 +332,13 @@ export function ReportSeries() {
}}
placeholder="Select event"
items={eventNames}
- className="flex-1"
/>
{showFormula && (
<Button
type="button"
variant="outline"
icon={PiIcon}
+ className="flex-1 justify-start text-left px-4"
onClick={() => {
dispatch(
addSerie({
@@ -402,9 +348,9 @@ export function ReportSeries() {
}),
);
}}
- className="px-4"
>
Add Formula
+ <PlusIcon className="size-4 ml-auto text-muted-foreground" />
</Button>
)}
</div>
diff --git a/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx b/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx
new file mode 100644
index 000000000..d647df985
--- /dev/null
+++ b/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx
@@ -0,0 +1,114 @@
+import { ColorSquare } from '@/components/color-square';
+import { useDispatch } from '@/redux';
+import { shortId } from '@openpanel/common';
+import { alphabetIds } from '@openpanel/constants';
+import type { IChartEvent, IChartEventItem } from '@openpanel/validation';
+import { FilterIcon } from 'lucide-react';
+import { ReportSegment } from '../ReportSegment';
+import { changeEvent } from '../reportSlice';
+import { EventPropertiesCombobox } from './EventPropertiesCombobox';
+import { PropertiesCombobox } from './PropertiesCombobox';
+import { FiltersList } from './filters/FiltersList';
+
+export interface ReportSeriesItemProps
+ extends React.HTMLAttributes<HTMLDivElement> {
+ event: IChartEventItem | IChartEvent;
+ index: number;
+ showSegment: boolean;
+ showAddFilter: boolean;
+ isSelectManyEvents: boolean;
+ renderDragHandle?: (index: number) => React.ReactNode;
+}
+
+export function ReportSeriesItem({
+ event,
+ index,
+ showSegment,
+ showAddFilter,
+ isSelectManyEvents,
+ renderDragHandle,
+ ...props
+}: ReportSeriesItemProps) {
+ const dispatch = useDispatch();
+
+ // Normalize event to have type field
+ const normalizedEvent: IChartEventItem =
+ 'type' in event ? event : { ...event, type: 'event' as const };
+
+ const isFormula = normalizedEvent.type === 'formula';
+ const chartEvent = isFormula
+ ? null
+ : (normalizedEvent as IChartEventItem & { type: 'event' });
+
+ return (
+ <div {...props}>
+ <div className="flex items-center gap-2 p-2 group">
+ {renderDragHandle ? (
+ renderDragHandle(index)
+ ) : (
+ <ColorSquare>
+ <span className="block">{alphabetIds[index]}</span>
+ </ColorSquare>
+ )}
+ {props.children}
+ </div>
+
+ {/* Segment and Filter buttons - only for events */}
+ {chartEvent && (showSegment || showAddFilter) && (
+ <div className="flex gap-2 p-2 pt-0">
+ {showSegment && (
+ <ReportSegment
+ value={chartEvent.segment}
+ onChange={(segment) => {
+ dispatch(
+ changeEvent({
+ ...chartEvent,
+ segment,
+ }),
+ );
+ }}
+ />
+ )}
+ {showAddFilter && (
+ <PropertiesCombobox
+ event={chartEvent}
+ onSelect={(action) => {
+ dispatch(
+ changeEvent({
+ ...chartEvent,
+ filters: [
+ ...chartEvent.filters,
+ {
+ id: shortId(),
+ name: action.value,
+ operator: 'is',
+ value: [],
+ },
+ ],
+ }),
+ );
+ }}
+ >
+ {(setOpen) => (
+ <button
+ onClick={() => setOpen((p) => !p)}
+ type="button"
+ className="flex items-center gap-1 rounded-md border border-border bg-card p-1 px-2 text-sm font-medium leading-none"
+ >
+ <FilterIcon size={12} /> Add filter
+ </button>
+ )}
+ </PropertiesCombobox>
+ )}
+
+ {showSegment && chartEvent.segment.startsWith('property_') && (
+ <EventPropertiesCombobox event={chartEvent} />
+ )}
+ </div>
+ )}
+
+ {/* Filters - only for events */}
+ {chartEvent && !isSelectManyEvents && <FiltersList event={chartEvent} />}
+ </div>
+ );
+}
diff --git a/apps/start/src/components/report/sidebar/ReportSettings.tsx b/apps/start/src/components/report/sidebar/ReportSettings.tsx
index a212db84b..6c31095be 100644
--- a/apps/start/src/components/report/sidebar/ReportSettings.tsx
+++ b/apps/start/src/components/report/sidebar/ReportSettings.tsx
@@ -1,32 +1,46 @@
import { Combobox } from '@/components/ui/combobox';
import { useDispatch, useSelector } from '@/redux';
+import { ComboboxEvents } from '@/components/ui/combobox-events';
import { InputEnter } from '@/components/ui/input-enter';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
+import { useAppParams } from '@/hooks/use-app-params';
+import { useEventNames } from '@/hooks/use-event-names';
import { useMemo } from 'react';
import {
changeCriteria,
changeFunnelGroup,
changeFunnelWindow,
changePrevious,
+ changeSankeyExclude,
+ changeSankeyInclude,
+ changeSankeyMode,
+ changeSankeySteps,
changeUnit,
} from '../reportSlice';
export function ReportSettings() {
const chartType = useSelector((state) => state.report.chartType);
const previous = useSelector((state) => state.report.previous);
- const criteria = useSelector((state) => state.report.criteria);
const unit = useSelector((state) => state.report.unit);
- const funnelGroup = useSelector((state) => state.report.funnelGroup);
- const funnelWindow = useSelector((state) => state.report.funnelWindow);
+ const options = useSelector((state) => state.report.options);
+
+ const retentionOptions = options?.type === 'retention' ? options : undefined;
+ const criteria = retentionOptions?.criteria ?? 'on_or_after';
+
+ const funnelOptions = options?.type === 'funnel' ? options : undefined;
+ const funnelGroup = funnelOptions?.funnelGroup;
+ const funnelWindow = funnelOptions?.funnelWindow;
const dispatch = useDispatch();
+ const { projectId } = useAppParams();
+ const eventNames = useEventNames({ projectId });
const fields = useMemo(() => {
const fields = [];
- if (chartType !== 'retention') {
+ if (chartType !== 'retention' && chartType !== 'sankey') {
fields.push('previous');
}
@@ -40,6 +54,13 @@ export function ReportSettings() {
fields.push('funnelWindow');
}
+ if (chartType === 'sankey') {
+ fields.push('sankeyMode');
+ fields.push('sankeySteps');
+ fields.push('sankeyExclude');
+ fields.push('sankeyInclude');
+ }
+
return fields;
}, [chartType]);
@@ -50,7 +71,7 @@ export function ReportSettings() {
return (
<div>
<h3 className="mb-2 font-medium">Settings</h3>
- <div className="col rounded-lg border bg-card p-4 gap-2">
+ <div className="col rounded-lg border bg-card p-4 gap-4">
{fields.includes('previous') && (
<Label className="flex items-center justify-between mb-0">
<span className="whitespace-nowrap">
@@ -64,7 +85,9 @@ export function ReportSettings() {
)}
{fields.includes('criteria') && (
<div className="flex items-center justify-between gap-4">
- <span className="whitespace-nowrap font-medium">Criteria</span>
+ <Label className="whitespace-nowrap font-medium mb-0">
+ Criteria
+ </Label>
<Combobox
align="end"
placeholder="Select criteria"
@@ -85,7 +108,7 @@ export function ReportSettings() {
)}
{fields.includes('unit') && (
<div className="flex items-center justify-between gap-4">
- <span className="whitespace-nowrap font-medium">Unit</span>
+ <Label className="whitespace-nowrap font-medium mb-0">Unit</Label>
<Combobox
align="end"
placeholder="Unit"
@@ -108,7 +131,9 @@ export function ReportSettings() {
)}
{fields.includes('funnelGroup') && (
<div className="flex items-center justify-between gap-4">
- <span className="whitespace-nowrap font-medium">Funnel Group</span>
+ <Label className="whitespace-nowrap font-medium mb-0">
+ Funnel Group
+ </Label>
<Combobox
align="end"
placeholder="Default: Session"
@@ -133,7 +158,9 @@ export function ReportSettings() {
)}
{fields.includes('funnelWindow') && (
<div className="flex items-center justify-between gap-4">
- <span className="whitespace-nowrap font-medium">Funnel Window</span>
+ <Label className="whitespace-nowrap font-medium mb-0">
+ Funnel Window
+ </Label>
<InputEnter
type="number"
value={funnelWindow ? String(funnelWindow) : ''}
@@ -149,6 +176,89 @@ export function ReportSettings() {
/>
</div>
)}
+ {fields.includes('sankeyMode') && options?.type === 'sankey' && (
+ <div className="flex items-center justify-between gap-4">
+ <Label className="whitespace-nowrap font-medium mb-0">Mode</Label>
+ <Combobox
+ align="end"
+ placeholder="Select mode"
+ value={options?.mode || 'after'}
+ onChange={(val) => {
+ dispatch(
+ changeSankeyMode(val as 'between' | 'after' | 'before'),
+ );
+ }}
+ items={[
+ {
+ label: 'After',
+ value: 'after',
+ },
+ {
+ label: 'Before',
+ value: 'before',
+ },
+ {
+ label: 'Between',
+ value: 'between',
+ },
+ ]}
+ />
+ </div>
+ )}
+ {fields.includes('sankeySteps') && options?.type === 'sankey' && (
+ <div className="flex items-center justify-between gap-4">
+ <Label className="whitespace-nowrap font-medium mb-0">Steps</Label>
+ <InputEnter
+ type="number"
+ value={options?.steps ? String(options.steps) : '5'}
+ placeholder="Default: 5"
+ onChangeValue={(value) => {
+ const parsed = Number.parseInt(value, 10);
+ if (Number.isNaN(parsed) || parsed < 2 || parsed > 10) {
+ dispatch(changeSankeySteps(5));
+ } else {
+ dispatch(changeSankeySteps(parsed));
+ }
+ }}
+ />
+ </div>
+ )}
+ {fields.includes('sankeyExclude') && options?.type === 'sankey' && (
+ <div className="flex flex-col">
+ <Label className="whitespace-nowrap font-medium">
+ Exclude Events
+ </Label>
+ <ComboboxEvents
+ multiple
+ searchable
+ value={options?.exclude || []}
+ onChange={(value) => {
+ dispatch(changeSankeyExclude(value));
+ }}
+ items={eventNames.filter((item) => item.name !== '*')}
+ placeholder="Select events to exclude"
+ />
+ </div>
+ )}
+ {fields.includes('sankeyInclude') && options?.type === 'sankey' && (
+ <div className="flex flex-col">
+ <Label className="whitespace-nowrap font-medium">
+ Include events
+ </Label>
+ <ComboboxEvents
+ multiple
+ searchable
+ value={options?.include || []}
+ onChange={(value) => {
+ dispatch(
+ changeSankeyInclude(value.length > 0 ? value : undefined),
+ );
+ }}
+ items={eventNames.filter((item) => item.name !== '*')}
+ placeholder="Leave empty to include all"
+ />
+ </div>
+ )}
</div>
</div>
);
diff --git a/apps/start/src/components/report/sidebar/ReportSidebar.tsx b/apps/start/src/components/report/sidebar/ReportSidebar.tsx
index da28bb758..df8a48e8b 100644
--- a/apps/start/src/components/report/sidebar/ReportSidebar.tsx
+++ b/apps/start/src/components/report/sidebar/ReportSidebar.tsx
@@ -5,14 +5,24 @@ import { useSelector } from '@/redux';
import { ReportBreakdowns } from './ReportBreakdowns';
import { ReportSeries } from './ReportSeries';
import { ReportSettings } from './ReportSettings';
+import { ReportFixedEvents } from './report-fixed-events';
export function ReportSidebar() {
- const { chartType } = useSelector((state) => state.report);
- const showBreakdown = chartType !== 'retention';
+ const { chartType, options } = useSelector((state) => state.report);
+ const showBreakdown = chartType !== 'retention' && chartType !== 'sankey';
+ const showFixedEvents = chartType === 'sankey';
return (
<>
<div className="flex flex-col gap-8">
- <ReportSeries />
+ {showFixedEvents ? (
+ <ReportFixedEvents
+ numberOfEvents={
+ options?.type === 'sankey' && options.mode === 'between' ? 2 : 1
+ }
+ />
+ ) : (
+ <ReportSeries />
+ )}
{showBreakdown && <ReportBreakdowns />}
<ReportSettings />
</div>
diff --git a/apps/start/src/components/report/sidebar/report-fixed-events.tsx b/apps/start/src/components/report/sidebar/report-fixed-events.tsx
new file mode 100644
index 000000000..bdea470e1
--- /dev/null
+++ b/apps/start/src/components/report/sidebar/report-fixed-events.tsx
@@ -0,0 +1,223 @@
+import { ColorSquare } from '@/components/color-square';
+import { ComboboxEvents } from '@/components/ui/combobox-events';
+import { Input } from '@/components/ui/input';
+import { InputEnter } from '@/components/ui/input-enter';
+import { useAppParams } from '@/hooks/use-app-params';
+import { useDebounceFn } from '@/hooks/use-debounce-fn';
+import { useEventNames } from '@/hooks/use-event-names';
+import { useDispatch, useSelector } from '@/redux';
+import { alphabetIds } from '@openpanel/constants';
+import type {
+ IChartEvent,
+ IChartEventItem,
+ IChartFormula,
+} from '@openpanel/validation';
+import {
+ addSerie,
+ changeEvent,
+ duplicateEvent,
+ removeEvent,
+} from '../reportSlice';
+import type { ReportEventMoreProps } from './ReportEventMore';
+import { ReportEventMore } from './ReportEventMore';
+import { ReportSeriesItem } from './ReportSeriesItem';
+
+export function ReportFixedEvents({
+ numberOfEvents,
+}: {
+ numberOfEvents: number;
+}) {
+ const selectedSeries = useSelector((state) => state.report.series);
+ const chartType = useSelector((state) => state.report.chartType);
+ const dispatch = useDispatch();
+ const { projectId } = useAppParams();
+ const eventNames = useEventNames({
+ projectId,
+ });
+
+ const showSegment = !['retention', 'funnel', 'sankey'].includes(chartType);
+ const showAddFilter = !['retention'].includes(chartType);
+ const showDisplayNameInput = !['retention', 'sankey'].includes(chartType);
+ const dispatchChangeEvent = useDebounceFn((event: IChartEventItem) => {
+ dispatch(changeEvent(event));
+ });
+ const isSelectManyEvents = chartType === 'retention';
+
+ const handleMore = (event: IChartEventItem | IChartEvent) => {
+ const callback: ReportEventMoreProps['onClick'] = (action) => {
+ switch (action) {
+ case 'remove': {
+ return dispatch(
+ removeEvent({
+ id: 'type' in event ? event.id : (event as IChartEvent).id,
+ }),
+ );
+ }
+ case 'duplicate': {
+ const normalized =
+ 'type' in event ? event : { ...event, type: 'event' as const };
+ return dispatch(duplicateEvent(normalized));
+ }
+ }
+ };
+
+ return callback;
+ };
+
+ const dispatchChangeFormula = useDebounceFn((formula: IChartFormula) => {
+ dispatch(changeEvent(formula));
+ });
+
+ const showFormula =
+ chartType !== 'conversion' &&
+ chartType !== 'funnel' &&
+ chartType !== 'retention' &&
+ chartType !== 'sankey';
+
+ return (
+ <div>
+ <h3 className="mb-2 font-medium">Metrics</h3>
+ <div className="flex flex-col gap-4">
+ {Array.from({ length: numberOfEvents }, (_, index) => ({
+ slotId: `fixed-event-slot-${index}`,
+ index,
+ })).map(({ slotId, index }) => {
+ const event = selectedSeries[index];
+
+ // If no event exists at this index, render an empty slot
+ if (!event) {
+ return (
+ <div key={slotId} className="rounded-lg border bg-def-100">
+ <div className="flex items-center gap-2 p-2">
+ <ColorSquare>
+ <span className="block">{alphabetIds[index]}</span>
+ </ColorSquare>
+ <ComboboxEvents
+ className="flex-1"
+ searchable
+ multiple={isSelectManyEvents as false}
+ value={''}
+ onChange={(value) => {
+ if (isSelectManyEvents) {
+ dispatch(
+ addSerie({
+ type: 'event',
+ segment: 'user',
+ name: value,
+ filters: [
+ {
+ name: 'name',
+ operator: 'is',
+ value: [value],
+ },
+ ],
+ }),
+ );
+ } else {
+ dispatch(
+ addSerie({
+ type: 'event',
+ name: value,
+ segment: 'event',
+ filters: [],
+ }),
+ );
+ }
+ }}
+ items={eventNames}
+ placeholder="Select event"
+ />
+ </div>
+ </div>
+ );
+ }
+
+ const isFormula = event.type === 'formula';
+ if (isFormula) {
+ return null;
+ }
+
+ return (
+ <ReportSeriesItem
+ key={event.id}
+ event={event}
+ index={index}
+ showSegment={showSegment}
+ showAddFilter={showAddFilter}
+ isSelectManyEvents={isSelectManyEvents}
+ className="rounded-lg border bg-def-100"
+ >
+ <ComboboxEvents
+ className="flex-1"
+ searchable
+ multiple={isSelectManyEvents as false}
+ value={
+ (isSelectManyEvents
+ ? ((
+ event as IChartEventItem & {
+ type: 'event';
+ }
+ ).filters[0]?.value ?? [])
+ : (
+ event as IChartEventItem & {
+ type: 'event';
+ }
+ ).name) as any
+ }
+ onChange={(value) => {
+ dispatch(
+ changeEvent(
+ Array.isArray(value)
+ ? {
+ id: event.id,
+ type: 'event',
+ segment: 'user',
+ filters: [
+ {
+ name: 'name',
+ operator: 'is',
+ value: value,
+ },
+ ],
+ name: '*',
+ }
+ : {
+ ...event,
+ type: 'event',
+ name: value,
+ filters: [],
+ },
+ ),
+ );
+ }}
+ items={eventNames}
+ placeholder="Select event"
+ />
+ {showDisplayNameInput && (
+ <Input
+ placeholder={
+ (event as IChartEventItem & { type: 'event' }).name
+ ? `${(event as IChartEventItem & { type: 'event' }).name} (${alphabetIds[index]})`
+ : 'Display name'
+ }
+ defaultValue={
+ (event as IChartEventItem & { type: 'event' }).displayName
+ }
+ onChange={(e) => {
+ dispatchChangeEvent({
+ ...(event as IChartEventItem & {
+ type: 'event';
+ }),
+ displayName: e.target.value,
+ });
+ }}
+ />
+ )}
+ <ReportEventMore onClick={handleMore(event)} />
+ </ReportSeriesItem>
+ );
+ })}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/start/src/components/ui/combobox-events.tsx b/apps/start/src/components/ui/combobox-events.tsx
index c9b3fd015..78e53c452 100644
--- a/apps/start/src/components/ui/combobox-events.tsx
+++ b/apps/start/src/components/ui/combobox-events.tsx
@@ -178,7 +178,7 @@ export function ComboboxEvents<
<CommandEmpty>Nothing selected</CommandEmpty>
<VirtualList
- height={400}
+ height={300}
data={items.filter((item) => {
if (search === '') return true;
return item.name.toLowerCase().includes(search.toLowerCase());
diff --git a/apps/start/src/components/ui/label.tsx b/apps/start/src/components/ui/label.tsx
index 6f7cea77f..61c5a2377 100644
--- a/apps/start/src/components/ui/label.tsx
+++ b/apps/start/src/components/ui/label.tsx
@@ -5,7 +5,7 @@ import type { VariantProps } from 'class-variance-authority';
import * as React from 'react';
const labelVariants = cva(
- 'mb-3 text-sm block font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
+ 'mb-3 text-sm block font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-foreground/70',
);
const Label = React.forwardRef<
diff --git a/apps/start/src/integrations/tanstack-query/root-provider.tsx b/apps/start/src/integrations/tanstack-query/root-provider.tsx
index 50ee2ac85..a015111b5 100644
--- a/apps/start/src/integrations/tanstack-query/root-provider.tsx
+++ b/apps/start/src/integrations/tanstack-query/root-provider.tsx
@@ -25,12 +25,40 @@ export function createTRPCClientWithHeaders(apiUrl: string) {
transformer: superjson,
url: `${apiUrl}/trpc`,
headers: () => getIsomorphicHeaders(),
- fetch: (url, options) => {
- return fetch(url, {
- ...options,
- mode: 'cors',
- credentials: 'include',
- });
+ fetch: async (url, options) => {
+ try {
+ console.log('fetching', url, options);
+ const response = await fetch(url, {
+ ...options,
+ mode: 'cors',
+ credentials: 'include',
+ });
+
+ // Log HTTP errors on server
+ if (!response.ok && typeof window === 'undefined') {
+ const text = await response.clone().text();
+ console.error('[tRPC SSR Error]', {
+ url: url.toString(),
+ status: response.status,
+ statusText: response.statusText,
+ body: text,
+ options,
+ });
+ }
+
+ return response;
+ } catch (error) {
+ // Log fetch errors on server
+ if (typeof window === 'undefined') {
+ console.error('[tRPC SSR Error]', {
+ url: url.toString(),
+ error: error instanceof Error ? error.message : String(error),
+ stack: error instanceof Error ? error.stack : undefined,
+ options,
+ });
+ }
+ throw error;
+ }
},
}),
],
diff --git a/apps/start/src/modals/index.tsx b/apps/start/src/modals/index.tsx
index e723eaf34..bc835c98a 100644
--- a/apps/start/src/modals/index.tsx
+++ b/apps/start/src/modals/index.tsx
@@ -30,7 +30,9 @@ import OverviewFilters from './overview-filters';
import RequestPasswordReset from './request-reset-password';
import SaveReport from './save-report';
import SelectBillingPlan from './select-billing-plan';
+import ShareDashboardModal from './share-dashboard-modal';
import ShareOverviewModal from './share-overview-modal';
+import ShareReportModal from './share-report-modal';
import ViewChartUsers from './view-chart-users';
const modals = {
@@ -51,6 +53,8 @@ const modals = {
EditReport: EditReport,
EditReference: EditReference,
ShareOverviewModal: ShareOverviewModal,
+ ShareDashboardModal: ShareDashboardModal,
+ ShareReportModal: ShareReportModal,
AddReference: AddReference,
ViewChartUsers: ViewChartUsers,
Instructions: Instructions,
diff --git a/apps/start/src/modals/overview-chart-details.tsx b/apps/start/src/modals/overview-chart-details.tsx
index f5ccfd006..1ab580e91 100644
--- a/apps/start/src/modals/overview-chart-details.tsx
+++ b/apps/start/src/modals/overview-chart-details.tsx
@@ -1,12 +1,12 @@
import { ReportChart } from '@/components/report-chart';
import { ScrollArea } from '@/components/ui/scroll-area';
-import type { IChartProps } from '@openpanel/validation';
+import type { IReport } from '@openpanel/validation';
import { ModalContent, ModalHeader } from './Modal/Container';
type Props = {
- chart: IChartProps;
+ chart: IReport;
};
const OverviewChartDetails = (props: Props) => {
diff --git a/apps/start/src/modals/save-report.tsx b/apps/start/src/modals/save-report.tsx
index eb8eb3fbf..c59fdb0e4 100644
--- a/apps/start/src/modals/save-report.tsx
+++ b/apps/start/src/modals/save-report.tsx
@@ -10,7 +10,7 @@ import { Controller, useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
-import type { IChartProps } from '@openpanel/validation';
+import type { IReport } from '@openpanel/validation';
import { Input } from '@/components/ui/input';
import { useTRPC } from '@/integrations/trpc/react';
@@ -21,7 +21,7 @@ import { popModal } from '.';
import { ModalContent, ModalHeader } from './Modal/Container';
type SaveReportProps = {
- report: IChartProps;
+ report: IReport;
disableRedirect?: boolean;
};
diff --git a/apps/start/src/modals/share-dashboard-modal.tsx b/apps/start/src/modals/share-dashboard-modal.tsx
new file mode 100644
index 000000000..3a2e1ca83
--- /dev/null
+++ b/apps/start/src/modals/share-dashboard-modal.tsx
@@ -0,0 +1,192 @@
+import { ButtonContainer } from '@/components/button-container';
+import { Button } from '@/components/ui/button';
+import { useAppParams } from '@/hooks/use-app-params';
+import { handleError } from '@/integrations/trpc/react';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { useNavigate } from '@tanstack/react-router';
+import { useForm } from 'react-hook-form';
+import { toast } from 'sonner';
+import type { z } from 'zod';
+
+import { zShareDashboard } from '@openpanel/validation';
+
+import { Input } from '@/components/ui/input';
+import { Tooltiper } from '@/components/ui/tooltip';
+import { useTRPC } from '@/integrations/trpc/react';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { CheckCircle2, Copy, ExternalLink, TrashIcon } from 'lucide-react';
+import { useState } from 'react';
+import { popModal } from '.';
+import { ModalContent, ModalHeader } from './Modal/Container';
+
+const validator = zShareDashboard;
+
+type IForm = z.infer<typeof validator>;
+
+export default function ShareDashboardModal({
+ dashboardId,
+}: {
+ dashboardId: string;
+}) {
+ const { projectId, organizationId } = useAppParams();
+ const navigate = useNavigate();
+ const [copied, setCopied] = useState(false);
+
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+
+ // Fetch current share status
+ const shareQuery = useQuery(
+ trpc.share.dashboard.queryOptions({
+ dashboardId,
+ }),
+ );
+
+ const existingShare = shareQuery.data;
+ const isShared = existingShare?.public ?? false;
+ const shareUrl = existingShare?.id
+ ? `${window.location.origin}/share/dashboard/${existingShare.id}`
+ : '';
+
+ const { register, handleSubmit, watch } = useForm<IForm>({
+ resolver: zodResolver(validator),
+ defaultValues: {
+ public: true,
+ password: existingShare?.password ? '••••••••' : '',
+ projectId,
+ organizationId,
+ dashboardId,
+ },
+ });
+
+ const password = watch('password');
+
+ const mutation = useMutation(
+ trpc.share.createDashboard.mutationOptions({
+ onError: handleError,
+ onSuccess(res) {
+ queryClient.invalidateQueries(trpc.share.dashboard.pathFilter());
+ toast('Success', {
+ description: `Your dashboard is now ${
+ res.public ? 'public' : 'private'
+ }`,
+ action: res.public
+ ? {
+ label: 'View',
+ onClick: () =>
+ navigate({
+ to: '/share/dashboard/$shareId',
+ params: {
+ shareId: res.id,
+ },
+ }),
+ }
+ : undefined,
+ });
+ popModal();
+ },
+ }),
+ );
+
+ const handleCopyLink = () => {
+ navigator.clipboard.writeText(shareUrl);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ toast('Link copied to clipboard');
+ };
+
+ const handleMakePrivate = () => {
+ mutation.mutate({
+ public: false,
+ password: null,
+ projectId,
+ organizationId,
+ dashboardId,
+ });
+ };
+
+ return (
+ <ModalContent className="max-w-md">
+ <ModalHeader
+ title="Dashboard public availability"
+ text={
+ isShared
+ ? 'Your dashboard is currently public and can be accessed by anyone with the link.'
+ : 'You can choose if you want to add a password to make it a bit more private.'
+ }
+ />
+
+ {isShared && (
+ <div className="p-4 bg-def-100 border rounded-lg space-y-3">
+ <div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
+ <CheckCircle2 className="size-4" />
+ <span className="font-medium">Currently shared</span>
+ </div>
+ <div className="flex items-center gap-1">
+ <Input value={shareUrl} readOnly className="flex-1 text-sm" />
+ <Tooltiper content="Copy link">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={handleCopyLink}
+ >
+ {copied ? (
+ <CheckCircle2 className="size-4" />
+ ) : (
+ <Copy className="size-4" />
+ )}
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Open in new tab">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => window.open(shareUrl, '_blank')}
+ >
+ <ExternalLink className="size-4" />
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Make private">
+ <Button
+ type="button"
+ variant="destructive"
+ onClick={handleMakePrivate}
+ >
+ <TrashIcon className="size-4" />
+ </Button>
+ </Tooltiper>
+ </div>
+ </div>
+ )}
+
+ <form
+ onSubmit={handleSubmit((values) => {
+ mutation.mutate({
+ ...values,
+ // Only send password if it's not the placeholder
+ password:
+ values.password === '••••••••' ? null : values.password || null,
+ });
+ })}
+ >
+ <Input
+ {...register('password')}
+ placeholder="Enter your password (optional)"
+ size="large"
+ type={password === '••••••••' ? 'text' : 'password'}
+ />
+ <ButtonContainer>
+ <Button type="button" variant="outline" onClick={() => popModal()}>
+ Cancel
+ </Button>
+
+ <Button type="submit">
+ {isShared ? 'Update' : 'Make it public'}
+ </Button>
+ </ButtonContainer>
+ </form>
+ </ModalContent>
+ );
+}
diff --git a/apps/start/src/modals/share-overview-modal.tsx b/apps/start/src/modals/share-overview-modal.tsx
index 5ee503d2b..5d4b35630 100644
--- a/apps/start/src/modals/share-overview-modal.tsx
+++ b/apps/start/src/modals/share-overview-modal.tsx
@@ -11,8 +11,11 @@ import type { z } from 'zod';
import { zShareOverview } from '@openpanel/validation';
import { Input } from '@/components/ui/input';
+import { Tooltiper } from '@/components/ui/tooltip';
import { useTRPC } from '@/integrations/trpc/react';
-import { useMutation, useQueryClient } from '@tanstack/react-query';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { CheckCircle2, Copy, ExternalLink, TrashIcon } from 'lucide-react';
+import { useState } from 'react';
import { popModal } from '.';
import { ModalContent, ModalHeader } from './Modal/Container';
@@ -23,19 +26,36 @@ type IForm = z.infer<typeof validator>;
export default function ShareOverviewModal() {
const { projectId, organizationId } = useAppParams();
const navigate = useNavigate();
+ const [copied, setCopied] = useState(false);
- const { register, handleSubmit } = useForm<IForm>({
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+
+ // Fetch current share status
+ const shareQuery = useQuery(
+ trpc.share.overview.queryOptions({
+ projectId,
+ }),
+ );
+
+ const existingShare = shareQuery.data;
+ const isShared = existingShare?.public ?? false;
+ const shareUrl = existingShare?.id
+ ? `${window.location.origin}/share/overview/${existingShare.id}`
+ : '';
+
+ const { register, handleSubmit, watch } = useForm<IForm>({
resolver: zodResolver(validator),
defaultValues: {
public: true,
- password: '',
+ password: existingShare?.password ? '••••••••' : '',
projectId,
organizationId,
},
});
- const trpc = useTRPC();
- const queryClient = useQueryClient();
+ const password = watch('password');
+
const mutation = useMutation(
trpc.share.createOverview.mutationOptions({
onError: handleError,
@@ -45,47 +65,122 @@ export default function ShareOverviewModal() {
description: `Your overview is now ${
res.public ? 'public' : 'private'
}`,
- action: {
- label: 'View',
- onClick: () =>
- navigate({
- to: '/share/overview/$shareId',
- params: {
- shareId: res.id,
- },
- }),
- },
+ action: res.public
+ ? {
+ label: 'View',
+ onClick: () =>
+ navigate({
+ to: '/share/overview/$shareId',
+ params: {
+ shareId: res.id,
+ },
+ }),
+ }
+ : undefined,
});
popModal();
},
}),
);
+ const handleCopyLink = () => {
+ navigator.clipboard.writeText(shareUrl);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ toast('Link copied to clipboard');
+ };
+
+ const handleMakePrivate = () => {
+ mutation.mutate({
+ public: false,
+ password: null,
+ projectId,
+ organizationId,
+ });
+ };
+
return (
<ModalContent className="max-w-md">
<ModalHeader
- title="Dashboard public availability"
- text="You can choose if you want to add a password to make it a bit more private."
+ title="Overview public availability"
+ text={
+ isShared
+ ? 'Your overview is currently public and can be accessed by anyone with the link.'
+ : 'You can choose if you want to add a password to make it a bit more private.'
+ }
/>
+
+ {isShared && (
+ <div className="p-4 bg-def-100 border rounded-lg space-y-3">
+ <div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
+ <CheckCircle2 className="size-4" />
+ <span className="font-medium">Currently shared</span>
+ </div>
+ <div className="flex items-center gap-1">
+ <Input value={shareUrl} readOnly className="flex-1 text-sm" />
+ <Tooltiper content="Copy link">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={handleCopyLink}
+ >
+ {copied ? (
+ <CheckCircle2 className="size-4" />
+ ) : (
+ <Copy className="size-4" />
+ )}
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Open in new tab">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => window.open(shareUrl, '_blank')}
+ >
+ <ExternalLink className="size-4" />
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Make private">
+ <Button
+ type="button"
+ variant="destructive"
+ onClick={handleMakePrivate}
+ >
+ <TrashIcon className="size-4" />
+ </Button>
+ </Tooltiper>
+ </div>
+ </div>
+ )}
+
<form
onSubmit={handleSubmit((values) => {
- mutation.mutate(values);
+ mutation.mutate({
+ ...values,
+ // Only send password if it's not the placeholder
+ password:
+ values.password === '••••••••' ? null : values.password || null,
+ });
})}
>
<Input
{...register('password')}
- placeholder="Enter your password"
+ placeholder="Enter your password (optional)"
size="large"
+ type={password === '••••••••' ? 'text' : 'password'}
/>
<ButtonContainer>
<Button type="button" variant="outline" onClick={() => popModal()}>
Cancel
</Button>
- <Button type="submit" loading={mutation.isPending}>
- Make it public
+
+ <Button type="submit">
+ {isShared ? 'Update' : 'Make it public'}
</Button>
</ButtonContainer>
</form>
</ModalContent>
);
-}
+}
\ No newline at end of file
diff --git a/apps/start/src/modals/share-report-modal.tsx b/apps/start/src/modals/share-report-modal.tsx
new file mode 100644
index 000000000..be98d241d
--- /dev/null
+++ b/apps/start/src/modals/share-report-modal.tsx
@@ -0,0 +1,186 @@
+import { ButtonContainer } from '@/components/button-container';
+import { Button } from '@/components/ui/button';
+import { useAppParams } from '@/hooks/use-app-params';
+import { handleError } from '@/integrations/trpc/react';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { useNavigate } from '@tanstack/react-router';
+import { useForm } from 'react-hook-form';
+import { toast } from 'sonner';
+import type { z } from 'zod';
+
+import { zShareReport } from '@openpanel/validation';
+
+import { Input } from '@/components/ui/input';
+import { Tooltiper } from '@/components/ui/tooltip';
+import { useTRPC } from '@/integrations/trpc/react';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { CheckCircle2, Copy, ExternalLink, TrashIcon } from 'lucide-react';
+import { useState } from 'react';
+import { popModal } from '.';
+import { ModalContent, ModalHeader } from './Modal/Container';
+
+const validator = zShareReport;
+
+type IForm = z.infer<typeof validator>;
+
+export default function ShareReportModal({ reportId }: { reportId: string }) {
+ const { projectId, organizationId } = useAppParams();
+ const navigate = useNavigate();
+ const [copied, setCopied] = useState(false);
+
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+
+ // Fetch current share status
+ const shareQuery = useQuery(
+ trpc.share.report.queryOptions({
+ reportId,
+ }),
+ );
+
+ const existingShare = shareQuery.data;
+ const isShared = existingShare?.public ?? false;
+ const shareUrl = existingShare?.id
+ ? `${window.location.origin}/share/report/${existingShare.id}`
+ : '';
+
+ const { register, handleSubmit, watch } = useForm<IForm>({
+ resolver: zodResolver(validator),
+ defaultValues: {
+ public: true,
+ password: existingShare?.password ? '••••••••' : '',
+ projectId,
+ organizationId,
+ reportId,
+ },
+ });
+
+ const password = watch('password');
+
+ const mutation = useMutation(
+ trpc.share.createReport.mutationOptions({
+ onError: handleError,
+ onSuccess(res) {
+ queryClient.invalidateQueries(trpc.share.report.pathFilter());
+ toast('Success', {
+ description: `Your report is now ${res.public ? 'public' : 'private'}`,
+ action: res.public
+ ? {
+ label: 'View',
+ onClick: () =>
+ navigate({
+ to: '/share/report/$shareId',
+ params: {
+ shareId: res.id,
+ },
+ }),
+ }
+ : undefined,
+ });
+ popModal();
+ },
+ }),
+ );
+
+ const handleCopyLink = () => {
+ navigator.clipboard.writeText(shareUrl);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ toast('Link copied to clipboard');
+ };
+
+ const handleMakePrivate = () => {
+ mutation.mutate({
+ public: false,
+ password: null,
+ projectId,
+ organizationId,
+ reportId,
+ });
+ };
+
+ return (
+ <ModalContent className="max-w-md">
+ <ModalHeader
+ title="Report public availability"
+ text={
+ isShared
+ ? 'Your report is currently public and can be accessed by anyone with the link.'
+ : 'You can choose if you want to add a password to make it a bit more private.'
+ }
+ />
+
+ {isShared && (
+ <div className="p-4 bg-def-100 border rounded-lg space-y-3">
+ <div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
+ <CheckCircle2 className="size-4" />
+ <span className="font-medium">Currently shared</span>
+ </div>
+ <div className="flex items-center gap-1">
+ <Input value={shareUrl} readOnly className="flex-1 text-sm" />
+ <Tooltiper content="Copy link">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={handleCopyLink}
+ >
+ {copied ? (
+ <CheckCircle2 className="size-4" />
+ ) : (
+ <Copy className="size-4" />
+ )}
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Open in new tab">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => window.open(shareUrl, '_blank')}
+ >
+ <ExternalLink className="size-4" />
+ </Button>
+ </Tooltiper>
+ <Tooltiper content="Make private">
+ <Button
+ type="button"
+ variant="destructive"
+ onClick={handleMakePrivate}
+ >
+ <TrashIcon className="size-4" />
+ </Button>
+ </Tooltiper>
+ </div>
+ </div>
+ )}
+
+ <form
+ onSubmit={handleSubmit((values) => {
+ mutation.mutate({
+ ...values,
+ // Only send password if it's not the placeholder
+ password:
+ values.password === '••••••••' ? null : values.password || null,
+ });
+ })}
+ >
+ <Input
+ {...register('password')}
+ placeholder="Enter your password (optional)"
+ size="large"
+ type={password === '••••••••' ? 'text' : 'password'}
+ />
+ <ButtonContainer>
+ <Button type="button" variant="outline" onClick={() => popModal()}>
+ Cancel
+ </Button>
+
+ <Button type="submit">
+ {isShared ? 'Update' : 'Make it public'}
+ </Button>
+ </ButtonContainer>
+ </form>
+ </ModalContent>
+ );
+}
\ No newline at end of file
diff --git a/apps/start/src/modals/view-chart-users.tsx b/apps/start/src/modals/view-chart-users.tsx
index 31c7f760c..44f4380ea 100644
--- a/apps/start/src/modals/view-chart-users.tsx
+++ b/apps/start/src/modals/view-chart-users.tsx
@@ -13,7 +13,7 @@ import { useTRPC } from '@/integrations/trpc/react';
import type { IChartData } from '@/trpc/client';
import { cn } from '@/utils/cn';
import { getProfileName } from '@/utils/getters';
-import type { IChartInput } from '@openpanel/validation';
+import type { IReportInput } from '@openpanel/validation';
import { useQuery } from '@tanstack/react-query';
import { useVirtualizer } from '@tanstack/react-virtual';
import { useEffect, useMemo, useState } from 'react';
@@ -152,7 +152,7 @@ function ProfileList({ profiles }: { profiles: any[] }) {
// Chart-specific props and component
interface ChartUsersViewProps {
chartData: IChartData;
- report: IChartInput;
+ report: IReportInput;
date: string;
}
@@ -279,7 +279,7 @@ function ChartUsersView({ chartData, report, date }: ChartUsersViewProps) {
// Funnel-specific props and component
interface FunnelUsersViewProps {
- report: IChartInput;
+ report: IReportInput;
stepIndex: number;
}
@@ -297,8 +297,14 @@ function FunnelUsersView({ report, stepIndex }: FunnelUsersViewProps) {
series: report.series,
stepIndex: stepIndex,
showDropoffs: showDropoffs,
- funnelWindow: report.funnelWindow,
- funnelGroup: report.funnelGroup,
+ funnelWindow:
+ report.options?.type === 'funnel'
+ ? report.options.funnelWindow
+ : undefined,
+ funnelGroup:
+ report.options?.type === 'funnel'
+ ? report.options.funnelGroup
+ : undefined,
breakdowns: report.breakdowns,
},
{
@@ -371,12 +377,12 @@ type ViewChartUsersProps =
| {
type: 'chart';
chartData: IChartData;
- report: IChartInput;
+ report: IReportInput;
date: string;
}
| {
type: 'funnel';
- report: IChartInput;
+ report: IReportInput;
stepIndex: number;
};
diff --git a/apps/start/src/routeTree.gen.ts b/apps/start/src/routeTree.gen.ts
index a75fc4b09..5d5144014 100644
--- a/apps/start/src/routeTree.gen.ts
+++ b/apps/start/src/routeTree.gen.ts
@@ -16,6 +16,9 @@ import { Route as PublicRouteImport } from './routes/_public'
import { Route as LoginRouteImport } from './routes/_login'
import { Route as AppRouteImport } from './routes/_app'
import { Route as IndexRouteImport } from './routes/index'
+import { Route as WidgetTestRouteImport } from './routes/widget/test'
+import { Route as WidgetRealtimeRouteImport } from './routes/widget/realtime'
+import { Route as WidgetCounterRouteImport } from './routes/widget/counter'
import { Route as ApiHealthcheckRouteImport } from './routes/api/healthcheck'
import { Route as ApiConfigRouteImport } from './routes/api/config'
import { Route as PublicOnboardingRouteImport } from './routes/_public.onboarding'
@@ -23,7 +26,9 @@ import { Route as LoginResetPasswordRouteImport } from './routes/_login.reset-pa
import { Route as LoginLoginRouteImport } from './routes/_login.login'
import { Route as AppOrganizationIdRouteImport } from './routes/_app.$organizationId'
import { Route as AppOrganizationIdIndexRouteImport } from './routes/_app.$organizationId.index'
+import { Route as ShareReportShareIdRouteImport } from './routes/share.report.$shareId'
import { Route as ShareOverviewShareIdRouteImport } from './routes/share.overview.$shareId'
+import { Route as ShareDashboardShareIdRouteImport } from './routes/share.dashboard.$shareId'
import { Route as StepsOnboardingProjectRouteImport } from './routes/_steps.onboarding.project'
import { Route as AppOrganizationIdSettingsRouteImport } from './routes/_app.$organizationId.settings'
import { Route as AppOrganizationIdBillingRouteImport } from './routes/_app.$organizationId.billing'
@@ -58,6 +63,7 @@ import { Route as AppOrganizationIdProjectIdSettingsTabsIndexRouteImport } from
import { Route as AppOrganizationIdProjectIdProfilesTabsIndexRouteImport } from './routes/_app.$organizationId.$projectId.profiles._tabs.index'
import { Route as AppOrganizationIdProjectIdNotificationsTabsIndexRouteImport } from './routes/_app.$organizationId.$projectId.notifications._tabs.index'
import { Route as AppOrganizationIdProjectIdEventsTabsIndexRouteImport } from './routes/_app.$organizationId.$projectId.events._tabs.index'
+import { Route as AppOrganizationIdProjectIdSettingsTabsWidgetsRouteImport } from './routes/_app.$organizationId.$projectId.settings._tabs.widgets'
import { Route as AppOrganizationIdProjectIdSettingsTabsImportsRouteImport } from './routes/_app.$organizationId.$projectId.settings._tabs.imports'
import { Route as AppOrganizationIdProjectIdSettingsTabsEventsRouteImport } from './routes/_app.$organizationId.$projectId.settings._tabs.events'
import { Route as AppOrganizationIdProjectIdSettingsTabsDetailsRouteImport } from './routes/_app.$organizationId.$projectId.settings._tabs.details'
@@ -117,6 +123,21 @@ const IndexRoute = IndexRouteImport.update({
path: '/',
getParentRoute: () => rootRouteImport,
} as any)
+const WidgetTestRoute = WidgetTestRouteImport.update({
+ id: '/widget/test',
+ path: '/widget/test',
+ getParentRoute: () => rootRouteImport,
+} as any)
+const WidgetRealtimeRoute = WidgetRealtimeRouteImport.update({
+ id: '/widget/realtime',
+ path: '/widget/realtime',
+ getParentRoute: () => rootRouteImport,
+} as any)
+const WidgetCounterRoute = WidgetCounterRouteImport.update({
+ id: '/widget/counter',
+ path: '/widget/counter',
+ getParentRoute: () => rootRouteImport,
+} as any)
const ApiHealthcheckRoute = ApiHealthcheckRouteImport.update({
id: '/api/healthcheck',
path: '/api/healthcheck',
@@ -164,11 +185,21 @@ const AppOrganizationIdIndexRoute = AppOrganizationIdIndexRouteImport.update({
path: '/',
getParentRoute: () => AppOrganizationIdRoute,
} as any)
+const ShareReportShareIdRoute = ShareReportShareIdRouteImport.update({
+ id: '/share/report/$shareId',
+ path: '/share/report/$shareId',
+ getParentRoute: () => rootRouteImport,
+} as any)
const ShareOverviewShareIdRoute = ShareOverviewShareIdRouteImport.update({
id: '/share/overview/$shareId',
path: '/share/overview/$shareId',
getParentRoute: () => rootRouteImport,
} as any)
+const ShareDashboardShareIdRoute = ShareDashboardShareIdRouteImport.update({
+ id: '/share/dashboard/$shareId',
+ path: '/share/dashboard/$shareId',
+ getParentRoute: () => rootRouteImport,
+} as any)
const StepsOnboardingProjectRoute = StepsOnboardingProjectRouteImport.update({
id: '/onboarding/project',
path: '/onboarding/project',
@@ -396,6 +427,12 @@ const AppOrganizationIdProjectIdEventsTabsIndexRoute =
path: '/',
getParentRoute: () => AppOrganizationIdProjectIdEventsTabsRoute,
} as any)
+const AppOrganizationIdProjectIdSettingsTabsWidgetsRoute =
+ AppOrganizationIdProjectIdSettingsTabsWidgetsRouteImport.update({
+ id: '/widgets',
+ path: '/widgets',
+ getParentRoute: () => AppOrganizationIdProjectIdSettingsTabsRoute,
+ } as any)
const AppOrganizationIdProjectIdSettingsTabsImportsRoute =
AppOrganizationIdProjectIdSettingsTabsImportsRouteImport.update({
id: '/imports',
@@ -494,11 +531,16 @@ export interface FileRoutesByFullPath {
'/onboarding': typeof PublicOnboardingRoute
'/api/config': typeof ApiConfigRoute
'/api/healthcheck': typeof ApiHealthcheckRoute
+ '/widget/counter': typeof WidgetCounterRoute
+ '/widget/realtime': typeof WidgetRealtimeRoute
+ '/widget/test': typeof WidgetTestRoute
'/$organizationId/$projectId': typeof AppOrganizationIdProjectIdRouteWithChildren
'/$organizationId/billing': typeof AppOrganizationIdBillingRoute
'/$organizationId/settings': typeof AppOrganizationIdSettingsRoute
'/onboarding/project': typeof StepsOnboardingProjectRoute
+ '/share/dashboard/$shareId': typeof ShareDashboardShareIdRoute
'/share/overview/$shareId': typeof ShareOverviewShareIdRoute
+ '/share/report/$shareId': typeof ShareReportShareIdRoute
'/$organizationId/': typeof AppOrganizationIdIndexRoute
'/$organizationId/$projectId/chat': typeof AppOrganizationIdProjectIdChatRoute
'/$organizationId/$projectId/dashboards': typeof AppOrganizationIdProjectIdDashboardsRoute
@@ -539,6 +581,7 @@ export interface FileRoutesByFullPath {
'/$organizationId/$projectId/settings/details': typeof AppOrganizationIdProjectIdSettingsTabsDetailsRoute
'/$organizationId/$projectId/settings/events': typeof AppOrganizationIdProjectIdSettingsTabsEventsRoute
'/$organizationId/$projectId/settings/imports': typeof AppOrganizationIdProjectIdSettingsTabsImportsRoute
+ '/$organizationId/$projectId/settings/widgets': typeof AppOrganizationIdProjectIdSettingsTabsWidgetsRoute
'/$organizationId/$projectId/events/': typeof AppOrganizationIdProjectIdEventsTabsIndexRoute
'/$organizationId/$projectId/notifications/': typeof AppOrganizationIdProjectIdNotificationsTabsIndexRoute
'/$organizationId/$projectId/profiles/': typeof AppOrganizationIdProjectIdProfilesTabsIndexRoute
@@ -553,10 +596,15 @@ export interface FileRoutesByTo {
'/onboarding': typeof PublicOnboardingRoute
'/api/config': typeof ApiConfigRoute
'/api/healthcheck': typeof ApiHealthcheckRoute
+ '/widget/counter': typeof WidgetCounterRoute
+ '/widget/realtime': typeof WidgetRealtimeRoute
+ '/widget/test': typeof WidgetTestRoute
'/$organizationId/billing': typeof AppOrganizationIdBillingRoute
'/$organizationId/settings': typeof AppOrganizationIdSettingsRoute
'/onboarding/project': typeof StepsOnboardingProjectRoute
+ '/share/dashboard/$shareId': typeof ShareDashboardShareIdRoute
'/share/overview/$shareId': typeof ShareOverviewShareIdRoute
+ '/share/report/$shareId': typeof ShareReportShareIdRoute
'/$organizationId': typeof AppOrganizationIdIndexRoute
'/$organizationId/$projectId/chat': typeof AppOrganizationIdProjectIdChatRoute
'/$organizationId/$projectId/dashboards': typeof AppOrganizationIdProjectIdDashboardsRoute
@@ -595,6 +643,7 @@ export interface FileRoutesByTo {
'/$organizationId/$projectId/settings/details': typeof AppOrganizationIdProjectIdSettingsTabsDetailsRoute
'/$organizationId/$projectId/settings/events': typeof AppOrganizationIdProjectIdSettingsTabsEventsRoute
'/$organizationId/$projectId/settings/imports': typeof AppOrganizationIdProjectIdSettingsTabsImportsRoute
+ '/$organizationId/$projectId/settings/widgets': typeof AppOrganizationIdProjectIdSettingsTabsWidgetsRoute
'/$organizationId/$projectId/profiles/$profileId/events': typeof AppOrganizationIdProjectIdProfilesProfileIdTabsEventsRoute
}
export interface FileRoutesById {
@@ -610,11 +659,16 @@ export interface FileRoutesById {
'/_public/onboarding': typeof PublicOnboardingRoute
'/api/config': typeof ApiConfigRoute
'/api/healthcheck': typeof ApiHealthcheckRoute
+ '/widget/counter': typeof WidgetCounterRoute
+ '/widget/realtime': typeof WidgetRealtimeRoute
+ '/widget/test': typeof WidgetTestRoute
'/_app/$organizationId/$projectId': typeof AppOrganizationIdProjectIdRouteWithChildren
'/_app/$organizationId/billing': typeof AppOrganizationIdBillingRoute
'/_app/$organizationId/settings': typeof AppOrganizationIdSettingsRoute
'/_steps/onboarding/project': typeof StepsOnboardingProjectRoute
+ '/share/dashboard/$shareId': typeof ShareDashboardShareIdRoute
'/share/overview/$shareId': typeof ShareOverviewShareIdRoute
+ '/share/report/$shareId': typeof ShareReportShareIdRoute
'/_app/$organizationId/': typeof AppOrganizationIdIndexRoute
'/_app/$organizationId/$projectId/chat': typeof AppOrganizationIdProjectIdChatRoute
'/_app/$organizationId/$projectId/dashboards': typeof AppOrganizationIdProjectIdDashboardsRoute
@@ -662,6 +716,7 @@ export interface FileRoutesById {
'/_app/$organizationId/$projectId/settings/_tabs/details': typeof AppOrganizationIdProjectIdSettingsTabsDetailsRoute
'/_app/$organizationId/$projectId/settings/_tabs/events': typeof AppOrganizationIdProjectIdSettingsTabsEventsRoute
'/_app/$organizationId/$projectId/settings/_tabs/imports': typeof AppOrganizationIdProjectIdSettingsTabsImportsRoute
+ '/_app/$organizationId/$projectId/settings/_tabs/widgets': typeof AppOrganizationIdProjectIdSettingsTabsWidgetsRoute
'/_app/$organizationId/$projectId/events/_tabs/': typeof AppOrganizationIdProjectIdEventsTabsIndexRoute
'/_app/$organizationId/$projectId/notifications/_tabs/': typeof AppOrganizationIdProjectIdNotificationsTabsIndexRoute
'/_app/$organizationId/$projectId/profiles/_tabs/': typeof AppOrganizationIdProjectIdProfilesTabsIndexRoute
@@ -679,11 +734,16 @@ export interface FileRouteTypes {
| '/onboarding'
| '/api/config'
| '/api/healthcheck'
+ | '/widget/counter'
+ | '/widget/realtime'
+ | '/widget/test'
| '/$organizationId/$projectId'
| '/$organizationId/billing'
| '/$organizationId/settings'
| '/onboarding/project'
+ | '/share/dashboard/$shareId'
| '/share/overview/$shareId'
+ | '/share/report/$shareId'
| '/$organizationId/'
| '/$organizationId/$projectId/chat'
| '/$organizationId/$projectId/dashboards'
@@ -724,6 +784,7 @@ export interface FileRouteTypes {
| '/$organizationId/$projectId/settings/details'
| '/$organizationId/$projectId/settings/events'
| '/$organizationId/$projectId/settings/imports'
+ | '/$organizationId/$projectId/settings/widgets'
| '/$organizationId/$projectId/events/'
| '/$organizationId/$projectId/notifications/'
| '/$organizationId/$projectId/profiles/'
@@ -738,10 +799,15 @@ export interface FileRouteTypes {
| '/onboarding'
| '/api/config'
| '/api/healthcheck'
+ | '/widget/counter'
+ | '/widget/realtime'
+ | '/widget/test'
| '/$organizationId/billing'
| '/$organizationId/settings'
| '/onboarding/project'
+ | '/share/dashboard/$shareId'
| '/share/overview/$shareId'
+ | '/share/report/$shareId'
| '/$organizationId'
| '/$organizationId/$projectId/chat'
| '/$organizationId/$projectId/dashboards'
@@ -780,6 +846,7 @@ export interface FileRouteTypes {
| '/$organizationId/$projectId/settings/details'
| '/$organizationId/$projectId/settings/events'
| '/$organizationId/$projectId/settings/imports'
+ | '/$organizationId/$projectId/settings/widgets'
| '/$organizationId/$projectId/profiles/$profileId/events'
id:
| '__root__'
@@ -794,11 +861,16 @@ export interface FileRouteTypes {
| '/_public/onboarding'
| '/api/config'
| '/api/healthcheck'
+ | '/widget/counter'
+ | '/widget/realtime'
+ | '/widget/test'
| '/_app/$organizationId/$projectId'
| '/_app/$organizationId/billing'
| '/_app/$organizationId/settings'
| '/_steps/onboarding/project'
+ | '/share/dashboard/$shareId'
| '/share/overview/$shareId'
+ | '/share/report/$shareId'
| '/_app/$organizationId/'
| '/_app/$organizationId/$projectId/chat'
| '/_app/$organizationId/$projectId/dashboards'
@@ -846,6 +918,7 @@ export interface FileRouteTypes {
| '/_app/$organizationId/$projectId/settings/_tabs/details'
| '/_app/$organizationId/$projectId/settings/_tabs/events'
| '/_app/$organizationId/$projectId/settings/_tabs/imports'
+ | '/_app/$organizationId/$projectId/settings/_tabs/widgets'
| '/_app/$organizationId/$projectId/events/_tabs/'
| '/_app/$organizationId/$projectId/notifications/_tabs/'
| '/_app/$organizationId/$projectId/profiles/_tabs/'
@@ -862,7 +935,12 @@ export interface RootRouteChildren {
StepsRoute: typeof StepsRouteWithChildren
ApiConfigRoute: typeof ApiConfigRoute
ApiHealthcheckRoute: typeof ApiHealthcheckRoute
+ WidgetCounterRoute: typeof WidgetCounterRoute
+ WidgetRealtimeRoute: typeof WidgetRealtimeRoute
+ WidgetTestRoute: typeof WidgetTestRoute
+ ShareDashboardShareIdRoute: typeof ShareDashboardShareIdRoute
ShareOverviewShareIdRoute: typeof ShareOverviewShareIdRoute
+ ShareReportShareIdRoute: typeof ShareReportShareIdRoute
}
declare module '@tanstack/react-router' {
@@ -902,6 +980,27 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
+ '/widget/test': {
+ id: '/widget/test'
+ path: '/widget/test'
+ fullPath: '/widget/test'
+ preLoaderRoute: typeof WidgetTestRouteImport
+ parentRoute: typeof rootRouteImport
+ }
+ '/widget/realtime': {
+ id: '/widget/realtime'
+ path: '/widget/realtime'
+ fullPath: '/widget/realtime'
+ preLoaderRoute: typeof WidgetRealtimeRouteImport
+ parentRoute: typeof rootRouteImport
+ }
+ '/widget/counter': {
+ id: '/widget/counter'
+ path: '/widget/counter'
+ fullPath: '/widget/counter'
+ preLoaderRoute: typeof WidgetCounterRouteImport
+ parentRoute: typeof rootRouteImport
+ }
'/api/healthcheck': {
id: '/api/healthcheck'
path: '/api/healthcheck'
@@ -965,6 +1064,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AppOrganizationIdIndexRouteImport
parentRoute: typeof AppOrganizationIdRoute
}
+ '/share/report/$shareId': {
+ id: '/share/report/$shareId'
+ path: '/share/report/$shareId'
+ fullPath: '/share/report/$shareId'
+ preLoaderRoute: typeof ShareReportShareIdRouteImport
+ parentRoute: typeof rootRouteImport
+ }
'/share/overview/$shareId': {
id: '/share/overview/$shareId'
path: '/share/overview/$shareId'
@@ -972,6 +1078,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ShareOverviewShareIdRouteImport
parentRoute: typeof rootRouteImport
}
+ '/share/dashboard/$shareId': {
+ id: '/share/dashboard/$shareId'
+ path: '/share/dashboard/$shareId'
+ fullPath: '/share/dashboard/$shareId'
+ preLoaderRoute: typeof ShareDashboardShareIdRouteImport
+ parentRoute: typeof rootRouteImport
+ }
'/_steps/onboarding/project': {
id: '/_steps/onboarding/project'
path: '/onboarding/project'
@@ -1245,6 +1358,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AppOrganizationIdProjectIdEventsTabsIndexRouteImport
parentRoute: typeof AppOrganizationIdProjectIdEventsTabsRoute
}
+ '/_app/$organizationId/$projectId/settings/_tabs/widgets': {
+ id: '/_app/$organizationId/$projectId/settings/_tabs/widgets'
+ path: '/widgets'
+ fullPath: '/$organizationId/$projectId/settings/widgets'
+ preLoaderRoute: typeof AppOrganizationIdProjectIdSettingsTabsWidgetsRouteImport
+ parentRoute: typeof AppOrganizationIdProjectIdSettingsTabsRoute
+ }
'/_app/$organizationId/$projectId/settings/_tabs/imports': {
id: '/_app/$organizationId/$projectId/settings/_tabs/imports'
path: '/imports'
@@ -1508,6 +1628,7 @@ interface AppOrganizationIdProjectIdSettingsTabsRouteChildren {
AppOrganizationIdProjectIdSettingsTabsDetailsRoute: typeof AppOrganizationIdProjectIdSettingsTabsDetailsRoute
AppOrganizationIdProjectIdSettingsTabsEventsRoute: typeof AppOrganizationIdProjectIdSettingsTabsEventsRoute
AppOrganizationIdProjectIdSettingsTabsImportsRoute: typeof AppOrganizationIdProjectIdSettingsTabsImportsRoute
+ AppOrganizationIdProjectIdSettingsTabsWidgetsRoute: typeof AppOrganizationIdProjectIdSettingsTabsWidgetsRoute
AppOrganizationIdProjectIdSettingsTabsIndexRoute: typeof AppOrganizationIdProjectIdSettingsTabsIndexRoute
}
@@ -1521,6 +1642,8 @@ const AppOrganizationIdProjectIdSettingsTabsRouteChildren: AppOrganizationIdProj
AppOrganizationIdProjectIdSettingsTabsEventsRoute,
AppOrganizationIdProjectIdSettingsTabsImportsRoute:
AppOrganizationIdProjectIdSettingsTabsImportsRoute,
+ AppOrganizationIdProjectIdSettingsTabsWidgetsRoute:
+ AppOrganizationIdProjectIdSettingsTabsWidgetsRoute,
AppOrganizationIdProjectIdSettingsTabsIndexRoute:
AppOrganizationIdProjectIdSettingsTabsIndexRoute,
}
@@ -1751,7 +1874,12 @@ const rootRouteChildren: RootRouteChildren = {
StepsRoute: StepsRouteWithChildren,
ApiConfigRoute: ApiConfigRoute,
ApiHealthcheckRoute: ApiHealthcheckRoute,
+ WidgetCounterRoute: WidgetCounterRoute,
+ WidgetRealtimeRoute: WidgetRealtimeRoute,
+ WidgetTestRoute: WidgetTestRoute,
+ ShareDashboardShareIdRoute: ShareDashboardShareIdRoute,
ShareOverviewShareIdRoute: ShareOverviewShareIdRoute,
+ ShareReportShareIdRoute: ShareReportShareIdRoute,
}
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
diff --git a/apps/start/src/routes/__root.tsx b/apps/start/src/routes/__root.tsx
index c76afa363..a7e591902 100644
--- a/apps/start/src/routes/__root.tsx
+++ b/apps/start/src/routes/__root.tsx
@@ -2,7 +2,6 @@ import {
HeadContent,
Scripts,
createRootRouteWithContext,
- useRouteContext,
} from '@tanstack/react-router';
import 'flag-icons/css/flag-icons.min.css';
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
index 641ce5396..7660d690e 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
@@ -12,6 +12,7 @@ import {
BarChartHorizontalIcon,
ChartScatterIcon,
ConeIcon,
+ GitBranchIcon,
Globe2Icon,
HashIcon,
LayoutPanelTopIcon,
@@ -153,6 +154,7 @@ function Component() {
area: AreaChartIcon,
retention: ChartScatterIcon,
conversion: TrendingUpIcon,
+ sankey: GitBranchIcon,
}[report.chartType];
return (
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
index 503cb1e80..31e52d3c3 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
@@ -1,6 +1,5 @@
import { FullPageEmptyState } from '@/components/full-page-empty-state';
import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
-import { ReportChart } from '@/components/report-chart';
import { Button, LinkButton } from '@/components/ui/button';
import {
DropdownMenu,
@@ -9,48 +8,36 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
-import { cn } from '@/utils/cn';
import { createProjectTitle } from '@/utils/title';
import {
- CopyIcon,
LayoutPanelTopIcon,
MoreHorizontal,
PlusIcon,
RotateCcw,
- Trash,
+ ShareIcon,
TrashIcon,
} from 'lucide-react';
import { toast } from 'sonner';
-import { timeWindows } from '@openpanel/constants';
-
import FullPageLoadingState from '@/components/full-page-loading-state';
+import {
+ GrafanaGrid,
+ type Layout,
+ useReportLayouts,
+} from '@/components/grafana-grid';
import { OverviewInterval } from '@/components/overview/overview-interval';
import { OverviewRange } from '@/components/overview/overview-range';
import { PageContainer } from '@/components/page-container';
import { PageHeader } from '@/components/page-header';
+import {
+ ReportItem,
+ ReportItemSkeleton,
+} from '@/components/report/report-item';
import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react';
-import { showConfirm } from '@/modals';
+import { pushModal, showConfirm } from '@/modals';
import { useMutation, useQuery } from '@tanstack/react-query';
import { createFileRoute, useRouter } from '@tanstack/react-router';
-import { useCallback, useEffect, useMemo, useState } from 'react';
-import { Responsive, WidthProvider } from 'react-grid-layout';
-import 'react-grid-layout/css/styles.css';
-import 'react-resizable/css/styles.css';
-
-const ResponsiveGridLayout = WidthProvider(Responsive);
-
-type Layout = {
- i: string;
- x: number;
- y: number;
- w: number;
- h: number;
- minW?: number;
- minH?: number;
- maxW?: number;
- maxH?: number;
-};
+import { useCallback, useEffect, useState } from 'react';
export const Route = createFileRoute(
'/_app/$organizationId/$projectId/dashboards_/$dashboardId',
@@ -94,180 +81,6 @@ export const Route = createFileRoute(
pendingComponent: FullPageLoadingState,
});
-// Report Skeleton Component
-function ReportSkeleton() {
- return (
- <div className="card h-full flex flex-col animate-pulse">
- <div className="flex items-center justify-between border-b border-border p-4">
- <div className="flex-1">
- <div className="h-5 w-32 bg-muted rounded mb-2" />
- <div className="h-4 w-24 bg-muted/50 rounded" />
- </div>
- <div className="flex items-center gap-2">
- <div className="w-8 h-8 bg-muted rounded" />
- <div className="w-8 h-8 bg-muted rounded" />
- </div>
- </div>
- <div className="p-4 flex-1 flex items-center justify-center aspect-video" />
- </div>
- );
-}
-
-// Report Item Component
-function ReportItem({
- report,
- organizationId,
- projectId,
- range,
- startDate,
- endDate,
- interval,
- onDelete,
- onDuplicate,
-}: {
- report: any;
- organizationId: string;
- projectId: string;
- range: any;
- startDate: any;
- endDate: any;
- interval: any;
- onDelete: (reportId: string) => void;
- onDuplicate: (reportId: string) => void;
-}) {
- const router = useRouter();
- const chartRange = report.range;
-
- return (
- <div className="card h-full flex flex-col">
- <div className="flex items-center hover:bg-muted/50 justify-between border-b border-border p-4 leading-none [&_svg]:hover:opacity-100">
- <div
- className="flex-1 cursor-pointer -m-4 p-4"
- onClick={(event) => {
- if (event.metaKey) {
- window.open(
- `/${organizationId}/${projectId}/reports/${report.id}`,
- '_blank',
- );
- return;
- }
- router.navigate({
- from: Route.fullPath,
- to: '/$organizationId/$projectId/reports/$reportId',
- params: {
- reportId: report.id,
- },
- });
- }}
- onKeyUp={(e) => {
- if (e.key === 'Enter' || e.key === ' ') {
- router.navigate({
- from: Route.fullPath,
- to: '/$organizationId/$projectId/reports/$reportId',
- params: {
- reportId: report.id,
- },
- });
- }
- }}
- role="button"
- tabIndex={0}
- >
- <div className="font-medium">{report.name}</div>
- {chartRange !== null && (
- <div className="mt-2 flex gap-2 ">
- <span
- className={
- (chartRange !== range && range !== null) ||
- (startDate && endDate)
- ? 'line-through'
- : ''
- }
- >
- {timeWindows[chartRange as keyof typeof timeWindows]?.label}
- </span>
- {startDate && endDate ? (
- <span>Custom dates</span>
- ) : (
- range !== null &&
- chartRange !== range && (
- <span>
- {timeWindows[range as keyof typeof timeWindows]?.label}
- </span>
- )
- )}
- </div>
- )}
- </div>
- <div className="flex items-center gap-2">
- <div className="drag-handle cursor-move p-2 hover:bg-muted rounded">
- <svg
- width="16"
- height="16"
- viewBox="0 0 16 16"
- fill="currentColor"
- className="opacity-30 hover:opacity-100"
- >
- <circle cx="4" cy="4" r="1.5" />
- <circle cx="4" cy="8" r="1.5" />
- <circle cx="4" cy="12" r="1.5" />
- <circle cx="12" cy="4" r="1.5" />
- <circle cx="12" cy="8" r="1.5" />
- <circle cx="12" cy="12" r="1.5" />
- </svg>
- </div>
- <DropdownMenu>
- <DropdownMenuTrigger className="flex h-8 w-8 items-center justify-center rounded hover:border">
- <MoreHorizontal size={16} />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="w-[200px]">
- <DropdownMenuItem
- onClick={(event) => {
- event.stopPropagation();
- onDuplicate(report.id);
- }}
- >
- <CopyIcon size={16} className="mr-2" />
- Duplicate
- </DropdownMenuItem>
- <DropdownMenuGroup>
- <DropdownMenuItem
- className="text-destructive"
- onClick={(event) => {
- event.stopPropagation();
- onDelete(report.id);
- }}
- >
- <Trash size={16} className="mr-2" />
- Delete
- </DropdownMenuItem>
- </DropdownMenuGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- </div>
- <div
- className={cn(
- 'p-4 overflow-auto flex-1',
- report.chartType === 'metric' && 'p-0',
- )}
- >
- <ReportChart
- report={
- {
- ...report,
- range: range ?? report.range,
- startDate: startDate ?? null,
- endDate: endDate ?? null,
- interval: interval ?? report.interval,
- } as any
- }
- />
- </div>
- </div>
- );
-}
-
function Component() {
const router = useRouter();
const { organizationId, dashboardId, projectId } = Route.useParams();
@@ -363,26 +176,7 @@ function Component() {
);
// Convert reports to grid layout format for all breakpoints
- const layouts = useMemo(() => {
- const baseLayout = reports.map((report, index) => ({
- i: report.id,
- x: report.layout?.x ?? (index % 2) * 6,
- y: report.layout?.y ?? Math.floor(index / 2) * 4,
- w: report.layout?.w ?? 6,
- h: report.layout?.h ?? 4,
- minW: 3,
- minH: 3,
- }));
-
- // Create responsive layouts for different breakpoints
- return {
- lg: baseLayout,
- md: baseLayout,
- sm: baseLayout.map((item) => ({ ...item, w: Math.min(item.w, 6) })),
- xs: baseLayout.map((item) => ({ ...item, w: 4, x: 0 })),
- xxs: baseLayout.map((item) => ({ ...item, w: 2, x: 0 })),
- };
- }, [reports]);
+ const layouts = useReportLayouts(reports);
const handleLayoutChange = useCallback((newLayout: Layout[]) => {
// This is called during dragging/resizing, we'll save on drag/resize stop
@@ -463,7 +257,7 @@ function Component() {
<PageHeader
title={dashboard.name}
description="View and manage your reports"
- className="mb-0"
+ className="mb-4"
actions={
<>
<OverviewRange />
@@ -484,6 +278,14 @@ function Component() {
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-[200px]">
<DropdownMenuGroup>
+ <DropdownMenuItem
+ onClick={() =>
+ pushModal('ShareDashboardModal', { dashboardId })
+ }
+ >
+ <ShareIcon className="mr-2 size-4" />
+ Share dashboard
+ </DropdownMenuItem>
<DropdownMenuItem
onClick={() =>
showConfirm({
@@ -532,69 +334,43 @@ function Component() {
</FullPageEmptyState>
) : !isGridReady || reportsQuery.isLoading ? (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
- <ReportSkeleton />
- <ReportSkeleton />
- <ReportSkeleton />
- <ReportSkeleton />
- <ReportSkeleton />
- <ReportSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
</div>
) : (
- <div className="w-full overflow-hidden -mx-4">
- <style>{`
- .react-grid-item {
- transition: ${enableTransitions ? 'transform 200ms ease, width 200ms ease, height 200ms ease' : 'none'} !important;
- }
- .react-grid-item.react-grid-placeholder {
- background: none !important;
- opacity: 0.5;
- transition-duration: 100ms;
- border-radius: 0.5rem;
- border: 1px dashed var(--primary);
- }
- .react-grid-item.resizing {
- transition: none !important;
- }
- `}</style>
- <ResponsiveGridLayout
- className="layout"
- layouts={layouts}
- breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
- cols={{ lg: 12, md: 12, sm: 6, xs: 4, xxs: 2 }}
- rowHeight={100}
- onLayoutChange={handleLayoutChange}
- onDragStop={handleDragStop}
- onResizeStop={handleResizeStop}
- draggableHandle=".drag-handle"
- compactType="vertical"
- preventCollision={false}
- isDraggable={true}
- isResizable={true}
- margin={[16, 16]}
- transformScale={1}
- useCSSTransforms={true}
- >
- {reports.map((report) => (
- <div key={report.id}>
- <ReportItem
- report={report}
- organizationId={organizationId}
- projectId={projectId}
- range={range}
- startDate={startDate}
- endDate={endDate}
- interval={interval}
- onDelete={(reportId) => {
- reportDeletion.mutate({ reportId });
- }}
- onDuplicate={(reportId) => {
- reportDuplicate.mutate({ reportId });
- }}
- />
- </div>
- ))}
- </ResponsiveGridLayout>
- </div>
+ <GrafanaGrid
+ transitions={enableTransitions}
+ layouts={layouts}
+ onLayoutChange={handleLayoutChange}
+ onDragStop={handleDragStop}
+ onResizeStop={handleResizeStop}
+ isDraggable={true}
+ isResizable={true}
+ >
+ {reports.map((report) => (
+ <div key={report.id}>
+ <ReportItem
+ report={report}
+ organizationId={organizationId}
+ projectId={projectId}
+ range={range}
+ startDate={startDate}
+ endDate={endDate}
+ interval={interval}
+ onDelete={(reportId) => {
+ reportDeletion.mutate({ reportId });
+ }}
+ onDuplicate={(reportId) => {
+ reportDuplicate.mutate({ reportId });
+ }}
+ />
+ </div>
+ ))}
+ </GrafanaGrid>
)}
</PageContainer>
);
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.pages.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.pages.tsx
index 539e4cb13..365121afc 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.pages.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.pages.tsx
@@ -274,20 +274,16 @@ const PageCard = memo(
</div>
<ReportChart
options={{
- hideID: true,
hideXAxis: true,
hideYAxis: true,
aspectRatio: 0.15,
}}
report={{
- lineType: 'linear',
breakdowns: [],
- name: 'screen_view',
metric: 'sum',
range,
interval,
previous: true,
-
chartType: 'linear',
projectId,
series: [
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.reports_.$reportId.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.reports_.$reportId.tsx
index 714ec89f1..c60c92fb8 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.reports_.$reportId.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.reports_.$reportId.tsx
@@ -36,5 +36,6 @@ function Component() {
const { reportId } = Route.useParams();
const trpc = useTRPC();
const query = useSuspenseQuery(trpc.report.get.queryOptions({ reportId }));
+ console.log(query.data);
return <ReportEditor report={query.data} />;
}
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tsx
index 620894cdb..2acfa01d9 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tsx
@@ -42,6 +42,7 @@ function ProjectDashboard() {
{ id: 'details', label: 'Details' },
{ id: 'events', label: 'Events' },
{ id: 'clients', label: 'Clients' },
+ { id: 'widgets', label: 'Widgets' },
{ id: 'imports', label: 'Imports' },
];
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.widgets.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.widgets.tsx
new file mode 100644
index 000000000..536b27d5b
--- /dev/null
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.widgets.tsx
@@ -0,0 +1,370 @@
+import CopyInput from '@/components/forms/copy-input';
+import FullPageLoadingState from '@/components/full-page-loading-state';
+import Syntax from '@/components/syntax';
+import { Button } from '@/components/ui/button';
+import { Label } from '@/components/ui/label';
+import { Switch } from '@/components/ui/switch';
+import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
+import { useAppContext } from '@/hooks/use-app-context';
+import { useAppParams } from '@/hooks/use-app-params';
+import { useTRPC } from '@/integrations/trpc/react';
+import type {
+ IRealtimeWidgetOptions,
+ IWidgetType,
+} from '@openpanel/validation';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { createFileRoute } from '@tanstack/react-router';
+import { ExternalLinkIcon } from 'lucide-react';
+import { useEffect, useState } from 'react';
+import { toast } from 'sonner';
+
+export const Route = createFileRoute(
+ '/_app/$organizationId/$projectId/settings/_tabs/widgets',
+)({
+ component: Component,
+});
+
+function Component() {
+ const { projectId, organizationId } = useAppParams();
+ const { dashboardUrl } = useAppContext();
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+
+ // Fetch both widget types
+ const realtimeWidgetQuery = useQuery(
+ trpc.widget.get.queryOptions({ projectId, type: 'realtime' }),
+ );
+ const counterWidgetQuery = useQuery(
+ trpc.widget.get.queryOptions({ projectId, type: 'counter' }),
+ );
+
+ // Toggle mutation
+ const toggleMutation = useMutation(
+ trpc.widget.toggle.mutationOptions({
+ onSuccess: (_, variables) => {
+ queryClient.invalidateQueries(
+ trpc.widget.get.queryFilter({ projectId, type: variables.type }),
+ );
+ toast.success(variables.enabled ? 'Widget enabled' : 'Widget disabled');
+ },
+ onError: (error) => {
+ toast.error(error.message || 'Failed to update widget');
+ },
+ }),
+ );
+
+ // Update options mutation
+ const updateOptionsMutation = useMutation(
+ trpc.widget.updateOptions.mutationOptions({
+ onSuccess: () => {
+ queryClient.invalidateQueries(
+ trpc.widget.get.queryFilter({ projectId, type: 'realtime' }),
+ );
+ toast.success('Widget options updated');
+ },
+ onError: (error) => {
+ toast.error(error.message || 'Failed to update options');
+ },
+ }),
+ );
+
+ const handleToggle = (type: IWidgetType, enabled: boolean) => {
+ toggleMutation.mutate({
+ projectId,
+ organizationId,
+ type,
+ enabled,
+ });
+ };
+
+ if (realtimeWidgetQuery.isLoading || counterWidgetQuery.isLoading) {
+ return <FullPageLoadingState />;
+ }
+
+ const realtimeWidget = realtimeWidgetQuery.data;
+ const counterWidget = counterWidgetQuery.data;
+
+ return (
+ <div className="space-y-6">
+ {realtimeWidget && (
+ <RealtimeWidgetSection
+ widget={realtimeWidget as any}
+ dashboardUrl={dashboardUrl}
+ isToggling={toggleMutation.isPending}
+ isUpdatingOptions={updateOptionsMutation.isPending}
+ onToggle={(enabled) => handleToggle('realtime', enabled)}
+ onUpdateOptions={(options) =>
+ updateOptionsMutation.mutate({
+ projectId,
+ organizationId,
+ options,
+ })
+ }
+ />
+ )}
+
+ {counterWidget && (
+ <CounterWidgetSection
+ widget={counterWidget}
+ dashboardUrl={dashboardUrl}
+ isToggling={toggleMutation.isPending}
+ onToggle={(enabled) => handleToggle('counter', enabled)}
+ />
+ )}
+ </div>
+ );
+}
+
+interface RealtimeWidgetSectionProps {
+ widget: {
+ id: string;
+ public: boolean;
+ options: IRealtimeWidgetOptions;
+ } | null;
+ dashboardUrl: string;
+ isToggling: boolean;
+ isUpdatingOptions: boolean;
+ onToggle: (enabled: boolean) => void;
+ onUpdateOptions: (options: IRealtimeWidgetOptions) => void;
+}
+
+function RealtimeWidgetSection({
+ widget,
+ dashboardUrl,
+ isToggling,
+ isUpdatingOptions,
+ onToggle,
+ onUpdateOptions,
+}: RealtimeWidgetSectionProps) {
+ const isEnabled = widget?.public ?? false;
+ const widgetUrl =
+ isEnabled && widget?.id
+ ? `${dashboardUrl}/widget/realtime?shareId=${widget.id}`
+ : null;
+ const embedCode = widgetUrl
+ ? `<iframe src="${widgetUrl}" width="100%" height="400" frameborder="0" style="border-radius: 8px;"></iframe>`
+ : null;
+
+ // Default options
+ const defaultOptions: IRealtimeWidgetOptions = {
+ type: 'realtime',
+ referrers: true,
+ countries: true,
+ paths: false,
+ };
+
+ const [options, setOptions] = useState<IRealtimeWidgetOptions>(
+ (widget?.options as IRealtimeWidgetOptions) || defaultOptions,
+ );
+
+ // Update local options when widget data changes
+ useEffect(() => {
+ if (widget?.options) {
+ setOptions(widget.options as IRealtimeWidgetOptions);
+ }
+ }, [widget?.options]);
+
+ const handleUpdateOptions = (newOptions: IRealtimeWidgetOptions) => {
+ setOptions(newOptions);
+ onUpdateOptions(newOptions);
+ };
+
+ return (
+ <Widget className="max-w-screen-md w-full">
+ <WidgetHead className="row items-center justify-between gap-6">
+ <div className="space-y-2">
+ <span className="title">Realtime Widget</span>
+ <p className="text-muted-foreground">
+ Embed a realtime visitor counter widget on your website. The widget
+ shows live visitor count, activity histogram, top countries,
+ referrers and paths.
+ </p>
+ </div>
+ <Switch
+ checked={isEnabled}
+ onCheckedChange={onToggle}
+ disabled={isToggling}
+ />
+ </WidgetHead>
+ {isEnabled && (
+ <WidgetBody className="space-y-6">
+ <div className="space-y-4">
+ <h3 className="text-sm font-medium">Widget Options</h3>
+ <div className="space-y-3">
+ <div className="flex items-center justify-between">
+ <Label htmlFor="referrers" className="text-sm">
+ Show Referrers
+ </Label>
+ <Switch
+ id="referrers"
+ checked={options.referrers}
+ onCheckedChange={(checked) =>
+ handleUpdateOptions({ ...options, referrers: checked })
+ }
+ disabled={isUpdatingOptions}
+ />
+ </div>
+ <div className="flex items-center justify-between">
+ <Label htmlFor="countries" className="text-sm">
+ Show Countries
+ </Label>
+ <Switch
+ id="countries"
+ checked={options.countries}
+ onCheckedChange={(checked) =>
+ handleUpdateOptions({ ...options, countries: checked })
+ }
+ disabled={isUpdatingOptions}
+ />
+ </div>
+ <div className="flex items-center justify-between">
+ <Label htmlFor="paths" className="text-sm">
+ Show Paths
+ </Label>
+ <Switch
+ id="paths"
+ checked={options.paths}
+ onCheckedChange={(checked) =>
+ handleUpdateOptions({ ...options, paths: checked })
+ }
+ disabled={isUpdatingOptions}
+ />
+ </div>
+ </div>
+ </div>
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Widget URL</h3>
+ <CopyInput label="" value={widgetUrl!} className="w-full" />
+ <p className="text-xs text-muted-foreground">
+ Direct link to the widget. You can open this in a new tab or embed
+ it.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Embed Code</h3>
+ <Syntax code={embedCode!} language="bash" />
+ <p className="text-xs text-muted-foreground">
+ Copy this code and paste it into your website HTML where you want
+ the widget to appear.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Preview</h3>
+ <div className="border rounded-lg overflow-hidden">
+ <iframe
+ src={widgetUrl!}
+ width="100%"
+ height="600"
+ className="border-0"
+ title="Realtime Widget Preview"
+ />
+ </div>
+ <div className="flex gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ icon={ExternalLinkIcon}
+ onClick={() =>
+ window.open(widgetUrl!, '_blank', 'noopener,noreferrer')
+ }
+ >
+ Open in new tab
+ </Button>
+ </div>
+ </div>
+ </WidgetBody>
+ )}
+ </Widget>
+ );
+}
+
+interface CounterWidgetSectionProps {
+ widget: {
+ id: string;
+ public: boolean;
+ } | null;
+ dashboardUrl: string;
+ isToggling: boolean;
+ onToggle: (enabled: boolean) => void;
+}
+
+function CounterWidgetSection({
+ widget,
+ dashboardUrl,
+ isToggling,
+ onToggle,
+}: CounterWidgetSectionProps) {
+ const isEnabled = widget?.public ?? false;
+ const counterUrl =
+ isEnabled && widget?.id
+ ? `${dashboardUrl}/widget/counter?shareId=${widget.id}`
+ : null;
+ const counterEmbedCode = counterUrl
+ ? `<iframe src="${counterUrl}" height="32" style="border: none; overflow: hidden;" title="Visitor Counter"></iframe>`
+ : null;
+
+ return (
+ <Widget className="max-w-screen-md w-full">
+ <WidgetHead className="row items-center justify-between gap-6">
+ <div className="space-y-2">
+ <span className="title">Counter Widget</span>
+ <p className="text-muted-foreground">
+ A compact live visitor counter badge you can embed anywhere. Shows
+ the current number of unique visitors with a live indicator.
+ </p>
+ </div>
+ <Switch
+ checked={isEnabled}
+ onCheckedChange={onToggle}
+ disabled={isToggling}
+ />
+ </WidgetHead>
+ {isEnabled && counterUrl && (
+ <WidgetBody className="space-y-6">
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Widget URL</h3>
+ <CopyInput label="" value={counterUrl} className="w-full" />
+ <p className="text-xs text-muted-foreground">
+ Direct link to the counter widget.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Embed Code</h3>
+ <Syntax code={counterEmbedCode!} language="bash" />
+ <p className="text-xs text-muted-foreground">
+ Copy this code and paste it into your website HTML where you want
+ the counter to appear.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <h3 className="text-sm font-medium">Preview</h3>
+ <div className="border rounded-lg p-4 bg-muted/30">
+ <iframe
+ src={counterUrl}
+ height="32"
+ className="border-0"
+ title="Counter Widget Preview"
+ />
+ </div>
+ <div className="flex gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ icon={ExternalLinkIcon}
+ onClick={() =>
+ window.open(counterUrl, '_blank', 'noopener,noreferrer')
+ }
+ >
+ Open in new tab
+ </Button>
+ </div>
+ </div>
+ </WidgetBody>
+ )}
+ </Widget>
+ );
+}
diff --git a/apps/start/src/routes/share.dashboard.$shareId.tsx b/apps/start/src/routes/share.dashboard.$shareId.tsx
new file mode 100644
index 000000000..f6d76fa7c
--- /dev/null
+++ b/apps/start/src/routes/share.dashboard.$shareId.tsx
@@ -0,0 +1,158 @@
+import { ShareEnterPassword } from '@/components/auth/share-enter-password';
+import { FullPageEmptyState } from '@/components/full-page-empty-state';
+import FullPageLoadingState from '@/components/full-page-loading-state';
+import { GrafanaGrid, useReportLayouts } from '@/components/grafana-grid';
+import { LoginNavbar } from '@/components/login-navbar';
+import { OverviewInterval } from '@/components/overview/overview-interval';
+import { OverviewRange } from '@/components/overview/overview-range';
+import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
+import { ReportChart } from '@/components/report-chart';
+import {
+ ReportItem,
+ ReportItemReadOnly,
+ ReportItemSkeleton,
+} from '@/components/report/report-item';
+import { useTRPC } from '@/integrations/trpc/react';
+import { cn } from '@/utils/cn';
+import { timeWindows } from '@openpanel/constants';
+import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
+import { createFileRoute, notFound, useSearch } from '@tanstack/react-router';
+import { z } from 'zod';
+
+const shareSearchSchema = z.object({
+ header: z.optional(z.number().or(z.string().or(z.boolean()))),
+});
+
+export const Route = createFileRoute('/share/dashboard/$shareId')({
+ component: RouteComponent,
+ validateSearch: shareSearchSchema,
+ loader: async ({ context, params }) => {
+ const share = await context.queryClient.ensureQueryData(
+ context.trpc.share.dashboard.queryOptions({
+ shareId: params.shareId,
+ }),
+ );
+
+ return { share };
+ },
+ head: ({ loaderData }) => {
+ if (!loaderData || !loaderData.share) {
+ return {
+ meta: [
+ {
+ title: 'Share not found - OpenPanel.dev',
+ },
+ ],
+ };
+ }
+
+ return {
+ meta: [
+ {
+ title: `${loaderData.share.dashboard?.name} - ${loaderData.share.organization?.name} - OpenPanel.dev`,
+ },
+ ],
+ };
+ },
+ pendingComponent: FullPageLoadingState,
+ errorComponent: () => (
+ <FullPageEmptyState
+ title="Share not found"
+ description="The dashboard you are looking for does not exist."
+ className="min-h-[calc(100vh-theme(spacing.16))]"
+ />
+ ),
+});
+
+function RouteComponent() {
+ const { shareId } = Route.useParams();
+ const { header } = useSearch({ from: '/share/dashboard/$shareId' });
+ const trpc = useTRPC();
+ const { range, startDate, endDate, interval } = useOverviewOptions();
+
+ const shareQuery = useSuspenseQuery(
+ trpc.share.dashboard.queryOptions({
+ shareId,
+ }),
+ );
+
+ const reportsQuery = useQuery(
+ trpc.share.dashboardReports.queryOptions({
+ shareId,
+ }),
+ );
+
+ const hasAccess = shareQuery.data?.hasAccess;
+
+ if (!shareQuery.data) {
+ throw notFound();
+ }
+
+ if (!shareQuery.data.public) {
+ throw notFound();
+ }
+
+ const share = shareQuery.data;
+
+ // Handle password protection
+ if (share.password && !hasAccess) {
+ return <ShareEnterPassword shareId={share.id} shareType="dashboard" />;
+ }
+
+ const isHeaderVisible =
+ header !== '0' && header !== 0 && header !== 'false' && header !== false;
+
+ const reports = reportsQuery.data ?? [];
+
+ // Convert reports to grid layout format for all breakpoints
+ const layouts = useReportLayouts(reports);
+
+ return (
+ <div>
+ {isHeaderVisible && (
+ <div className="mx-auto max-w-7xl">
+ <LoginNavbar className="relative p-4" />
+ </div>
+ )}
+ <div className="sticky-header [animation-range:50px_100px]!">
+ <div className="p-4 col gap-2 mx-auto max-w-7xl">
+ <div className="row justify-between">
+ <div className="flex gap-2">
+ <OverviewRange />
+ <OverviewInterval />
+ </div>
+ </div>
+ </div>
+ </div>
+ <div className="mx-auto max-w-7xl p-4">
+ {reportsQuery.isLoading ? (
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ <ReportItemSkeleton />
+ </div>
+ ) : reports.length === 0 ? (
+ <FullPageEmptyState title="No reports" />
+ ) : (
+ <GrafanaGrid layouts={layouts}>
+ {reports.map((report) => (
+ <div key={report.id}>
+ <ReportItemReadOnly
+ report={report}
+ shareId={shareId}
+ range={range}
+ startDate={startDate}
+ endDate={endDate}
+ interval={interval}
+ />
+ </div>
+ ))}
+ </GrafanaGrid>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/start/src/routes/share.overview.$shareId.tsx b/apps/start/src/routes/share.overview.$shareId.tsx
index 1d1a703ed..43734311c 100644
--- a/apps/start/src/routes/share.overview.$shareId.tsx
+++ b/apps/start/src/routes/share.overview.$shareId.tsx
@@ -12,9 +12,8 @@ import OverviewTopGeo from '@/components/overview/overview-top-geo';
import OverviewTopPages from '@/components/overview/overview-top-pages';
import OverviewTopSources from '@/components/overview/overview-top-sources';
import { useTRPC } from '@/integrations/trpc/react';
-import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
+import { useSuspenseQuery } from '@tanstack/react-query';
import { createFileRoute, notFound, useSearch } from '@tanstack/react-router';
-import { EyeClosedIcon, FrownIcon } from 'lucide-react';
import { z } from 'zod';
const shareSearchSchema = z.object({
diff --git a/apps/start/src/routes/share.report.$shareId.tsx b/apps/start/src/routes/share.report.$shareId.tsx
new file mode 100644
index 000000000..dd88838aa
--- /dev/null
+++ b/apps/start/src/routes/share.report.$shareId.tsx
@@ -0,0 +1,123 @@
+import { ShareEnterPassword } from '@/components/auth/share-enter-password';
+import { FullPageEmptyState } from '@/components/full-page-empty-state';
+import FullPageLoadingState from '@/components/full-page-loading-state';
+import { LoginNavbar } from '@/components/login-navbar';
+import { OverviewInterval } from '@/components/overview/overview-interval';
+import { OverviewRange } from '@/components/overview/overview-range';
+import { ReportChart } from '@/components/report-chart';
+import { useTRPC } from '@/integrations/trpc/react';
+import { useSuspenseQuery } from '@tanstack/react-query';
+import { createFileRoute, notFound, useSearch } from '@tanstack/react-router';
+import { z } from 'zod';
+
+const shareSearchSchema = z.object({
+ header: z.optional(z.number().or(z.string().or(z.boolean()))),
+});
+
+export const Route = createFileRoute('/share/report/$shareId')({
+ component: RouteComponent,
+ validateSearch: shareSearchSchema,
+ loader: async ({ context, params }) => {
+ const share = await context.queryClient.ensureQueryData(
+ context.trpc.share.report.queryOptions({
+ shareId: params.shareId,
+ }),
+ );
+
+ if (!share) {
+ return { share: null };
+ }
+
+ return { share };
+ },
+ head: ({ loaderData }) => {
+ if (!loaderData || !loaderData.share) {
+ return {
+ meta: [
+ {
+ title: 'Share not found - OpenPanel.dev',
+ },
+ ],
+ };
+ }
+
+ return {
+ meta: [
+ {
+ title: `${loaderData.share.report.name || 'Report'} - ${loaderData.share.organization?.name} - OpenPanel.dev`,
+ },
+ ],
+ };
+ },
+ pendingComponent: FullPageLoadingState,
+ errorComponent: () => (
+ <FullPageEmptyState
+ title="Share not found"
+ description="The report you are looking for does not exist."
+ className="min-h-[calc(100vh-theme(spacing.16))]"
+ />
+ ),
+});
+
+function RouteComponent() {
+ const { shareId } = Route.useParams();
+ const { header } = useSearch({ from: '/share/report/$shareId' });
+ const trpc = useTRPC();
+ const shareQuery = useSuspenseQuery(
+ trpc.share.report.queryOptions({
+ shareId,
+ }),
+ );
+
+ const hasAccess = shareQuery.data?.hasAccess;
+
+ if (!shareQuery.data) {
+ throw notFound();
+ }
+
+ if (!shareQuery.data.public) {
+ throw notFound();
+ }
+
+ const share = shareQuery.data;
+
+ console.log('share', share);
+
+ // Handle password protection
+ if (share.password && !hasAccess) {
+ return <ShareEnterPassword shareId={share.id} shareType="report" />;
+ }
+
+ const isHeaderVisible =
+ header !== '0' && header !== 0 && header !== 'false' && header !== false;
+
+ return (
+ <div>
+ {isHeaderVisible && (
+ <div className="mx-auto max-w-7xl">
+ <LoginNavbar className="relative p-4" />
+ </div>
+ )}
+ <div className="sticky-header [animation-range:50px_100px]!">
+ <div className="p-4 col gap-2 mx-auto max-w-7xl">
+ <div className="row justify-between">
+ <div className="flex gap-2">
+ <OverviewRange />
+ <OverviewInterval />
+ </div>
+ </div>
+ </div>
+ </div>
+ <div className="mx-auto max-w-7xl p-4">
+ <div className="card">
+ <div className="p-4 border-b">
+ <div className="font-medium text-xl">{share.report.name}</div>
+ </div>
+ <div className="p-4">
+ <ReportChart report={share.report} shareId={shareId} />
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/start/src/routes/widget/counter.tsx b/apps/start/src/routes/widget/counter.tsx
new file mode 100644
index 000000000..a55e7c81a
--- /dev/null
+++ b/apps/start/src/routes/widget/counter.tsx
@@ -0,0 +1,86 @@
+import { AnimatedNumber } from '@/components/animated-number';
+import { Ping } from '@/components/ping';
+import { useNumber } from '@/hooks/use-numer-formatter';
+import useWS from '@/hooks/use-ws';
+import { useTRPC } from '@/integrations/trpc/react';
+import type { RouterOutputs } from '@/trpc/client';
+import { useQuery, useQueryClient } from '@tanstack/react-query';
+import { createFileRoute } from '@tanstack/react-router';
+import { z } from 'zod';
+
+const widgetSearchSchema = z.object({
+ shareId: z.string(),
+ limit: z.number().default(10),
+ color: z.string().optional(),
+});
+
+export const Route = createFileRoute('/widget/counter')({
+ component: RouteComponent,
+ validateSearch: widgetSearchSchema,
+});
+
+function RouteComponent() {
+ const { shareId, limit, color } = Route.useSearch();
+ const trpc = useTRPC();
+
+ // Fetch widget data
+ const { data, isLoading } = useQuery(
+ trpc.widget.counter.queryOptions({ shareId }),
+ );
+
+ if (isLoading) {
+ return (
+ <div className="flex items-center gap-2 px-2 h-8">
+ <Ping />
+ <AnimatedNumber value={0} suffix=" unique visitors" />
+ </div>
+ );
+ }
+
+ if (!data) {
+ return (
+ <div className="flex items-center gap-2 px-2 h-8">
+ <Ping className="bg-orange-500" />
+ <AnimatedNumber value={0} suffix=" unique visitors" />
+ </div>
+ );
+ }
+
+ return <CounterWidget shareId={shareId} data={data} />;
+}
+
+interface RealtimeWidgetProps {
+ shareId: string;
+ data: RouterOutputs['widget']['counter'];
+}
+
+function CounterWidget({ shareId, data }: RealtimeWidgetProps) {
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+ const number = useNumber();
+
+ // WebSocket subscription for real-time updates
+ useWS<number>(
+ `/live/visitors/${data.projectId}`,
+ (res) => {
+ if (!document.hidden) {
+ queryClient.refetchQueries(
+ trpc.widget.counter.queryFilter({ shareId }),
+ );
+ }
+ },
+ {
+ debounce: {
+ delay: 1000,
+ maxWait: 60000,
+ },
+ },
+ );
+
+ return (
+ <div className="flex items-center gap-2 px-2 h-8">
+ <Ping />
+ <AnimatedNumber value={data.counter} suffix=" unique visitors" />
+ </div>
+ );
+}
diff --git a/apps/start/src/routes/widget/realtime.tsx b/apps/start/src/routes/widget/realtime.tsx
new file mode 100644
index 000000000..f1044da41
--- /dev/null
+++ b/apps/start/src/routes/widget/realtime.tsx
@@ -0,0 +1,528 @@
+import { AnimatedNumber } from '@/components/animated-number';
+import {
+ ChartTooltipContainer,
+ ChartTooltipHeader,
+ ChartTooltipItem,
+} from '@/components/charts/chart-tooltip';
+import { LogoSquare } from '@/components/logo';
+import { Ping } from '@/components/ping';
+import { SerieIcon } from '@/components/report-chart/common/serie-icon';
+import { useNumber } from '@/hooks/use-numer-formatter';
+import useWS from '@/hooks/use-ws';
+import { useTRPC } from '@/integrations/trpc/react';
+import { countries } from '@/translations/countries';
+import type { RouterOutputs } from '@/trpc/client';
+import { cn } from '@/utils/cn';
+import { getChartColor } from '@/utils/theme';
+import { useQuery, useQueryClient } from '@tanstack/react-query';
+import { createFileRoute } from '@tanstack/react-router';
+import type React from 'react';
+import {
+ Bar,
+ BarChart,
+ ResponsiveContainer,
+ Tooltip,
+ XAxis,
+ YAxis,
+} from 'recharts';
+import { z } from 'zod';
+
+const widgetSearchSchema = z.object({
+ shareId: z.string(),
+ limit: z.number().default(10),
+ color: z.string().optional(),
+});
+
+export const Route = createFileRoute('/widget/realtime')({
+ component: RouteComponent,
+ validateSearch: widgetSearchSchema,
+});
+
+function RouteComponent() {
+ const { shareId, limit, color } = Route.useSearch();
+ const trpc = useTRPC();
+
+ // Fetch widget data
+ const { data: widgetData, isLoading } = useQuery(
+ trpc.widget.realtimeData.queryOptions({ shareId }),
+ );
+
+ if (isLoading) {
+ return <RealtimeWidgetSkeleton limit={limit} />;
+ }
+
+ if (!widgetData) {
+ return (
+ <div className="flex h-screen w-full center-center bg-background text-foreground col p-4">
+ <LogoSquare className="size-10 mb-4" />
+ <h1 className="text-xl font-semibold">Widget not found</h1>
+ <p className="mt-2 text-sm text-muted-foreground">
+ This widget is not available or has been removed.
+ </p>
+ </div>
+ );
+ }
+
+ return (
+ <RealtimeWidget
+ shareId={shareId}
+ limit={limit}
+ data={widgetData}
+ color={color}
+ />
+ );
+}
+
+interface RealtimeWidgetProps {
+ shareId: string;
+ limit: number;
+ color: string | undefined;
+ data: RouterOutputs['widget']['realtimeData'];
+}
+
+function RealtimeWidget({ shareId, data, limit, color }: RealtimeWidgetProps) {
+ const trpc = useTRPC();
+ const queryClient = useQueryClient();
+ const number = useNumber();
+
+ // WebSocket subscription for real-time updates
+ useWS<number>(
+ `/live/visitors/${data.projectId}`,
+ () => {
+ if (!document.hidden) {
+ queryClient.refetchQueries(
+ trpc.widget.realtimeData.queryFilter({ shareId }),
+ );
+ }
+ },
+ {
+ debounce: {
+ delay: 1000,
+ maxWait: 60000,
+ },
+ },
+ );
+
+ const maxDomain =
+ Math.max(...data.histogram.map((item) => item.sessionCount), 1) * 1.2;
+
+ const grids = (() => {
+ const countries = data.countries.length > 0 ? 1 : 0;
+ const referrers = data.referrers.length > 0 ? 1 : 0;
+ const paths = data.paths.length > 0 ? 1 : 0;
+ const value = countries + referrers + paths;
+ if (value === 3) return 'md:grid-cols-3';
+ if (value === 2) return 'md:grid-cols-2';
+ return 'md:grid-cols-1';
+ })();
+
+ return (
+ <div className="flex h-screen w-full flex-col bg-background text-foreground">
+ {/* Header with live counter */}
+ <div className="border-b p-6 pb-3">
+ <div className="flex items-center justify-between w-full h-4">
+ <div className="flex items-center gap-3 w-full">
+ <Ping />
+ <div className="text-sm font-medium text-muted-foreground flex-1">
+ USERS IN LAST 30 MINUTES
+ </div>
+ {data.project.domain && <SerieIcon name={data.project.domain} />}
+ </div>
+ </div>
+
+ <div className="row">
+ <div className="font-mono text-6xl font-bold h-18 text-foreground">
+ <AnimatedNumber value={data.liveCount} />
+ </div>
+ </div>
+
+ <div className="flex h-20 w-full flex-col -mt-4">
+ <div className="flex-1">
+ <ResponsiveContainer width="100%" height="100%">
+ <BarChart
+ data={data.histogram}
+ margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
+ >
+ <Tooltip
+ content={CustomTooltip}
+ cursor={{ fill: 'var(--def-100)', radius: 4 }}
+ />
+ <XAxis
+ dataKey="time"
+ axisLine={false}
+ tickLine={false}
+ tick={{ fill: 'var(--muted-foreground)', fontSize: 10 }}
+ ticks={[
+ data.histogram[0].time,
+ data.histogram[data.histogram.length - 1].time,
+ ]}
+ interval="preserveStartEnd"
+ />
+ <YAxis hide domain={[0, maxDomain]} />
+ <Bar
+ dataKey="sessionCount"
+ isAnimationActive={false}
+ radius={[4, 4, 4, 4]}
+ fill={color || 'var(--chart-0)'}
+ />
+ </BarChart>
+ </ResponsiveContainer>
+ </div>
+ </div>
+ </div>
+
+ <div className="flex flex-1 flex-col gap-6 overflow-auto p-6 hide-scrollbar">
+ {/* Histogram */}
+ {/* Countries and Referrers */}
+ {(data.countries.length > 0 || data.referrers.length > 0) && (
+ <div className={cn('grid grid-cols-1 gap-6', grids)}>
+ {/* Countries */}
+ {data.countries.length > 0 && (
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ COUNTRY
+ </div>
+ <div className="col">
+ {(() => {
+ const { visible, rest, restCount } = getRestItems(
+ data.countries,
+ limit,
+ );
+ return (
+ <>
+ {visible.map((item) => (
+ <RowItem key={item.country} count={item.count}>
+ <div className="flex items-center gap-2">
+ <SerieIcon name={item.country} />
+ <span className="text-sm">
+ {countries[
+ item.country as keyof typeof countries
+ ] || item.country}
+ </span>
+ </div>
+ </RowItem>
+ ))}
+ {rest.length > 0 && (
+ <RestRow
+ firstName={
+ countries[
+ rest[0].country as keyof typeof countries
+ ] || rest[0].country
+ }
+ restCount={rest.length}
+ totalCount={restCount}
+ type="countries"
+ />
+ )}
+ </>
+ );
+ })()}
+ </div>
+ </div>
+ )}
+
+ {/* Referrers */}
+ {data.referrers.length > 0 && (
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ REFERRER
+ </div>
+ <div className="col">
+ {(() => {
+ const { visible, rest, restCount } = getRestItems(
+ data.referrers,
+ limit,
+ );
+ return (
+ <>
+ {visible.map((item) => (
+ <RowItem key={item.referrer} count={item.count}>
+ <div className="flex items-center gap-2">
+ <SerieIcon name={item.referrer} />
+ <span className="truncate text-sm">
+ {item.referrer}
+ </span>
+ </div>
+ </RowItem>
+ ))}
+ {rest.length > 0 && (
+ <RestRow
+ firstName={rest[0].referrer}
+ restCount={rest.length}
+ totalCount={restCount}
+ type="referrers"
+ />
+ )}
+ </>
+ );
+ })()}
+ </div>
+ </div>
+ )}
+
+ {/* Paths */}
+ {data.paths.length > 0 && (
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ PATH
+ </div>
+ <div className="col">
+ {(() => {
+ const { visible, rest, restCount } = getRestItems(
+ data.paths,
+ limit,
+ );
+ return (
+ <>
+ {visible.map((item) => (
+ <RowItem key={item.path} count={item.count}>
+ <span className="truncate text-sm">
+ {item.path}
+ </span>
+ </RowItem>
+ ))}
+ {rest.length > 0 && (
+ <RestRow
+ firstName={rest[0].path}
+ restCount={rest.length}
+ totalCount={restCount}
+ type="paths"
+ />
+ )}
+ </>
+ );
+ })()}
+ </div>
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
+
+// Custom tooltip component that uses portals to escape overflow hidden
+const CustomTooltip = ({ active, payload, coordinate }: any) => {
+ const number = useNumber();
+
+ if (!active || !payload || !payload.length) {
+ return null;
+ }
+
+ const data = payload[0].payload;
+
+ return (
+ <ChartTooltipContainer className="max-w-[100px]">
+ <ChartTooltipHeader>
+ <div>{data.time}</div>
+ </ChartTooltipHeader>
+ <ChartTooltipItem color={getChartColor(0)} innerClassName="row gap-1">
+ <div className="flex-1">Visitors</div>
+ <div>{number.short(data.sessionCount)}</div>
+ </ChartTooltipItem>
+ </ChartTooltipContainer>
+ );
+};
+
+function RowItem({
+ children,
+ count,
+}: { children: React.ReactNode; count: number }) {
+ const number = useNumber();
+ return (
+ <div className="h-10 text-sm flex items-center justify-between px-3 py-2 border-b hover:bg-foreground/5 -mx-3">
+ {children}
+ <span className="font-semibold">{number.short(count)}</span>
+ </div>
+ );
+}
+
+function getRestItems<T extends { count: number }>(
+ items: T[],
+ limit: number,
+): { visible: T[]; rest: T[]; restCount: number } {
+ const visible = items.slice(0, limit);
+ const rest = items.slice(limit);
+ const restCount = rest.reduce((sum, item) => sum + item.count, 0);
+ return { visible, rest, restCount };
+}
+
+function RestRow({
+ firstName,
+ restCount,
+ totalCount,
+ type,
+}: {
+ firstName: string;
+ restCount: number;
+ totalCount: number;
+ type: 'countries' | 'referrers' | 'paths';
+}) {
+ const number = useNumber();
+ const otherCount = restCount - 1;
+ const typeLabel =
+ type === 'countries'
+ ? otherCount === 1
+ ? 'country'
+ : 'countries'
+ : type === 'referrers'
+ ? otherCount === 1
+ ? 'referrer'
+ : 'referrers'
+ : otherCount === 1
+ ? 'path'
+ : 'paths';
+
+ return (
+ <div className="h-10 text-sm flex items-center justify-between px-3 py-2 border-b hover:bg-foreground/5 -mx-3">
+ <span className="truncate">
+ {firstName} and {otherCount} more {typeLabel}...
+ </span>
+ <span className="font-semibold">{number.short(totalCount)}</span>
+ </div>
+ );
+}
+
+// Pre-generated skeleton keys to avoid index-based keys in render
+const SKELETON_KEYS = {
+ countries: [
+ 'country-0',
+ 'country-1',
+ 'country-2',
+ 'country-3',
+ 'country-4',
+ 'country-5',
+ 'country-6',
+ 'country-7',
+ 'country-8',
+ 'country-9',
+ ],
+ referrers: [
+ 'referrer-0',
+ 'referrer-1',
+ 'referrer-2',
+ 'referrer-3',
+ 'referrer-4',
+ 'referrer-5',
+ 'referrer-6',
+ 'referrer-7',
+ 'referrer-8',
+ 'referrer-9',
+ ],
+ paths: [
+ 'path-0',
+ 'path-1',
+ 'path-2',
+ 'path-3',
+ 'path-4',
+ 'path-5',
+ 'path-6',
+ 'path-7',
+ 'path-8',
+ 'path-9',
+ ],
+};
+
+// Pre-generated skeleton histogram data
+const SKELETON_HISTOGRAM = [
+ 24, 48, 21, 32, 19, 16, 52, 14, 11, 7, 12, 18, 25, 65, 55, 62, 9, 68, 10, 31,
+ 58, 70, 10, 47, 43, 10, 38, 35, 41, 28,
+];
+
+function RealtimeWidgetSkeleton({ limit }: { limit: number }) {
+ const itemCount = Math.min(limit, 5);
+
+ return (
+ <div className="flex h-screen w-full flex-col bg-background text-foreground animate-pulse">
+ {/* Header with live counter */}
+ <div className="border-b p-6 pb-3">
+ <div className="flex items-center justify-between w-full h-4">
+ <div className="flex items-center gap-3 w-full">
+ <div className="size-2 rounded-full bg-muted" />
+ <div className="text-sm font-medium text-muted-foreground flex-1">
+ USERS IN LAST 30 MINUTES
+ </div>
+ </div>
+ <div className="size-4 shrink-0 rounded bg-muted" />
+ </div>
+
+ <div className="row">
+ <div className="font-mono text-6xl font-bold h-18 flex items-center py-4 gap-1 row">
+ <div className="h-full w-6 bg-muted rounded" />
+ <div className="h-full w-6 bg-muted rounded" />
+ </div>
+ </div>
+
+ <div className="flex h-20 w-full flex-col -mt-4 pb-2.5">
+ <div className="flex-1 row gap-1 h-full">
+ {SKELETON_HISTOGRAM.map((item, index) => (
+ <div
+ key={index.toString()}
+ style={{ height: `${item}%` }}
+ className="h-full w-full bg-muted rounded mt-auto"
+ />
+ ))}
+ </div>
+ <div className="row justify-between pt-2">
+ <div className="h-3 w-8 bg-muted rounded" />
+ <div className="h-3 w-8 bg-muted rounded" />
+ </div>
+ </div>
+ </div>
+
+ <div className="flex flex-1 flex-col gap-6 overflow-auto p-6 hide-scrollbar">
+ {/* Countries, Referrers, and Paths skeleton */}
+ <div className="grid grid-cols-1 gap-6 md:grid-cols-3">
+ {/* Countries skeleton */}
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ COUNTRY
+ </div>
+ <div className="col">
+ {SKELETON_KEYS.countries.slice(0, itemCount).map((key) => (
+ <RowItemSkeleton key={key} />
+ ))}
+ </div>
+ </div>
+
+ {/* Referrers skeleton */}
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ REFERRER
+ </div>
+ <div className="col">
+ {SKELETON_KEYS.referrers.slice(0, itemCount).map((key) => (
+ <RowItemSkeleton key={key} />
+ ))}
+ </div>
+ </div>
+
+ {/* Paths skeleton */}
+ <div className="flex flex-col">
+ <div className="mb-3 text-xs font-medium text-muted-foreground">
+ PATH
+ </div>
+ <div className="col">
+ {SKELETON_KEYS.paths.slice(0, itemCount).map((key) => (
+ <RowItemSkeleton key={key} />
+ ))}
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function RowItemSkeleton() {
+ return (
+ <div className="h-10 text-sm flex items-center justify-between px-3 py-2 border-b -mx-3">
+ <div className="flex items-center gap-2">
+ <div className="size-5 rounded bg-muted" />
+ <div className="h-4 w-24 bg-muted rounded" />
+ </div>
+ <div className="h-4 w-8 bg-muted rounded" />
+ </div>
+ );
+}
diff --git a/apps/start/src/routes/widget/test.tsx b/apps/start/src/routes/widget/test.tsx
new file mode 100644
index 000000000..947192ec1
--- /dev/null
+++ b/apps/start/src/routes/widget/test.tsx
@@ -0,0 +1,34 @@
+import { createFileRoute } from '@tanstack/react-router';
+
+export const Route = createFileRoute('/widget/test')({
+ component: RouteComponent,
+});
+
+function RouteComponent() {
+ return (
+ <div className="center-center h-screen w-screen gap-4">
+ <iframe
+ title="Realtime Widget"
+ src="http://localhost:3000/widget/realtime?shareId=qkC561&limit=2"
+ width="300"
+ height="400"
+ className="rounded-xl border"
+ />
+ <iframe
+ title="Realtime Widget"
+ src="http://localhost:3000/widget/realtime?shareId=qkC562&limit=2"
+ width="300"
+ height="400"
+ className="rounded-xl border"
+ />
+ <iframe
+ title="Counter Widget"
+ src="http://localhost:3000/widget/counter?shareId=qkC561"
+ height="32"
+ width="auto"
+ frameBorder="0"
+ className="rounded-xl border"
+ />
+ </div>
+ );
+}
diff --git a/package.json b/package.json
index 526de4edd..0d54abed9 100644
--- a/package.json
+++ b/package.json
@@ -61,7 +61,8 @@
"nuqs": "patches/nuqs.patch"
},
"overrides": {
- "rolldown": "1.0.0-beta.43"
+ "rolldown": "1.0.0-beta.43",
+ "esm-env": "npm:esm-env-runtime@^0.1.0"
}
}
-}
+}
\ No newline at end of file
diff --git a/packages/constants/index.ts b/packages/constants/index.ts
index 013b2cfb7..27cf4119f 100644
--- a/packages/constants/index.ts
+++ b/packages/constants/index.ts
@@ -109,6 +109,7 @@ export const chartTypes = {
funnel: 'Funnel',
retention: 'Retention',
conversion: 'Conversion',
+ sankey: 'Sankey',
} as const;
export const chartSegments = {
diff --git a/packages/db/code-migrations/9-migrate-options.ts b/packages/db/code-migrations/9-migrate-options.ts
new file mode 100644
index 000000000..c39e4b6d3
--- /dev/null
+++ b/packages/db/code-migrations/9-migrate-options.ts
@@ -0,0 +1,90 @@
+import type { IReportOptions } from '@openpanel/validation';
+import { db } from '../index';
+import { printBoxMessage } from './helpers';
+
+export async function up() {
+ printBoxMessage('🔄 Migrating Legacy Fields to Options', []);
+
+ // Get all reports
+ const reports = await db.report.findMany({
+ select: {
+ id: true,
+ chartType: true,
+ funnelGroup: true,
+ funnelWindow: true,
+ criteria: true,
+ options: true,
+ name: true,
+ },
+ });
+
+ let migratedCount = 0;
+ let skippedCount = 0;
+
+ for (const report of reports) {
+ const currentOptions = report.options as IReportOptions | null | undefined;
+
+ // Skip if options already exists and is valid
+ if (
+ currentOptions &&
+ typeof currentOptions === 'object' &&
+ 'type' in currentOptions
+ ) {
+ skippedCount++;
+ continue;
+ }
+
+ let newOptions: IReportOptions | null = null;
+
+ // Migrate based on chart type
+ if (report.chartType === 'funnel') {
+ // Only create options if we have legacy fields to migrate
+ if (report.funnelGroup || report.funnelWindow !== null) {
+ newOptions = {
+ type: 'funnel',
+ funnelGroup: report.funnelGroup ?? undefined,
+ funnelWindow: report.funnelWindow ?? undefined,
+ };
+ }
+ } else if (report.chartType === 'retention') {
+ // Only create options if we have criteria to migrate
+ if (report.criteria) {
+ newOptions = {
+ type: 'retention',
+ criteria: report.criteria as 'on_or_after' | 'on' | undefined,
+ };
+ }
+ } else if (report.chartType === 'sankey') {
+ // Sankey should already have options, but if not, skip
+ skippedCount++;
+ continue;
+ }
+
+ // Only update if we have new options to set
+ if (newOptions) {
+ console.log(
+ `Migrating report ${report.name} (${report.id}) - chartType: ${report.chartType}`,
+ );
+
+ await db.report.update({
+ where: { id: report.id },
+ data: {
+ options: newOptions,
+ // Set legacy fields to null after migration
+ funnelGroup: null,
+ funnelWindow: null,
+ criteria: report.chartType === 'retention' ? null : report.criteria,
+ },
+ });
+
+ migratedCount++;
+ } else {
+ skippedCount++;
+ }
+ }
+
+ printBoxMessage('✅ Migration Complete', [
+ `Migrated: ${migratedCount} reports`,
+ `Skipped: ${skippedCount} reports (already migrated or no legacy fields)`,
+ ]);
+}
diff --git a/packages/db/index.ts b/packages/db/index.ts
index 51ca6b9ff..06c41720c 100644
--- a/packages/db/index.ts
+++ b/packages/db/index.ts
@@ -16,6 +16,7 @@ export * from './src/services/share.service';
export * from './src/services/session.service';
export * from './src/services/funnel.service';
export * from './src/services/conversion.service';
+export * from './src/services/sankey.service';
export * from './src/services/user.service';
export * from './src/services/reference.service';
export * from './src/services/id.service';
diff --git a/packages/db/prisma/migrations/20251219125331_report_options/migration.sql b/packages/db/prisma/migrations/20251219125331_report_options/migration.sql
new file mode 100644
index 000000000..a393dd294
--- /dev/null
+++ b/packages/db/prisma/migrations/20251219125331_report_options/migration.sql
@@ -0,0 +1,5 @@
+-- AlterEnum
+ALTER TYPE "public"."ChartType" ADD VALUE 'sankey';
+
+-- AlterTable
+ALTER TABLE "public"."reports" ADD COLUMN "options" JSONB;
diff --git a/packages/db/prisma/migrations/20260109144217_add_share_dashboard_and_report/migration.sql b/packages/db/prisma/migrations/20260109144217_add_share_dashboard_and_report/migration.sql
new file mode 100644
index 000000000..11d347b4e
--- /dev/null
+++ b/packages/db/prisma/migrations/20260109144217_add_share_dashboard_and_report/migration.sql
@@ -0,0 +1,53 @@
+-- CreateTable
+CREATE TABLE "public"."share_dashboards" (
+ "id" TEXT NOT NULL,
+ "dashboardId" TEXT NOT NULL,
+ "organizationId" TEXT NOT NULL,
+ "projectId" TEXT NOT NULL,
+ "public" BOOLEAN NOT NULL DEFAULT false,
+ "password" TEXT,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+-- CreateTable
+CREATE TABLE "public"."share_reports" (
+ "id" TEXT NOT NULL,
+ "reportId" UUID NOT NULL,
+ "organizationId" TEXT NOT NULL,
+ "projectId" TEXT NOT NULL,
+ "public" BOOLEAN NOT NULL DEFAULT false,
+ "password" TEXT,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "share_dashboards_id_key" ON "public"."share_dashboards"("id");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "share_dashboards_dashboardId_key" ON "public"."share_dashboards"("dashboardId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "share_reports_id_key" ON "public"."share_reports"("id");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "share_reports_reportId_key" ON "public"."share_reports"("reportId");
+
+-- AddForeignKey
+ALTER TABLE "public"."share_dashboards" ADD CONSTRAINT "share_dashboards_dashboardId_fkey" FOREIGN KEY ("dashboardId") REFERENCES "public"."dashboards"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_dashboards" ADD CONSTRAINT "share_dashboards_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "public"."organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_dashboards" ADD CONSTRAINT "share_dashboards_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "public"."projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_reports" ADD CONSTRAINT "share_reports_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "public"."reports"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_reports" ADD CONSTRAINT "share_reports_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "public"."organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_reports" ADD CONSTRAINT "share_reports_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "public"."projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/packages/db/prisma/migrations/20260113151311_add_share_widget/migration.sql b/packages/db/prisma/migrations/20260113151311_add_share_widget/migration.sql
new file mode 100644
index 000000000..807cccf4c
--- /dev/null
+++ b/packages/db/prisma/migrations/20260113151311_add_share_widget/migration.sql
@@ -0,0 +1,19 @@
+-- CreateTable
+CREATE TABLE "public"."share_widgets" (
+ "id" TEXT NOT NULL,
+ "projectId" TEXT NOT NULL,
+ "organizationId" TEXT NOT NULL,
+ "public" BOOLEAN NOT NULL DEFAULT true,
+ "options" JSONB NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "share_widgets_id_key" ON "public"."share_widgets"("id");
+
+-- AddForeignKey
+ALTER TABLE "public"."share_widgets" ADD CONSTRAINT "share_widgets_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "public"."projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "public"."share_widgets" ADD CONSTRAINT "share_widgets_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "public"."organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma
index 3b4d5dfeb..7131231e6 100644
--- a/packages/db/prisma/schema.prisma
+++ b/packages/db/prisma/schema.prisma
@@ -46,16 +46,19 @@ model Chat {
}
model Organization {
- id String @id @default(dbgenerated("gen_random_uuid()"))
+ id String @id @default(dbgenerated("gen_random_uuid()"))
name String
projects Project[]
members Member[]
createdByUserId String?
- createdBy User? @relation(name: "organizationCreatedBy", fields: [createdByUserId], references: [id], onDelete: SetNull)
+ createdBy User? @relation(name: "organizationCreatedBy", fields: [createdByUserId], references: [id], onDelete: SetNull)
ProjectAccess ProjectAccess[]
Client Client[]
Dashboard Dashboard[]
ShareOverview ShareOverview[]
+ ShareDashboard ShareDashboard[]
+ ShareReport ShareReport[]
+ ShareWidget ShareWidget[]
integrations Integration[]
invites Invite[]
timezone String?
@@ -185,13 +188,16 @@ model Project {
/// [IPrismaProjectFilters]
filters Json @default("[]")
- clients Client[]
- reports Report[]
- dashboards Dashboard[]
- share ShareOverview?
- meta EventMeta[]
- references Reference[]
- access ProjectAccess[]
+ clients Client[]
+ reports Report[]
+ dashboards Dashboard[]
+ share ShareOverview?
+ shareDashboards ShareDashboard[]
+ shareReports ShareReport[]
+ shareWidgets ShareWidget[]
+ meta EventMeta[]
+ references Reference[]
+ access ProjectAccess[]
notificationRules NotificationRule[]
notifications Notification[]
@@ -279,16 +285,18 @@ enum ChartType {
funnel
retention
conversion
+ sankey
}
model Dashboard {
- id String @id @default(dbgenerated("gen_random_uuid()"))
+ id String @id @default(dbgenerated("gen_random_uuid()"))
name String
- organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String
projectId String
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
reports Report[]
+ share ShareDashboard?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@ -321,10 +329,13 @@ model Report {
criteria String?
funnelGroup String?
funnelWindow Float?
+ /// [IReportOptions]
+ options Json?
dashboardId String
dashboard Dashboard @relation(fields: [dashboardId], references: [id], onDelete: Cascade)
layout ReportLayout?
+ share ShareReport?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@ -369,6 +380,53 @@ model ShareOverview {
@@map("shares")
}
+model ShareDashboard {
+ id String @unique
+ dashboardId String @unique
+ dashboard Dashboard @relation(fields: [dashboardId], references: [id], onDelete: Cascade)
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
+ organizationId String
+ projectId String
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ public Boolean @default(false)
+ password String?
+ createdAt DateTime @default(now())
+ updatedAt DateTime @default(now()) @updatedAt
+
+ @@map("share_dashboards")
+}
+
+model ShareReport {
+ id String @unique
+ reportId String @unique @db.Uuid
+ report Report @relation(fields: [reportId], references: [id], onDelete: Cascade)
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
+ organizationId String
+ projectId String
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ public Boolean @default(false)
+ password String?
+ createdAt DateTime @default(now())
+ updatedAt DateTime @default(now()) @updatedAt
+
+ @@map("share_reports")
+}
+
+model ShareWidget {
+ id String @unique
+ projectId String
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
+ organizationId String
+ public Boolean @default(true)
+ /// [IPrismaWidgetOptions]
+ options Json
+ createdAt DateTime @default(now())
+ updatedAt DateTime @default(now()) @updatedAt
+
+ @@map("share_widgets")
+}
+
model EventMeta {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
diff --git a/packages/db/src/clickhouse/query-builder.ts b/packages/db/src/clickhouse/query-builder.ts
index 80bf708c3..cdbb23daf 100644
--- a/packages/db/src/clickhouse/query-builder.ts
+++ b/packages/db/src/clickhouse/query-builder.ts
@@ -203,6 +203,13 @@ export class Query<T = any> {
return this;
}
+ rawHaving(condition: string): this {
+ if (condition) {
+ this._having.push({ condition, operator: 'AND' });
+ }
+ return this;
+ }
+
andHaving(column: string, operator: Operator, value: SqlParam): this {
const condition = this.buildCondition(column, operator, value);
this._having.push({ condition, operator: 'AND' });
diff --git a/packages/db/src/engine/fetch.ts b/packages/db/src/engine/fetch.ts
index 954c98e99..ecc377686 100644
--- a/packages/db/src/engine/fetch.ts
+++ b/packages/db/src/engine/fetch.ts
@@ -53,9 +53,6 @@ export async function fetch(plan: Plan): Promise<ConcreteSeries[]> {
previous: plan.input.previous ?? false,
limit: plan.input.limit,
offset: plan.input.offset,
- criteria: plan.input.criteria,
- funnelGroup: plan.input.funnelGroup,
- funnelWindow: plan.input.funnelWindow,
};
// Execute query
diff --git a/packages/db/src/engine/index.ts b/packages/db/src/engine/index.ts
index 4769db9e2..bf61b2c7c 100644
--- a/packages/db/src/engine/index.ts
+++ b/packages/db/src/engine/index.ts
@@ -4,7 +4,7 @@ import { alphabetIds } from '@openpanel/constants';
import type {
FinalChart,
IChartEventItem,
- IChartInput,
+ IReportInput,
} from '@openpanel/validation';
import { chQuery } from '../clickhouse/client';
import {
@@ -26,7 +26,7 @@ import type { ConcreteSeries } from './types';
* Chart Engine - Main entry point
* Executes the pipeline: normalize -> plan -> fetch -> compute -> format
*/
-export async function executeChart(input: IChartInput): Promise<FinalChart> {
+export async function executeChart(input: IReportInput): Promise<FinalChart> {
// Stage 1: Normalize input
const normalized = await normalize(input);
@@ -83,7 +83,7 @@ export async function executeChart(input: IChartInput): Promise<FinalChart> {
* Executes a simplified pipeline: normalize -> fetch aggregate -> format
*/
export async function executeAggregateChart(
- input: IChartInput,
+ input: IReportInput,
): Promise<FinalChart> {
// Stage 1: Normalize input
const normalized = await normalize(input);
diff --git a/packages/db/src/engine/normalize.ts b/packages/db/src/engine/normalize.ts
index ed37a3e67..f77818ae1 100644
--- a/packages/db/src/engine/normalize.ts
+++ b/packages/db/src/engine/normalize.ts
@@ -2,8 +2,8 @@ import { alphabetIds } from '@openpanel/constants';
import type {
IChartEvent,
IChartEventItem,
- IChartInput,
- IChartInputWithDates,
+ IReportInput,
+ IReportInputWithDates,
} from '@openpanel/validation';
import { getChartStartEndDate } from '../services/chart.service';
import { getSettingsForProject } from '../services/organization.service';
@@ -15,8 +15,8 @@ export type NormalizedInput = Awaited<ReturnType<typeof normalize>>;
* Normalize a chart input into a clean structure with dates and normalized series
*/
export async function normalize(
- input: IChartInput,
-): Promise<IChartInputWithDates & { series: SeriesDefinition[] }> {
+ input: IReportInput,
+): Promise<IReportInputWithDates & { series: SeriesDefinition[] }> {
const { timezone } = await getSettingsForProject(input.projectId);
const { startDate, endDate } = getChartStartEndDate(
{
diff --git a/packages/db/src/engine/types.ts b/packages/db/src/engine/types.ts
index 7aad9c31d..774755bea 100644
--- a/packages/db/src/engine/types.ts
+++ b/packages/db/src/engine/types.ts
@@ -4,8 +4,8 @@ import type {
IChartEventFilter,
IChartEventItem,
IChartFormula,
- IChartInput,
- IChartInputWithDates,
+ IReportInput,
+ IReportInputWithDates,
} from '@openpanel/validation';
/**
@@ -50,7 +50,7 @@ export type ConcreteSeries = {
export type Plan = {
concreteSeries: ConcreteSeries[];
definitions: SeriesDefinition[];
- input: IChartInputWithDates;
+ input: IReportInputWithDates;
timezone: string;
};
diff --git a/packages/db/src/services/chart.service.ts b/packages/db/src/services/chart.service.ts
index 7ce69f812..568ea7883 100644
--- a/packages/db/src/services/chart.service.ts
+++ b/packages/db/src/services/chart.service.ts
@@ -3,7 +3,7 @@ import sqlstring from 'sqlstring';
import { DateTime, stripLeadingAndTrailingSlashes } from '@openpanel/common';
import type {
IChartEventFilter,
- IChartInput,
+ IReportInput,
IChartRange,
IGetChartDataInput,
} from '@openpanel/validation';
@@ -973,7 +973,7 @@ export function getChartStartEndDate(
startDate,
endDate,
range,
- }: Pick<IChartInput, 'endDate' | 'startDate' | 'range'>,
+ }: Pick<IReportInput, 'endDate' | 'startDate' | 'range'>,
timezone: string,
) {
if (startDate && endDate) {
diff --git a/packages/db/src/services/conversion.service.ts b/packages/db/src/services/conversion.service.ts
index f7e7b86b9..c60a4a437 100644
--- a/packages/db/src/services/conversion.service.ts
+++ b/packages/db/src/services/conversion.service.ts
@@ -1,5 +1,5 @@
import { NOT_SET_VALUE } from '@openpanel/constants';
-import type { IChartEvent, IChartInput } from '@openpanel/validation';
+import type { IChartEvent, IChartBreakdown, IReportInput } from '@openpanel/validation';
import { omit } from 'ramda';
import { TABLE_NAMES, ch } from '../clickhouse/client';
import { clix } from '../clickhouse/query-builder';
@@ -16,21 +16,23 @@ export class ConversionService {
projectId,
startDate,
endDate,
- funnelGroup,
- funnelWindow = 24,
+ options,
series,
breakdowns = [],
limit,
interval,
timezone,
- }: Omit<IChartInput, 'range' | 'previous' | 'metric' | 'chartType'> & {
+ }: Omit<IReportInput, 'range' | 'previous' | 'metric' | 'chartType'> & {
timezone: string;
}) {
+ const funnelOptions = options?.type === 'funnel' ? options : undefined;
+ const funnelGroup = funnelOptions?.funnelGroup;
+ const funnelWindow = funnelOptions?.funnelWindow ?? 24;
const group = funnelGroup === 'profile_id' ? 'profile_id' : 'session_id';
const breakdownColumns = breakdowns.map(
- (b, index) => `${getSelectPropertyKey(b.name)} as b_${index}`,
+ (b: IChartBreakdown, index: number) => `${getSelectPropertyKey(b.name)} as b_${index}`,
);
- const breakdownGroupBy = breakdowns.map((b, index) => `b_${index}`);
+ const breakdownGroupBy = breakdowns.map((b: IChartBreakdown, index: number) => `b_${index}`);
const events = onlyReportEvents(series);
diff --git a/packages/db/src/services/funnel.service.ts b/packages/db/src/services/funnel.service.ts
index 9ecc204d3..74211c735 100644
--- a/packages/db/src/services/funnel.service.ts
+++ b/packages/db/src/services/funnel.service.ts
@@ -2,7 +2,7 @@ import { ifNaN } from '@openpanel/common';
import type {
IChartEvent,
IChartEventItem,
- IChartInput,
+ IReportInput,
} from '@openpanel/validation';
import { last, reverse, uniq } from 'ramda';
import sqlstring from 'sqlstring';
@@ -185,16 +185,19 @@ export class FunnelService {
startDate,
endDate,
series,
- funnelWindow = 24,
- funnelGroup,
+ options,
breakdowns = [],
limit,
timezone = 'UTC',
- }: IChartInput & { timezone: string; events?: IChartEvent[] }) {
+ }: IReportInput & { timezone: string; events?: IChartEvent[] }) {
if (!startDate || !endDate) {
throw new Error('startDate and endDate are required');
}
+ const funnelOptions = options?.type === 'funnel' ? options : undefined;
+ const funnelWindow = funnelOptions?.funnelWindow ?? 24;
+ const funnelGroup = funnelOptions?.funnelGroup;
+
const eventSeries = onlyReportEvents(series);
if (eventSeries.length === 0) {
diff --git a/packages/db/src/services/reports.service.ts b/packages/db/src/services/reports.service.ts
index 7f8c79c41..ff205dc31 100644
--- a/packages/db/src/services/reports.service.ts
+++ b/packages/db/src/services/reports.service.ts
@@ -8,9 +8,9 @@ import type {
IChartEventFilter,
IChartEventItem,
IChartLineType,
- IChartProps,
IChartRange,
- ICriteria,
+ IReport,
+ IReportOptions,
} from '@openpanel/validation';
import type { Report as DbReport, ReportLayout } from '../prisma-client';
@@ -65,17 +65,22 @@ export function transformReportEventItem(
export function transformReport(
report: DbReport & { layout?: ReportLayout | null },
-): IChartProps & { id: string; layout?: ReportLayout | null } {
+): IReport & {
+ id: string;
+ layout?: ReportLayout | null;
+} {
+ const options = report.options as IReportOptions | null | undefined;
+
return {
id: report.id,
projectId: report.projectId,
- series:
- (report.events as IChartEventItem[]).map(transformReportEventItem) ?? [],
- breakdowns: report.breakdowns as IChartBreakdown[],
+ name: report.name || 'Untitled',
chartType: report.chartType,
lineType: (report.lineType as IChartLineType) ?? lineTypes.monotone,
interval: report.interval,
- name: report.name || 'Untitled',
+ series:
+ (report.events as IChartEventItem[]).map(transformReportEventItem) ?? [],
+ breakdowns: report.breakdowns as IChartBreakdown[],
range:
report.range in deprecated_timeRanges
? '30d'
@@ -84,10 +89,8 @@ export function transformReport(
formula: report.formula ?? undefined,
metric: report.metric ?? 'sum',
unit: report.unit ?? undefined,
- criteria: (report.criteria as ICriteria) ?? undefined,
- funnelGroup: report.funnelGroup ?? undefined,
- funnelWindow: report.funnelWindow ?? undefined,
layout: report.layout ?? undefined,
+ options: options ?? undefined,
};
}
diff --git a/packages/db/src/services/sankey.service.ts b/packages/db/src/services/sankey.service.ts
new file mode 100644
index 000000000..64417c446
--- /dev/null
+++ b/packages/db/src/services/sankey.service.ts
@@ -0,0 +1,783 @@
+import { chartColors } from '@openpanel/constants';
+import { type IChartEventFilter, zChartEvent } from '@openpanel/validation';
+import { z } from 'zod';
+import { TABLE_NAMES, ch } from '../clickhouse/client';
+import { clix } from '../clickhouse/query-builder';
+import { getEventFiltersWhereClause } from './chart.service';
+
+export const zGetSankeyInput = z.object({
+ projectId: z.string(),
+ startDate: z.string(),
+ endDate: z.string(),
+ steps: z.number().min(2).max(10).default(5),
+ mode: z.enum(['between', 'after', 'before']),
+ startEvent: zChartEvent,
+ endEvent: zChartEvent.optional(),
+ exclude: z.array(z.string()).default([]),
+ include: z.array(z.string()).optional(),
+});
+
+export type IGetSankeyInput = z.infer<typeof zGetSankeyInput> & {
+ timezone: string;
+};
+
+export class SankeyService {
+ constructor(private client: typeof ch) {}
+
+ getRawWhereClause(type: 'events' | 'sessions', filters: IChartEventFilter[]) {
+ const where = getEventFiltersWhereClause(
+ filters.map((item) => {
+ if (type === 'sessions') {
+ if (item.name === 'path') {
+ return { ...item, name: 'entry_path' };
+ }
+ if (item.name === 'origin') {
+ return { ...item, name: 'entry_origin' };
+ }
+ if (item.name.startsWith('properties.__query.utm_')) {
+ return {
+ ...item,
+ name: item.name.replace('properties.__query.utm_', 'utm_'),
+ };
+ }
+ return item;
+ }
+ return item;
+ }),
+ );
+
+ return Object.values(where).join(' AND ');
+ }
+
+ private buildEventNameFilter(
+ include: string[] | undefined,
+ exclude: string[],
+ startEventName: string | undefined,
+ endEventName: string | undefined,
+ ) {
+ if (include && include.length > 0) {
+ const eventNames = [...include, startEventName, endEventName]
+ .filter((item) => item !== undefined)
+ .map((e) => `'${e!.replace(/'/g, "''")}'`)
+ .join(', ');
+ return `name IN (${eventNames})`;
+ }
+ if (exclude.length > 0) {
+ const excludedNames = exclude
+ .map((e) => `'${e.replace(/'/g, "''")}'`)
+ .join(', ');
+ return `name NOT IN (${excludedNames})`;
+ }
+ return null;
+ }
+
+ private buildSessionEventCTE(
+ event: z.infer<typeof zChartEvent>,
+ projectId: string,
+ startDate: string,
+ endDate: string,
+ timezone: string,
+ ): ReturnType<typeof clix> {
+ return clix(this.client, timezone)
+ .select<{ session_id: string }>(['session_id'])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('name', '=', event.name)
+ .where('created_at', 'BETWEEN', [
+ clix.datetime(startDate, 'toDateTime'),
+ clix.datetime(endDate, 'toDateTime'),
+ ])
+ .rawWhere(this.getRawWhereClause('events', event.filters))
+ .groupBy(['session_id']);
+ }
+
+ private getModeConfig(
+ mode: 'after' | 'before' | 'between',
+ startEvent: z.infer<typeof zChartEvent> | undefined,
+ endEvent: z.infer<typeof zChartEvent> | undefined,
+ hasStartEventCTE: boolean,
+ hasEndEventCTE: boolean,
+ steps: number,
+ ): { sessionFilter: string; eventsSliceExpr: string } {
+ const defaultSliceExpr = `arraySlice(events_deduped, 1, ${steps})`;
+
+ if (mode === 'after' && startEvent) {
+ const escapedStartEvent = startEvent.name.replace(/'/g, "''");
+ const sessionFilter = hasStartEventCTE
+ ? 'session_id IN (SELECT session_id FROM start_event_sessions)'
+ : `arrayExists(x -> x = '${escapedStartEvent}', events_deduped)`;
+ const eventsSliceExpr = `arraySlice(events_deduped, arrayFirstIndex(x -> x = '${escapedStartEvent}', events_deduped), ${steps})`;
+ return { sessionFilter, eventsSliceExpr };
+ }
+
+ if (mode === 'before' && startEvent) {
+ const escapedStartEvent = startEvent.name.replace(/'/g, "''");
+ const sessionFilter = hasStartEventCTE
+ ? 'session_id IN (SELECT session_id FROM start_event_sessions)'
+ : `arrayExists(x -> x = '${escapedStartEvent}', events_deduped)`;
+ const eventsSliceExpr = `arraySlice(
+ events_deduped,
+ greatest(1, arrayFirstIndex(x -> x = '${escapedStartEvent}', events_deduped) - ${steps} + 1),
+ arrayFirstIndex(x -> x = '${escapedStartEvent}', events_deduped) - greatest(1, arrayFirstIndex(x -> x = '${escapedStartEvent}', events_deduped) - ${steps} + 1) + 1
+ )`;
+ return { sessionFilter, eventsSliceExpr };
+ }
+
+ if (mode === 'between' && startEvent && endEvent) {
+ const escapedStartEvent = startEvent.name.replace(/'/g, "''");
+ const escapedEndEvent = endEvent.name.replace(/'/g, "''");
+ let sessionFilter = '';
+ if (hasStartEventCTE && hasEndEventCTE) {
+ sessionFilter =
+ 'session_id IN (SELECT session_id FROM start_event_sessions) AND session_id IN (SELECT session_id FROM end_event_sessions)';
+ } else if (hasStartEventCTE) {
+ sessionFilter = `session_id IN (SELECT session_id FROM start_event_sessions) AND arrayExists(x -> x = '${escapedEndEvent}', events_deduped)`;
+ } else if (hasEndEventCTE) {
+ sessionFilter = `arrayExists(x -> x = '${escapedStartEvent}', events_deduped) AND session_id IN (SELECT session_id FROM end_event_sessions)`;
+ } else {
+ sessionFilter = `arrayExists(x -> x = '${escapedStartEvent}', events_deduped) AND arrayExists(x -> x = '${escapedEndEvent}', events_deduped)`;
+ }
+ return { sessionFilter, eventsSliceExpr: defaultSliceExpr };
+ }
+
+ return { sessionFilter: '', eventsSliceExpr: defaultSliceExpr };
+ }
+
+ private async executeBetweenMode(
+ sessionPathsQuery: ReturnType<typeof clix>,
+ startEvent: z.infer<typeof zChartEvent>,
+ endEvent: z.infer<typeof zChartEvent>,
+ steps: number,
+ COLORS: string[],
+ timezone: string,
+ ): Promise<{
+ nodes: Array<{
+ id: string;
+ label: string;
+ nodeColor: string;
+ percentage?: number;
+ value?: number;
+ step?: number;
+ }>;
+ links: Array<{ source: string; target: string; value: number }>;
+ }> {
+ // Find sessions where startEvent comes before endEvent
+ const betweenSessionsQuery = clix(this.client, timezone)
+ .with('session_paths', sessionPathsQuery)
+ .select<{
+ session_id: string;
+ events: string[];
+ start_index: number;
+ end_index: number;
+ }>([
+ 'session_id',
+ 'events',
+ `arrayFirstIndex(x -> x = '${startEvent.name.replace(/'/g, "''")}', events) as start_index`,
+ `arrayFirstIndex(x -> x = '${endEvent.name.replace(/'/g, "''")}', events) as end_index`,
+ ])
+ .from('session_paths')
+ .having('start_index', '>', 0)
+ .having('end_index', '>', 0)
+ .rawHaving('start_index < end_index');
+
+ // Get the slice between start and end
+ const betweenPathsQuery = clix(this.client, timezone)
+ .with('between_sessions', betweenSessionsQuery)
+ .select<{
+ session_id: string;
+ events: string[];
+ entry_event: string;
+ }>([
+ 'session_id',
+ 'arraySlice(events, start_index, end_index - start_index + 1) as events',
+ 'events[start_index] as entry_event',
+ ])
+ .from('between_sessions');
+
+ // Get top entry events
+ const topEntriesQuery = clix(this.client, timezone)
+ .with('session_paths', betweenPathsQuery)
+ .select<{ entry_event: string; count: number }>([
+ 'entry_event',
+ 'count() as count',
+ ])
+ .from('session_paths')
+ .groupBy(['entry_event'])
+ .orderBy('count', 'DESC')
+ .limit(3);
+
+ const topEntries = await topEntriesQuery.execute();
+
+ if (topEntries.length === 0) {
+ return { nodes: [], links: [] };
+ }
+
+ const topEntryEvents = topEntries.map((e) => e.entry_event);
+ const totalSessions = topEntries.reduce((sum, e) => sum + e.count, 0);
+
+ // Get transitions for between mode
+ const transitionsQuery = clix(this.client, timezone)
+ .with('between_sessions', betweenSessionsQuery)
+ .with(
+ 'session_paths',
+ clix(this.client, timezone)
+ .select([
+ 'session_id',
+ 'arraySlice(events, start_index, end_index - start_index + 1) as events',
+ ])
+ .from('between_sessions')
+ .having('events[1]', 'IN', topEntryEvents),
+ )
+ .select<{
+ source: string;
+ target: string;
+ step: number;
+ value: number;
+ }>([
+ 'pair.1 as source',
+ 'pair.2 as target',
+ 'pair.3 as step',
+ 'count() as value',
+ ])
+ .from(
+ clix.exp(
+ '(SELECT arrayJoin(arrayMap(i -> (events[i], events[i + 1], i), range(1, length(events)))) as pair FROM session_paths WHERE length(events) >= 2)',
+ ),
+ )
+ .groupBy(['source', 'target', 'step'])
+ .orderBy('step', 'ASC')
+ .orderBy('value', 'DESC');
+
+ const transitions = await transitionsQuery.execute();
+
+ return this.buildSankeyFromTransitions(
+ transitions,
+ topEntries,
+ totalSessions,
+ steps,
+ COLORS,
+ );
+ }
+
+ private async executeSimpleMode(
+ sessionPathsQuery: ReturnType<typeof clix>,
+ steps: number,
+ COLORS: string[],
+ timezone: string,
+ ): Promise<{
+ nodes: Array<{
+ id: string;
+ label: string;
+ nodeColor: string;
+ percentage?: number;
+ value?: number;
+ step?: number;
+ }>;
+ links: Array<{ source: string; target: string; value: number }>;
+ }> {
+ // Get top entry events
+ const topEntriesQuery = clix(this.client, timezone)
+ .with('session_paths', sessionPathsQuery)
+ .select<{ entry_event: string; count: number }>([
+ 'entry_event',
+ 'count() as count',
+ ])
+ .from('session_paths')
+ .groupBy(['entry_event'])
+ .orderBy('count', 'DESC')
+ .limit(3);
+
+ const topEntries = await topEntriesQuery.execute();
+
+ if (topEntries.length === 0) {
+ return { nodes: [], links: [] };
+ }
+
+ const topEntryEvents = topEntries.map((e) => e.entry_event);
+ const totalSessions = topEntries.reduce((sum, e) => sum + e.count, 0);
+
+ // Get transitions
+ const transitionsQuery = clix(this.client, timezone)
+ .with('session_paths_base', sessionPathsQuery)
+ .with(
+ 'session_paths',
+ clix(this.client, timezone)
+ .select(['session_id', 'events'])
+ .from('session_paths_base')
+ .having('events[1]', 'IN', topEntryEvents),
+ )
+ .select<{
+ source: string;
+ target: string;
+ step: number;
+ value: number;
+ }>([
+ 'pair.1 as source',
+ 'pair.2 as target',
+ 'pair.3 as step',
+ 'count() as value',
+ ])
+ .from(
+ clix.exp(
+ '(SELECT arrayJoin(arrayMap(i -> (events[i], events[i + 1], i), range(1, length(events)))) as pair FROM session_paths WHERE length(events) >= 2)',
+ ),
+ )
+ .groupBy(['source', 'target', 'step'])
+ .orderBy('step', 'ASC')
+ .orderBy('value', 'DESC');
+
+ const transitions = await transitionsQuery.execute();
+
+ return this.buildSankeyFromTransitions(
+ transitions,
+ topEntries,
+ totalSessions,
+ steps,
+ COLORS,
+ );
+ }
+
+ async getSankey({
+ projectId,
+ startDate,
+ endDate,
+ steps = 5,
+ mode,
+ startEvent,
+ endEvent,
+ exclude = [],
+ include,
+ timezone,
+ }: IGetSankeyInput): Promise<{
+ nodes: Array<{
+ id: string;
+ label: string;
+ nodeColor: string;
+ percentage?: number;
+ value?: number;
+ step?: number;
+ }>;
+ links: Array<{ source: string; target: string; value: number }>;
+ }> {
+ const COLORS = chartColors.map((color) => color.main);
+
+ // 1. Build event name filter
+ const eventNameFilter = this.buildEventNameFilter(
+ include,
+ exclude,
+ startEvent?.name,
+ endEvent?.name,
+ );
+
+ // 2. Build ordered events query
+ // For screen_view events, use the path instead of the event name for more meaningful flow visualization
+ const orderedEventsQuery = clix(this.client, timezone)
+ .select<{
+ session_id: string;
+ event_name: string;
+ created_at: string;
+ }>([
+ 'session_id',
+ // "if(name = 'screen_view', path, name) as event_name",
+ 'name as event_name',
+ 'created_at',
+ ])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', 'BETWEEN', [
+ clix.datetime(startDate, 'toDateTime'),
+ clix.datetime(endDate, 'toDateTime'),
+ ])
+ .orderBy('session_id', 'ASC')
+ .orderBy('created_at', 'ASC');
+
+ if (eventNameFilter) {
+ orderedEventsQuery.rawWhere(eventNameFilter);
+ }
+
+ // 3. Build session event CTEs
+ const startEventCTE = startEvent
+ ? this.buildSessionEventCTE(
+ startEvent,
+ projectId,
+ startDate,
+ endDate,
+ timezone,
+ )
+ : null;
+ const endEventCTE =
+ mode === 'between' && endEvent
+ ? this.buildSessionEventCTE(
+ endEvent,
+ projectId,
+ startDate,
+ endDate,
+ timezone,
+ )
+ : null;
+
+ // 4. Build deduped events CTE
+ const eventsDedupedCTE = clix(this.client, timezone)
+ .with('ordered_events', orderedEventsQuery)
+ .select<{
+ session_id: string;
+ events_deduped: string[];
+ }>([
+ 'session_id',
+ `arrayFilter(
+ (x, i) -> i = 1 OR x != events_raw[i - 1],
+ groupArray(event_name) as events_raw,
+ arrayEnumerate(events_raw)
+ ) as events_deduped`,
+ ])
+ .from('ordered_events')
+ .groupBy(['session_id']);
+
+ // 5. Get mode-specific config
+ const { sessionFilter, eventsSliceExpr } = this.getModeConfig(
+ mode,
+ startEvent,
+ endEvent,
+ startEventCTE !== null,
+ endEventCTE !== null,
+ steps,
+ );
+
+ // 6. Build truncate expression (for 'after' mode)
+ const truncateAtRepeatExpr = `if(
+ arrayFirstIndex(x -> x > 1, arrayEnumerateUniq(events_sliced)) = 0,
+ events_sliced,
+ arraySlice(
+ events_sliced,
+ 1,
+ arrayFirstIndex(x -> x > 1, arrayEnumerateUniq(events_sliced)) - 1
+ )
+ )`;
+ const eventsExpr =
+ mode === 'before' ? 'events_sliced' : truncateAtRepeatExpr;
+
+ // 7. Build session paths query with conditional CTEs
+ const eventCTEs: Array<{ name: string; query: ReturnType<typeof clix> }> =
+ [];
+ if (startEventCTE) {
+ eventCTEs.push({ name: 'start_event_sessions', query: startEventCTE });
+ }
+ if (endEventCTE) {
+ eventCTEs.push({ name: 'end_event_sessions', query: endEventCTE });
+ }
+
+ const sessionPathsQuery = eventCTEs
+ .reduce(
+ (builder, cte) => builder.with(cte.name, cte.query),
+ clix(this.client, timezone),
+ )
+ .with('events_deduped_cte', eventsDedupedCTE)
+ .with(
+ 'events_sliced_cte',
+ clix(this.client, timezone)
+ .select<{
+ session_id: string;
+ events_sliced: string[];
+ }>(['session_id', `${eventsSliceExpr} as events_sliced`])
+ .from('events_deduped_cte')
+ .rawHaving(sessionFilter || '1 = 1'),
+ )
+ .select<{
+ session_id: string;
+ entry_event: string;
+ events: string[];
+ }>(['session_id', `${eventsExpr} as events`, 'events[1] as entry_event'])
+ .from('events_sliced_cte')
+ .having('length(events)', '>=', 2);
+
+ // 8. Execute mode-specific logic
+ if (mode === 'between' && startEvent && endEvent) {
+ return this.executeBetweenMode(
+ sessionPathsQuery,
+ startEvent,
+ endEvent,
+ steps,
+ COLORS,
+ timezone,
+ );
+ }
+
+ return this.executeSimpleMode(sessionPathsQuery, steps, COLORS, timezone);
+ }
+
+ private buildSankeyFromTransitions(
+ transitions: Array<{
+ source: string;
+ target: string;
+ step: number;
+ value: number;
+ }>,
+ topEntries: Array<{ entry_event: string; count: number }>,
+ totalSessions: number,
+ steps: number,
+ COLORS: string[],
+ ) {
+ if (transitions.length === 0) {
+ return { nodes: [], links: [] };
+ }
+
+ const TOP_DESTINATIONS_PER_NODE = 3;
+
+ // Build the sankey progressively step by step
+ const nodes = new Map<
+ string,
+ { event: string; value: number; step: number; color: string }
+ >();
+ const links: Array<{ source: string; target: string; value: number }> = [];
+
+ // Helper to create unique node ID
+ const getNodeId = (event: string, step: number) => `${event}::step${step}`;
+
+ // Group transitions by step
+ const transitionsByStep = new Map<number, typeof transitions>();
+ for (const t of transitions) {
+ if (!transitionsByStep.has(t.step)) {
+ transitionsByStep.set(t.step, []);
+ }
+ transitionsByStep.get(t.step)!.push(t);
+ }
+
+ // Initialize with entry events (step 1)
+ const activeNodes = new Map<string, string>(); // event -> nodeId
+ topEntries.forEach((entry, idx) => {
+ const nodeId = getNodeId(entry.entry_event, 1);
+ nodes.set(nodeId, {
+ event: entry.entry_event,
+ value: entry.count,
+ step: 1,
+ color: COLORS[idx % COLORS.length]!,
+ });
+ activeNodes.set(entry.entry_event, nodeId);
+ });
+
+ // Process each step: from active nodes, find top destinations
+ for (let step = 1; step < steps; step++) {
+ const stepTransitions = transitionsByStep.get(step) || [];
+ const nextActiveNodes = new Map<string, string>();
+
+ // For each currently active node, find its top destinations
+ for (const [sourceEvent, sourceNodeId] of activeNodes) {
+ // Get transitions FROM this source event
+ const fromSource = stepTransitions
+ .filter((t) => t.source === sourceEvent)
+ .sort((a, b) => b.value - a.value)
+ .slice(0, TOP_DESTINATIONS_PER_NODE);
+
+ for (const t of fromSource) {
+ // Skip self-loops
+ if (t.source === t.target) continue;
+
+ const targetNodeId = getNodeId(t.target, step + 1);
+
+ // Add link using unique node IDs
+ links.push({
+ source: sourceNodeId,
+ target: targetNodeId,
+ value: t.value,
+ });
+
+ // Add/update target node
+ const existing = nodes.get(targetNodeId);
+ if (existing) {
+ existing.value += t.value;
+ } else {
+ // Inherit color from source or assign new
+ const sourceData = nodes.get(sourceNodeId);
+ nodes.set(targetNodeId, {
+ event: t.target,
+ value: t.value,
+ step: step + 1,
+ color: sourceData?.color || COLORS[nodes.size % COLORS.length]!,
+ });
+ }
+
+ nextActiveNodes.set(t.target, targetNodeId);
+ }
+ }
+
+ // Update active nodes for next iteration
+ activeNodes.clear();
+ for (const [event, nodeId] of nextActiveNodes) {
+ activeNodes.set(event, nodeId);
+ }
+
+ // Stop if no more nodes to process
+ if (activeNodes.size === 0) break;
+ }
+
+ // Filter links by threshold (0.25% of total sessions)
+ const MIN_LINK_PERCENT = 0.25;
+ const minLinkValue = Math.ceil((totalSessions * MIN_LINK_PERCENT) / 100);
+ const filteredLinks = links.filter((link) => link.value >= minLinkValue);
+
+ // Find all nodes referenced by remaining links
+ const referencedNodeIds = new Set<string>();
+ filteredLinks.forEach((link) => {
+ referencedNodeIds.add(link.source);
+ referencedNodeIds.add(link.target);
+ });
+
+ // Recompute node values from filtered links
+ const nodeValuesFromLinks = new Map<string, number>();
+ filteredLinks.forEach((link) => {
+ const current = nodeValuesFromLinks.get(link.target) || 0;
+ nodeValuesFromLinks.set(link.target, current + link.value);
+ });
+
+ // For entry nodes (step 1), only keep them if they have outgoing links after filtering
+ nodes.forEach((nodeData, nodeId) => {
+ if (nodeData.step === 1) {
+ const hasOutgoing = filteredLinks.some((l) => l.source === nodeId);
+ if (!hasOutgoing) {
+ referencedNodeIds.delete(nodeId);
+ }
+ }
+ });
+
+ // Build final nodes array sorted by step then value
+ const finalNodes = Array.from(nodes.entries())
+ .filter(([id]) => referencedNodeIds.has(id))
+ .map(([id, data]) => {
+ const value =
+ data.step === 1
+ ? data.value
+ : nodeValuesFromLinks.get(id) || data.value;
+ return {
+ id,
+ label: data.event,
+ nodeColor: data.color,
+ percentage: (value / totalSessions) * 100,
+ value,
+ step: data.step,
+ };
+ })
+ .sort((a, b) => {
+ if (a.step !== b.step) return a.step - b.step;
+ return b.value - a.value;
+ });
+
+ // Sanity check: Ensure all link endpoints exist in nodes
+ const nodeIds = new Set(finalNodes.map((n) => n.id));
+ const validLinks = filteredLinks.filter(
+ (link) => nodeIds.has(link.source) && nodeIds.has(link.target),
+ );
+
+ // Combine final nodes with the same event name
+ // A final node is one that has no outgoing links
+ const nodesWithOutgoing = new Set(validLinks.map((l) => l.source));
+ const finalNodeIds = new Set(
+ finalNodes.filter((n) => !nodesWithOutgoing.has(n.id)).map((n) => n.id),
+ );
+
+ // Group final nodes by event name
+ const finalNodesByEvent = new Map<string, typeof finalNodes>();
+ finalNodes.forEach((node) => {
+ if (finalNodeIds.has(node.id)) {
+ if (!finalNodesByEvent.has(node.label)) {
+ finalNodesByEvent.set(node.label, []);
+ }
+ finalNodesByEvent.get(node.label)!.push(node);
+ }
+ });
+
+ // Create merged nodes and remap links
+ const nodeIdRemap = new Map<string, string>(); // old nodeId -> new merged nodeId
+ const mergedNodes = new Map<string, (typeof finalNodes)[0]>(); // merged nodeId -> node data
+
+ finalNodesByEvent.forEach((nodesToMerge, eventName) => {
+ if (nodesToMerge.length > 1) {
+ // Merge multiple final nodes with same event name
+ const maxStep = Math.max(...nodesToMerge.map((n) => n.step || 0));
+ const totalValue = nodesToMerge.reduce(
+ (sum, n) => sum + (n.value || 0),
+ 0,
+ );
+ const mergedNodeId = `${eventName}::final`;
+ const firstNode = nodesToMerge[0]!;
+
+ // Create merged node at the maximum step
+ mergedNodes.set(mergedNodeId, {
+ id: mergedNodeId,
+ label: eventName,
+ nodeColor: firstNode.nodeColor,
+ percentage: (totalValue / totalSessions) * 100,
+ value: totalValue,
+ step: maxStep,
+ });
+
+ // Map all old node IDs to the merged node ID
+ nodesToMerge.forEach((node) => {
+ nodeIdRemap.set(node.id, mergedNodeId);
+ });
+ }
+ });
+
+ // Update links to point to merged nodes
+ const remappedLinks = validLinks.map((link) => {
+ const newSource = nodeIdRemap.get(link.source) || link.source;
+ const newTarget = nodeIdRemap.get(link.target) || link.target;
+ return {
+ source: newSource,
+ target: newTarget,
+ value: link.value,
+ };
+ });
+
+ // Combine merged nodes with non-final nodes
+ const nonFinalNodes = finalNodes.filter((n) => !finalNodeIds.has(n.id));
+ const finalNodesList = Array.from(mergedNodes.values());
+
+ // Remove old final nodes that were merged
+ const mergedOldNodeIds = new Set(nodeIdRemap.keys());
+ const remainingNodes = nonFinalNodes.filter(
+ (n) => !mergedOldNodeIds.has(n.id),
+ );
+
+ // Combine all nodes and sort
+ const allNodes = [...remainingNodes, ...finalNodesList].sort((a, b) => {
+ if (a.step !== b.step) return a.step! - b.step!;
+ return b.value! - a.value!;
+ });
+
+ // Aggregate links that now point to the same merged target
+ const linkMap = new Map<string, number>(); // "source->target" -> value
+ remappedLinks.forEach((link) => {
+ const key = `${link.source}->${link.target}`;
+ linkMap.set(key, (linkMap.get(key) || 0) + link.value);
+ });
+
+ const aggregatedLinks = Array.from(linkMap.entries())
+ .map(([key, value]) => {
+ const parts = key.split('->');
+ if (parts.length !== 2) return null;
+ return { source: parts[0]!, target: parts[1]!, value };
+ })
+ .filter(
+ (link): link is { source: string; target: string; value: number } =>
+ link !== null,
+ );
+
+ // Final sanity check: Ensure all link endpoints exist in nodes
+ const finalNodeIdsSet = new Set(allNodes.map((n) => n.id));
+ const finalValidLinks: Array<{
+ source: string;
+ target: string;
+ value: number;
+ }> = aggregatedLinks.filter(
+ (link) =>
+ finalNodeIdsSet.has(link.source) && finalNodeIdsSet.has(link.target),
+ );
+
+ return {
+ nodes: allNodes,
+ links: finalValidLinks,
+ };
+ }
+}
+
+export const sankeyService = new SankeyService(ch);
diff --git a/packages/db/src/services/share.service.ts b/packages/db/src/services/share.service.ts
index a1149f528..eac8f06f1 100644
--- a/packages/db/src/services/share.service.ts
+++ b/packages/db/src/services/share.service.ts
@@ -1,4 +1,5 @@
import { db } from '../prisma-client';
+import { getProjectAccess } from './access.service';
export function getShareOverviewById(id: string) {
return db.shareOverview.findFirst({
@@ -18,3 +19,197 @@ export function getShareByProjectId(projectId: string) {
},
});
}
+
+// Dashboard sharing functions
+export function getShareDashboardById(id: string) {
+ return db.shareDashboard.findFirst({
+ where: {
+ id,
+ },
+ include: {
+ dashboard: {
+ include: {
+ project: true,
+ },
+ },
+ },
+ });
+}
+
+export function getShareDashboardByDashboardId(dashboardId: string) {
+ return db.shareDashboard.findUnique({
+ where: {
+ dashboardId,
+ },
+ });
+}
+
+// Report sharing functions
+export function getShareReportById(id: string) {
+ return db.shareReport.findFirst({
+ where: {
+ id,
+ },
+ include: {
+ report: {
+ include: {
+ project: true,
+ },
+ },
+ },
+ });
+}
+
+export function getShareReportByReportId(reportId: string) {
+ return db.shareReport.findUnique({
+ where: {
+ reportId,
+ },
+ });
+}
+
+// Validation for secure endpoints
+export async function validateReportAccess(
+ reportId: string,
+ shareId: string,
+ shareType: 'dashboard' | 'report',
+) {
+ if (shareType === 'dashboard') {
+ const share = await db.shareDashboard.findUnique({
+ where: { id: shareId },
+ include: {
+ dashboard: {
+ include: {
+ reports: {
+ where: { id: reportId },
+ },
+ },
+ },
+ },
+ });
+
+ if (!share || !share.public) {
+ throw new Error('Share not found or not public');
+ }
+
+ if (!share.dashboard.reports.some((r) => r.id === reportId)) {
+ throw new Error('Report does not belong to this dashboard');
+ }
+
+ return share;
+ }
+
+ const share = await db.shareReport.findUnique({
+ where: { id: shareId },
+ include: {
+ report: true,
+ },
+ });
+
+ if (!share || !share.public) {
+ throw new Error('Share not found or not public');
+ }
+
+ if (share.reportId !== reportId) {
+ throw new Error('Report ID mismatch');
+ }
+
+ return share;
+}
+
+// Unified validation for share access
+export async function validateShareAccess(
+ shareId: string,
+ reportId: string,
+ ctx: {
+ cookies: Record<string, string | undefined>;
+ session?: { userId?: string | null };
+ },
+): Promise<{ projectId: string; isValid: boolean }> {
+ // Check ShareDashboard first
+ const dashboardShare = await db.shareDashboard.findUnique({
+ where: { id: shareId },
+ include: {
+ dashboard: {
+ include: {
+ reports: {
+ where: { id: reportId },
+ },
+ },
+ },
+ },
+ });
+
+ if (
+ dashboardShare?.dashboard?.reports &&
+ dashboardShare.dashboard.reports.length > 0
+ ) {
+ if (!dashboardShare.public) {
+ throw new Error('Share not found or not public');
+ }
+
+ const projectId = dashboardShare.projectId;
+
+ // If no password is set, share is public and accessible
+ if (!dashboardShare.password) {
+ return {
+ projectId,
+ isValid: true,
+ };
+ }
+
+ // If password is set, require cookie OR member access
+ const hasCookie = !!ctx.cookies[`shared-dashboard-${shareId}`];
+ const hasMemberAccess =
+ ctx.session?.userId &&
+ (await getProjectAccess({
+ userId: ctx.session.userId,
+ projectId,
+ }));
+
+ return {
+ projectId,
+ isValid: hasCookie || !!hasMemberAccess,
+ };
+ }
+
+ // Check ShareReport
+ const reportShare = await db.shareReport.findUnique({
+ where: { id: shareId, reportId },
+ include: {
+ report: true,
+ },
+ });
+
+ if (reportShare) {
+ if (!reportShare.public) {
+ throw new Error('Share not found or not public');
+ }
+
+ const projectId = reportShare.projectId;
+
+ // If no password is set, share is public and accessible
+ if (!reportShare.password) {
+ return {
+ projectId,
+ isValid: true,
+ };
+ }
+
+ // If password is set, require cookie OR member access
+ const hasCookie = !!ctx.cookies[`shared-report-${shareId}`];
+ const hasMemberAccess =
+ ctx.session?.userId &&
+ (await getProjectAccess({
+ userId: ctx.session.userId,
+ projectId,
+ }));
+
+ return {
+ projectId,
+ isValid: hasCookie || !!hasMemberAccess,
+ };
+ }
+
+ throw new Error('Share not found');
+}
diff --git a/packages/db/src/types.ts b/packages/db/src/types.ts
index ee1a915d3..f695e68c6 100644
--- a/packages/db/src/types.ts
+++ b/packages/db/src/types.ts
@@ -3,6 +3,7 @@ import type {
IIntegrationConfig,
INotificationRuleConfig,
IProjectFilters,
+ IWidgetOptions,
InsightPayload,
} from '@openpanel/validation';
import type {
@@ -20,6 +21,7 @@ declare global {
type IPrismaNotificationPayload = INotificationPayload;
type IPrismaProjectFilters = IProjectFilters[];
type IPrismaProjectInsightPayload = InsightPayload;
+ type IPrismaWidgetOptions = IWidgetOptions;
type IPrismaClickhouseEvent = IClickhouseEvent;
type IPrismaClickhouseProfile = IClickhouseProfile;
type IPrismaClickhouseBotEvent = IClickhouseBotEvent;
diff --git a/packages/trpc/src/root.ts b/packages/trpc/src/root.ts
index 517db51b2..88c19045c 100644
--- a/packages/trpc/src/root.ts
+++ b/packages/trpc/src/root.ts
@@ -20,6 +20,7 @@ import { sessionRouter } from './routers/session';
import { shareRouter } from './routers/share';
import { subscriptionRouter } from './routers/subscription';
import { userRouter } from './routers/user';
+import { widgetRouter } from './routers/widget';
import { createTRPCRouter } from './trpc';
/**
* This is the primary router for your server.
@@ -49,6 +50,7 @@ export const appRouter = createTRPCRouter({
realtime: realtimeRouter,
chat: chatRouter,
insight: insightRouter,
+ widget: widgetRouter,
});
// export type definition of API
diff --git a/packages/trpc/src/routers/auth.ts b/packages/trpc/src/routers/auth.ts
index ccfc7f7b3..fa22019ad 100644
--- a/packages/trpc/src/routers/auth.ts
+++ b/packages/trpc/src/routers/auth.ts
@@ -352,8 +352,23 @@ export const authRouter = createTRPCRouter({
)
.input(zSignInShare)
.mutation(async ({ input, ctx }) => {
- const { password, shareId } = input;
- const share = await getShareOverviewById(input.shareId);
+ const { password, shareId, shareType = 'overview' } = input;
+
+ let share: { password: string | null; public: boolean } | null = null;
+ let cookieName = '';
+
+ if (shareType === 'overview') {
+ share = await getShareOverviewById(shareId);
+ cookieName = `shared-overview-${shareId}`;
+ } else if (shareType === 'dashboard') {
+ const { getShareDashboardById } = await import('@openpanel/db');
+ share = await getShareDashboardById(shareId);
+ cookieName = `shared-dashboard-${shareId}`;
+ } else if (shareType === 'report') {
+ const { getShareReportById } = await import('@openpanel/db');
+ share = await getShareReportById(shareId);
+ cookieName = `shared-report-${shareId}`;
+ }
if (!share) {
throw TRPCNotFoundError('Share not found');
@@ -373,7 +388,7 @@ export const authRouter = createTRPCRouter({
throw TRPCAccessError('Incorrect password');
}
- ctx.setCookie(`shared-overview-${shareId}`, '1', {
+ ctx.setCookie(cookieName, '1', {
maxAge: 60 * 60 * 24 * 7,
...COOKIE_OPTIONS,
});
diff --git a/packages/trpc/src/routers/chart.ts b/packages/trpc/src/routers/chart.ts
index 66badb859..dacbb6368 100644
--- a/packages/trpc/src/routers/chart.ts
+++ b/packages/trpc/src/routers/chart.ts
@@ -11,7 +11,6 @@ import {
clix,
conversionService,
createSqlBuilder,
- db,
formatClickhouseDate,
funnelService,
getChartPrevStartEndDate,
@@ -19,15 +18,16 @@ import {
getEventFiltersWhereClause,
getEventMetasCached,
getProfilesCached,
+ getReportById,
getSelectPropertyKey,
getSettingsForProject,
onlyReportEvents,
+ sankeyService,
+ validateShareAccess,
} from '@openpanel/db';
import {
type IChartEvent,
- zChartEvent,
- zChartEventFilter,
- zChartInput,
+ zReportInput,
zChartSeries,
zCriteria,
zRange,
@@ -333,124 +333,342 @@ export const chartRouter = createTRPCRouter({
};
}),
- funnel: protectedProcedure.input(zChartInput).query(async ({ input }) => {
- const { timezone } = await getSettingsForProject(input.projectId);
- const currentPeriod = getChartStartEndDate(input, timezone);
- const previousPeriod = getChartPrevStartEndDate(currentPeriod);
+ funnel: publicProcedure
+ .input(
+ zReportInput.and(
+ z.object({
+ shareId: z.string().optional(),
+ reportId: z.string().optional(),
+ }),
+ ),
+ )
+ .query(async ({ input, ctx }) => {
+ let chartInput = input;
- const [current, previous] = await Promise.all([
- funnelService.getFunnel({ ...input, ...currentPeriod, timezone }),
- input.previous
- ? funnelService.getFunnel({ ...input, ...previousPeriod, timezone })
- : Promise.resolve(null),
- ]);
+ if (input.shareId) {
+ // Require reportId when shareId provided
+ if (!input.reportId) {
+ throw new Error('reportId required with shareId');
+ }
- return {
- current,
- previous,
- };
- }),
+ // Validate share access
+ const shareValidation = await validateShareAccess(
+ input.shareId,
+ input.reportId,
+ {
+ cookies: ctx.cookies,
+ session: ctx.session?.userId
+ ? { userId: ctx.session.userId }
+ : undefined,
+ },
+ );
+ if (!shareValidation.isValid) {
+ throw TRPCAccessError('You do not have access to this share');
+ }
+
+ // Fetch report and merge date overrides
+ const report = await getReportById(input.reportId);
+ if (!report) {
+ throw TRPCAccessError('Report not found');
+ }
+
+ chartInput = {
+ ...report,
+ // Only allow date overrides
+ range: input.range ?? report.range,
+ startDate: input.startDate ?? report.startDate,
+ endDate: input.endDate ?? report.endDate,
+ interval: input.interval ?? report.interval,
+ };
+ } else {
+ // Regular member access check
+ if (!ctx.session?.userId) {
+ throw TRPCAccessError('Authentication required');
+ }
+ const access = await getProjectAccess({
+ projectId: input.projectId,
+ userId: ctx.session.userId,
+ });
+ if (!access) {
+ throw TRPCAccessError('You do not have access to this project');
+ }
+ }
+
+ const { timezone } = await getSettingsForProject(chartInput.projectId);
+ const currentPeriod = getChartStartEndDate(chartInput, timezone);
+ const previousPeriod = getChartPrevStartEndDate(currentPeriod);
- conversion: protectedProcedure.input(zChartInput).query(async ({ input }) => {
+ const [current, previous] = await Promise.all([
+ funnelService.getFunnel({ ...chartInput, ...currentPeriod, timezone }),
+ chartInput.previous
+ ? funnelService.getFunnel({
+ ...chartInput,
+ ...previousPeriod,
+ timezone,
+ })
+ : Promise.resolve(null),
+ ]);
+
+ return {
+ current,
+ previous,
+ };
+ }),
+
+ conversion: publicProcedure
+ .input(
+ zReportInput.and(
+ z.object({
+ shareId: z.string().optional(),
+ reportId: z.string().optional(),
+ }),
+ ),
+ )
+ .query(async ({ input, ctx }) => {
+ let chartInput = input;
+
+ if (input.shareId) {
+ // Require reportId when shareId provided
+ if (!input.reportId) {
+ throw new Error('reportId required with shareId');
+ }
+
+ // Validate share access
+ const shareValidation = await validateShareAccess(
+ input.shareId,
+ input.reportId,
+ {
+ cookies: ctx.cookies,
+ session: ctx.session?.userId
+ ? { userId: ctx.session.userId }
+ : undefined,
+ },
+ );
+ if (!shareValidation.isValid) {
+ throw TRPCAccessError('You do not have access to this share');
+ }
+
+ // Fetch report and merge date overrides
+ const report = await getReportById(input.reportId);
+ if (!report) {
+ throw TRPCAccessError('Report not found');
+ }
+
+ chartInput = {
+ ...report,
+ // Only allow date overrides
+ range: input.range ?? report.range,
+ startDate: input.startDate ?? report.startDate,
+ endDate: input.endDate ?? report.endDate,
+ interval: input.interval ?? report.interval,
+ };
+ } else {
+ // Regular member access check
+ if (!ctx.session?.userId) {
+ throw TRPCAccessError('Authentication required');
+ }
+ const access = await getProjectAccess({
+ projectId: input.projectId,
+ userId: ctx.session.userId,
+ });
+ if (!access) {
+ throw TRPCAccessError('You do not have access to this project');
+ }
+ }
+
+ const { timezone } = await getSettingsForProject(chartInput.projectId);
+ const currentPeriod = getChartStartEndDate(chartInput, timezone);
+ const previousPeriod = getChartPrevStartEndDate(currentPeriod);
+
+ const interval = chartInput.interval;
+
+ const [current, previous] = await Promise.all([
+ conversionService.getConversion({
+ ...chartInput,
+ ...currentPeriod,
+ interval,
+ timezone,
+ }),
+ chartInput.previous
+ ? conversionService.getConversion({
+ ...chartInput,
+ ...previousPeriod,
+ interval,
+ timezone,
+ })
+ : Promise.resolve(null),
+ ]);
+
+ return {
+ current: current.map((serie, sIndex) => ({
+ ...serie,
+ data: serie.data.map((d, dIndex) => ({
+ ...d,
+ previousRate: previous?.[sIndex]?.data?.[dIndex]?.rate,
+ })),
+ })),
+ previous,
+ };
+ }),
+
+ sankey: protectedProcedure.input(zReportInput).query(async ({ input }) => {
const { timezone } = await getSettingsForProject(input.projectId);
const currentPeriod = getChartStartEndDate(input, timezone);
- const previousPeriod = getChartPrevStartEndDate(currentPeriod);
-
- const [current, previous] = await Promise.all([
- conversionService.getConversion({ ...input, ...currentPeriod, timezone }),
- input.previous
- ? conversionService.getConversion({
- ...input,
- ...previousPeriod,
- timezone,
- })
- : Promise.resolve(null),
- ]);
- return {
- current: current.map((serie, sIndex) => ({
- ...serie,
- data: serie.data.map((d, dIndex) => ({
- ...d,
- previousRate: previous?.[sIndex]?.data?.[dIndex]?.rate,
- })),
- })),
- previous,
- };
+ // 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)
+ .input(
+ zReportInput.and(
+ z.object({
+ shareId: z.string().optional(),
+ reportId: z.string().optional(),
+ }),
+ ),
+ )
.query(async ({ input, ctx }) => {
- if (ctx.session.userId) {
+ let chartInput = input;
+
+ if (input.shareId) {
+ // Require reportId when shareId provided
+ if (!input.reportId) {
+ throw new Error('reportId required with shareId');
+ }
+
+ // Validate share access
+ const shareValidation = await validateShareAccess(
+ input.shareId,
+ input.reportId,
+ ctx,
+ );
+
+ if (!shareValidation.isValid) {
+ throw TRPCAccessError('You do not have access to this share');
+ }
+
+ // Fetch report and merge date overrides
+ const report = await getReportById(input.reportId);
+ if (!report) {
+ throw TRPCAccessError('Report not found');
+ }
+
+ chartInput = {
+ ...report,
+ // Only allow date overrides
+ range: input.range ?? report.range,
+ startDate: input.startDate ?? report.startDate,
+ endDate: input.endDate ?? report.endDate,
+ interval: input.interval ?? report.interval,
+ };
+ } else {
+ // Regular member access check
+ if (!ctx.session?.userId) {
+ throw TRPCAccessError('Authentication required');
+ }
const access = await getProjectAccess({
projectId: input.projectId,
userId: ctx.session.userId,
});
if (!access) {
- const share = await db.shareOverview.findFirst({
- where: {
- projectId: input.projectId,
- },
- });
-
- if (!share) {
- throw TRPCAccessError('You do not have access to this project');
- }
- }
- } else {
- const share = await db.shareOverview.findFirst({
- where: {
- projectId: input.projectId,
- },
- });
-
- if (!share) {
throw TRPCAccessError('You do not have access to this project');
}
}
- // Use new chart engine
- return ChartEngine.execute(input);
+ return ChartEngine.execute(chartInput);
}),
aggregate: publicProcedure
- .input(zChartInput)
+ .input(
+ zReportInput.and(
+ z.object({
+ shareId: z.string().optional(),
+ reportId: z.string().optional(),
+ }),
+ ),
+ )
.query(async ({ input, ctx }) => {
- if (ctx.session.userId) {
+ let chartInput = input;
+
+ if (input.shareId) {
+ // Require reportId when shareId provided
+ if (!input.reportId) {
+ throw new Error('reportId required with shareId');
+ }
+
+ // Validate share access
+ const shareValidation = await validateShareAccess(
+ input.shareId,
+ input.reportId,
+ {
+ cookies: ctx.cookies,
+ session: ctx.session?.userId
+ ? { userId: ctx.session.userId }
+ : undefined,
+ },
+ );
+ if (!shareValidation.isValid) {
+ throw TRPCAccessError('You do not have access to this share');
+ }
+
+ // Fetch report and merge date overrides
+ const report = await getReportById(input.reportId);
+ if (!report) {
+ throw TRPCAccessError('Report not found');
+ }
+
+ chartInput = {
+ ...report,
+ // Only allow date overrides
+ range: input.range ?? report.range,
+ startDate: input.startDate ?? report.startDate,
+ endDate: input.endDate ?? report.endDate,
+ interval: input.interval ?? report.interval,
+ };
+ } else {
+ // Regular member access check
+ if (!ctx.session?.userId) {
+ throw TRPCAccessError('Authentication required');
+ }
const access = await getProjectAccess({
projectId: input.projectId,
userId: ctx.session.userId,
});
if (!access) {
- const share = await db.shareOverview.findFirst({
- where: {
- projectId: input.projectId,
- },
- });
-
- if (!share) {
- throw TRPCAccessError('You do not have access to this project');
- }
- }
- } else {
- const share = await db.shareOverview.findFirst({
- where: {
- projectId: input.projectId,
- },
- });
-
- if (!share) {
throw TRPCAccessError('You do not have access to this project');
}
}
- // Use aggregate chart engine (optimized for bar/pie charts)
- return AggregateChartEngine.execute(input);
+ return AggregateChartEngine.execute(chartInput);
}),
- cohort: protectedProcedure
+ cohort: publicProcedure
.input(
z.object({
projectId: z.string(),
@@ -461,26 +679,110 @@ export const chartRouter = createTRPCRouter({
endDate: z.string().nullish(),
interval: zTimeInterval.default('day'),
range: zRange,
+ shareId: z.string().optional(),
+ reportId: z.string().optional(),
}),
)
- .query(async ({ input }) => {
- const { timezone } = await getSettingsForProject(input.projectId);
- const { projectId, firstEvent, secondEvent } = input;
- const dates = getChartStartEndDate(input, timezone);
+ .query(async ({ input, ctx }) => {
+ let projectId = input.projectId;
+ let firstEvent = input.firstEvent;
+ let secondEvent = input.secondEvent;
+ let criteria = input.criteria;
+ let dateRange = input.range;
+ let startDate = input.startDate;
+ let endDate = input.endDate;
+ let interval = input.interval;
+
+ if (input.shareId) {
+ // Require reportId when shareId provided
+ if (!input.reportId) {
+ throw new Error('reportId required with shareId');
+ }
+
+ // Validate share access
+ const shareValidation = await validateShareAccess(
+ input.shareId,
+ input.reportId,
+ {
+ cookies: ctx.cookies,
+ session: ctx.session?.userId
+ ? { userId: ctx.session.userId }
+ : undefined,
+ },
+ );
+ if (!shareValidation.isValid) {
+ throw TRPCAccessError('You do not have access to this share');
+ }
+
+ // Fetch report and extract events
+ const report = await getReportById(input.reportId);
+ if (!report) {
+ throw TRPCAccessError('Report not found');
+ }
+
+ projectId = report.projectId;
+ const retentionOptions = report.options?.type === 'retention' ? report.options : undefined;
+ criteria = retentionOptions?.criteria ?? criteria;
+ dateRange = input.range ?? report.range;
+ startDate = input.startDate ?? report.startDate;
+ endDate = input.endDate ?? report.endDate;
+ interval = input.interval ?? report.interval;
+
+ // Extract events from report series
+ const eventSeries = onlyReportEvents(report.series);
+ const extractedFirstEvent = (
+ eventSeries[0]?.filters?.[0]?.value ?? []
+ ).map(String);
+ const extractedSecondEvent = (
+ eventSeries[1]?.filters?.[0]?.value ?? []
+ ).map(String);
+
+ if (
+ extractedFirstEvent.length === 0 ||
+ extractedSecondEvent.length === 0
+ ) {
+ throw new Error('Report must have at least 2 event series');
+ }
+
+ firstEvent = extractedFirstEvent;
+ secondEvent = extractedSecondEvent;
+ } else {
+ // Regular member access check
+ if (!ctx.session?.userId) {
+ throw TRPCAccessError('Authentication required');
+ }
+ const access = await getProjectAccess({
+ projectId: input.projectId,
+ userId: ctx.session.userId,
+ });
+ if (!access) {
+ throw TRPCAccessError('You do not have access to this project');
+ }
+ }
+
+ const { timezone } = await getSettingsForProject(projectId);
+ const dates = getChartStartEndDate(
+ {
+ range: dateRange,
+ startDate,
+ endDate,
+ },
+ timezone,
+ );
const diffInterval = {
minute: () => differenceInDays(dates.endDate, dates.startDate),
hour: () => differenceInDays(dates.endDate, dates.startDate),
day: () => differenceInDays(dates.endDate, dates.startDate),
week: () => differenceInWeeks(dates.endDate, dates.startDate),
month: () => differenceInMonths(dates.endDate, dates.startDate),
- }[input.interval]();
+ }[interval]();
const sqlInterval = {
minute: 'DAY',
hour: 'DAY',
day: 'DAY',
week: 'WEEK',
month: 'MONTH',
- }[input.interval];
+ }[interval];
const sqlToStartOf = {
minute: 'toDate',
@@ -488,9 +790,9 @@ export const chartRouter = createTRPCRouter({
day: 'toDate',
week: 'toStartOfWeek',
month: 'toStartOfMonth',
- }[input.interval];
+ }[interval];
- const countCriteria = input.criteria === 'on_or_after' ? '>=' : '=';
+ const countCriteria = criteria === 'on_or_after' ? '>=' : '=';
const usersSelect = range(0, diffInterval + 1)
.map(
diff --git a/packages/trpc/src/routers/report.ts b/packages/trpc/src/routers/report.ts
index b17acb8ca..8ca15e882 100644
--- a/packages/trpc/src/routers/report.ts
+++ b/packages/trpc/src/routers/report.ts
@@ -1,7 +1,7 @@
import { z } from 'zod';
import { db, getReportById, getReportsByDashboardId } from '@openpanel/db';
-import { zReportInput } from '@openpanel/validation';
+import { zReport } from '@openpanel/validation';
import { getProjectAccess } from '../access';
import { TRPCAccessError } from '../errors';
@@ -21,7 +21,7 @@ export const reportRouter = createTRPCRouter({
create: protectedProcedure
.input(
z.object({
- report: zReportInput.omit({ projectId: true }),
+ report: zReport.omit({ projectId: true }),
dashboardId: z.string(),
}),
)
@@ -55,10 +55,8 @@ export const reportRouter = createTRPCRouter({
formula: report.formula,
previous: report.previous ?? false,
unit: report.unit,
- criteria: report.criteria,
metric: report.metric === 'count' ? 'sum' : report.metric,
- funnelGroup: report.funnelGroup,
- funnelWindow: report.funnelWindow,
+ options: report.options,
},
});
}),
@@ -66,7 +64,7 @@ export const reportRouter = createTRPCRouter({
.input(
z.object({
reportId: z.string(),
- report: zReportInput.omit({ projectId: true }),
+ report: zReport.omit({ projectId: true }),
}),
)
.mutation(async ({ input: { report, reportId }, ctx }) => {
@@ -100,10 +98,8 @@ export const reportRouter = createTRPCRouter({
formula: report.formula,
previous: report.previous ?? false,
unit: report.unit,
- criteria: report.criteria,
metric: report.metric === 'count' ? 'sum' : report.metric,
- funnelGroup: report.funnelGroup,
- funnelWindow: report.funnelWindow,
+ options: report.options,
},
});
}),
@@ -171,10 +167,8 @@ export const reportRouter = createTRPCRouter({
formula: report.formula,
previous: report.previous,
unit: report.unit,
- criteria: report.criteria,
metric: report.metric,
- funnelGroup: report.funnelGroup,
- funnelWindow: report.funnelWindow,
+ options: report.options,
},
});
}),
diff --git a/packages/trpc/src/routers/share.ts b/packages/trpc/src/routers/share.ts
index 15f9d8b07..92dc9b1b3 100644
--- a/packages/trpc/src/routers/share.ts
+++ b/packages/trpc/src/routers/share.ts
@@ -1,11 +1,23 @@
import ShortUniqueId from 'short-unique-id';
-import { db } from '@openpanel/db';
-import { zShareOverview } from '@openpanel/validation';
+import {
+ db,
+ getReportById,
+ getReportsByDashboardId,
+ getShareDashboardById,
+ getShareReportById,
+ transformReport,
+} from '@openpanel/db';
+import {
+ zShareDashboard,
+ zShareOverview,
+ zShareReport,
+} from '@openpanel/validation';
import { hashPassword } from '@openpanel/auth';
import { z } from 'zod';
-import { TRPCNotFoundError } from '../errors';
+import { getProjectAccess } from '../access';
+import { TRPCAccessError, TRPCNotFoundError } from '../errors';
import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
const uid = new ShortUniqueId({ length: 6 });
@@ -85,4 +97,203 @@ export const shareRouter = createTRPCRouter({
},
});
}),
+
+ // Dashboard sharing
+ dashboard: publicProcedure
+ .input(
+ z
+ .object({
+ dashboardId: z.string(),
+ })
+ .or(
+ z.object({
+ shareId: z.string(),
+ }),
+ ),
+ )
+ .query(async ({ input, ctx }) => {
+ const share = await db.shareDashboard.findUnique({
+ include: {
+ organization: {
+ select: {
+ name: true,
+ },
+ },
+ project: {
+ select: {
+ name: true,
+ },
+ },
+ dashboard: {
+ select: {
+ name: true,
+ },
+ },
+ },
+ where:
+ 'dashboardId' in input
+ ? {
+ dashboardId: input.dashboardId,
+ }
+ : {
+ id: input.shareId,
+ },
+ });
+
+ if (!share) {
+ if ('shareId' in input) {
+ throw TRPCNotFoundError('Dashboard share not found');
+ }
+ return null;
+ }
+
+ return {
+ ...share,
+ hasAccess: !!ctx.cookies[`shared-dashboard-${share?.id}`],
+ };
+ }),
+
+ createDashboard: protectedProcedure
+ .input(zShareDashboard)
+ .mutation(async ({ input, ctx }) => {
+ const access = await getProjectAccess({
+ projectId: input.projectId,
+ userId: ctx.session.userId,
+ });
+
+ if (!access) {
+ throw TRPCAccessError('You do not have access to this project');
+ }
+
+ const passwordHash = input.password
+ ? await hashPassword(input.password)
+ : null;
+
+ return db.shareDashboard.upsert({
+ where: {
+ dashboardId: input.dashboardId,
+ },
+ create: {
+ id: uid.rnd(),
+ organizationId: input.organizationId,
+ projectId: input.projectId,
+ dashboardId: input.dashboardId,
+ public: input.public,
+ password: passwordHash,
+ },
+ update: {
+ public: input.public,
+ password: passwordHash,
+ },
+ });
+ }),
+
+ dashboardReports: publicProcedure
+ .input(
+ z.object({
+ shareId: z.string(),
+ }),
+ )
+ .query(async ({ input, ctx }) => {
+ const share = await getShareDashboardById(input.shareId);
+
+ if (!share || !share.public) {
+ throw TRPCNotFoundError('Dashboard share not found');
+ }
+
+ // Check password access
+ const hasAccess = !!ctx.cookies[`shared-dashboard-${share.id}`];
+ if (share.password && !hasAccess) {
+ throw TRPCAccessError('Password required');
+ }
+
+ return getReportsByDashboardId(share.dashboardId);
+ }),
+
+ // Report sharing
+ report: publicProcedure
+ .input(
+ z
+ .object({
+ reportId: z.string(),
+ })
+ .or(
+ z.object({
+ shareId: z.string(),
+ }),
+ ),
+ )
+ .query(async ({ input, ctx }) => {
+ const share = await db.shareReport.findUnique({
+ include: {
+ organization: {
+ select: {
+ name: true,
+ },
+ },
+ project: {
+ select: {
+ name: true,
+ },
+ },
+ report: true,
+ },
+ where:
+ 'reportId' in input
+ ? {
+ reportId: input.reportId,
+ }
+ : {
+ id: input.shareId,
+ },
+ });
+
+ if (!share) {
+ if ('shareId' in input) {
+ throw TRPCNotFoundError('Report share not found');
+ }
+ return null;
+ }
+
+ return {
+ ...share,
+ hasAccess: !!ctx.cookies[`shared-report-${share?.id}`],
+ report: transformReport(share.report),
+ };
+ }),
+
+ createReport: protectedProcedure
+ .input(zShareReport)
+ .mutation(async ({ input, ctx }) => {
+ const access = await getProjectAccess({
+ projectId: input.projectId,
+ userId: ctx.session.userId,
+ });
+
+ if (!access) {
+ throw TRPCAccessError('You do not have access to this project');
+ }
+
+ const passwordHash = input.password
+ ? await hashPassword(input.password)
+ : null;
+
+ return db.shareReport.upsert({
+ where: {
+ reportId: input.reportId,
+ },
+ create: {
+ id: uid.rnd(),
+ organizationId: input.organizationId,
+ projectId: input.projectId,
+ reportId: input.reportId,
+ public: input.public,
+ password: passwordHash,
+ },
+ update: {
+ public: input.public,
+ password: passwordHash,
+ },
+ });
+ }),
});
diff --git a/packages/trpc/src/routers/widget.ts b/packages/trpc/src/routers/widget.ts
new file mode 100644
index 000000000..ff43a31fa
--- /dev/null
+++ b/packages/trpc/src/routers/widget.ts
@@ -0,0 +1,298 @@
+import ShortUniqueId from 'short-unique-id';
+import { z } from 'zod';
+
+import {
+ TABLE_NAMES,
+ ch,
+ clix,
+ db,
+ eventBuffer,
+ getSettingsForProject,
+} from '@openpanel/db';
+import {
+ zCounterWidgetOptions,
+ zRealtimeWidgetOptions,
+ zWidgetOptions,
+ zWidgetType,
+} from '@openpanel/validation';
+
+import { TRPCNotFoundError } from '../errors';
+import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
+
+const uid = new ShortUniqueId({ length: 6 });
+
+// Helper to find widget by projectId and type
+async function findWidgetByType(projectId: string, type: string) {
+ const widgets = await db.shareWidget.findMany({
+ where: { projectId },
+ });
+ return widgets.find(
+ (w) => (w.options as z.infer<typeof zWidgetOptions>)?.type === type,
+ );
+}
+
+export const widgetRouter = createTRPCRouter({
+ // Get widget by projectId and type (returns null if not found or not public)
+ get: protectedProcedure
+ .input(z.object({ projectId: z.string(), type: zWidgetType }))
+ .query(async ({ input }) => {
+ const widget = await findWidgetByType(input.projectId, input.type);
+
+ if (!widget) {
+ return null;
+ }
+
+ return widget;
+ }),
+
+ // Toggle widget public status (creates if doesn't exist)
+ toggle: protectedProcedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ organizationId: z.string(),
+ type: zWidgetType,
+ enabled: z.boolean(),
+ }),
+ )
+ .mutation(async ({ input }) => {
+ const existing = await findWidgetByType(input.projectId, input.type);
+
+ if (existing) {
+ return db.shareWidget.update({
+ where: { id: existing.id },
+ data: { public: input.enabled },
+ });
+ }
+
+ // Create new widget with default options
+ const defaultOptions =
+ input.type === 'realtime'
+ ? {
+ type: 'realtime' as const,
+ referrers: true,
+ countries: true,
+ paths: false,
+ }
+ : { type: 'counter' as const };
+
+ return db.shareWidget.create({
+ data: {
+ id: uid.rnd(),
+ projectId: input.projectId,
+ organizationId: input.organizationId,
+ public: input.enabled,
+ options: defaultOptions,
+ },
+ });
+ }),
+
+ // Update widget options (for realtime widget)
+ updateOptions: protectedProcedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ organizationId: z.string(),
+ options: zWidgetOptions,
+ }),
+ )
+ .mutation(async ({ input }) => {
+ const existing = await findWidgetByType(
+ input.projectId,
+ input.options.type,
+ );
+
+ if (existing) {
+ return db.shareWidget.update({
+ where: { id: existing.id },
+ data: { options: input.options },
+ });
+ }
+
+ // Create new widget if it doesn't exist
+ return db.shareWidget.create({
+ data: {
+ id: uid.rnd(),
+ projectId: input.projectId,
+ organizationId: input.organizationId,
+ public: false,
+ options: input.options,
+ },
+ });
+ }),
+
+ counter: publicProcedure
+ .input(z.object({ shareId: z.string() }))
+ .query(async ({ input }) => {
+ const widget = await db.shareWidget.findUnique({
+ where: {
+ id: input.shareId,
+ },
+ });
+
+ if (!widget || !widget.public) {
+ throw TRPCNotFoundError('Widget not found');
+ }
+
+ if (widget.options.type !== 'counter') {
+ throw TRPCNotFoundError('Invalid widget type');
+ }
+
+ return {
+ projectId: widget.projectId,
+ counter: await eventBuffer.getActiveVisitorCount(widget.projectId),
+ };
+ }),
+
+ realtimeData: publicProcedure
+ .input(z.object({ shareId: z.string() }))
+ .query(async ({ input }) => {
+ // Validate ShareWidget exists and is public
+ const widget = await db.shareWidget.findUnique({
+ where: {
+ id: input.shareId,
+ },
+ include: {
+ project: {
+ select: {
+ domain: true,
+ name: true,
+ },
+ },
+ },
+ });
+
+ if (!widget || !widget.public) {
+ throw TRPCNotFoundError('Widget not found');
+ }
+
+ const { projectId, options } = widget;
+
+ if (options.type !== 'realtime') {
+ throw TRPCNotFoundError('Invalid widget type');
+ }
+
+ const { timezone } = await getSettingsForProject(projectId);
+
+ // Always fetch live count and histogram
+ const totalSessionsQuery = clix(ch, timezone)
+ .select<{ total_sessions: number }>([
+ 'uniq(session_id) as total_sessions',
+ ])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', '>=', clix.exp('now() - INTERVAL 30 MINUTE'));
+
+ const minuteCountsQuery = clix(ch, timezone)
+ .select<{
+ minute: string;
+ session_count: number;
+ visitor_count: number;
+ }>([
+ `${clix.toStartOf('created_at', 'minute')} as minute`,
+ 'uniq(session_id) as session_count',
+ 'uniq(profile_id) as visitor_count',
+ ])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', '>=', clix.exp('now() - INTERVAL 30 MINUTE'))
+ .groupBy(['minute'])
+ .orderBy('minute', 'ASC')
+ .fill(
+ clix.exp('toStartOfMinute(now() - INTERVAL 30 MINUTE)'),
+ clix.exp('toStartOfMinute(now())'),
+ clix.exp('INTERVAL 1 MINUTE'),
+ );
+
+ // Conditionally fetch countries
+ const countriesQueryPromise = options.countries
+ ? clix(ch, timezone)
+ .select<{
+ country: string;
+ count: number;
+ }>(['country', 'uniq(session_id) as count'])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', '>=', clix.exp('now() - INTERVAL 30 MINUTE'))
+ .where('country', '!=', '')
+ .where('country', 'IS NOT NULL')
+ .groupBy(['country'])
+ .orderBy('count', 'DESC')
+ .limit(10)
+ .execute()
+ : Promise.resolve<Array<{ country: string; count: number }>>([]);
+
+ // Conditionally fetch referrers
+ const referrersQueryPromise = options.referrers
+ ? clix(ch, timezone)
+ .select<{ referrer: string; count: number }>([
+ 'referrer_name as referrer',
+ 'uniq(session_id) as count',
+ ])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', '>=', clix.exp('now() - INTERVAL 30 MINUTE'))
+ .where('referrer_name', '!=', '')
+ .where('referrer_name', 'IS NOT NULL')
+ .groupBy(['referrer_name'])
+ .orderBy('count', 'DESC')
+ .limit(10)
+ .execute()
+ : Promise.resolve<Array<{ referrer: string; count: number }>>([]);
+
+ // Conditionally fetch paths
+ const pathsQueryPromise = options.paths
+ ? clix(ch, timezone)
+ .select<{ path: string; count: number }>([
+ 'path',
+ 'uniq(session_id) as count',
+ ])
+ .from(TABLE_NAMES.events)
+ .where('project_id', '=', projectId)
+ .where('created_at', '>=', clix.exp('now() - INTERVAL 30 MINUTE'))
+ .where('path', '!=', '')
+ .where('path', 'IS NOT NULL')
+ .groupBy(['path'])
+ .orderBy('count', 'DESC')
+ .limit(10)
+ .execute()
+ : Promise.resolve<Array<{ path: string; count: number }>>([]);
+
+ const [totalSessions, minuteCounts, countries, referrers, paths] =
+ await Promise.all([
+ totalSessionsQuery.execute(),
+ minuteCountsQuery.execute(),
+ countriesQueryPromise,
+ referrersQueryPromise,
+ pathsQueryPromise,
+ ]);
+
+ return {
+ projectId,
+ liveCount: totalSessions[0]?.total_sessions || 0,
+ project: widget.project,
+ histogram: minuteCounts.map((item) => ({
+ minute: item.minute,
+ sessionCount: item.session_count,
+ visitorCount: item.visitor_count,
+ timestamp: new Date(item.minute).getTime(),
+ time: new Date(item.minute).toLocaleTimeString([], {
+ hour: '2-digit',
+ minute: '2-digit',
+ }),
+ })),
+ countries: countries.map((item) => ({
+ country: item.country,
+ count: item.count,
+ })),
+ referrers: referrers.map((item) => ({
+ referrer: item.referrer,
+ count: item.count,
+ })),
+ paths: paths.map((item) => ({
+ path: item.path,
+ count: item.count,
+ })),
+ };
+ }),
+});
diff --git a/packages/validation/src/index.ts b/packages/validation/src/index.ts
index 250bf426c..0d7dc1c6f 100644
--- a/packages/validation/src/index.ts
+++ b/packages/validation/src/index.ts
@@ -86,41 +86,12 @@ export const zChartBreakdown = z.object({
name: z.string(),
});
-// Support both old format (array of events without type) and new format (array of event/formula items)
-// Preprocess to normalize: if item has 'type' field, use discriminated union; otherwise, add type: 'event'
-export const zChartSeries = z.preprocess((val) => {
- if (!val) return val;
- let processedVal = val;
-
- // If the input is an object with numeric keys, convert it to an array
- if (typeof val === 'object' && val !== null && !Array.isArray(val)) {
- const keys = Object.keys(val).sort(
- (a, b) => Number.parseInt(a) - Number.parseInt(b),
- );
- processedVal = keys.map((key) => (val as any)[key]);
- }
-
- if (!Array.isArray(processedVal)) return processedVal;
-
- return processedVal.map((item: any) => {
- // If item already has type field, return as-is
- if (item && typeof item === 'object' && 'type' in item) {
- return item;
- }
- // Otherwise, add type: 'event' for backward compatibility
- if (item && typeof item === 'object' && 'name' in item) {
- return { ...item, type: 'event' };
- }
- return item;
- });
-}, z
+export const zChartSeries = z
.array(zChartEventItem)
.describe(
'Array of series (events or formulas) to be tracked and displayed in the chart',
- ));
+ );
-// Keep zChartEvents as an alias for backward compatibility during migration
-export const zChartEvents = zChartSeries;
export const zChartBreakdowns = z.array(zChartBreakdown);
export const zChartType = z.enum(objectToZodEnums(chartTypes));
@@ -135,7 +106,61 @@ export const zRange = z.enum(objectToZodEnums(timeWindows));
export const zCriteria = z.enum(['on_or_after', 'on']);
-export const zChartInputBase = z.object({
+// Report Options - Discriminated union based on chart type
+export const zFunnelOptions = z.object({
+ type: z.literal('funnel'),
+ funnelGroup: z.string().optional(),
+ funnelWindow: z.number().optional(),
+});
+
+export const zRetentionOptions = z.object({
+ type: z.literal('retention'),
+ criteria: zCriteria.optional(),
+});
+
+export const zSankeyOptions = z.object({
+ type: z.literal('sankey'),
+ mode: z.enum(['between', 'after', 'before']),
+ steps: z.number().min(2).max(10).default(5),
+ exclude: z.array(z.string()).default([]),
+ include: z.array(z.string()).optional(),
+});
+
+export const zReportOptions = z.discriminatedUnion('type', [
+ zFunnelOptions,
+ zRetentionOptions,
+ zSankeyOptions,
+]);
+
+export type IReportOptions = z.infer<typeof zReportOptions>;
+export type ISankeyOptions = z.infer<typeof zSankeyOptions>;
+
+export const zWidgetType = z.enum(['realtime', 'counter']);
+export type IWidgetType = z.infer<typeof zWidgetType>;
+
+export const zRealtimeWidgetOptions = z.object({
+ type: z.literal('realtime'),
+ referrers: z.boolean().default(true),
+ countries: z.boolean().default(true),
+ paths: z.boolean().default(false),
+});
+
+export const zCounterWidgetOptions = z.object({
+ type: z.literal('counter'),
+});
+
+export const zWidgetOptions = z.discriminatedUnion('type', [
+ zRealtimeWidgetOptions,
+ zCounterWidgetOptions,
+]);
+
+export type IWidgetOptions = z.infer<typeof zWidgetOptions>;
+export type ICounterWidgetOptions = z.infer<typeof zCounterWidgetOptions>;
+export type IRealtimeWidgetOptions = z.infer<typeof zRealtimeWidgetOptions>;
+
+// Base input schema - for API calls, engine, chart queries
+export const zReportInput = z.object({
+ projectId: z.string().describe('The ID of the project this chart belongs to'),
chartType: zChartType
.default('linear')
.describe('What type of chart should be displayed'),
@@ -153,6 +178,18 @@ export const zChartInputBase = z.object({
range: zRange
.default('30d')
.describe('The time range for which data should be displayed'),
+ startDate: z
+ .string()
+ .nullish()
+ .describe(
+ 'Custom start date for the data range (overrides range if provided)',
+ ),
+ endDate: z
+ .string()
+ .nullish()
+ .describe(
+ 'Custom end date for the data range (overrides range if provided)',
+ ),
previous: z
.boolean()
.default(false)
@@ -166,19 +203,6 @@ export const zChartInputBase = z.object({
.describe(
'The aggregation method for the metric (e.g., sum, count, average)',
),
- projectId: z.string().describe('The ID of the project this chart belongs to'),
- startDate: z
- .string()
- .nullish()
- .describe(
- 'Custom start date for the data range (overrides range if provided)',
- ),
- endDate: z
- .string()
- .nullish()
- .describe(
- 'Custom end date for the data range (overrides range if provided)',
- ),
limit: z
.number()
.optional()
@@ -187,32 +211,14 @@ export const zChartInputBase = z.object({
.number()
.optional()
.describe('Skip how many series should be returned'),
- criteria: zCriteria
+ options: zReportOptions
.optional()
- .describe('Filtering criteria for retention chart (e.g., on_or_after, on)'),
- funnelGroup: z
- .string()
+ .describe('Chart-specific options (funnel, retention, sankey)'),
+ // Optional display fields
+ name: z.string().optional().describe('The user-defined name for the report'),
+ lineType: zLineType
.optional()
- .describe(
- 'Group identifier for funnel analysis, e.g. "profile_id" or "session_id"',
- ),
- funnelWindow: z
- .number()
- .optional()
- .describe('Time window in hours for funnel analysis'),
-});
-
-export const zChartInput = z.preprocess((val) => {
- if (val && typeof val === 'object' && 'events' in val && !('series' in val)) {
- // Migrate old 'events' field to 'series'
- return { ...val, series: val.events };
- }
- return val;
-}, zChartInputBase);
-
-export const zReportInput = zChartInputBase.extend({
- name: z.string().describe('The user-defined name for the report'),
- lineType: zLineType.describe('The visual style of the line in the chart'),
+ .describe('The visual style of the line in the chart'),
unit: z
.string()
.optional()
@@ -221,17 +227,19 @@ export const zReportInput = zChartInputBase.extend({
),
});
-export const zChartInputAI = zReportInput
- .omit({
- startDate: true,
- endDate: true,
- lineType: true,
- unit: true,
- })
- .extend({
- startDate: z.string().describe('The start date for the report'),
- endDate: z.string().describe('The end date for the report'),
- });
+// Complete report schema - for saved reports
+export const zReport = zReportInput.extend({
+ name: z
+ .string()
+ .default('Untitled')
+ .describe('The user-defined name for the report'),
+ lineType: zLineType
+ .default('monotone')
+ .describe('The visual style of the line in the chart'),
+});
+
+// Alias for backward compatibility
+export const zChartInput = zReportInput;
export const zInviteUser = z.object({
email: z.string().email(),
@@ -247,6 +255,22 @@ export const zShareOverview = z.object({
public: z.boolean(),
});
+export const zShareDashboard = z.object({
+ organizationId: z.string(),
+ projectId: z.string(),
+ dashboardId: z.string(),
+ password: z.string().nullable(),
+ public: z.boolean(),
+});
+
+export const zShareReport = z.object({
+ organizationId: z.string(),
+ projectId: z.string(),
+ reportId: z.string(),
+ password: z.string().nullable(),
+ public: z.boolean(),
+});
+
export const zCreateReference = z.object({
title: z.string(),
description: z.string().nullish(),
@@ -486,6 +510,10 @@ export type IRequestResetPassword = z.infer<typeof zRequestResetPassword>;
export const zSignInShare = z.object({
password: z.string().min(1),
shareId: z.string().min(1),
+ shareType: z
+ .enum(['overview', 'dashboard', 'report'])
+ .optional()
+ .default('overview'),
});
export type ISignInShare = z.infer<typeof zSignInShare>;
diff --git a/packages/validation/src/test.ts b/packages/validation/src/test.ts
deleted file mode 100644
index 34d3fbc6b..000000000
--- a/packages/validation/src/test.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { zChartEvents } from '.';
-
-const events = [
- {
- id: 'sAmT',
- type: 'event',
- name: 'session_end',
- segment: 'event',
- filters: [],
- },
- {
- id: '5K2v',
- type: 'event',
- name: 'session_start',
- segment: 'event',
- filters: [],
- },
- {
- id: 'lQiQ',
- type: 'formula',
- formula: 'A/B',
- displayName: '',
- },
-];
-
-const res = zChartEvents.safeParse(events);
-
-console.log(res);
diff --git a/packages/validation/src/types.validation.ts b/packages/validation/src/types.validation.ts
index 38a134188..920e10daa 100644
--- a/packages/validation/src/types.validation.ts
+++ b/packages/validation/src/types.validation.ts
@@ -10,26 +10,28 @@ import type {
zChartEventItem,
zChartEventSegment,
zChartFormula,
- zChartInput,
- zChartInputAI,
zChartSeries,
zChartType,
zCriteria,
zLineType,
zMetric,
zRange,
+ zReport,
zReportInput,
zTimeInterval,
} from './index';
-export type IChartInput = z.infer<typeof zChartInput>;
-export type IChartInputAi = z.infer<typeof zChartInputAI>;
-export type IChartProps = z.infer<typeof zReportInput> & {
- name: string;
- lineType: IChartLineType;
- unit?: string;
- previousIndicatorInverted?: boolean;
-};
+// For saved reports - complete report with required display fields
+export type IReport = z.infer<typeof zReport>;
+
+// For API/engine use - flexible input
+export type IReportInput = z.infer<typeof zReportInput>;
+
+// With resolved dates (engine internal)
+export interface IReportInputWithDates extends IReportInput {
+ startDate: string;
+ endDate: string;
+}
export type IChartEvent = z.infer<typeof zChartEvent>;
export type IChartFormula = z.infer<typeof zChartFormula>;
export type IChartEventItem = z.infer<typeof zChartEventItem>;
@@ -48,16 +50,12 @@ export type IChartType = z.infer<typeof zChartType>;
export type IChartMetric = z.infer<typeof zMetric>;
export type IChartLineType = z.infer<typeof zLineType>;
export type IChartRange = z.infer<typeof zRange>;
-export interface IChartInputWithDates extends IChartInput {
- startDate: string;
- endDate: string;
-}
export type IGetChartDataInput = {
event: IChartEvent;
projectId: string;
startDate: string;
endDate: string;
-} & Omit<IChartInput, 'series' | 'name' | 'startDate' | 'endDate' | 'range'>;
+} & Omit<IReportInput, 'series' | 'startDate' | 'endDate' | 'range'>;
export type ICriteria = z.infer<typeof zCriteria>;
export type PreviousValue =
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0d300ac34..e3106017d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -33,6 +33,7 @@ catalogs:
overrides:
rolldown: 1.0.0-beta.43
+ esm-env: npm:esm-env-runtime@^0.1.0
patchedDependencies:
nuqs:
@@ -417,8 +418,8 @@ importers:
specifier: ^0.99.0
'@number-flow/react':
- specifier: 0.3.5
+ specifier: 0.5.10
'@openpanel/common':
specifier: workspace:^
version: link:../../packages/common
@@ -784,8 +785,8 @@ importers:
specifier: 1.9.4
version: 1.9.4
'@cloudflare/vite-plugin':
- specifier: ^1.13.12
+ specifier: 1.20.3
'@openpanel/db':
specifier: workspace:*
version: link:../../packages/db
@@ -847,8 +848,8 @@ importers:
specifier: ^4.2.4
version: 4.2.4
wrangler:
- specifier: ^4.42.2
- version: 4.42.2
+ specifier: 4.59.1
+ version: 4.59.1
apps/worker:
dependencies:
@@ -2843,47 +2844,51 @@ packages:
resolution: {integrity: sha512-+tv3z+SPp+gqTIcImN9o0hqE9xyfQjI1XD9pL6NuKjua9B1y7mNYv0S9cP+QEbA4ppVgGZEmKOvHX5G5Ei1CVA==}
engines: {node: '>=18.0.0'}
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-HtZuh166y0Olbj9bqqySckz0Rw9uHjggJeoGbDx5x+sgezBXlxO6tQSig2RZw5tgObF8mWI8zaPvQMkQZtAODw==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-Nu8ahitGFFJztxUml9oD/DLb7Z28C8cd8F46IVQ7y5Btz575pvMY8AqZsXkX7Gds29eCKdMgIHjIvzskHgPSFg==}
+ engines: {node: '>=18.0.0'}
+
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-99nEvuOTCGGGRNaIat8UVVXJ27aZK+U09SYDp0kVjQLwC9wyxcrQ28IqLwrQq2DjWLmBI1+UalGJzdPqYgPlRw==}
peerDependencies:
- unenv: 2.0.0-rc.21
- workerd: ^1.20250927.0
+ unenv: 2.0.0-rc.24
+ workerd: ^1.20251202.0
peerDependenciesMeta:
workerd:
optional: true
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-JEcrUF1uXxMQfp+RcGw7ov5K8uOGX0arFYdyO3QfHrjWspHnsw0zOYL+4083itEInRVnZjS5LunpsNpxSVbCEw==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-o6ePNfGpu2AKCi7bs32fOl121qFvdyi2fSblF6xID7aHFosqEfZAgCUaJ86LvXJWcPeUl+B0sFII67N5st1rBg==}
peerDependencies:
vite: ^6.1.0 || ^7.0.0
- wrangler: ^4.42.2
+ wrangler: ^4.59.1
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-yph0H+8mMOK5Z9oDwjb8rI96oTVt4no5lZ43aorcbzsWG9VUIaXSXlBBoB3von6p4YCRW+J3n36fBM9XZ6TLaA==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-UGAjrGLev2/CMLZy7b+v1NIXA4Hupc/QJBFlJwMqldywMcJ/iEqvuUYYuVI2wZXuXeWkgmgFP87oFDQsg78YTQ==}
engines: {node: '>=16'}
cpu: [x64]
os: [darwin]
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-Yc4lMGSbM4AEtYRpyDpmk77MsHb6X2BSwJgMgGsLVPmckM7ZHivZkJChfcNQjZ/MGR6nkhYc4iF6TcVS+UMEVw==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-YFAZwidLCQVa6rKCCaiWrhA+eh87a7MUhyd9lat3KSbLBAGpYM+ORpyTXpi2Gjm3j6Mp1e/wtzcFTSeMIy2UqA==}
engines: {node: '>=16'}
cpu: [arm64]
os: [darwin]
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-AjoQnylw4/5G6SmfhZRsli7EuIK7ZMhmbxtU0jkpciTlVV8H01OsFOgS1d8zaTXMfkWamEfMouy8oH/L7B9YcQ==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-zx1GW6FwfOBjCV7QUCRzGRkViUtn3Is/zaaVPmm57xyy9sjtInx6/SdeBr2Y45tx9AnOP1CnaOFFdmH1P7VIEg==}
engines: {node: '>=16'}
cpu: [x64]
os: [linux]
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-hRy9yyvzVq1HsqHZUmFkAr0C8JGjAD/PeeVEGCKL3jln3M9sNCKIrbDXiL+efe+EwajJNNlDxpO+s30uVWVaRg==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-wFVKxNvCyjRaAcgiSnJNJAmIos3p3Vv6Uhf4pFUZ9JIxr69GNlLWlm9SdCPvtwNFAjzSoDaKzDwjj5xqpuCS6Q==}
engines: {node: '>=16'}
cpu: [arm64]
os: [linux]
- '@cloudflare/[email protected]':
- resolution: {integrity: sha512-Gm0RR+ehfNMsScn2pUcn3N9PDUpy7FyvV9ecHEyclKttvztyFOcmsF14bxEaSVv7iM4TxWEBn1rclmYHxDM4ow==}
+ '@cloudflare/[email protected]':
+ resolution: {integrity: sha512-zWgd77L7OI1BxgBbG+2gybDahIMgPX5iNo6e3LqcEz1Xm3KfiqgnDyMBcxeQ7xDrj7fHUGAlc//QnKvDchuUoQ==}
engines: {node: '>=16'}
cpu: [x64]
os: [win32]
@@ -3018,12 +3023,6 @@ packages:
cpu: [ppc64]
os: [aix]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q==}
- engines: {node: '>=18'}
- cpu: [ppc64]
- os: [aix]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==}
engines: {node: '>=18'}
@@ -3072,12 +3071,6 @@ packages:
cpu: [arm64]
os: [android]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-bBy69pgfhMGtCnwpC/x5QhfxAz/cBgQ9enbtwjf6V9lnPI/hMyT9iWpR1arm0l3kttTr4L0KSLpKmLp/ilKS9A==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [android]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==}
engines: {node: '>=18'}
@@ -3126,12 +3119,6 @@ packages:
cpu: [arm]
os: [android]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-QNdQEps7DfFwE3hXiU4BZeOV68HHzYwGd0Nthhd3uCkkEKK7/R6MTgM0P7H7FAs5pU/DIWsviMmEGxEoxIZ+ZQ==}
- engines: {node: '>=18'}
- cpu: [arm]
- os: [android]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==}
engines: {node: '>=18'}
@@ -3180,12 +3167,6 @@ packages:
cpu: [x64]
os: [android]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-TVhdVtQIFuVpIIR282btcGC2oGQoSfZfmBdTip2anCaVYcqWlZXGcdcKIUklfX2wj0JklNYgz39OBqh2cqXvcQ==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [android]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw==}
engines: {node: '>=18'}
@@ -3234,12 +3215,6 @@ packages:
cpu: [arm64]
os: [darwin]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-Y1giCfM4nlHDWEfSckMzeWNdQS31BQGs9/rouw6Ub91tkK79aIMTH3q9xHvzH8d0wDru5Ci0kWB8b3up/nl16g==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [darwin]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg==}
engines: {node: '>=18'}
@@ -3288,12 +3263,6 @@ packages:
cpu: [x64]
os: [darwin]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-CJsry8ZGM5VFVeyUYB3cdKpd/H69PYez4eJh1W/t38vzutdjEjtP7hB6eLKBoOdxcAlCtEYHzQ/PJ/oU9I4u0A==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [darwin]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ==}
engines: {node: '>=18'}
@@ -3342,12 +3311,6 @@ packages:
cpu: [arm64]
os: [freebsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-yYq+39NlTRzU2XmoPW4l5Ifpl9fqSk0nAJYM/V/WUGPEFfek1epLHJIkTQM6bBs1swApjO5nWgvr843g6TjxuQ==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [freebsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q==}
engines: {node: '>=18'}
@@ -3396,12 +3359,6 @@ packages:
cpu: [x64]
os: [freebsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-0FgvOJ6UUMflsHSPLzdfDnnBBVoCDtBTVyn/MrWloUNvq/5SFmh13l3dvgRPkDihRxb77Y17MbqbCAa2strMQQ==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [freebsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg==}
engines: {node: '>=18'}
@@ -3450,12 +3407,6 @@ packages:
cpu: [arm64]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-+89UsQTfXdmjIvZS6nUnOOLoXnkUTB9hR5QAeLrQdzOSWZvNSAXAtcRDHWtqAUtAmv7ZM1WPOOeSxDzzzMogiQ==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw==}
engines: {node: '>=18'}
@@ -3504,12 +3455,6 @@ packages:
cpu: [arm]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-kro4c0P85GMfFYqW4TWOpvmF8rFShbWGnrLqlzp4X1TNWjRY3JMYUfDCtOxPKOIY8B0WC8HN51hGP4I4hz4AaQ==}
- engines: {node: '>=18'}
- cpu: [arm]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw==}
engines: {node: '>=18'}
@@ -3558,12 +3503,6 @@ packages:
cpu: [ia32]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-yTEjoapy8UP3rv8dB0ip3AfMpRbyhSN3+hY8mo/i4QXFeDxmiYbEKp3ZRjBKcOP862Ua4b1PDfwlvbuwY7hIGQ==}
- engines: {node: '>=18'}
- cpu: [ia32]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A==}
engines: {node: '>=18'}
@@ -3612,12 +3551,6 @@ packages:
cpu: [loong64]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-NeqqYkrcGzFwi6CGRGNMOjWGGSYOpqwCjS9fvaUlX5s3zwOtn1qwg1s2iE2svBe4Q/YOG1q6875lcAoQK/F4VA==}
- engines: {node: '>=18'}
- cpu: [loong64]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ==}
engines: {node: '>=18'}
@@ -3666,12 +3599,6 @@ packages:
cpu: [mips64el]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-IcvTlF9dtLrfL/M8WgNI/qJYBENP3ekgsHbYUIzEzq5XJzzVEV/fXY9WFPfEEXmu3ck2qJP8LG/p3Q8f7Zc2Xg==}
- engines: {node: '>=18'}
- cpu: [mips64el]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA==}
engines: {node: '>=18'}
@@ -3720,12 +3647,6 @@ packages:
cpu: [ppc64]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-HOy0aLTJTVtoTeGZh4HSXaO6M95qu4k5lJcH4gxv56iaycfz1S8GO/5Jh6X4Y1YiI0h7cRyLi+HixMR+88swag==}
- engines: {node: '>=18'}
- cpu: [ppc64]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w==}
engines: {node: '>=18'}
@@ -3774,12 +3695,6 @@ packages:
cpu: [riscv64]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-i8JUDAufpz9jOzo4yIShCTcXzS07vEgWzyX3NH2G7LEFVgrLEhjwL3ajFE4fZI3I4ZgiM7JH3GQ7ReObROvSUA==}
- engines: {node: '>=18'}
- cpu: [riscv64]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg==}
engines: {node: '>=18'}
@@ -3828,12 +3743,6 @@ packages:
cpu: [s390x]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-jFnu+6UbLlzIjPQpWCNh5QtrcNfMLjgIavnwPQAfoGx4q17ocOU9MsQ2QVvFxwQoWpZT8DvTLooTvmOQXkO51g==}
- engines: {node: '>=18'}
- cpu: [s390x]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA==}
engines: {node: '>=18'}
@@ -3882,12 +3791,6 @@ packages:
cpu: [x64]
os: [linux]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-6e0cvXwzOnVWJHq+mskP8DNSrKBr1bULBvnFLpc1KY+d+irZSgZ02TGse5FsafKS5jg2e4pbvK6TPXaF/A6+CA==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [linux]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg==}
engines: {node: '>=18'}
@@ -3918,12 +3821,6 @@ packages:
cpu: [arm64]
os: [netbsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-vUnkBYxZW4hL/ie91hSqaSNjulOnYXE1VSLusnvHg2u3jewJBz3YzB9+oCw8DABeVqZGg94t9tyZFoHma8gWZQ==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [netbsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q==}
engines: {node: '>=18'}
@@ -3972,12 +3869,6 @@ packages:
cpu: [x64]
os: [netbsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-XAg8pIQn5CzhOB8odIcAm42QsOfa98SBeKUdo4xa8OvX8LbMZqEtgeWE9P/Wxt7MlG2QqvjGths+nq48TrUiKw==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [netbsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g==}
engines: {node: '>=18'}
@@ -4008,12 +3899,6 @@ packages:
cpu: [arm64]
os: [openbsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-Ct2WcFEANlFDtp1nVAXSNBPDxyU+j7+tId//iHXU2f/lN5AmO4zLyhDcpR5Cz1r08mVxzt3Jpyt4PmXQ1O6+7A==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [openbsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ==}
engines: {node: '>=18'}
@@ -4062,12 +3947,6 @@ packages:
cpu: [x64]
os: [openbsd]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-xAGGhyOQ9Otm1Xu8NT1ifGLnA6M3sJxZ6ixylb+vIUVzvvd6GOALpwQrYrtlPouMqd/vSbgehz6HaVk4+7Afhw==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [openbsd]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA==}
engines: {node: '>=18'}
@@ -4140,12 +4019,6 @@ packages:
cpu: [x64]
os: [sunos]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-Mw+tzy4pp6wZEK0+Lwr76pWLjrtjmJyUB23tHKqEDP74R3q95luY/bXqXZeYl4NYlvwOqoRKlInQialgCKy67Q==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [sunos]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw==}
engines: {node: '>=18'}
@@ -4194,12 +4067,6 @@ packages:
cpu: [arm64]
os: [win32]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-AVUP428VQTSddguz9dO9ngb+E5aScyg7nOeJDrF1HPYu555gmza3bDGMPhmVXL8svDSoqPCsCPjb265yG/kLKQ==}
- engines: {node: '>=18'}
- cpu: [arm64]
- os: [win32]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ==}
engines: {node: '>=18'}
@@ -4248,12 +4115,6 @@ packages:
cpu: [ia32]
os: [win32]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-i1sW+1i+oWvQzSgfRcxxG2k4I9n3O9NRqy8U+uugaT2Dy7kLO9Y7wI72haOahxceMX8hZAzgGou1FhndRldxRg==}
- engines: {node: '>=18'}
- cpu: [ia32]
- os: [win32]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww==}
engines: {node: '>=18'}
@@ -4302,12 +4163,6 @@ packages:
cpu: [x64]
os: [win32]
- '@esbuild/[email protected]':
- resolution: {integrity: sha512-nOT2vZNw6hJ+z43oP1SPea/G/6AbN6X+bGNhNuq8NtRHy4wsMhw765IKLNmnjek7GvjWBYQ8Q5VBoYTFg9y1UQ==}
- engines: {node: '>=18'}
- cpu: [x64]
- os: [win32]
-
'@esbuild/[email protected]':
resolution: {integrity: sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ==}
engines: {node: '>=18'}
@@ -4829,9 +4684,6 @@ packages:
'@jridgewell/[email protected]':
resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==}
- '@jridgewell/[email protected]':
- resolution: {integrity: sha512-Wf963MzWtA2sjrNt+g18IAln9lKnlRp+K2eH4jjIoF1wYeq3aMREpG09xhlhdzS0EjwU7qmUJYangWa+151vZw==}
-
'@jridgewell/[email protected]':
resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==}
@@ -5209,12 +5061,6 @@ packages:
engines: {node: '>=10'}
deprecated: This functionality has been moved to @npmcli/fs
- '@number-flow/[email protected]':
- resolution: {integrity: sha512-jkN4hqdYVbmxlEHD8sPF98f3AmQ3wGhHRJHYfgX9p9TsO3UyEky687qX8HSnTsk0ja6ZULzuHTA8MWoWqqTOQA==}
- peerDependencies:
- react: ^18 || ^19.0.0-rc-915b914b3a-20240515
- react-dom: ^18
-
'@number-flow/[email protected]':
resolution: {integrity: sha512-a8Wh5eNITn7Km4xbddAH7QH8eNmnduR6k34ER1hkHSGO4H2yU1DDnuAWLQM99vciGInFODemSc0tdxrXkJEpbA==}
peerDependencies:
@@ -11474,11 +11320,6 @@ packages:
engines: {node: '>=18'}
hasBin: true
- resolution: {integrity: sha512-8pgjLUcUjcgDg+2Q4NYXnPbo/vncAY4UmyaCm0jZevERqCHZIaWwdJHkf8XQtu4AxSKCdvrUbT0XUr1IdZzI8Q==}
- engines: {node: '>=18'}
- hasBin: true
-
resolution: {integrity: sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==}
engines: {node: '>=18'}
@@ -11520,8 +11361,9 @@ packages:
resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==}
engines: {node: '>=12'}
- resolution: {integrity: sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA==}
+ resolution: {integrity: sha512-s5c/JKEF8faaXr3y1O9IZljnVO4FXFvmxB+/dGAKWUQF2nyjsoALGN5MCNu4ZLbAVLmtNFwU0fwb8FExIRwWmw==}
+ engines: {pnpm: ^9.0.0}
resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==}
@@ -13929,8 +13771,8 @@ packages:
resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==}
engines: {node: '>=12'}
- resolution: {integrity: sha512-sKCNYNzXG6l8qg0Oo7y8WcDKcpbgw0qwZsxNpdZilFTR4EavRow2TlcwuPSVN99jqAjhz0M4VXvTdSGdtJ2VfQ==}
+ resolution: {integrity: sha512-pUsbDlumPaTzliA+J9HMAM74nLR8wqpCQNOESximab51jAfvL7ZaP5Npzh4PWNV0Jfq28tlqazakuJcw6w5qlA==}
engines: {node: '>=18.0.0'}
hasBin: true
@@ -14355,9 +14197,6 @@ packages:
resolution: {integrity: sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==}
- resolution: {integrity: sha512-BpNMhQnRAHOFbi0giD+dMnDoaPibVW22Vl2CWfZZIlpgTtixmbPm+Cv7a7F7FrEc/dTOECMS/T8V5rltIGI0tw==}
-
resolution: {integrity: sha512-FPr1DumWyGi5Nucoug14bC6xEz70A1TnhgSHhKyfqjgji2SOTz+iLJxKtv37N5JyJbteGYCm6NQ9p1O4KZ7iiA==}
@@ -18102,17 +17941,17 @@ packages:
resolution: {integrity: sha512-U0IUQHKXXn6PFo9nqsHphVCE5m3IntqZNB9Jjn7EB1lrR7YTDY3YWgFvEvwniTzXSvOH/XMzAZaIfJF/LvHYXg==}
- resolution: {integrity: sha512-HwaJmXO3M1r4S8x2ea2vy8Rw/y/38HRQuK/gNDRQ7w9cJXn6xSl1sIIqKCffULSUjul3wV3I3Nd/GfbmsRReEA==}
+ resolution: {integrity: sha512-ov6Pt4k6d/ALfJja/EIHohT9IrY/f6GAa0arWEPat2qekp78xHbVM7jSxNWAMbaE7ZmnQQIFEGD1ZhAWZmQKIg==}
engines: {node: '>=16'}
hasBin: true
- resolution: {integrity: sha512-1iTnbjB4F12KSP1zbfxQL495xarS+vdrZnulQP2SEcAxDTUGn7N9zk1O2WtFOc+Fhcgl+9/sdz/4AL9pF34Pwg==}
- engines: {node: '>=18.0.0'}
+ resolution: {integrity: sha512-5DddGSNxHd6dOjREWTDQdovQlZ1Lh80NNRXZFQ4/CrK3fNyVIBj9tqCs9pmXMNrKQ/AnKNeYzEs/l1kr8rHhOg==}
+ engines: {node: '>=20.0.0'}
hasBin: true
peerDependencies:
- '@cloudflare/workers-types': ^4.20251008.0
+ '@cloudflare/workers-types': ^4.20260111.0
peerDependenciesMeta:
'@cloudflare/workers-types':
optional: true
@@ -18348,9 +18187,6 @@ packages:
typescript: ^4.9.4 || ^5.0.2
zod: ^3
- resolution: {integrity: sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==}
-
resolution: {integrity: sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==}
@@ -19972,42 +19808,47 @@ snapshots:
dependencies:
mime: 3.0.0
+ '@cloudflare/[email protected]':
dependencies:
- unenv: 2.0.0-rc.21
+ mime: 3.0.0
+
+ dependencies:
+ unenv: 2.0.0-rc.24
optionalDependencies:
- workerd: 1.20251008.0
+ workerd: 1.20260111.0
dependencies:
- '@cloudflare/unenv-preset': 2.7.7([email protected])([email protected])
+ '@cloudflare/unenv-preset': 2.9.0([email protected])([email protected])
'@remix-run/node-fetch-server': 0.8.1
+ defu: 6.1.4
get-port: 7.1.0
- miniflare: 4.20251008.0
+ miniflare: 4.20260111.0
picocolors: 1.1.1
- tinyglobby: 0.2.14
- unenv: 2.0.0-rc.21
+ tinyglobby: 0.2.15
+ unenv: 2.0.0-rc.24
- wrangler: 4.42.2
+ wrangler: 4.59.1
ws: 8.18.0
transitivePeerDependencies:
- bufferutil
- utf-8-validate
- workerd
- '@cloudflare/[email protected]':
+ '@cloudflare/[email protected]':
optional: true
- '@cloudflare/[email protected]':
+ '@cloudflare/[email protected]':
optional: true
- '@cloudflare/[email protected]':
+ '@cloudflare/[email protected]':
optional: true
- '@cloudflare/[email protected]':
+ '@cloudflare/[email protected]':
optional: true
- '@cloudflare/[email protected]':
+ '@cloudflare/[email protected]':
optional: true
'@colors/[email protected]': {}
@@ -20147,9 +19988,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20174,9 +20012,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20201,9 +20036,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20228,9 +20060,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20255,9 +20084,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20282,9 +20108,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20309,9 +20132,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20336,9 +20156,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20363,9 +20180,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20390,9 +20204,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20417,9 +20228,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20444,9 +20252,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20471,9 +20276,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20498,9 +20300,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20525,9 +20324,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20552,9 +20348,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20579,9 +20372,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20597,9 +20387,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20624,9 +20411,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20642,9 +20426,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20669,9 +20450,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20708,9 +20486,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20735,9 +20510,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20762,9 +20534,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -20789,9 +20558,6 @@ snapshots:
'@esbuild/[email protected]':
optional: true
- '@esbuild/[email protected]':
- optional: true
-
'@esbuild/[email protected]':
optional: true
@@ -21280,8 +21046,7 @@ snapshots:
- encoding
- supports-color
- optional: true
+ '@img/[email protected]': {}
optionalDependencies:
@@ -21521,7 +21286,7 @@ snapshots:
dependencies:
'@jridgewell/set-array': 1.1.2
'@jridgewell/sourcemap-codec': 1.5.5
- '@jridgewell/trace-mapping': 0.3.22
+ '@jridgewell/trace-mapping': 0.3.30
'@jridgewell/[email protected]':
dependencies:
@@ -21549,11 +21314,6 @@ snapshots:
'@jridgewell/[email protected]': {}
- '@jridgewell/[email protected]':
- dependencies:
- '@jridgewell/resolve-uri': 3.1.2
- '@jridgewell/sourcemap-codec': 1.5.5
-
'@jridgewell/[email protected]':
dependencies:
'@jridgewell/resolve-uri': 3.1.2
@@ -21944,16 +21704,9 @@ snapshots:
mkdirp: 1.0.4
rimraf: 3.0.2
- dependencies:
- esm-env: 1.2.2
- number-flow: 0.3.10
- react: 19.2.3
- react-dom: 19.2.3([email protected])
-
dependencies:
- esm-env: 1.2.2
number-flow: 0.5.8
react: 19.2.3
react-dom: 19.2.3([email protected])
@@ -29540,34 +29293,6 @@ snapshots:
'@esbuild/win32-ia32': 0.25.3
'@esbuild/win32-x64': 0.25.3
- optionalDependencies:
- '@esbuild/aix-ppc64': 0.25.4
- '@esbuild/android-arm': 0.25.4
- '@esbuild/android-arm64': 0.25.4
- '@esbuild/android-x64': 0.25.4
- '@esbuild/darwin-arm64': 0.25.4
- '@esbuild/darwin-x64': 0.25.4
- '@esbuild/freebsd-arm64': 0.25.4
- '@esbuild/freebsd-x64': 0.25.4
- '@esbuild/linux-arm': 0.25.4
- '@esbuild/linux-arm64': 0.25.4
- '@esbuild/linux-ia32': 0.25.4
- '@esbuild/linux-loong64': 0.25.4
- '@esbuild/linux-mips64el': 0.25.4
- '@esbuild/linux-ppc64': 0.25.4
- '@esbuild/linux-riscv64': 0.25.4
- '@esbuild/linux-s390x': 0.25.4
- '@esbuild/linux-x64': 0.25.4
- '@esbuild/netbsd-arm64': 0.25.4
- '@esbuild/netbsd-x64': 0.25.4
- '@esbuild/openbsd-arm64': 0.25.4
- '@esbuild/openbsd-x64': 0.25.4
- '@esbuild/sunos-x64': 0.25.4
- '@esbuild/win32-arm64': 0.25.4
- '@esbuild/win32-ia32': 0.25.4
- '@esbuild/win32-x64': 0.25.4
-
optionalDependencies:
'@esbuild/aix-ppc64': 0.25.9
@@ -29669,7 +29394,7 @@ snapshots:
@@ -32834,20 +32559,20 @@ snapshots:
dependencies:
'@cspotcode/source-map-support': 0.8.1
acorn: 8.14.0
acorn-walk: 8.3.2
exit-hook: 2.2.1
glob-to-regexp: 0.4.1
- sharp: 0.33.5
+ sharp: 0.34.5
stoppable: 1.1.0
undici: 7.14.0
- workerd: 1.20251008.0
+ workerd: 1.20260111.0
ws: 8.18.0
youch: 4.1.0-beta.10
- zod: 3.22.3
+ zod: 3.25.76
transitivePeerDependencies:
- bufferutil
- utf-8-validate
@@ -33322,7 +33047,7 @@ snapshots:
untyped: 2.0.0
unwasm: 0.3.11
- youch: 4.1.0-beta.11
+ youch: 4.1.0-beta.13
youch-core: 0.3.3
transitivePeerDependencies:
- '@azure/app-configuration'
@@ -33445,13 +33170,9 @@ snapshots:
- dependencies:
- esm-env: 1.2.2
-
dependencies:
- esm-env: 1.2.2
dependencies:
@@ -35789,7 +35510,6 @@ snapshots:
'@img/sharp-win32-arm64': 0.34.5
'@img/sharp-win32-ia32': 0.34.5
'@img/sharp-win32-x64': 0.34.5
- optional: true
dependencies:
@@ -37678,24 +37398,24 @@ snapshots:
optionalDependencies:
- '@cloudflare/workerd-darwin-64': 1.20251008.0
- '@cloudflare/workerd-darwin-arm64': 1.20251008.0
- '@cloudflare/workerd-linux-64': 1.20251008.0
- '@cloudflare/workerd-linux-arm64': 1.20251008.0
- '@cloudflare/workerd-windows-64': 1.20251008.0
+ '@cloudflare/workerd-darwin-64': 1.20260111.0
+ '@cloudflare/workerd-darwin-arm64': 1.20260111.0
+ '@cloudflare/workerd-linux-64': 1.20260111.0
+ '@cloudflare/workerd-linux-arm64': 1.20260111.0
+ '@cloudflare/workerd-windows-64': 1.20260111.0
dependencies:
- '@cloudflare/kv-asset-handler': 0.4.0
- '@cloudflare/unenv-preset': 2.7.7([email protected])([email protected])
+ '@cloudflare/kv-asset-handler': 0.4.1
+ '@cloudflare/unenv-preset': 2.9.0([email protected])([email protected])
blake3-wasm: 2.1.5
- esbuild: 0.25.4
- miniflare: 4.20251008.0
+ esbuild: 0.27.0
+ miniflare: 4.20260111.0
path-to-regexp: 6.3.0
- unenv: 2.0.0-rc.21
- workerd: 1.20251008.0
+ unenv: 2.0.0-rc.24
+ workerd: 1.20260111.0
optionalDependencies:
fsevents: 2.3.3
transitivePeerDependencies:
@@ -37860,8 +37580,8 @@ snapshots:
dependencies:
'@poppinss/colors': 4.1.5
- '@poppinss/dumper': 0.6.4
- '@speed-highlight/core': 1.2.7
+ '@poppinss/dumper': 0.6.5
+ '@speed-highlight/core': 1.2.12
cookie: 1.0.2
youch-core: 0.3.3
@@ -37923,8 +37643,6 @@ snapshots:
typescript: 5.9.3
zod: 3.25.76
-
diff --git a/vitest.workspace.ts b/vitest.workspace.ts
index 779844e4f..1809144db 100644
--- a/vitest.workspace.ts
+++ b/vitest.workspace.ts
@@ -1 +1 @@
-export default ['packages/*', 'apps/*'];
+export default ['packages/*', 'apps/*', '!apps/start'];