Skip to content

fix: domains count and date time selection text#4001

Merged
chronark merged 4 commits intomainfrom
fix-domains-count
Sep 24, 2025
Merged

fix: domains count and date time selection text#4001
chronark merged 4 commits intomainfrom
fix-domains-count

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Sep 19, 2025

What does this PR do?

This PR only fetches last 3 domain from domains table and reverts dateTime component's selection text.
Fixes # (issue)

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Make a deploy a couple of times make sure you only see last 3
  • DeploymentsList default time selection should be "Select Time Range"

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features
    • Default time range label now shows “Select Time Range” when no time filter is applied.
    • Button styling more clearly indicates an unselected time range.
    • Title updates dynamically as filters change, resetting to “Select Time Range” if no time-related filters are present.
    • Domains view now loads domains only for the active deployment, so domain lists reflect the current deployment.

@changeset-bot
Copy link

changeset-bot bot commented Sep 19, 2025

⚠️ No Changeset found

Latest commit: 30c52c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Sep 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
dashboard Ready Ready Preview Comment Sep 19, 2025 1:16pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
engineering Ignored Ignored Preview Sep 19, 2025 1:16pm

@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

Thank you for following the naming conventions for pull request titles! 🙏

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

📝 Walkthrough

Walkthrough

Replaces the hardcoded "Last 12 hours" default in the deployment time-range UI with an internal TITLE_EMPTY_DEFAULT = "Select Time Range", changes the effect to react to filters (resetting title when no time filters exist), scopes domains queries to a project's live deployment, and adds a nullable deploymentId to the Domain schema and listDomains output.

Changes

