Skip to content
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

feat: mobile-sidbar-sync-with-desktop #2180

Merged

Conversation

AkshayBandi027
Copy link
Contributor

@AkshayBandi027 AkshayBandi027 commented Oct 4, 2024

What does this PR do?

Fixes #2171

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?

  • Go to dashboard
  • open menu to see changes.

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
unkey-sidebar.mp4

Summary by CodeRabbit

  • New Features
    • Enhanced sidebar navigation with dynamic workspace-based links.
    • Introduced a Feedback component in the mobile sidebar.
    • Added a new template for "Protecting Digital Content Access" in the templates collection.
  • Improvements
    • Streamlined navigation setup for better maintainability.
    • Updated MobileSideBar to utilize workspace data for rendering links.
    • Enhanced audit log data retrieval and presentation logic.
  • Bug Fixes
    • Removed unused components to clean up the codebase.
    • Improved rendering logic for handling empty states in audit logs.

Copy link

changeset-bot bot commented Oct 4, 2024

⚠️ No Changeset found

Latest commit: e71a256

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

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
planetfall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
unkey-engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 10:36am

Copy link

vercel bot commented Oct 4, 2024

@AkshayBandi027 is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Warning

Rate limit exceeded

@AkshayBandi027 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 31165df and e71a256.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant modifications to the sidebar navigation components within the dashboard application. Key changes include the restructuring of the desktop-sidebar.tsx to utilize dynamic navigation generation through the createWorkspaceNavigation function, replacing hardcoded items. The MobileSideBar component is updated to accept a workspace prop, enhancing its functionality. Additionally, a new constants file, workspace-navigations.tsx, is created to manage navigation items and their properties. Unused components, such as DiscordIcon and Tag, have been removed to streamline the codebase.

Changes

File Path Change Summary
apps/dashboard/app/(app)/desktop-sidebar.tsx Removed unused components; redefined navigation using createWorkspaceNavigation and updated imports.
apps/dashboard/app/(app)/layout.tsx Added workspace prop to MobileSideBar component.
apps/dashboard/app/(app)/mobile-sidebar.tsx Updated to use workspace prop; replaced hardcoded links with dynamic navigation mapping.
apps/dashboard/lib/constants/workspace-navigations.tsx Introduced constants and functions for workspace navigation; defined NavItem type and created createWorkspaceNavigation function.

Assessment against linked issues

