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: Added the use case category in templates page #2314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bitbrief
Copy link

@bitbrief bitbrief commented Oct 10, 2024

What does this PR do?

Added the use case category in the templates page with all the working features of other categories like language and framework.

Screenshot 2024-10-11 at 1 57 44 AM

Fixes #2289

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?

  • Navigate to the templates section of the landing page
  • See the newly added use case category
  • Ran the landing page locally and navigating to the templates section.
  • Interacted with the newly added category to check for its working according to the other categories.

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

    • Introduced a new filtering mechanism for templates based on use cases, allowing users to filter selections more effectively.
    • Added an accordion section in the template form for selecting multiple use cases.
    • Enhanced the template display to include use case information alongside existing tags.
  • Bug Fixes

    • Improved logic for handling framework filtering in the template selection interface.
  • Documentation

    • Updated types and properties in the schema to include use cases for better clarity and organization.

Copy link

changeset-bot bot commented Oct 10, 2024

⚠️ No Changeset found

Latest commit: 2e7efb5

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 10, 2024

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

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 11, 2024 2:15pm

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

📝 Walkthrough

Walkthrough

The changes introduce a new property usecases to the schema object in the templates form, allowing for an array of strings to be managed. The getDefaulTemplatesFormValues function is updated to initialize usecases based on the browser context, while the updateUrl function is modified to manage URL parameters accordingly. Additionally, the TemplatesClient component is enhanced with filtering capabilities based on use cases, and new types and constants are defined in the data module to support this feature.

Changes

File Change Summary
apps/dashboard/lib/templates-form.ts Added usecases: z.array(z.string()) to schema; updated getDefaulTemplatesFormValues and updateUrl to handle use cases.
apps/www/app/templates/client.tsx Added SparkleIcon; implemented filtering by use cases; updated rendering for templates.
apps/www/app/templates/data.ts Introduced usecases constant and Usecase type; updated Template type to include usecase.
apps/www/lib/templates-form.ts Similar changes as in dashboard, added usecases to schema and updated related functions.

Assessment against linked issues

Objective Addressed Explanation
Add a category in the templates called use case (2289)

Suggested labels

🕹️ oss.gg, :joystick: 750 points, hacktoberfest

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr
  • MichaelUnkey

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

vercel bot commented Oct 10, 2024

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

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Oct 10, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Oct 10, 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: 2

🧹 Outside diff range and nitpick comments (6)
apps/dashboard/lib/templates-form.ts (2)

11-11: LGTM! Consider adding a comment for clarity.

The addition of usecases to the schema is consistent with the existing structure and aligns with the PR objective.

Consider adding a brief comment explaining the purpose of the usecases field, similar to the existing comments for other fields. For example:

  /** Array of use case identifiers */
  usecases: z.array(z.string()),

67-75: LGTM! Minor formatting suggestion.

The implementation of usecases handling in the updateUrl function is correct and consistent with other form values.

There's a minor indentation issue on line 67. Consider removing the extra space to maintain consistent formatting:

- 
apps/www/app/templates/data.ts (3)

20-21: LGTM! Consider adding a comment for the usecases constant.

The addition of the usecases constant and Usecase type is a good approach for maintaining type safety and consistency across the codebase. This will help prevent typos and ensure that only valid use cases are used.

Consider adding a brief comment above the usecases constant to explain its purpose and how it relates to the templates. For example:

// Defines the available use case categories for templates
export const usecases = ["Boilerplate", "Route protection", "RABC"] as const;

Line range hint 67-343: LGTM! Consider fixing the capitalization of "RABC".

The addition of the usecase property to all template objects is consistent with the changes made to the Template type and aligns with the PR objectives. This will allow for proper categorization and filtering of templates based on their use cases.

There's a minor inconsistency in the capitalization of "RABC" throughout the file. It should be "RBAC" (Role-Based Access Control). Please update the following lines:

  • Line 20: Change "RABC" to "RBAC" in the usecases constant
  • Lines 79, 103, 139, 151, and 330: Change "RABC" to "RBAC" in the respective template objects

This will ensure consistency and correctness in the use case terminology.


Action Required: Correct "RABC" to "RBAC" in data.ts

The verification script identified several instances where "RABC" is still used instead of "RBAC". Please update the following lines in apps/www/app/templates/data.ts:

  • Replace all occurrences of usecase: "RABC" with usecase: "RBAC".
  • Ensure that the usecases array no longer includes "RABC" but uses "RBAC" where appropriate.

This correction will align the terminology with the standard "Role-Based Access Control" acronym, improving code clarity and consistency.

🔗 Analysis chain

Line range hint 1-343: Overall, the changes successfully implement the new "use case" category.

The modifications to this file align well with the PR objectives of adding a new "use case" category to the templates page. The implementation includes:

  1. A new usecases constant and Usecase type for type-safe use of the defined categories.
  2. An updated Template type that includes the new usecase property.
  3. Addition of the usecase property to all template objects in the templates constant.

These changes provide a solid foundation for categorizing and filtering templates based on their use cases, enhancing the user experience as intended.

To ensure that all templates have been properly updated with the new usecase property, please run the following verification script:

This script will help ensure that all templates have been properly updated and that the "RABC" to "RBAC" correction has been applied consistently.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all templates have the usecase property

# Test: Check if any template is missing the usecase property
missing_usecase=$(rg -U 'title:.*\n(?:(?!usecase:).)*?},' apps/www/app/templates/data.ts)

if [ -n "$missing_usecase" ]; then
  echo "The following templates are missing the usecase property:"
  echo "$missing_usecase"
else
  echo "All templates have the usecase property."
fi

# Test: Check for any remaining "RABC" occurrences that should be "RBAC"
rabc_occurrences=$(rg 'RABC' apps/www/app/templates/data.ts)

