-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(dashboard): add pagination, server-side search #1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gora050
wants to merge
9
commits into
openclaw:main
Choose a base branch
from
gora050:feat/dashboard-pagination-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
026b292
feat(dashboard): add pagination, server-side search, and skill count
gora050 79d04b4
Greptile fixes
gora050 97fc742
fix(dashboard): denormalize skill count via Trigger, add search index…
gora050 89fcb1b
fix(dashboard): backfill activeSkillCount on publishers
gora050 c740953
Update .gitignore
gora050 2943426
revert counter
gora050 2ff24f6
remove search from PR
gora050 dc98b36
revert schema
gora050 9d95314
tests
gora050 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| import { getAuthUserId } from "@convex-dev/auth/server"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| vi.mock("@convex-dev/auth/server", () => ({ | ||
| getAuthUserId: vi.fn(), | ||
| authTables: {}, | ||
| })); | ||
|
|
||
| import { countDashboard, searchDashboard } from "./skills"; | ||
|
|
||
| type WrappedHandler<TArgs, TResult = unknown> = { | ||
| _handler: (ctx: unknown, args: TArgs) => Promise<TResult>; | ||
| }; | ||
|
|
||
| const countHandler = ( | ||
| countDashboard as unknown as WrappedHandler< | ||
| { ownerUserId?: string; ownerPublisherId?: string }, | ||
| number | ||
| > | ||
| )._handler; | ||
|
|
||
| const searchHandler = ( | ||
| searchDashboard as unknown as WrappedHandler< | ||
| { ownerUserId?: string; ownerPublisherId?: string; search: string; limit?: number }, | ||
| Array<{ slug: string }> | ||
| > | ||
| )._handler; | ||
|
|
||
| function makeSkill(slug: string, overrides: Record<string, unknown> = {}) { | ||
| return { | ||
| _id: `skills:${slug}`, | ||
| _creationTime: 1, | ||
| slug, | ||
| displayName: slug.charAt(0).toUpperCase() + slug.slice(1), | ||
| summary: `${slug} integration.`, | ||
| ownerUserId: "users:owner", | ||
| ownerPublisherId: undefined, | ||
| canonicalSkillId: undefined, | ||
| forkOf: undefined, | ||
| latestVersionId: undefined, | ||
| tags: {}, | ||
| badges: undefined, | ||
| stats: { downloads: 0, installsCurrent: 0, installsAllTime: 0, stars: 0, versions: 1, comments: 0 }, | ||
| createdAt: 1, | ||
| updatedAt: 2, | ||
| softDeletedAt: undefined, | ||
| moderationStatus: "active", | ||
| moderationFlags: [], | ||
| moderationReason: undefined, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| /** Build a mock ctx where `skills` queries return `allSkills`, | ||
| * and search-index queries return `searchHits` (defaults to allSkills). */ | ||
| function makeCtx( | ||
| allSkills: ReturnType<typeof makeSkill>[], | ||
| searchHits?: ReturnType<typeof makeSkill>[], | ||
| ) { | ||
| return { | ||
| db: { | ||
| get: vi.fn(async (id: string) => { | ||
| if (id === "users:owner") { | ||
| return { _id: "users:owner", _creationTime: 1, handle: "owner", displayName: "Owner" }; | ||
| } | ||
| if (id === "publishers:pub") { | ||
| return { | ||
| _id: "publishers:pub", | ||
| _creationTime: 1, | ||
| kind: "user", | ||
| handle: "owner", | ||
| displayName: "Owner", | ||
| linkedUserId: "users:owner", | ||
| }; | ||
| } | ||
| return null; | ||
| }), | ||
| query: vi.fn((table: string) => { | ||
| if (table === "publisherMembers") { | ||
| return { | ||
| withIndex: vi.fn(() => ({ | ||
| unique: vi.fn().mockResolvedValue(null), | ||
| })), | ||
| }; | ||
| } | ||
| if (table === "skills") { | ||
| const makeFilterChain = (items: ReturnType<typeof makeSkill>[]) => ({ | ||
| order: vi.fn(() => ({ | ||
| take: vi.fn().mockResolvedValue(items), | ||
| paginate: vi.fn().mockResolvedValue({ | ||
| page: items, | ||
| isDone: true, | ||
| continueCursor: "", | ||
| }), | ||
| })), | ||
| collect: vi.fn().mockResolvedValue(items), | ||
| }); | ||
| return { | ||
| withIndex: vi.fn(() => ({ | ||
| filter: vi.fn(() => makeFilterChain(allSkills)), | ||
| ...makeFilterChain(allSkills), | ||
| })), | ||
| withSearchIndex: vi.fn(() => ({ | ||
| take: vi.fn().mockResolvedValue(searchHits ?? allSkills), | ||
| })), | ||
| }; | ||
| } | ||
| if (table === "skillBadges") { | ||
| return { | ||
| withIndex: vi.fn(() => ({ | ||
| take: vi.fn().mockResolvedValue([]), | ||
| })), | ||
| }; | ||
| } | ||
| throw new Error(`unexpected table ${table}`); | ||
| }), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // countDashboard | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("skills.countDashboard", () => { | ||
| it("counts skills for ownerUserId", async () => { | ||
| const ctx = makeCtx([makeSkill("a"), makeSkill("b"), makeSkill("c")]); | ||
| const result = await countHandler(ctx as never, { ownerUserId: "users:owner" } as never); | ||
| expect(result).toBe(3); | ||
| }); | ||
|
|
||
| it("counts skills for ownerPublisherId", async () => { | ||
| const ctx = makeCtx([makeSkill("a"), makeSkill("b")]); | ||
| const result = await countHandler(ctx as never, { ownerPublisherId: "publishers:pub" } as never); | ||
| expect(result).toBe(2); | ||
| }); | ||
|
|
||
| it("returns 0 when no owner specified", async () => { | ||
| const ctx = makeCtx([makeSkill("a")]); | ||
| const result = await countHandler(ctx as never, {}); | ||
| expect(result).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // searchDashboard | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("skills.searchDashboard", () => { | ||
| const allSkills = [ | ||
| makeSkill("slack", { displayName: "Slack", summary: "Slack messaging." }), | ||
| makeSkill("stripe", { displayName: "Stripe", summary: "Payment processing." }), | ||
| makeSkill("github", { displayName: "GitHub", summary: "Code hosting." }), | ||
| ]; | ||
|
|
||
| it("returns empty array when search is empty", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const ctx = makeCtx(allSkills); | ||
| const result = await searchHandler(ctx as never, { | ||
| ownerUserId: "users:owner", | ||
| search: "", | ||
| } as never); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("returns matched skills from search index", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const hits = [allSkills[0]]; // Slack | ||
| const ctx = makeCtx(allSkills, hits); | ||
| const result = await searchHandler(ctx as never, { | ||
| ownerUserId: "users:owner", | ||
| search: "Slack", | ||
| } as never); | ||
| expect(result).toEqual([expect.objectContaining({ slug: "slack" })]); | ||
| }); | ||
|
|
||
| it("returns multiple search hits", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const hits = [allSkills[0], allSkills[2]]; // Slack, GitHub | ||
| const ctx = makeCtx(allSkills, hits); | ||
| const result = await searchHandler(ctx as never, { | ||
| ownerUserId: "users:owner", | ||
| search: "integration", | ||
| } as never); | ||
| expect(result).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("returns empty when no hits", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const ctx = makeCtx(allSkills, []); | ||
| const result = await searchHandler(ctx as never, { | ||
| ownerUserId: "users:owner", | ||
| search: "nonexistent", | ||
| } as never); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("returns empty when no owner specified", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const ctx = makeCtx(allSkills); | ||
| const result = await searchHandler(ctx as never, { search: "slack" } as never); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("works with ownerPublisherId", async () => { | ||
| vi.mocked(getAuthUserId).mockResolvedValue("users:owner" as never); | ||
| const hits = [allSkills[1]]; // Stripe | ||
| const ctx = makeCtx(allSkills, hits); | ||
| const result = await searchHandler(ctx as never, { | ||
| ownerPublisherId: "publishers:pub", | ||
| search: "Stripe", | ||
| } as never); | ||
| expect(result).toEqual([expect.objectContaining({ slug: "stripe" })]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.