Skip to content

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

fix: five issues the verification pass confirmed are still real

Carl-Gerhard Lindesvärdcd489afbc22e
diff --git a/apps/start/src/components/ui/combobox-advanced.tsx b/apps/start/src/components/ui/combobox-advanced.tsx
index 238328a75..e20e945d4 100644
--- a/apps/start/src/components/ui/combobox-advanced.tsx
+++ b/apps/start/src/components/ui/combobox-advanced.tsx
@@ -81,15 +81,7 @@ export function ComboboxAdvanced({
};
const data = React.useMemo(() => {
- return [
- ...(inputValue === ''
- ? []
- : [
- {
- value: inputValue,
- label: `Pick '${inputValue}'`,
- },
- ]),
+ const known = [
...value.map((val) => {
const item = items.find((item) => item.value === val);
return item
@@ -98,7 +90,18 @@ export function ComboboxAdvanced({
}),
...selectables,
].filter((item) => item.value);
- }, [inputValue, selectables, items]);
+
+ // The "Pick '…'" entry is only offered for a value that is not already in
+ // the list. Offering it for an exact match gave two rows the same `value`,
+ // which is the list's React key, and the duplicate made the real row
+ // unselectable.
+ const isNewValue =
+ inputValue !== '' && !known.some((item) => item.value === inputValue);
+
+ return isNewValue
+ ? [{ value: inputValue, label: `Pick '${inputValue}'` }, ...known]
+ : known;
+ }, [inputValue, selectables, items, value]);
const trigger = children ?? (
<Button autoHeight className={className} size={size} variant={'outline'}>
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 5b2d8885d..5bdb71231 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
@@ -304,6 +304,7 @@ function Component() {
<LinkButton
from={Route.fullPath}
icon={PlusIcon}
+ search={{ dashboardId }}
to={'/$organizationId/$projectId/reports'}
>
<span className="max-sm:hidden">Create report</span>
@@ -369,6 +370,7 @@ function Component() {
className="mt-14"
from={Route.fullPath}
icon={PlusIcon}
+ search={{ dashboardId }}
to={'/$organizationId/$projectId/reports'}
>
Create report
diff --git a/packages/core/src/modules/export/export.routes.ts b/packages/core/src/modules/export/export.routes.ts
index 0d05a3a0b..7c20febe1 100644
--- a/packages/core/src/modules/export/export.routes.ts
+++ b/packages/core/src/modules/export/export.routes.ts
@@ -169,6 +169,20 @@ const zExportCharts = zReport
events: z.array(zExportChartSeriesItem).optional(),
});
+/**
+ * An unparseable `start`/`end` is treated as absent, not as an Invalid Date.
+ * `new Date('garbage')` survives construction and only throws when something
+ * downstream formats it, which surfaced as a 500 carrying a raw RangeError on
+ * a documented public endpoint.
+ */
+function parseDateParam(value: string | undefined): Date | undefined {
+ if (!value) {
+ return undefined;
+ }
+ const parsed = new Date(value);
+ return Number.isNaN(parsed.getTime()) ? undefined : parsed;
+}
+
export const exportRoutes = defineRoutes((app) =>
app
// Query-string coercion, LOCAL to this surface (see http/query.ts).
@@ -199,8 +213,8 @@ export const exportRoutes = defineRoutes((app) =>
events: (Array.isArray(event) ? event : [event]).filter(
(s): s is string => typeof s === 'string'
),
- startDate: start ? new Date(start) : undefined,
- endDate: end ? new Date(end) : undefined,
+ startDate: parseDateParam(start),
+ endDate: parseDateParam(end),
cursor,
take,
profileId,
diff --git a/packages/core/src/modules/notification/notification.rpc.ts b/packages/core/src/modules/notification/notification.rpc.ts
index c18570c4f..1498465d3 100644
--- a/packages/core/src/modules/notification/notification.rpc.ts
+++ b/packages/core/src/modules/notification/notification.rpc.ts
@@ -40,9 +40,6 @@ export const notificationRouter = createTRPCRouter({
.mutation(async ({ input, ctx }) => {
const userId = ctx.session.userId;
- // Clear the cache for the project
- await getNotificationRulesByProjectId.clear(ctx, input.projectId);
-
await ctx.services.auth.requireProjectAccess({
userId,
projectId: input.projectId,
@@ -58,7 +55,11 @@ export const notificationRouter = createTRPCRouter({
});
}
- return createOrUpdateNotificationRule(ctx, input);
+ const rule = await createOrUpdateNotificationRule(ctx, input);
+ // After the write, not before: the cache is what session-end reads to
+ // decide which rules fire, so it is stale only once the row has changed.
+ await getNotificationRulesByProjectId.clear(ctx, input.projectId);
+ return rule;
}),
deleteRule: protectedProcedure
@@ -73,6 +74,8 @@ export const notificationRouter = createTRPCRouter({
level: 'write',
});
- return deleteNotificationRule(ctx, input.id);
+ const deleted = await deleteNotificationRule(ctx, input.id);
+ await getNotificationRulesByProjectId.clear(ctx, rule.projectId);
+ return deleted;
}),
});
diff --git a/packages/core/src/modules/subscription/subscription.service.ts b/packages/core/src/modules/subscription/subscription.service.ts
index 35ad283d3..b00ae6ca1 100644
--- a/packages/core/src/modules/subscription/subscription.service.ts
+++ b/packages/core/src/modules/subscription/subscription.service.ts
@@ -163,9 +163,22 @@ export async function getUsage(deps: ServiceDeps, organizationId: string) {
organization.subscriptionStartsAt &&
organization.subscriptionEndsAt
) {
+ // The CURRENT billing period, not the whole subscription term. The usage
+ // counter this chart sits beside resets each period, and
+ // `subscriptionStartsAt` is overwritten with each period start on renewal,
+ // so one interval from it is the period the counter belongs to. A term
+ // running years out — a seeded org, or a long commitment — would otherwise
+ // bucket thousands of days and repeat week numbers along the axis.
+ const periodEnd = addMonths(
+ organization.subscriptionStartsAt,
+ organization.subscriptionInterval === 'year' ? 12 : 1
+ );
return getOrganizationBillingEventsCountSerieCached(deps, organization, {
startDate: organization.subscriptionStartsAt,
- endDate: organization.subscriptionEndsAt,
+ endDate:
+ periodEnd < organization.subscriptionEndsAt
+ ? periodEnd
+ : organization.subscriptionEndsAt,
});
}