if [ -n "$rabc_occurrences" ]; then
  echo "The following lines still contain 'RABC' instead of 'RBAC':"
  echo "$rabc_occurrences"
else
  echo "No 'RABC' occurrences found. All have been correctly changed to 'RBAC'."
fi

Length of output: 1391

apps/www/app/templates/client.tsx (1)

Line range hint 499-514: Refactor template tag rendering to avoid duplication

The code for rendering template tags for framework, language, and usecase repeats similar patterns. Consider refactoring this into a reusable component or a function to render tags dynamically, which will make the code cleaner and easier to maintain.

Here's how you might refactor it:

function renderTemplateTags(template: Template) {
  const tags = [
    template.framework,
    template.language,
    template.usecase,
  ].filter((tag): tag is string => tag !== undefined);

  return tags.map((tag) => (
    <div
      key={tag}
      className="px-2 py-1 text-xs rounded-md bg-[rgb(26,26,26)] text-white/60"
    >
      {tag}
    </div>
  ));
}

Then use it in your component:

<div className="flex flex-row flex-wrap justify-start w-full h-full gap-3">
  {renderTemplateTags(template)}
</div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0608fee and 711c353.

📒 Files selected for processing (4)
  • apps/dashboard/lib/templates-form.ts (4 hunks)
  • apps/www/app/templates/client.tsx (9 hunks)
  • apps/www/app/templates/data.ts (26 hunks)
  • apps/www/lib/templates-form.ts (5 hunks)
🧰 Additional context used
🔇 Additional comments (9)
apps/dashboard/lib/templates-form.ts (2)

28-28: LGTM! Consistent implementation of usecases initialization.

The changes correctly handle the initialization of usecases for both browser and non-browser contexts. The implementation is consistent with how other form values are managed.

Also applies to: 37-37, 43-43


Line range hint 1-105: Overall implementation looks good and aligns with PR objectives.

The changes consistently implement the new usecases property across the file, including schema definition, default value initialization, and URL parameter handling. This implementation successfully adds support for the new "use case" category in the templates page, as outlined in the PR objectives.

The code follows existing patterns and integrates well with the current structure. No significant issues were found in the logic or functionality.

apps/www/lib/templates-form.ts (6)

3-3: LGTM: Import statement for usecases added correctly.

The import statement for usecases is correctly added and uses a relative path consistent with the project structure.


12-12: LGTM: Usecases property added to schema correctly.

The usecases property is correctly added to the schema object using z.array(z.string()). This is consistent with the existing schema structure and appropriate for storing multiple use cases.


29-29: LGTM: Usecases added to default form values correctly.

The usecases property is correctly added to the default form values, initialized as an empty array when not in a browser environment. This is consistent with the existing function structure and ensures that the default form values include the new usecases property.


38-38: LGTM: Usecases added to URL parameter handling correctly.

The usecases property is correctly added to the URL parameter handling logic. It's retrieved from the URL parameters and included in the returned object, consistent with the handling of other properties. The logic correctly handles both the presence and absence of usecases in the URL.

Also applies to: 44-44


60-67: LGTM: Usecases handling added to updateUrl function correctly.

The usecases property is correctly added to the updateUrl function. The logic is consistent with the handling of other properties and correctly manages multiple usecases in the URL. It properly clears existing usecase parameters before adding new ones, ensuring accurate URL representation of the form state.


Line range hint 1-105: Summary: Implementation of "use case" category is complete and aligns with PR objectives.

The changes in this file successfully implement the new "use case" category for the templates page. The modifications include:

  1. Adding usecases to the schema
  2. Updating default form values
  3. Handling usecases in URL parameters
  4. Updating the URL with usecases values

These changes are consistent with the existing code structure and patterns, and they fully align with the PR objectives outlined in issue #2289. The implementation allows for proper management of use cases in form values, URL parameters, and schema validation, enhancing the templates page functionality as intended.

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

51-51: LGTM! The Template type has been correctly updated.

The addition of the usecase: Usecase; property to the Template type is consistent with the newly defined Usecase type. This ensures type safety and enforces the inclusion of a valid use case for each template.

apps/www/app/templates/client.tsx Show resolved Hide resolved
apps/www/app/templates/client.tsx Show resolved Hide resolved
@bitbrief bitbrief changed the title Added the use case category in templates page feat: Added the use case category in templates page Oct 10, 2024
@ankurjaiswalofficial
Copy link

/assign

Copy link

oss-gg bot commented Oct 11, 2024

You already have an open issue assigned to you here. Once that's closed or unassigned, only then we recommend you to take up more.

@ankurjaiswalofficial
Copy link

/assign

Copy link

oss-gg bot commented Oct 11, 2024

You already have an open issue assigned to you here. Once that's closed or unassigned, only then we recommend you to take up more.

@bitbrief
Copy link
Author

Hi @perkinsjr, when you have a moment, could you take a look at this PR? I'd love your feedback.

@harshsbhat
Copy link
Contributor

@bitbrief I am not the maintainer of this repo. But it should be RBAC (role-based access control) and not RABC

@bitbrief
Copy link
Author

Yeah I was wondering about the order.

@bitbrief
Copy link
Author

Hi maintainers,

I hope this message finds you well. I wanted to follow up regarding my pull request.

I understand that everyone is busy, but I would appreciate any updates on its status. If there’s anything further I need to do or if there are any concerns regarding the PR, please let me know.

Thank you for your time and help!

@chronark
Copy link
Collaborator

I don't think the current 3 usecases are what we really want in the end. I also think a template may have multiple usecases, not just a single one

wdyt @perkinsjr?

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.

Add a category in the templates called use case
6 participants