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

style: sort languages and frameworks alphabetically in the template filter #2502

Closed
wants to merge 16 commits into from

Conversation

ShreyasLakhani
Copy link

@ShreyasLakhani ShreyasLakhani commented Oct 19, 2024

What does this PR do?

This PR implements a new feature that allows users to filter items by category, enhancing the user experience by making it easier to find relevant items. This change fixes issue #2432, which requested this functionality. No additional dependencies are required for this change.

Fixes #2432

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?

  • Test A : go to https://unkey.com/templates and check that filters on left side is proper filtered or not.
  • Test B : Check that the application does not crash when no category is selected and that all items are displayed.

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

    • Enhanced framework filtering functionality with improved alphabetical sorting for better user experience.
    • Streamlined presentation of filtering options in the AccordionContent.
  • Bug Fixes

    • Removed commented-out code for a cleaner and more readable component structure.

Copy link

changeset-bot bot commented Oct 19, 2024

⚠️ No Changeset found

Latest commit: bc426f4

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

@ShreyasLakhani 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 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

vercel bot commented Oct 19, 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 30, 2024 11:26am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 30, 2024 11:26am

Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request modifies the TemplatesClient component in apps/www/app/templates/client.tsx by introducing a sorting mechanism for the frameworks displayed in the filter section. The frameworks are now sorted alphabetically using the localeCompare method before rendering, ensuring a consistent order. The overall structure and functionality of the component, including the filtering logic and memoization of filtered templates, remain unchanged.

Changes

File Path Change Summary
apps/www/app/templates/client.tsx Added alphabetical sorting for frameworks in the filter section using localeCompare. Maintained existing filtering logic.

Assessment against linked issues

Objective Addressed Explanation
Filter options should be sorted alphabetically (#2432)

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

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

@ShreyasLakhani ShreyasLakhani changed the title fixes #2432 : Sort languages and frameworks alphabetically in the template filter Sort languages and frameworks alphabetically in the template filter Oct 19, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
apps/www/app/templates/client.tsx (1)

Line range hint 278-313: LGTM: Alphabetical sorting of framework options implemented.

The changes successfully implement the requested feature of sorting framework options alphabetically, consistent with the language filtering implementation. The functionality is preserved while improving the user experience.

Consider extracting the sorting logic into a reusable function to reduce code duplication:

const sortAlphabetically = (a: [string, any], b: [string, any]) => a[0].localeCompare(b[0]);

// Then use it like this:
Object.entries(languages).sort(sortAlphabetically).map(...)
Object.entries(frameworks).sort(sortAlphabetically).map(...)

This would make the code more DRY and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d774a4c and 435c84d.

📒 Files selected for processing (1)
  • apps/www/app/templates/client.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (2)
apps/www/app/templates/client.tsx (2)

Line range hint 218-254: LGTM: Alphabetical sorting of language options implemented.

The changes successfully implement the requested feature of sorting language options alphabetically. The use of localeCompare for sorting is appropriate and ensures correct alphabetical order. The existing functionality is preserved while improving the user experience.


Line range hint 218-313: Summary: PR objectives successfully implemented

The changes in this PR effectively address the issue #2432 by implementing alphabetical sorting for both language and framework filter options. This enhancement improves the user experience by making it easier to locate specific options within the filters.

Key points:

  1. The sorting is consistently implemented for both languages and frameworks.
  2. The existing functionality of the component is preserved.
  3. The changes are focused and do not introduce any apparent issues.

These modifications align well with the PR objectives and should provide a noticeable improvement in usability for the templates page.

@ShreyasLakhani ShreyasLakhani changed the title Sort languages and frameworks alphabetically in the template filter fix: Sort languages and frameworks alphabetically in the template filter Oct 19, 2024
@ShreyasLakhani ShreyasLakhani changed the title fix: Sort languages and frameworks alphabetically in the template filter fix(template): sort languages and frameworks alphabetically in the template filter Oct 19, 2024
@ShreyasLakhani ShreyasLakhani changed the title fix(template): sort languages and frameworks alphabetically in the template filter fix: sort languages and frameworks alphabetically in the template filter Oct 19, 2024
@ShreyasLakhani ShreyasLakhani changed the title fix: sort languages and frameworks alphabetically in the template filter style: sort languages and frameworks alphabetically in the template filter Oct 19, 2024
@ShreyasLakhani
Copy link
Author

@perkinsjr @chronark please review my PR and give feedback.

@shahilsinghyadav
Copy link

/assign

Copy link

oss-gg bot commented Oct 20, 2024

The /assign command can only be used on issues, not on pull requests.

@ShreyasLakhani
Copy link
Author

@perkinsjr @chronark @MichaelUnkey @mcstepp Can anyone review my PR?

@ShreyasLakhani
Copy link
Author

@chronark tell me is it works or not?

@@ -37,6 +37,9 @@ import { useEffect, useMemo } from "react";
import { useForm } from "react-hook-form";
import { type Framework, type Language, templates } from "./data";

// New reusable sorting function
const sortAlphabetically = (a: [string, any], b: [string, any]) => a[0].localeCompare(b[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use any

render={({ field }) => {
return (
{Object.entries(frameworks)
.sort(sortAlphabetically) // Use the new sorting function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use what you did in line 222

Copy link
Author

@ShreyasLakhani ShreyasLakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chronark done changes as per yours.

I hope this work.
Let me know if anything miss.

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

🧹 Outside diff range and nitpick comments (1)
apps/www/app/templates/client.tsx (1)

281-283: Fix misleading comment in frameworks sorting.

The comment incorrectly refers to "languages" instead of "frameworks".

-  .sort(([langA], [langB]) => langA.localeCompare(langB)) // Sort languages alphabetically
+  .sort(([frameworkA], [frameworkB]) => frameworkA.localeCompare(frameworkB)) // Sort frameworks alphabetically
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3ca455d and b286a73.

📒 Files selected for processing (1)
  • apps/www/app/templates/client.tsx (5 hunks)
🧰 Additional context used
🪛 Biome
apps/www/app/templates/client.tsx

[error] 41-41: This variable is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
Unsafe fix: If this is intentional, prepend sortAlphabetically with an underscore.

(lint/correctness/noUnusedVariables)

🔇 Additional comments (2)
apps/www/app/templates/client.tsx (2)

Line range hint 221-257: LGTM! Languages sorting implementation is correct.

The implementation correctly sorts languages alphabetically using localeCompare, maintaining type safety and readability.


Line range hint 221-316: Verify sorting implementation across the codebase.

The implementation successfully adds alphabetical sorting to both languages and frameworks sections. Let's verify there are no other instances requiring similar sorting.

✅ Verification successful

Sorting implementation is correctly applied where needed

The verification shows that:

  1. The alphabetical sorting in the languages and frameworks sections is consistent with other sorting implementations in the codebase
  2. Other instances of sorting are appropriately implemented for their specific use cases (e.g., date sorting for blog posts, name sorting for projects)
  3. No other instances of language/framework listings were found that would require similar alphabetical sorting
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other potential locations that might need alphabetical sorting

# Look for similar patterns of Object.entries().sort() that might need consistent sorting
rg -A 2 "Object\.entries\([^)]+\)\.sort\(" --type tsx --type jsx

# Look for potential framework/language related code that might need sorting
rg -l "frameworks|languages" --type tsx --type jsx

Length of output: 175


Script:

#!/bin/bash
# Description: Check for other potential locations that might need alphabetical sorting

# Look for similar patterns of Object.entries().sort() that might need consistent sorting
rg -A 2 "Object\.entries\([^)]+\)\.sort\("

# Look for potential framework/language related code that might need sorting
rg -l "frameworks|languages"

# Look for other potential sorting implementations
rg "\.sort\(\([a-zA-Z]" -A 2

Length of output: 4061

apps/www/app/templates/client.tsx Outdated Show resolved Hide resolved
Copy link
Author

@ShreyasLakhani ShreyasLakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chronark Rewrite the sorting logic.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ShreyasLakhani
Copy link
Author

ShreyasLakhani commented Oct 29, 2024

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

@ShreyasLakhani: I will redo the entire review of the PR as per your request.

✅ Actions performed

Full review triggered.

@ShreyasLakhani
Copy link
Author

@chronark can you please review my changes before end of the hacktoberfest

@chronark
Copy link
Collaborator

mate, what are we doing here?
CleanShot 2024-10-30 at 12 27 14@2x
it's not sorted again

@ShreyasLakhani ShreyasLakhani deleted the templete-filter branch October 30, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/templates filters should be ordered alphabetically
4 participants