feat: show how many resources use each resource type

Merged
BU
14h ago
+33-5

What does this PR do?

Resources → Resource Types now has a Resources column: how many resources in the workspace use each type. Types nobody uses show 0.

The counts come from the existing listResourceCountsByType endpoint (already used to rank the resource pickers), so there is no backend change. They load in their own loadResourceCounts, separately from the Workspace list, so changing a filter does not re-run the counts query. The counts reload when the workspace changes (cleared first, so another workspace's counts never show), on the refresh button, and whenever a resource is added, edited, deleted or restored, all without a page reload. If the counts request fails, the Workspace list still loads and the column shows - rather than a misleading 0. One file, ResourcesList.svelte (+33/-5).

The endpoint runs with the user's permissions, so a non-admin's counts include only the resources they can read: the same rows their Workspace tab lists.

flowchart TD
    A[User opens Resources, Resource Types tab] -->|Before| B[Each type is listed with no usage information]
    A -->|After| C[Each type shows how many resources use it]
    C --> D[Adding or deleting a resource updates the count]

Narrated recording, before then after (sound on):

https://github.com/user-attachments/assets/bffb58e4-4101-4df4-82bb-117e0c828eb2

The recording is the real app (frontend dev server from this checkout against the main backend image, CE v1.875.0). Before recording, the API created three instance types (postgresql, mysql, slack), two custom types (c_weather_api, c_unused_crm), two folders and eight resources. Some resources are in a folder alice cannot read and some belong to other users. Waits on page loads are shortened; nothing else is edited.

Edge cases and unchanged behaviour checked

All checked in the running app, on this branch:

  • Every type, as an admin and as a non-admin (alice): the column matches the number of Workspace-tab rows of that type, including the types at 0. The video shows the full comparison table, read from the page.
  • Non-admin: alice sees 5 of the 8 resources, and her postgresql count is 1, not 4.
  • Unused types, both instance (mysql) and custom (c_unused_crm), show 0.
  • Adding a MySQL resource from the Resource Types tab changes mysql from 0 to 1 at once. Deleting it from the Workspace tab brings it back to 0.
  • Unchanged: Edit on a custom type opens the resource type editor, and Delete removes an unused type.
  • Unchanged: the Workspace tab lists the same rows as on main.
  • Not covered: per-user drafts with no deployed resource are listed on the Workspace tab but are not resources yet, so the endpoint does not count them (not shown in the video).

Checks run

  • npm run lint (oxlint): passes.
  • prettier --check on the changed file: passes.
  • Not run: npm run check (svelte-check needs about 8 GB here) and npm run check:fast (no bun on this machine).
  • No test added: docs/validation.md asks for none on pure UI changes.

Related issue

Closes #270

AI tools (Claude Code) assisted with this change; the behaviour was verified in the running app as shown.


Summary by cubic

Adds a Resources column to the Resource Types tab showing how many resources use each type, with unused types reporting 0.

  • Counts come from the existing listResourceCountsByType endpoint, so there's no backend change.
  • Counts load on workspace load and when a resource is added, deleted, or restored, not on every filter change.
  • If the counts request fails, the resource list still loads and the column shows - instead of a misleading 0.
  • Counts respect user permissions, so a non-admin sees only the resources they can read.

Closes #270