Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import {
} from "@/components/ui/tooltip";
import { isDevMode } from "@/lib/dev-mode";
import type { ChartTransformResult } from "@/lib/metrics/transformer-types";
import type { DashboardChartWithRelations } from "@/types/dashboard";
import { type RouterOutputs } from "@/trpc/react";

import { useDashboard } from "./dashboard-context";
import { DashboardMetricChart } from "./dashboard-metric-chart";
import { MetricSettingsDrawer } from "./metric-settings-drawer";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

interface DashboardMetricCardProps {
dashboardChart: DashboardChartWithRelations;
teamId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Loader2 } from "lucide-react";
import { getLatestMetricValue } from "@/lib/metrics/get-latest-value";
import type { ChartTransformResult } from "@/lib/metrics/transformer-types";
import { cn } from "@/lib/utils";
import { api } from "@/trpc/react";
import { type RouterOutputs, api } from "@/trpc/react";

import { useDashboard } from "./dashboard-context";
import { DashboardMetricChart } from "./dashboard-metric-chart";
Expand All @@ -20,6 +20,9 @@ import {
SettingsTabContent,
} from "./drawer";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

interface DashboardMetricDrawerProps {
dashboardChartId: string;
teamId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ import {
import type { ChartTransformResult } from "@/lib/metrics/transformer-types";
import { getPlatformConfig } from "@/lib/platform-config";
import { cn } from "@/lib/utils";
import type { DashboardChartWithRelations } from "@/types/dashboard";
import { type RouterOutputs } from "@/trpc/react";

import { useDashboard } from "./dashboard-context";
import { DashboardMetricDrawer } from "./dashboard-metric-drawer";
import { useMetricDrawerMutations } from "./use-metric-drawer-mutations";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

interface MetricSettingsDrawerProps {
dashboardChart: DashboardChartWithRelations;
teamId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import { useCallback } from "react";

import { api } from "@/trpc/react";
import type { DashboardChartWithRelations } from "@/types/dashboard";
import { type RouterOutputs, api } from "@/trpc/react";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

export interface UseDashboardChartsReturn {
charts: DashboardChartWithRelations[];
Expand Down
6 changes: 4 additions & 2 deletions src/app/metric/_components/base/MetricDialogBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
DialogTrigger,
} from "@/components/ui/dialog";
import { cn } from "@/lib/utils";
import { api } from "@/trpc/react";
import type { DashboardChartWithRelations } from "@/types/dashboard";
import { type RouterOutputs, api } from "@/trpc/react";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

export interface MetricCreateInput {
templateId: string;
Expand Down
6 changes: 4 additions & 2 deletions src/app/metric/_components/manual/ManualMetricContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import { api } from "@/trpc/react";
import type { DashboardChartWithRelations } from "@/types/dashboard";
import { type RouterOutputs, api } from "@/trpc/react";

import { type PeriodRange, PeriodRangeStep } from "./period-range-step";

type DashboardChartWithRelations =
RouterOutputs["dashboard"]["getDashboardCharts"][number];

type UnitType = "number" | "percentage";
type Cadence = "daily" | "weekly" | "monthly";

Expand Down
8 changes: 6 additions & 2 deletions src/lib/goals/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export type Cadence = "DAILY" | "WEEKLY" | "MONTHLY";
export type GoalType = "ABSOLUTE" | "RELATIVE";
import { Cadence, GoalType } from "@prisma/client";

// Re-export Prisma enums for convenience
export { Cadence, GoalType };

// Custom status type (not in Prisma)
export type GoalStatus =
| "exceeded"
| "on_track"
Expand Down
11 changes: 6 additions & 5 deletions src/lib/metrics/transformer-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
* Types for AI-generated transformer code
* Used by both MetricTransformer and ChartTransformer
*/
import { Cadence } from "@prisma/client";

import type { ChartType } from "./utils";

// Re-export ChartType for convenience
export type { ChartType } from "./utils";

// Re-export Prisma enum for convenience
export { Cadence };

// =============================================================================
// Data Point Types
// =============================================================================
Expand Down Expand Up @@ -83,14 +88,10 @@ export type MetricTransformFn = (
context: TransformContext,
) => DataPoint[];

/**
* Cadence determines how data is aggregated for chart display
*/
export type Cadence = "DAILY" | "WEEKLY" | "MONTHLY";

/**
* Function signature for ChartTransformer code
* Transforms DataPoints into chart-ready configuration
* Cadence is re-exported from Prisma above
*/
export type ChartTransformFn = (
dataPoints: DataPoint[],
Expand Down
2 changes: 2 additions & 0 deletions src/server/api/utils/enrich-charts-with-goal-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type { ChartTransformResult } from "@/lib/metrics/transformer-types";

/**
* Dashboard chart with metric and chartTransformer included
* NOTE: This type must be manually defined here to avoid circular dependency.
* Cannot use tRPC RouterOutputs because AppRouter depends on this util file.
Comment on lines +13 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n src/server/api/utils/enrich-charts-with-goal-progress.ts

Repository: drifter089/orgOS

Length of output: 6454


🏁 Script executed:

# Search for getDashboardCharts router definition
rg -n "getDashboardCharts" --type=ts -A 10 src/server/api/routers/

Repository: drifter089/orgOS

Length of output: 974


🏁 Script executed:

# Look for the RouterOutputs type to understand tRPC output structure
rg -n "RouterOutputs" --type=ts src/server/

Repository: drifter089/orgOS

Length of output: 197


🏁 Script executed:

cat -n src/server/api/routers/dashboard.ts | head -150

Repository: drifter089/orgOS

Length of output: 5765


🏁 Script executed:

# Search for the complete getDashboardCharts definition and its return type
rg -n "getDashboardCharts" -A 50 src/server/api/routers/dashboard.ts | head -100

Repository: drifter089/orgOS

Length of output: 1847


🏁 Script executed:

# Search for usages of getDashboardCharts in client components
rg -n "getDashboardCharts" --type=ts --type=tsx src/app/ | head -20

Repository: drifter089/orgOS

Length of output: 87


🏁 Script executed:

# Check enrichChartsWithGoalProgress usage to see what fields are actually accessed
rg -n "enrichChartsWithGoalProgress" -B 2 -A 5 src/

Repository: drifter089/orgOS

Length of output: 3914


🏁 Script executed:

# Look at enrichChartRolesWithUserNames to see what it adds to the type
cat -n src/server/api/utils/organization-members.ts | grep -A 30 "enrichChartRolesWithUserNames"

Repository: drifter089/orgOS

Length of output: 1915


🏁 Script executed:

# Check if there are any TypeScript compilation errors in these files
rg -n "type DashboardChart" --type=ts src/server/api/

Repository: drifter089/orgOS

Length of output: 156


🏁 Script executed:

# Verify the function is being used correctly and all required fields are present
cat -n src/server/api/utils/organization-members.ts | sed -n '196,220p'

Repository: drifter089/orgOS

Length of output: 826


🏁 Script executed:

# Check how enrichChartRolesWithUserNames is called and what it receives
cat -n src/server/api/routers/dashboard.ts | sed -n '95,106p'

Repository: drifter089/orgOS

Length of output: 528


🏁 Script executed:

# Search for any type mismatch issues or related tests
find src -name "*.test.ts" -o -name "*.spec.ts" | xargs grep -l "enrichChartsWithGoalProgress" 2>/dev/null

Repository: drifter089/orgOS

Length of output: 44


🏁 Script executed:

# Check the Prisma schema for DashboardChart and related models
rg -n "model DashboardChart" -A 20 prisma/schema.prisma

Repository: drifter089/orgOS

Length of output: 960


🏁 Script executed:

# Check if there are any recent changes or related issues
rg -n "DashboardChartWithRelations" --type=ts src/

Repository: drifter089/orgOS

Length of output: 1644


🏁 Script executed:

# Compare the type definitions in different files
for file in "src/server/api/utils/enrich-charts-with-goal-progress.ts" "src/app/metric/_components/manual/ManualMetricContent.tsx" "src/app/dashboard/\[teamId\]/_components/use-dashboard-charts.ts"; do
  echo "=== $file ==="
  rg -A 15 "type DashboardChartWithRelations" "$file"
done

Repository: drifter089/orgOS

Length of output: 1087


🏁 Script executed:

# Check if client-side code is using data from the server endpoint
rg -n "getDashboardCharts" src/app/ -B 2 -A 5 | head -50

Repository: drifter089/orgOS

Length of output: 4145


🏁 Script executed:

# Check the AppRouter to see what RouterOutputs would infer
rg -n "export const appRouter" -A 20 src/server/api/root.ts

Repository: drifter089/orgOS

Length of output: 672


🏁 Script executed:

# Verify that the manual type is actually missing fields by checking what fields are accessed
rg -n "metric\." src/server/api/utils/enrich-charts-with-goal-progress.ts

Repository: drifter089/orgOS

Length of output: 652


🏁 Script executed:

# Check for metric.roles access in related code
rg -n "\.metric\.roles" src/server/api/ src/app/

Repository: drifter089/orgOS

Length of output: 380


🏁 Script executed:

# Check the generic constraint of enrichChartRolesWithUserNames
rg -B 2 -A 8 "enrichChartRolesWithUserNames<" src/server/api/utils/organization-members.ts

Repository: drifter089/orgOS

Length of output: 434


🏁 Script executed:

# Verify what the actual Prisma query returns for metric.roles
cat -n src/server/api/routers/dashboard.ts | sed -n '76,93p'

Repository: drifter089/orgOS

Length of output: 614


Type drift risk exists but is partially mitigated by the index signature.

The manual DashboardChartWithRelations type only documents fields required by enrichChartsWithGoalProgress (metric.id, metric.goal, chartTransformer.cadence, chartTransformer.selectedDimension). However, enrichChartRolesWithUserNames requires metric.roles which isn't declared in this type. While the [key: string]: unknown index signature masks this gap, it creates an implicit contract: if the Prisma query in getDashboardCharts changes, there's no type-level verification that all downstream functions still receive their required fields.

Consider documenting the required fields in a comment listing which properties the Prisma query must include, or extract a shared schema-driven type to eliminate the manual maintenance burden.

🤖 Prompt for AI Agents
In @src/server/api/utils/enrich-charts-with-goal-progress.ts around lines 13-14,
The custom type DashboardChartWithRelations used by enrichChartsWithGoalProgress
is underspecified: it documents
metric.id/metric.goal/chartTransformer.cadence/chartTransformer.selectedDimension
but omits metric.roles required by enrichChartRolesWithUserNames, and the
current [key: string]: unknown` index signature hides this mismatch; update the
types so the Prisma shape is explicit—either expand DashboardChartWithRelations
to include metric.roles (and any other fields consumed downstream) or extract a
shared schema-driven type used by getDashboardCharts,
enrichChartsWithGoalProgress, and enrichChartRolesWithUserNames; additionally
add a short comment listing the exact Prisma selection fields required so future
changes to getDashboardCharts surface type errors rather than being masked by
the index signature.

*/
type DashboardChartWithRelations = {
id: string;
Expand Down
4 changes: 0 additions & 4 deletions src/types/dashboard.ts

This file was deleted.