-
Notifications
You must be signed in to change notification settings - Fork 611
feat: add trpc and filters schema for root keys #3331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
70 changes: 70 additions & 0 deletions
70
apps/dashboard/app/(app)/settings/root-keys-v2/filters.schema.ts
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,70 @@ | ||
| import type { FilterValue, StringConfig } from "@/components/logs/validation/filter.types"; | ||
| import { parseAsFilterValueArray } from "@/components/logs/validation/utils/nuqs-parsers"; | ||
| import { createFilterOutputSchema } from "@/components/logs/validation/utils/structured-output-schema-generator"; | ||
| import { z } from "zod"; | ||
|
|
||
| const commonStringOperators = ["is", "contains"] as const; | ||
|
|
||
| export const rootKeysFilterOperatorEnum = z.enum(commonStringOperators); | ||
| export type RootKeysFilterOperator = z.infer<typeof rootKeysFilterOperatorEnum>; | ||
|
|
||
| export type FilterFieldConfigs = { | ||
| name: StringConfig<RootKeysFilterOperator>; | ||
| start: StringConfig<RootKeysFilterOperator>; | ||
| identity: StringConfig<RootKeysFilterOperator>; | ||
| permission: StringConfig<RootKeysFilterOperator>; | ||
| }; | ||
|
|
||
| export const rootKeysFilterFieldConfig: FilterFieldConfigs = { | ||
| name: { | ||
| type: "string", | ||
| operators: [...commonStringOperators], | ||
| }, | ||
| start: { | ||
| // Start of the `key` for security reasons | ||
| type: "string", | ||
| operators: [...commonStringOperators], | ||
| }, | ||
| identity: { | ||
| // ExternalId of creator user | ||
| type: "string", | ||
| operators: [...commonStringOperators], | ||
| }, | ||
| permission: { | ||
| type: "string", | ||
| operators: [...commonStringOperators], | ||
| }, | ||
| }; | ||
|
|
||
| const allFilterFieldNames = Object.keys(rootKeysFilterFieldConfig) as (keyof FilterFieldConfigs)[]; | ||
|
|
||
| if (allFilterFieldNames.length === 0) { | ||
| throw new Error("rootKeysFilterFieldConfig must contain at least one field definition."); | ||
| } | ||
|
|
||
| const [firstFieldName, ...restFieldNames] = allFilterFieldNames; | ||
|
|
||
| export const rootKeysFilterFieldEnum = z.enum([firstFieldName, ...restFieldNames]); | ||
| export const rootKeysListFilterFieldNames = allFilterFieldNames; | ||
| export type RootKeysFilterField = z.infer<typeof rootKeysFilterFieldEnum>; | ||
|
|
||
| export const filterOutputSchema = createFilterOutputSchema( | ||
| rootKeysFilterFieldEnum, | ||
| rootKeysFilterOperatorEnum, | ||
| rootKeysFilterFieldConfig, | ||
| ); | ||
|
|
||
| export type AllOperatorsUrlValue = { | ||
| value: string; | ||
| operator: RootKeysFilterOperator; | ||
| }; | ||
|
|
||
| export type RootKeysFilterValue = FilterValue<RootKeysFilterField, RootKeysFilterOperator>; | ||
|
|
||
| export type RootKeysQuerySearchParams = { | ||
| [K in RootKeysFilterField]?: AllOperatorsUrlValue[] | null; | ||
| }; | ||
|
|
||
| export const parseAsAllOperatorsFilterArray = parseAsFilterValueArray<RootKeysFilterOperator>([ | ||
| ...commonStringOperators, | ||
| ]); | ||
102 changes: 102 additions & 0 deletions
102
apps/dashboard/app/(app)/settings/root-keys-v2/navigation.tsx
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,102 @@ | ||
| "use client"; | ||
| import { QuickNavPopover } from "@/components/navbar-popover"; | ||
| import { Navbar } from "@/components/navigation/navbar"; | ||
| import { Badge } from "@/components/ui/badge"; | ||
| import { ChevronExpandY, Gear } from "@unkey/icons"; | ||
| import { Button, CopyButton } from "@unkey/ui"; | ||
| import Link from "next/link"; | ||
|
|
||
| const settingsNavbar = [ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a blocker here, but we should definitely put these kind of link lists into a constant to reuse in other pages, wdyt? |
||
| { | ||
| id: "general", | ||
| href: "general", | ||
| text: "General", | ||
| }, | ||
| { | ||
| id: "team", | ||
| href: "team", | ||
| text: "Team", | ||
| }, | ||
| { | ||
| id: "root-keys-v2", | ||
| href: "root-keys-v2", | ||
| text: "Root Keys", | ||
| }, | ||
| { | ||
| id: "billing", | ||
| href: "billing", | ||
| text: "Billing", | ||
| }, | ||
| ]; | ||
|
|
||
| export const Navigation = ({ | ||
| workspace, | ||
| activePage, | ||
| }: { | ||
| workspace: { | ||
| id: string; | ||
| name: string; | ||
| }; | ||
| activePage: { | ||
| href: string; | ||
| text: string; | ||
| }; | ||
| }) => { | ||
| return ( | ||
| <div className="flex flex-col w-full h-full"> | ||
| <Navbar> | ||
| <Navbar.Breadcrumbs icon={<Gear />}> | ||
| <Navbar.Breadcrumbs.Link href="/settings">Settings</Navbar.Breadcrumbs.Link> | ||
| <Navbar.Breadcrumbs.Link href={activePage.href} noop active> | ||
| <QuickNavPopover | ||
| items={settingsNavbar.flatMap((setting) => [ | ||
| { | ||
| id: setting.href, | ||
| label: setting.text, | ||
| href: `/settings/${setting.href}`, | ||
| }, | ||
| ])} | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shortcutKey="M" | ||
| > | ||
| <div className="flex items-center gap-1 p-1 rounded-lg hover:bg-gray-3"> | ||
| {activePage.text} | ||
| <ChevronExpandY className="size-4" /> | ||
| </div> | ||
| </QuickNavPopover> | ||
| </Navbar.Breadcrumbs.Link> | ||
| </Navbar.Breadcrumbs> | ||
| <Navbar.Actions> | ||
| {activePage.href === "general" && ( | ||
| <Badge | ||
| variant="secondary" | ||
| className="max-w-[160px] truncate whitespace-nowrap" | ||
| title={workspace.id} | ||
| > | ||
| {workspace.id} | ||
| <CopyButton value={workspace.id} /> | ||
| </Badge> | ||
| )} | ||
| {activePage.href === "root-keys-v2" && ( | ||
| <Link key="create-root-key" href="/settings/root-keys/new"> | ||
| <Button variant="primary">Create New Root Key</Button> | ||
| </Link> | ||
| )} | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {activePage.href === "billing" && ( | ||
| <> | ||
| <Link href="https://cal.com/james-r-perkins/sales" target="_blank"> | ||
| <Button type="button" variant="outline"> | ||
| Schedule a call | ||
| </Button> | ||
| </Link> | ||
| <Link href="mailto:support@unkey.dev"> | ||
| <Button type="button" variant="primary"> | ||
| Contact us | ||
| </Button> | ||
| </Link> | ||
| </> | ||
| )} | ||
| </Navbar.Actions> | ||
| </Navbar> | ||
| </div> | ||
| ); | ||
| }; | ||
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,52 @@ | ||
| "use client"; | ||
| import { trpc } from "@/lib/trpc/client"; | ||
| import { Navigation } from "./navigation"; | ||
|
|
||
| export default function RootKeysPage() { | ||
| const { data, isLoading, error } = trpc.settings.rootKeys.query.useQuery({ | ||
| limit: 10, | ||
| }); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Navigation | ||
| workspace={{ | ||
| id: "will-add-soon", | ||
| name: "will-add-soon", | ||
| }} | ||
| activePage={{ | ||
| href: "root-keys", | ||
| text: "Root Keys", | ||
| }} | ||
| /> | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className="flex flex-col p-6"> | ||
| <h1 className="text-2xl font-bold mb-4 text-foreground">Root Keys</h1> | ||
|
|
||
| {isLoading && <div className="text-grayA-11">Loading root keys...</div>} | ||
|
|
||
| {error && ( | ||
| <div className="text-red-11 bg-red-2 border border-red-6 rounded-md p-3"> | ||
| Error loading root keys: {error.message} | ||
| </div> | ||
| )} | ||
|
|
||
| {data && ( | ||
| <div className="space-y-4"> | ||
| <div className="text-sm text-grayA-11"> | ||
| Showing {data.keys.length} of {data.total} keys | ||
| {data.hasMore && " (more available)"} | ||
| </div> | ||
|
|
||
| <div className="space-y-3"> | ||
| {data.keys.map((key) => ( | ||
| <pre key={key.id} className="border-b "> | ||
| {JSON.stringify(key, null, 2)} | ||
| </pre> | ||
| ))} | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
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
Oops, something went wrong.
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.