Objective Addressed Explanation
Feedback / Discord buttons are not available on mobile nav (#2171)

Possibly related PRs

Suggested labels

🕹️ 750 points, Good first issue

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Oct 4, 2024

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

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: 6

🧹 Outside diff range and nitpick comments (2)
apps/dashboard/app/(app)/layout.tsx (1)

35-35: Consider adding a comment for clarity.

To improve code readability and maintain context for future developers, consider adding a brief comment explaining the purpose of passing the workspace prop to MobileSideBar. This can help clarify the intent behind this change, especially in relation to the new Feedback and Discord buttons.

Here's a suggested comment you could add above the MobileSideBar component:

+      {/* Passing workspace to MobileSideBar to enable Feedback and Discord buttons */}
       <MobileSideBar className="lg:hidden" workspace={workspace} />
apps/dashboard/app/(app)/mobile-sidebar.tsx (1)

64-64: Include rel="noopener noreferrer" when using target="_blank.

When using target="_blank" in links, it's recommended to include rel="noopener noreferrer" for security reasons. This prevents the new page from accessing the window.opener property, mitigating security risks like tab-nabbing.

Apply this diff:

<Link href={`${item.href}`} target="_blank" key={item.label}>
+  rel="noopener noreferrer"
🧰 Tools
🪛 Biome

[error] 64-64: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7ac47f and dd7ca0e.

📒 Files selected for processing (4)
  • apps/dashboard/app/(app)/desktop-sidebar.tsx (2 hunks)
  • apps/dashboard/app/(app)/layout.tsx (1 hunks)
  • apps/dashboard/app/(app)/mobile-sidebar.tsx (2 hunks)
  • apps/dashboard/lib/constants/workspace-navigations.tsx (1 hunks)
🧰 Additional context used
🪛 Biome
apps/dashboard/app/(app)/mobile-sidebar.tsx

[error] 49-49: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 64-64: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (4)
apps/dashboard/app/(app)/layout.tsx (1)

35-35: LGTM! Verify MobileSideBar implementation for new buttons.

The addition of the workspace prop to the MobileSideBar component is consistent with the PR objectives and aligns with how the DesktopSidebar is implemented. This change should enable the addition of Feedback and Discord buttons to the mobile navigation.

To ensure the PR objectives are fully met, please verify the implementation of the MobileSideBar component:

apps/dashboard/lib/constants/workspace-navigations.tsx (1)

129-129: Verify the Discord URL for accuracy

Ensure that the Discord URL "https://www.unkey.com/discord" is correct and directs users to the intended destination. If the correct URL is "https://unkey.dev/discord" or another address, please update it accordingly.

apps/dashboard/app/(app)/desktop-sidebar.tsx (2)

5-8: Imports navigation constants to centralize definitions

Great job importing createWorkspaceNavigation and resourcesNavigation from @/lib/constants/workspace-navigations. This promotes maintainability by centralizing navigation definitions and reduces redundancy.


47-47: Dynamically generates workspace navigation

Using createWorkspaceNavigation(workspace, segments) to generate workspaceNavigation enhances flexibility and keeps the navigation consistent with the workspace context and current segments.

apps/dashboard/app/(app)/mobile-sidebar.tsx Outdated Show resolved Hide resolved
apps/dashboard/app/(app)/mobile-sidebar.tsx Outdated Show resolved Hide resolved
apps/dashboard/lib/constants/workspace-navigations.tsx Outdated Show resolved Hide resolved
apps/dashboard/lib/constants/workspace-navigations.tsx Outdated Show resolved Hide resolved
apps/dashboard/lib/constants/workspace-navigations.tsx Outdated Show resolved Hide resolved
apps/dashboard/lib/constants/workspace-navigations.tsx Outdated Show resolved Hide resolved
@chronark chronark self-assigned this Oct 4, 2024
mcstepp and others added 9 commits October 5, 2024 06:53
…grade flow (unkeyed#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties
* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <[email protected]>
* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing
…d#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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: 9

🧹 Outside diff range and nitpick comments (15)
apps/docs/contributing/testing.mdx (1)

16-16: Approved: Improved clarity in API Tests section

The addition of "so we also use integration tests" enhances the explanation of why both unit and integration tests are necessary for the core product. This change improves the overall clarity of the testing documentation.

Consider further improving the sentence structure for even better readability. Here's a suggestion:

-`/apps/api` is our core product and needs to be heavily tested. Unit tests are not enough so we also use integration tests:
+`/apps/api` is our core product and requires thorough testing. Since unit tests alone are not sufficient, we also employ integration tests:

This minor refinement maintains the added context while improving the flow of the sentence.

oss.gg/7_create_a_template.md (4)

6-9: LGTM! Consider adding a contribution guide requirement.

The new requirements are excellent additions that promote open-source best practices and ensure accessibility for other developers. They clearly specify the need for open-source licensing, proper documentation, and provide options for where to host the code.

Consider adding a requirement for a basic contribution guide (e.g., CONTRIBUTING.md) to encourage community involvement and maintain consistency across contributions.


31-31: Great addition! Consider adding a brief description.

The new example, "Flask RBAC route protection using Unkey," is a valuable addition that demonstrates Unkey's integration with a popular web framework and addresses a common use case.

Consider adding a brief (one-line) description of what the example demonstrates, to give users a quick overview without needing to click through to the repository.


32-33: Excellent example! Consider standardizing the format.

The new example, "Time-Sensitive API Keys for Digital Content Access," is a great addition that showcases a specific and relevant use case for Unkey.

To maintain consistency, consider standardizing the format of all entries. For example, you could include the programming language or framework used in brackets after the title, similar to how the Flask example is formatted.


Line range hint 6-33: Overall, excellent updates that align with PR objectives.

The changes to this file significantly enhance the template creation guide by adding clear requirements for open-source contributions and providing diverse, practical examples of Unkey integration. These updates align well with the PR objectives of improving documentation and showcasing Unkey's capabilities.

To further improve the document's structure and maintainability:

  1. Consider creating a separate section for the list of examples, making it easier to add new entries in the future.
  2. Think about implementing a consistent format for example entries, possibly using a markdown table for better readability and easier parsing.
apps/dashboard/app/(app)/apis/create-api-button.tsx (2)

35-40: LGTM: Async onSuccess with revalidation.

The changes to the onSuccess callback are well-implemented:

  1. Making it async allows proper handling of the revalidate function.
  2. Revalidating the "/apis" route ensures the UI is updated with the new API.
  3. Moving router.push after revalidation ensures the new API is included in the updated view.

These changes align well with the PR objective of synchronizing the sidebar and improving user experience.

Consider adding a try-catch block around the revalidate and router.push calls to handle potential errors gracefully:

async onSuccess(res) {
  toast.success("Your API has been created");

  try {
    await revalidate("/apis");
    router.push(`/apis/${res.id}`);
  } catch (error) {
    console.error("Error updating UI:", error);
    toast.error("Created API, but failed to update UI. Please refresh.");
  }
}

Line range hint 48-48: Move router declaration to avoid potential issues.

The router variable is currently declared after it's used in the onSuccess callback. This could lead to runtime errors. To ensure router is available when needed, move its declaration to the beginning of the component.

Apply this change:

export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes<HTMLButtonElement>) => {
+  const router = useRouter();
   const form = useForm<z.infer<typeof formSchema>>({
     resolver: zodResolver(formSchema),
   });

   // ... rest of the component code ...

-  const router = useRouter();

   return (
     // ... component JSX ...
   );
};
apps/dashboard/app/(app)/audit/[bucket]/row.tsx (1)

102-103: Approve the update to use targets, with a suggestion for improvement.

The code has been correctly updated to use auditLog.targets instead of auditLog.resources, maintaining consistency with the type changes.

Consider improving type safety by specifying the type of the accumulator in the reduce function:

auditLog.targets.reduce((acc: Record<string, string>, t) => {
  acc[t.type] = t.id;
  return acc;
}, {})

This change will provide better type inference and catch potential errors earlier in the development process.

internal/db/src/schema/audit_logs.ts (2)

122-122: Consider removing redundant index on auditLogId.

The addition of an index on auditLogId in the auditLogTarget table may be unnecessary. Since auditLogId is already part of the primary key (as seen in the pk definition), it is automatically indexed by the database engine.

Consider removing this line to avoid redundant indexing:

- auditLog: index("audit_log_id").on(table.auditLogId),

This change would simplify the schema without impacting query performance.


Line range hint 1-138: Summary: Schema improvements enhance overall application performance.

While these changes to the audit logs schema are not directly related to the mobile sidebar sync mentioned in the PR title, they significantly improve the database structure and query performance for audit logs. This enhancement could indirectly benefit mobile users by providing faster access to audit information.

However, it's worth noting that these changes seem to be outside the scope of the PR objectives as described. Consider splitting these schema improvements into a separate PR for clearer tracking and easier review process.

apps/dashboard/app/(app)/desktop-sidebar.tsx (1)

2-2: LGTM! Consider grouping related imports.

The addition of createWorkspaceNavigation and resourcesNavigation imports aligns well with the PR objective. The removal of unused components (DiscordIcon and Tag) improves code cleanliness.

Consider grouping related imports together for better readability. For example:

import { createWorkspaceNavigation, resourcesNavigation } from "@/app/(app)/workspace-navigations";
import { Feedback } from "@/components/dashboard/feedback-component";
import { Badge } from "@/components/ui/badge";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
apps/dashboard/app/(app)/workspace-navigations.tsx (2)

49-49: Remove extra whitespace in className

There is an extra space between py-0.5 and font-mono in the className string on line 49. Removing the extra space improves code cleanliness.

Apply this diff:

-          "bg-background border text-content-subtle rounded text-xs px-1 py-0.5  font-mono ",
+          "bg-background border text-content-subtle rounded text-xs px-1 py-0.5 font-mono ",

58-58: Simplify the Pick types in function parameters

You can combine the two Pick types into a single Pick to simplify the type definition.

Apply this diff:

-export const createWorkspaceNavigation = (
-  workspace: Pick<Workspace, "features"> & Pick<Workspace, "betaFeatures">,
+export const createWorkspaceNavigation = (
+  workspace: Pick<Workspace, "features" | "betaFeatures">,
apps/dashboard/app/(app)/audit/[bucket]/page.tsx (2)

Line range hint 243-264: Inconsistent query parameter names in 'buildHref' function

The query parameters used in the buildHref function ("event", "user", "rootKey") are inconsistent with the ones used elsewhere in the application ("events", "users", "rootKeys"). This inconsistency may cause the filters to not work as expected when navigating through pagination or resetting filters.

Apply this diff to align the query parameter names:

function buildHref(override: Partial<Props["searchParams"]>): string {
  const searchParams = new URLSearchParams();
  const newBefore = override.before ?? before;
  if (newBefore) {
    searchParams.set("before", newBefore.toString());
  }

  for (const event of selectedEvents) {
-   searchParams.append("event", event);
+   searchParams.append("events", event);
  }

  for (const rootKey of selectedRootKeys) {
-   searchParams.append("rootKey", rootKey);
+   searchParams.append("rootKeys", rootKey);
  }

  for (const user of selectedUsers) {
-   searchParams.append("user", user);
+   searchParams.append("users", user);
  }
  return `/audit?${searchParams.toString()}`;
}

Line range hint 265-272: Consider batching or caching user data retrieval

The code fetches user data individually using clerkClient.users.getUser for each user ID. This could lead to performance issues if there are many user IDs. Consider batching the requests if the API supports it or implementing caching to reduce the number of API calls.

You might refactor the code as follows if batching is supported:

- const users = (
-   await Promise.all(userIds.map((userId) => clerkClient.users.getUser(userId).catch(() => null)))
- ).reduce(
-   (acc, u) => {
-     if (u) {
-       acc[u.id] = u;
-     }
-     return acc;
-   },
-   {} as Record<string, User>,
- );

+ const userBatch = await clerkClient.users.getUserList({ userId: userIds });
+ const users = userBatch.reduce(
+   (acc, u) => {
+     acc[u.id] = u;
+     return acc;
+   },
+   {} as Record<string, User>,
+ );

Ensure that the clerkClient supports batch retrieval of users.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dd7ca0e and 31165df.

⛔ Files ignored due to path filters (2)
  • apps/www/public/images/templates/pdf-view.png is excluded by !**/*.png
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • .github/workflows/autofix.ci.yaml (0 hunks)
  • apps/billing/package.json (1 hunks)
  • apps/dashboard/app/(app)/apis/create-api-button.tsx (2 hunks)
  • apps/dashboard/app/(app)/audit/[bucket]/export-csv.tsx (0 hunks)
  • apps/dashboard/app/(app)/audit/[bucket]/page.tsx (9 hunks)
  • apps/dashboard/app/(app)/audit/[bucket]/row.tsx (2 hunks)
  • apps/dashboard/app/(app)/desktop-sidebar.tsx (2 hunks)
  • apps/dashboard/app/(app)/mobile-sidebar.tsx (2 hunks)
  • apps/dashboard/app/(app)/settings/billing/stripe/success/page.tsx (3 hunks)
  • apps/dashboard/app/(app)/workspace-navigations.tsx (1 hunks)
  • apps/dashboard/package.json (1 hunks)
  • apps/docs/contributing/testing.mdx (1 hunks)
  • apps/workflows/package.json (1 hunks)
  • apps/www/app/templates/data.ts (1 hunks)
  • apps/www/package.json (1 hunks)
  • internal/db/src/schema/audit_logs.ts (3 hunks)
  • oss.gg/7_create_a_template.md (2 hunks)
💤 Files with no reviewable changes (2)
  • .github/workflows/autofix.ci.yaml
  • apps/dashboard/app/(app)/audit/[bucket]/export-csv.tsx
✅ Files skipped from review due to trivial changes (2)
  • apps/billing/package.json
  • apps/workflows/package.json
🧰 Additional context used
📓 Learnings (1)
apps/dashboard/app/(app)/settings/billing/stripe/success/page.tsx (1)
Learnt from: mcstepp
PR: unkeyed/unkey#2120
File: apps/dashboard/app/(app)/settings/billing/stripe/success/page.tsx:19-19
Timestamp: 2024-09-20T18:32:21.963Z
Learning: In the `StripeSuccess` function, TypeScript's type-checking of the `new_plan` parameter ensures that only "free", "pro", or undefined values are accepted, so additional runtime validation is not necessary.
🔇 Additional comments (31)
apps/docs/contributing/testing.mdx (1)

Line range hint 1-33: Verify relevance of testing documentation changes to PR objectives

While the improvements to the testing documentation are valuable, they don't seem to directly address the main objectives of this PR, which are to synchronize the mobile sidebar with the desktop version and add Feedback and Discord buttons to the mobile navigation.

Could you clarify how these changes to the testing documentation relate to the mobile sidebar synchronization feature? If they're not directly related, consider:

  1. Updating this file to include specific testing instructions for the new mobile sidebar features.
  2. Or, if these changes are unrelated, consider moving them to a separate PR focused on documentation improvements.
🧰 Tools
🪛 LanguageTool

[grammar] ~20-~20: Did you mean the adjective “end-to-end” (spelled with hyphens)?
Context: ...gration tests: ### integration Full end to end tests require a running API either loca...

(END_TO_END_HYPHEN)

apps/www/package.json (1)

71-71: Approve the @types/react-dom update, but clarification needed.

The update of @types/react-dom from ^18.2.25 to ^18.3.0 is a minor version bump, which is generally safe and follows semantic versioning principles. This change is approved from a technical standpoint.

However, I have a few points to consider:

  1. This update doesn't seem directly related to the PR's stated objectives of adding Feedback and Discord buttons to the mobile navigation bar.
  2. It's unclear why this update was included in this specific PR.

Could you please clarify:

  1. Why was this package update included in this PR?
  2. Is this update necessary for implementing the mobile navigation changes?
  3. Have you tested the application with this new version to ensure compatibility?

To verify the impact of this change, you can run the following command:

This will show the installed version and any peer dependencies, helping to ensure everything is compatible.

apps/dashboard/app/(app)/mobile-sidebar.tsx (8)

2-3: LGTM: New imports align with PR objectives.

The added imports for workspace navigation, feedback component, and UI elements are appropriate for implementing the synchronization of the mobile sidebar with the desktop version. These additions support the inclusion of Feedback and Discord buttons in the mobile navigation as per the PR objectives.

Also applies to: 5-5


15-21: LGTM: Props type update enables dynamic workspace navigation.

The addition of the workspace property to the Props type is well-structured and allows for passing necessary workspace data to the component. This change enables the rendering of dynamic workspace-specific navigation items, which aligns with the PR objectives of synchronizing the mobile sidebar with the desktop version.


24-25: LGTM: Function signature and hook updates support dynamic navigation.

The updated MobileSideBar function signature correctly includes the new workspace prop, reflecting the changes in the Props type. The switch to useSelectedLayoutSegments hook is appropriate for determining the current navigation state. These changes effectively support the implementation of dynamic navigation based on the workspace data, aligning with the PR objectives.


27-27: LGTM: Dynamic workspace navigation creation.

The use of createWorkspaceNavigation to generate navigation items dynamically based on the workspace data and current segments is an excellent approach. This implementation supports the PR objective of synchronizing the mobile sidebar with the desktop version, ensuring consistency across different device types.


45-54: LGTM: Effective dynamic rendering of workspace navigation.

The implementation of dynamic rendering for workspace navigation items is well-structured and maintainable. The use of SheetClose ensures proper closing of the mobile sidebar after selection, enhancing the user experience. The addition of the key prop to the Link component addresses a previous review comment, improving React's rendering efficiency.


60-69: LGTM: Consistent and effective resources navigation rendering.

The implementation of the resources navigation rendering is consistent with the workspace navigation and well-structured. The use of target="_blank" for resource links is appropriate for external resources. The dynamic rendering approach allows for easy updates to the resources list, enhancing maintainability. The key prop is correctly added to the Link component, addressing potential React rendering issues.


70-70: LGTM: Feedback component successfully integrated.

The addition of the Feedback component at the end of the resources section successfully addresses the PR objective of including a Feedback button in the mobile navigation. Its placement is logical and consistent with typical UI patterns, enhancing the user experience on mobile devices.


Line range hint 1-77: Great job implementing the mobile sidebar synchronization!

The changes in this file effectively address the PR objectives:

  1. The mobile sidebar is now synchronized with the desktop version.
  2. Feedback and resource navigation items (including Discord) are now accessible on mobile.
  3. The implementation uses dynamic rendering, enhancing maintainability and flexibility.
  4. Previous review comments about missing key props have been addressed.

These updates significantly improve the mobile user experience and consistency across devices. Well done!

apps/dashboard/app/(app)/apis/create-api-button.tsx (2)

2-2: LGTM: New import for revalidation.

The addition of the revalidate import is appropriate for updating the UI after creating a new API. This aligns well with the PR objective of synchronizing the sidebar.


Line range hint 1-96: Summary: Changes align with PR objectives, minor improvements suggested.

The modifications to the CreateApiButton component effectively contribute to synchronizing the sidebar by ensuring the UI is updated after creating a new API. This aligns well with the PR objectives of improving the mobile navigation experience.

Key improvements:

  1. Added revalidation after creating a new API.
  2. Made the onSuccess callback asynchronous for proper handling of asynchronous operations.

These changes enhance the user experience by ensuring that newly created APIs are immediately reflected in the UI.

Suggestions for further improvement:

  1. Move the router declaration to the beginning of the component to avoid potential issues.
  2. Consider adding error handling for the revalidation and navigation processes.

While these changes don't directly address the addition of Feedback and Discord buttons mentioned in the PR objectives, they do improve the overall functionality of the API creation process, which is a valuable enhancement to the dashboard.

apps/dashboard/app/(app)/audit/[bucket]/row.tsx (2)

17-17: Verify the intention behind broadening the actor.type.

The type of auditLog.actor.type has been changed from a specific union type to a more general string. While this allows for more flexibility, it also reduces type safety.

Could you clarify the reasoning behind this change? If it's to accommodate potential new actor types, consider using a union type with a catch-all string literal:

type: "key" | "user" | "system" | (string & {});

This approach maintains flexibility while preserving some type safety for known values.

✅ Verification successful

Verified the change to actor.type across the codebase.

The transition from a specific union type to string for auditLog.actor.type has been consistently applied and does not introduce type safety issues based on current usages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of actor.type in the codebase
# Expected result: Instances where actor.type is used, to ensure compatibility with the new type

rg --type typescript -g '!*.test.ts' -g '!*.spec.ts' 'actor\.type'

Length of output: 103


Script:

#!/bin/bash
# Description: Check for usage of actor.type in the codebase
# Expected result: Instances where actor.type is used, to ensure compatibility with the new type

rg 'actor\.type' --glob '!*.test.ts' --glob '!*.spec.ts' -g '*.ts' -g '*.tsx'

Length of output: 450


22-25: Approve renaming resources to targets, but clarification needed.

The renaming of resources to targets has been implemented correctly. This change appears to be a conceptual shift in how these entities are represented.

Could you provide more context on why this rename was necessary? How does it relate to the PR's main objective of synchronizing the mobile sidebar with the desktop version?

apps/dashboard/package.json (3)

Line range hint 3-3: Version bump looks good.

The version has been incremented to 0.1.36, which is appropriate for adding a new feature.


127-127: Minor type definition update.

The @types/react-dom package has been updated from 18.2.25 to 18.3.0. This is a minor update and shouldn't directly impact the new feature being added.


Line range hint 1-133: Verify if new dependencies are needed for the mobile sidebar feature.

The PR objectives mention adding Feedback and Discord buttons to the mobile navigation bar, but there are no new dependencies added in this file. Please confirm if any additional packages are required for implementing this feature.

✅ Verification successful

No new dependencies are needed for the mobile sidebar feature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any new dependencies related to mobile navigation or UI components have been added in other package.json files.

# Test: Search for changes in package.json files that might be related to the new feature.
git diff origin/main -- '**/package.json' | grep -E '^\+.*(@react-navigation|@react-native|react-native-.*|@ui-kitten|@expo)'

Length of output: 127


Script:

#!/bin/bash
# Description: List all newly added dependencies in package.json files to verify if any are needed for the mobile sidebar feature.

# Extract added lines from package.json files in the PR and list the newly added dependencies.
git diff origin/main -- '**/package.json' | grep -E '^\+.*"[^"]+":' | awk -F '"' '{print $2}'

Length of output: 95


Script:

#!/bin/bash
# Description: List all newly added dependencies in package.json files to verify if any are needed for the mobile sidebar feature.

# Extract all added dependencies and devDependencies in package.json files from the PR.
git diff origin/main -- '**/package.json' | grep -E '^\+.*"(dependencies|devDependencies)": {' -A 100 | grep -E '^\+ *"[^"]+":' | awk -F '"' '{print $2}'

Length of output: 155

internal/db/src/schema/audit_logs.ts (2)

43-49: LGTM! Improved relational structure for auditLogBucket.

The addition of auditLogBucketRelations enhances the schema by explicitly defining the relationships between auditLogBucket, workspaces, and auditLog. This improvement will facilitate more efficient queries and maintain data integrity.


81-84: LGTM! Enhanced query performance with new indexes.

The addition of indexes for bucketId, event, actorId, and time in the auditLog table will significantly improve read query performance for common audit log operations.

To ensure optimal performance, please monitor the impact of these new indexes on write operations. Run the following script to check the table statistics after a period of normal usage:

apps/dashboard/app/(app)/desktop-sidebar.tsx (2)

9-9: LGTM! Please clarify the purpose of the Loader2 import.

The addition of the Loader2 import from lucide-react is fine. However, it's not immediately clear how this relates to the PR objective of synchronizing the mobile sidebar with the desktop version.

Could you please explain the intended use of the Loader2 component in the context of this PR? Is it part of a loading state improvement for the sidebar?


Line range hint 1-164: Overall, the changes align well with the PR objectives.

The modifications to the desktop-sidebar.tsx file contribute significantly to synchronizing the mobile sidebar with the desktop version. Key improvements include:

  1. Dynamic generation of workspace navigation items.
  2. Removal of unused components and imports.
  3. Potential addition of loading state handling.

These changes enhance maintainability and flexibility, making it easier to keep the mobile and desktop sidebars in sync.

To fully meet the PR objectives:

  1. Ensure that the Feedback and Discord buttons are properly included in the createWorkspaceNavigation function.
  2. Verify that these buttons are accessible on mobile devices.
  3. Consider adding a comment explaining the purpose of the Loader2 component in the context of this PR.

Please run the verification script provided earlier to confirm the inclusion of Feedback and Discord buttons. Additionally, could you provide a screenshot or description of how these buttons appear on the mobile sidebar?

apps/www/app/templates/data.ts (1)

51-62: Summary of review findings

  1. The changes introduce a new "pdf-view" template entry, which is structurally correct and consistent with other entries.
  2. However, these changes appear to be unrelated to the PR objectives of synchronizing the mobile sidebar with the desktop version and adding Feedback and Discord buttons to the mobile navigation bar.

Please clarify the following:

  1. How do these changes relate to the PR objectives?
  2. If they are unrelated, should they be moved to a separate PR?
  3. Are there any missing changes that should be included to address the PR objectives?

This clarification will help ensure that the PR remains focused and traceable to its intended objectives.

apps/dashboard/app/(app)/audit/[bucket]/page.tsx (1)

78-78: Verify the compatibility of date comparison in query

When filtering logs based on createdAt using gte(table.createdAt, retentionCutoffUnixMilli), ensure that table.createdAt and retentionCutoffUnixMilli are in compatible formats. If table.createdAt is a timestamp or date object, it should be comparable to the Unix timestamp in milliseconds.

Run the following script to check the data types of createdAt fields:

If the database is not SQLite, adjust the command accordingly to match your database system.

apps/dashboard/app/(app)/settings/billing/stripe/success/page.tsx (8)

3-3: Import of insertAuditLogs is correctly added

The addition of insertAuditLogs import is appropriate and used effectively in the code.


8-8: Import of ingestAuditLogsTinybird is properly included

Including ingestAuditLogsTinybird from @/lib/tinybird is necessary for the audit logging functionality.


10-10: Import of defaultProSubscriptions is appropriate

The import of defaultProSubscriptions from @unkey/billing is correct and used appropriately to set default subscriptions when upgrading to "pro".


11-11: Importing headers from next/headers

Using headers from next/headers allows access to request headers, which is correctly implemented.


25-26: Ensure user authentication before proceeding

Fetching the current user with currentUser() and verifying both tenantId and user enhances security by redirecting unauthenticated users.


82-98: Database transaction update is well-structured

The workspace update within the transaction is correctly implemented, conditionally setting fields when upgrading to "pro".


100-116: Audit logs insertion within transaction

Inserting audit logs using insertAuditLogs(tx, {...}) within the transaction ensures atomicity, which is appropriate.


Line range hint 136-140: Event tracking with PostHog is properly implemented

Capturing the plan_changed event with PostHogClient when upgrading the plan ensures that analytics are accurately recorded.

apps/dashboard/app/(app)/desktop-sidebar.tsx Show resolved Hide resolved
apps/www/app/templates/data.ts Outdated Show resolved Hide resolved
apps/dashboard/app/(app)/audit/[bucket]/page.tsx Outdated Show resolved Hide resolved
apps/dashboard/app/(app)/audit/[bucket]/page.tsx Outdated Show resolved Hide resolved
Copy link

oss-gg bot commented Oct 5, 2024

Awarding AkshayBandi027: 300 points 🕹️ Well done! Check out your new contribution on oss.gg/AkshayBandi027

harshsbhat added a commit to harshsbhat/unkey that referenced this pull request Oct 5, 2024
* feat/mobile-sidbar-sync-with-desktop

* fix(billing): add missing subscription fields and audit logging to upgrade flow (unkeyed#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties

* refactor: query audit logs from planetscale (unkeyed#2181)

* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Unkey PDF Viewer template [SIDE QUEST] (unkeyed#2191)

* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <[email protected]>

* perf: add database indices (unkeyed#2192)

* fix: add header again

* docs: Removing pnpm test:routes (unkeyed#2184)

* fix: revalidate /apis after creating new API (unkeyed#2183)

* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing

* chore(deps-dev): bump @types/react-dom from 18.2.25 to 18.3.0 (unkeyed#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor/workspace-navigation

* ran fmt

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Meg Stepp <[email protected]>
Co-authored-by: Andreas Thomas <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <[email protected]>
Co-authored-by: Harsh Shrikant Bhat <[email protected]>
Co-authored-by: Gerald Maboshe <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Oct 5, 2024
* Add default bytes and prefix

* adding bytes and prefix columns in harness

* fmt

* Await

* Resolved changes

* typo

* Capital and Extra bracket

* [autofix.ci] apply automated fixes

* feat: mobile-sidbar-sync-with-desktop (#2180)

* feat/mobile-sidbar-sync-with-desktop

* fix(billing): add missing subscription fields and audit logging to upgrade flow (#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties

* refactor: query audit logs from planetscale (#2181)

* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Unkey PDF Viewer template [SIDE QUEST] (#2191)

* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <[email protected]>

* perf: add database indices (#2192)

* fix: add header again

* docs: Removing pnpm test:routes (#2184)

* fix: revalidate /apis after creating new API (#2183)

* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing

* chore(deps-dev): bump @types/react-dom from 18.2.25 to 18.3.0 (#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor/workspace-navigation

* ran fmt

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Meg Stepp <[email protected]>
Co-authored-by: Andreas Thomas <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <[email protected]>
Co-authored-by: Harsh Shrikant Bhat <[email protected]>
Co-authored-by: Gerald Maboshe <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: update go sdk code examples to the current sdk version (#2200)

* fix: update go sdk code examples to the current sdk version

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Akshay <[email protected]>
Co-authored-by: Meg Stepp <[email protected]>
Co-authored-by: Andreas Thomas <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <[email protected]>
Co-authored-by: Gerald Maboshe <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 2024
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feedback / Discord buttons are not available on mobile nav
6 participants