Cohort / File(s) Summary
Deployment List Datetime UI
apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx
Adds TITLE_EMPTY_DEFAULT = "Select Time Range", initializes title with it, changes effect dependency from title to filters, resets title when no time-related filter is present, and updates button label/styling checks to compare against the new default.
Project page — domains query scoped to deployment
apps/dashboard/app/(app)/projects/[projectId]/page.tsx
Replaces an unconditional domains query with a project-scoped useLiveQuery(...where(domain.deploymentId, project?.liveDeploymentId)) and adds the dependency so domains load only for the active deployment.
Domain schema & API output
apps/dashboard/lib/collections/deploy/domains.ts
apps/dashboard/lib/trpc/routers/deploy/domains/list.ts
Adds deploymentId: z.string().nullable() to the Domain schema (exported Domain type now includes `string

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as DeploymentListDatetime UI
  participant Filters as Filters Store/Props
  participant State as Local Title State

  Note over UI,Filters: On mount / when filters change
  Filters->>UI: emit filters[]
  UI->>State: evaluate filters for time-related entries
  alt time filter(s) present
    UI->>State: build timeValues (startTime/endTime/since) and set title accordingly
  else no time filter present
    UI->>State: set title to "Select Time Range"
  end
  State-->>UI: updated title -> UI re-renders button label/style
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Bug

Suggested reviewers

  • mcstepp
  • perkinsjr
  • chronark

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes the required sections and basic testing steps but contains a factual mismatch and omissions: it states the PR "fetches last 3 domain" while the diff shows domains are being filtered by project.liveDeploymentId and the Domain schema/trpc were updated to include deploymentId, and the description also omits a concrete "Fixes #" reference. Several template items (type-of-change selection and contributor checklist) are left unchecked which reduces reviewer clarity. Because of the inaccurate claim about domains and the missing issue reference, the description does not meet the template requirements. Update the PR description to accurately reflect the implemented changes (mention addition of deploymentId to the Domain schema, that listDomains now returns deploymentId, and that page.tsx filters domains by project.liveDeploymentId) and correct or remove the "last 3 domains" claim; add a proper "Fixes #" line or explain why none exists. Complete the "Type of change" selection and relevant checklist items or note why they are intentionally unchecked, and expand the "How should this be tested?" steps to include verifying domain filtering by deploymentId as well as the deployments list default label. After these edits the description should satisfy the repository template and be clear for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix: domains count and date time selection text" succinctly captures the two primary areas changed in the PR (domain-related behavior and the deployments datetime label) and is directly related to the provided changeset. It is concise and readable for a reviewer scanning history, though it is slightly ambiguous about whether domains are being limited to the "last three" or scoped by deploymentId. Overall the title accurately highlights the main intent of the changes.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-domains-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx (1)

79-82: Replace remaining "Last 12 hours" literals with the shared constant and stop using string-equality checks.

Update usages to reference the constant in apps/dashboard/components/logs/datetime/constants.ts (instead of comparing against the display string).

  • apps/dashboard/components/logs/datetime/constants.ts:49
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/controls/components/logs-datetime/index.tsx:14, 77
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-datetime/index.tsx:14, 77
  • apps/dashboard/app/(app)/ratelimits/_components/controls/components/namespace-list-datetime/index.tsx:14, 77
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/components/controls/components/logs-datetime/index.tsx:15, 81
  • apps/dashboard/app/(app)/logs/components/controls/components/logs-datetime/index.tsx:14, 77
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-datetime/index.tsx:15, 81
  • apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx:81
  • apps/dashboard/app/(app)/audit/components/controls/components/logs-datetime/index.tsx:14, 77
  • apps/dashboard/app/(app)/apis/_components/controls/components/logs-datetime/index.tsx:14, 77
🧹 Nitpick comments (6)
apps/dashboard/lib/trpc/routers/deploy/domains/list.ts (2)

22-24: Deterministic “last 3” with tie‑breaker

If multiple domains share the same createdAt, ordering can be unstable. Add a secondary sort (e.g., id) to keep results deterministic.

-        orderBy: (table, { desc }) => desc(table.createdAt),
+        orderBy: (table, { desc }) => [desc(table.createdAt), desc(table.id)],

22-24: Consider composite index for this query pattern

Filter by (workspaceId, projectId) and order by createdAt DESC is a perfect fit for a composite index to keep this LIMIT 3 query fast at scale.

Example (SQL; adjust names to your schema/migration tool):

CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_domains_ws_proj_createdat
  ON domains (workspace_id, project_id, created_at DESC);
apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx (4)

79-82: Update styling logic to new default label

The class toggle still references "Last 12 hours", so the button appears active even on the new default. Tie styles to TITLE_EMPTY_DEFAULT.

-            "group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
-            title ? "" : "opacity-50",
-            title !== "Last 12 hours" ? "bg-gray-4" : "",
+            "group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
+            title === TITLE_EMPTY_DEFAULT ? "opacity-50" : "",
+            title && title !== TITLE_EMPTY_DEFAULT ? "bg-gray-4" : "",

10-10: Narrow state type; title no longer null

Since the initial value is non-null and you always set strings, simplify the state type.

-  const [title, setTitle] = useState<string | null>(TITLE_EMPTY_DEFAULT);
+  const [title, setTitle] = useState<string>(TITLE_EMPTY_DEFAULT);

14-20: Simplify effect and avoid early returns

Use Array.some for clarity and to make intent explicit.

-    for (const filter of filters) {
-      if (["startTime", "endTime", "since"].includes(filter.field)) {
-        return;
-      }
-    }
-    setTitle(TITLE_EMPTY_DEFAULT);
+    const hasTime = filters.some((f) =>
+      ["startTime", "endTime", "since"].includes(f.field),
+    );
+    if (!hasTime) setTitle(TITLE_EMPTY_DEFAULT);

71-71: Remove unreachable fallback

With non-null title, the nullish coalesce is unnecessary.

-      initialTitle={title ?? ""}
+      initialTitle={title}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c87b938 and 6fbf615.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/deploy/domains/list.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-25T19:09:43.284Z
Learnt from: mcstepp
PR: unkeyed/unkey#3662
File: apps/dashboard/lib/trpc/routers/deployment/list.ts:11-11
Timestamp: 2025-07-25T19:09:43.284Z
Learning: In apps/dashboard/lib/trpc/routers/deployment/list.ts, the listDeployments procedure intentionally queries the versions table rather than a deployments table. The user mcstepp indicated that renaming the table would require a database migration, which was deferred for the current PR focused on UI features.

Applied to files:

  • apps/dashboard/lib/trpc/routers/deploy/domains/list.ts
🧬 Code graph analysis (1)
apps/dashboard/app/(app)/projects/[projectId]/deployments/components/controls/components/deployment-list-datetime/index.tsx (1)
apps/dashboard/app/(app)/projects/[projectId]/deployments/hooks/use-filters.ts (1)
  • useFilters (33-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: Vade Review
  • GitHub Check: Analyze (javascript-typescript)

Copy link
Collaborator

don’t revert it
fix it

those are 2 separate things

Copy link
Collaborator

show me all domains, where domain.deploymentId == project.liveDeploymentId

@ogzhanolguncu
Copy link
Contributor Author

shouldn't we suppose to show all the domains related to that deployment anyway which includes liveDeployentId?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
apps/dashboard/lib/trpc/routers/deploy/domains/list.ts (3)

16-22: Return shape LGTM; consider server-side filtering by live deployment.

Selecting deploymentId is good. To reduce payload and align with the “show domains for the live deployment” guidance, accept an optional deploymentId in the input and include it in the where clause when provided.

Apply this diff within the shown range to add the conditional filter:

       columns: {
         id: true,
         domain: true,
         projectId: true,
-        deploymentId: true,
+        deploymentId: true,
         type: true,
       },

And outside this hunk, update the input and where (example):

// change input
.input(z.object({ projectId: z.string(), deploymentId: z.string().optional() }))

// change where
.where((table, { eq, and }) =>
  input.deploymentId
    ? and(
        eq(table.workspaceId, ctx.workspace.id),
        eq(table.projectId, input.projectId),
        eq(table.deploymentId, input.deploymentId),
      )
    : and(eq(table.workspaceId, ctx.workspace.id), eq(table.projectId, input.projectId)),
)

24-31: Prefer structured error context.

Add minimal context (workspaceId, projectId) to the log to aid debugging; keep user-facing message unchanged.

- .catch((error) => {
-   console.error("Error querying domains:", error);
+ .catch((error) => {
+   console.error("Error querying domains", {
+     error,
+     workspaceId: ctx.workspace.id,
+     projectId: input.projectId,
+   });

16-22: Add DB index on deployment_id for anticipated filter.

If we start filtering by deploymentId, add an index to avoid full scans on large domain sets.

apps/dashboard/app/(app)/projects/[projectId]/page.tsx (2)

21-27: Guard against undefined in equality filter.

When project?.liveDeploymentId is undefined, passing it to eq() may yield no matches or throw depending on the query builder. Safer to short‑circuit to an empty result until the ID is known.

-  const domains = useLiveQuery(
-    (q) =>
-      q
-        .from({ domain: collections.domains })
-        .where(({ domain }) => eq(domain.deploymentId, project?.liveDeploymentId)),
-    [project?.liveDeploymentId],
-  );
+  const liveDeploymentId = project?.liveDeploymentId;
+  const domains = useLiveQuery(
+    (q) =>
+      liveDeploymentId
+        ? q.from({ domain: collections.domains }).where(({ domain }) => eq(domain.deploymentId, liveDeploymentId))
+        : q.from({ domain: collections.domains }).where(() => false),
+    [liveDeploymentId],
+  );

If where(() => false) isn’t supported in your query builder, render an empty state when !liveDeploymentId and skip the query.


63-66: Optional: empty state for no domains.

If there’s no live deployment or no matching domains, show an Empty state instead of a blank list for better UX.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94957db and 30c52c4.

📒 Files selected for processing (3)
  • apps/dashboard/app/(app)/projects/[projectId]/page.tsx (1 hunks)
  • apps/dashboard/lib/collections/deploy/domains.ts (1 hunks)
  • apps/dashboard/lib/trpc/routers/deploy/domains/list.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-25T19:09:43.284Z
Learnt from: mcstepp
PR: unkeyed/unkey#3662
File: apps/dashboard/lib/trpc/routers/deployment/list.ts:11-11
Timestamp: 2025-07-25T19:09:43.284Z
Learning: In apps/dashboard/lib/trpc/routers/deployment/list.ts, the listDeployments procedure intentionally queries the versions table rather than a deployments table. The user mcstepp indicated that renaming the table would require a database migration, which was deferred for the current PR focused on UI features.

Applied to files:

  • apps/dashboard/lib/trpc/routers/deploy/domains/list.ts
🧬 Code graph analysis (1)
apps/dashboard/app/(app)/projects/[projectId]/page.tsx (1)
internal/db/src/schema/domains.ts (1)
  • domains (4-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Vade Review
🔇 Additional comments (1)
apps/dashboard/lib/collections/deploy/domains.ts (1)

7-13: Schema update LGTM; aligns with DB.

deploymentId: z.string().nullable() matches the DB column being nullable. No further changes needed here.

@chronark chronark merged commit 770e92a into main Sep 24, 2025
18 checks passed
@chronark chronark deleted the fix-domains-count branch September 24, 2025 08:42
github-merge-queue bot pushed a commit that referenced this pull request Sep 25, 2025
* feat: add init lgos

* feat: fix prefixes and filters

* fix: add animated logdetails

* refactor: get rid of duplicated components

* fix: colors

* refactor: get rid of unsued

* refactor: use common component

* fix: live switch

* fix: table read source

* refactor: use common schema for logs

* refactor: use same filters

* refactor: make logs denser

* fix: make it denser

* fix: add missing hostname to table

* refactor: table columns and text contrasts

* fix: memo issue and add gateway to logs to deployments

* fix: color inconsistency

* fix: test and add tooltip

* fix: border-color

* fix: missing params

* fix: truncate long req and resp body

* fix: comments

* fix: props

* fix: conflict

* fix: small ui issue

* fix: make rollback and promote consistent

* fix: remove all animated props

---------

Co-authored-by: Andreas Thomas <dev@chronark.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants