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

Add clear filters functionlity, update filters styles #232

Merged
merged 6 commits into from
Dec 10, 2024
Merged

Add clear filters functionlity, update filters styles #232

merged 6 commits into from
Dec 10, 2024

Conversation

hta218
Copy link
Member

@hta218 hta218 commented Dec 10, 2024

Summary by CodeRabbit

  • New Features

    • Simplified header layout by removing the DialogDemo component.
    • Enhanced tooltip appearance with reduced padding.
    • Added functionality to display applied filters above pagination controls, allowing users to clear filters easily.
    • Introduced visual elements such as the CheckCircle icon in the sorting component.
  • Bug Fixes

    • Updated rendering logic for filter items to improve display options and consistency.
  • Documentation

    • Improved structure and readability of filter management components.

Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The pull request introduces several modifications across multiple components, primarily focusing on the user interface and structure of various elements. Key changes include the removal of the DialogDemo component from the DesktopHeader, adjustments to padding in the TooltipContent, and enhancements to the Filters component with a new FilterLabel. The ProductsPagination component now displays applied filters above pagination controls, while the Sort component has updated visual feedback for selected sorting options. Overall, the changes aim to streamline component functionality and improve the user experience.

Changes

File Path Change Summary
app/components/header/desktop-header.tsx Removed DialogDemo component from JSX, simplifying header layout while retaining core logic and hooks.
app/components/tooltip.tsx Modified TooltipContent padding from px-4 to px-3, with no other structural changes.
app/sections/collection-filters/filters.tsx Renamed ListItemFilter to FilterItem, updated parameters and rendering logic, added FilterLabel for consistent display.
app/sections/collection-filters/products-pagination.tsx Added appliedFilters to data from useLoaderData, enabling display of applied filters above pagination controls.
app/sections/collection-filters/sort.tsx Added CheckCircle icon, modified Link import, and updated rendering logic for current sort value.

Possibly related PRs

  • Update account pages #208: The changes in the DesktopHeader component may relate to the account pages, as both involve user interface elements that could impact the overall layout and navigation experience for users accessing account-related features.

Suggested labels

enhancement

Poem

In the header, a demo's gone,
Simplified, it carries on.
Tooltips now with snugger grace,
Filters dance in their new place.
Pagination shows what's applied,
Sorting shines with boldness, wide! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@hta218 hta218 merged commit bbdf99a into main Dec 10, 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 (7)
app/sections/collection-filters/sort.tsx (1)

1-1: Remove unused import

The CheckCircle icon is imported but never used in the code.

-import { CaretDown, CheckCircle } from "@phosphor-icons/react";
+import { CaretDown } from "@phosphor-icons/react";
app/sections/collection-filters/products-pagination.tsx (1)

41-64: Add accessibility improvements to filter tags

The filter tags implementation looks good but could benefit from accessibility enhancements.

 <Link
   key={label}
   to={getAppliedFilterLink(filter, params, location)}
-  className="px-2 py-1 border border-line-subtle hover:border-line items-center gap-2"
+  className="px-2 py-1 border border-line-subtle hover:border-line items-center gap-2 inline-flex"
+  aria-label={`Remove ${label} filter`}
   variant="custom"
 >
   <span>{label}</span>
-  <X className="w-4 h-4" />
+  <X className="w-4 h-4" aria-hidden="true" />
 </Link>
app/sections/collection-filters/filters.tsx (5)

47-49: Consider using filter IDs instead of labels for key generation.

The current implementation concatenates filter labels to generate a key. Using filter IDs would be more reliable as labels might not be unique or could contain special characters.

-  let appliedFiltersKeys = appliedFilters
-    .map((filter) => filter.label)
-    .join("-");
+  let appliedFiltersKeys = appliedFilters
+    .map((filter) => filter.id)
+    .join("-");

56-56: Optimize Accordion key generation.

Including expandFilters and showFiltersCount in the key is unnecessary as these props will trigger re-renders naturally when changed. Consider using only the appliedFiltersKeys.

-      key={appliedFiltersKeys + expandFilters.toString() + showFiltersCount}
+      key={appliedFiltersKeys}

Line range hint 141-232: Consider splitting FilterItem into separate components.

The component has grown complex with multiple display types. Consider:

  1. Splitting into separate components (ColorSwatchFilter, ButtonFilter, ListItemFilter).
  2. Extracting button styles to a constant.

This would improve maintainability and make the code more modular.

Example refactor:

const buttonStyles = {
  base: "px-3 py-1.5 border text-center",
  disabled: "diagonal text-body-subtle",
  checked: "border-line bg-body text-background",
  unchecked: "border-line-subtle hover:border-line",
} as const;

function ButtonFilter({ option, checked, onChange, showFiltersCount }) {
  return (
    <button
      type="button"
      className={cn(
        buttonStyles.base,
        option.count === 0 && buttonStyles.disabled,
        checked ? buttonStyles.checked : buttonStyles.unchecked
      )}
      onClick={onChange}
    >
      <FilterLabel option={option} showFiltersCount={showFiltersCount} />
    </button>
  );
}

// Similar components for ColorSwatchFilter and ListItemFilter

246-258: Consider memoizing FilterLabel for performance.

Since FilterLabel is used across all filter types and re-renders frequently, consider memoizing it with React.memo to prevent unnecessary re-renders.

-function FilterLabel({
+const FilterLabel = React.memo(function FilterLabel({
  option,
  showFiltersCount,
}: {
  option: Filter["values"][0];
  showFiltersCount: boolean;
}) {
  if (showFiltersCount) {
    return (
      <span>
        {option.label} <span>({option.count})</span>
      </span>
    );
  }
  return option.label;
-}
+});

Clear filters functionality is partially implemented but needs proper handling

The "Clear all filters" link exists in products-pagination.tsx, but it only uses a basic navigation to the pathname without any filter state management. For proper implementation:

  • The Link component in products-pagination.tsx needs to be enhanced with proper filter state clearing functionality
  • Consider adding a handler to properly reset all filter states when clicked
🔗 Analysis chain

Line range hint 1-1: Missing clear filters functionality mentioned in PR title.

The PR title mentions "Add clear filters functionality" but the implementation doesn't include this feature. Please clarify if this functionality will be added in a separate PR or if it should be implemented here.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any clear filters related code
rg -i "clear.?filter" --type ts --type tsx

Length of output: 72


Script:

#!/bin/bash
# Search for any clear filters related code, using ripgrep without file type restrictions
rg -i "clear.?filter"

# Also search for potential clear/reset functionality with different naming
rg -i "(clear|reset).*(filter|selection)"

# Look for filter-related components and their props/methods
ast-grep --pattern 'function $_($$$ filter $$$) {
  $$$
}'

Length of output: 214


Script:

#!/bin/bash
# Let's check the context around the "Clear all filters" text to understand its implementation
rg -B 5 -A 5 "Clear all filters" app/sections/collection-filters/products-pagination.tsx

# Look for any filter-related state management or handlers
ast-grep --pattern 'const $_ = $$$filter$$$'

# Check for any onClick or similar handlers that might be related to clearing filters
rg -i "on.*click.*clear" -A 2

Length of output: 593

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1f9dc and e47364b.

📒 Files selected for processing (5)
  • app/components/header/desktop-header.tsx (0 hunks)
  • app/components/tooltip.tsx (1 hunks)
  • app/sections/collection-filters/filters.tsx (7 hunks)
  • app/sections/collection-filters/products-pagination.tsx (2 hunks)
  • app/sections/collection-filters/sort.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • app/components/header/desktop-header.tsx
🔇 Additional comments (6)
app/components/tooltip.tsx (1)

33-33: LGTM: Minor padding adjustment

The horizontal padding reduction from px-4 to px-3 is a safe UI refinement.

app/sections/collection-filters/sort.tsx (2)

72-72: LGTM: Improved sort indicator

Changed from underline to bold for better visual feedback of the selected sort option.


4-4: Verify Link component behavior

The import source for Link has changed from @remix-run/react to a custom component. Ensure the custom Link component maintains the same navigation behavior.

✅ Verification successful

Custom Link component maintains proper navigation behavior

The custom Link component is a well-implemented wrapper around Remix's Link component (RemixLink). It:

  • Properly imports and extends Remix's Link functionality
  • Adds useful features like locale prefixing and styling variants
  • Forwards all standard Link props to the underlying RemixLink component
  • Maintains the core navigation behavior through proper prop forwarding
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the custom Link component properly handles navigation
ast-grep --pattern 'export default function Link({ $props }) {
  $$$
}'

Length of output: 73


Script:

#!/bin/bash
# Let's first find the custom Link component file
fd "link.tsx" --type f

# Then examine its implementation
rg -l "export.*function.*Link" --type ts --type tsx

# Look for any usage of Remix's Link component
rg "import.*Link.*from.*@remix-run/react" --type ts --type tsx

Length of output: 249


Script:

#!/bin/bash
# Let's examine the implementation of the custom Link component
cat app/components/link.tsx

# Look for any usage of Remix's Link component without file type flags
rg "import.*Link.*from.*@remix-run/react"

Length of output: 7580

app/sections/collection-filters/products-pagination.tsx (2)

29-34: LGTM: Type-safe loader data

Good use of TypeScript to ensure type safety with the added appliedFilters data.


60-62: LGTM: Clear filters functionality

The "Clear all filters" link implementation aligns with the PR objectives and provides a good user experience.

app/sections/collection-filters/filters.tsx (1)

62-62: LGTM! Clean implementation of display type handling.

The conditional className logic effectively handles different display types while maintaining clean code structure.

Also applies to: 92-94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant