Skip to content

Conversation

@kingston
Copy link
Collaborator

@kingston kingston commented Feb 4, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the combobox functionality for a more reliable and responsive user experience.
    • Updated component demos to feature improved layout consistency for a cleaner presentation.
  • Tests

    • Added a comprehensive test suite for the combobox component to validate user interactions and ensure robust performance.
  • Chores

    • Refined module exports and configuration settings to support a React-focused testing setup.
    • Updated dependency versions to align with current internal standards.

@linear
Copy link

linear bot commented Feb 4, 2025

ENG-493 Combobox - design update

kingston could we make the options inside the combobox to be more like shadcn in terms of that check icon is on the left since we made it like that in Figma?

Design: https://www.figma.com/design/syKDQG1N5vFDH0y67eUNXC/Baseplate-Design-System-2024?node-id=444-6768

Shadcn/ui example:

image.png

@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: 0ae99ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@halfdomelabs/ui-components Patch
@halfdomelabs/project-builder-lib Patch
@halfdomelabs/project-builder-web Patch
@halfdomelabs/baseplate-plugin-storage Patch
@halfdomelabs/project-builder-cli Patch
@halfdomelabs/project-builder-common Patch
@halfdomelabs/project-builder-server Patch
@halfdomelabs/project-builder-test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request updates several packages by upgrading the cmdk library for the combobox component and adjusting various configuration and dependency settings. Changes include an enhanced test suite for the combobox, new exports and configurations for Vitest supporting React, and layout modifications in story files. Additionally, test helper functions and setup configurations have been introduced to streamline testing, while an obsolete dummy test has been removed.

Changes

File(s) Change Summary
.changeset/serious-feet-hide.md Upgraded cmdk version for combobox; added combobox test; applied dependency patch update.
packages/tools/package.json, packages/tools/vitest.config.react.js Updated exports in package.json to add "./vitest-react"; added a new Vitest configuration file tailored for React with testing options and plugins.
packages/ui-components/package.json Upgraded cmdk dependency from 1.0.0 to 1.0.4; added new devDependencies for various Testing Library packages.
packages/ui-components/src/components/Combobox/Combobox.tsx,
.../Combobox.stories.tsx,
.../Combobox.test.tsx
Added DEFAULT_OPTION constant and enhanced documentation in the component; wrapped input component in a story <div> container; introduced a comprehensive test suite with a new TestCombobox component.
packages/ui-components/src/components/Select/Select.stories.tsx Wrapped <Select.Trigger> and <Select.Value> in a <div className="w-80"> for layout adjustments.
packages/ui-components/src/tests/render.test-helper.tsx,
packages/ui-components/src/tests/setup.ts
Introduced renderWithProviders helper and a context provider component; added jsdom polyfills and a mock implementation of ResizeObserver in the test setup.
packages/ui-components/vitest.config.ts Updated export to reference @halfdomelabs/tools/vitest-react instead of vitest-node.
packages/ui-components/src/dummy.test.ts Removed the dummy test file.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test File
    participant R as renderWithProviders()
    participant P as UiComponentProviders
    participant CSP as ComponentStringsProvider
    participant C as Component Under Test

    T->>R: Invoke renderWithProviders(component)
    R->>P: Wrap component with providers
    P->>CSP: Inject default component strings
    CSP->>C: Render component with context
    C-->>T: Return rendered output
Loading

🪧 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. (Beta)
  • @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

@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

🧹 Nitpick comments (7)
packages/tools/vitest.config.react.js (2)

4-16: Move setup instructions to documentation.

Consider moving the setup instructions from comments to a dedicated README or documentation file for better maintainability and visibility.


25-25: Consider making setup file path configurable.

The hardcoded setup file path './tests/setup.ts' might not work for all projects. Consider making it configurable through environment variables or a configuration file.

-    setupFiles: ['./tests/setup.ts'],
+    setupFiles: [process.env.VITEST_SETUP_FILE || './tests/setup.ts'],
packages/ui-components/src/tests/setup.ts (1)

14-24: Consider enhancing ResizeObserver mock.

The current ResizeObserver mock is minimal. For more accurate testing, consider implementing basic size tracking:

   globalThis.ResizeObserver = class ResizeObserver {
+    private callback: ResizeObserverCallback;
+    private elements = new Set<Element>();
+
+    constructor(callback: ResizeObserverCallback) {
+      this.callback = callback;
+    }
+
     observe(element: Element): void {
-      // do nothing
+      this.elements.add(element);
     }
+
     unobserve(element: Element): void {
-      // do nothing
+      this.elements.delete(element);
     }
+
     disconnect(): void {
-      // do nothing
+      this.elements.clear();
     }
   };
packages/ui-components/src/tests/render.test-helper.tsx (1)

10-23: LGTM! Consider making providers composable.

The implementation is clean and follows best practices. For future extensibility, consider making the providers composable:

+type ProvidersProps = {
+  children: React.ReactNode;
+  providers?: React.ComponentType<{ children: React.ReactNode }>[];
+};
+
 const UiComponentProviders = ({
   children,
+  providers = [],
-}: {
-  children: React.ReactNode;
-}): React.JSX.Element => (
+}: ProvidersProps): React.JSX.Element => (
+  providers.reduce(
+    (acc, Provider) => <Provider>{acc}</Provider>,
+    <ComponentStringsProvider value={DEFAULT_COMPONENT_STRINGS}>
+      {children}
+    </ComponentStringsProvider>
+  )
-  <ComponentStringsProvider value={DEFAULT_COMPONENT_STRINGS}>
-    {children}
-  </ComponentStringsProvider>
 );

 export const renderWithProviders = (
   ui: ReactElement,
-  options?: Omit<RenderOptions, 'wrapper'>,
+  options?: Omit<RenderOptions, 'wrapper'> & { providers?: ProvidersProps['providers'] },
-): RenderResult => render(ui, { wrapper: UiComponentProviders, ...options });
+): RenderResult => render(ui, { 
+  wrapper: ({ children }) => (
+    <UiComponentProviders providers={options?.providers}>{children}</UiComponentProviders>
+  ),
+  ...options 
+});
packages/ui-components/src/components/Combobox/Combobox.test.tsx (3)

48-71: LGTM! Consider adding accessibility tests.

The rendering tests are well-structured. Consider adding tests for:

  • ARIA labels and roles
  • Screen reader announcements
  • Focus management

73-126: LGTM! Consider adding error state tests.

The user interaction tests are comprehensive. Consider adding tests for:

  • Invalid input handling
  • Error state display
  • Network error handling

128-198: LGTM! Consider adding loading state tests.

The keyboard navigation tests are thorough. Consider adding tests for:

  • Loading state display
  • Async option loading
  • Debounced search
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 128f42b and 6833eba.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • .changeset/serious-feet-hide.md (1 hunks)
  • packages/tools/package.json (1 hunks)
  • packages/tools/vitest.config.react.js (1 hunks)
  • packages/ui-components/package.json (2 hunks)
  • packages/ui-components/src/components/Combobox/Combobox.stories.tsx (1 hunks)
  • packages/ui-components/src/components/Combobox/Combobox.test.tsx (1 hunks)
  • packages/ui-components/src/components/Combobox/Combobox.tsx (3 hunks)
  • packages/ui-components/src/components/Select/Select.stories.tsx (1 hunks)
  • packages/ui-components/src/dummy.test.ts (0 hunks)
  • packages/ui-components/src/tests/render.test-helper.tsx (1 hunks)
  • packages/ui-components/src/tests/setup.ts (1 hunks)
  • packages/ui-components/vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/ui-components/src/dummy.test.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/ui-components/vitest.config.ts
  • packages/ui-components/src/components/Select/Select.stories.tsx
  • packages/ui-components/src/components/Combobox/Combobox.stories.tsx
🔇 Additional comments (9)
packages/ui-components/src/tests/setup.ts (1)

1-10: LGTM!

The setup is well-documented with clear references to GitHub issues for the workarounds. The cleanup implementation is correct.

Also applies to: 27-29

packages/ui-components/src/components/Combobox/Combobox.test.tsx (1)

200-226: LGTM! Edge cases are well covered.

The edge case tests effectively cover important scenarios like empty results and maintaining selected values.

packages/ui-components/src/components/Combobox/Combobox.tsx (3)

59-59: LGTM! Good practice extracting the default option.

Extracting the default option into a named constant improves code maintainability and reduces magic values.


486-488: LGTM! Good documentation.

The added documentation improves code maintainability by clearly describing the component's purpose.


218-229: Verify the impact of removing isOpen from dependency array.

The removal of isOpen from the handleKeydown dependency array could lead to stale closure issues. The function might not have access to the latest isOpen state.

Run this script to check if isOpen is used within the function:

✅ Verification successful

Final Determination: No Stale Closure Issue Found

The ast-grep check confirms that the isOpen variable is not referenced within the handleKeydown callback. Since the function only calls setIsOpen based on certain key events and does not depend on the current isOpen value, omitting it from the dependency array is correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if isOpen is used within handleKeydown function
ast-grep --pattern $'const handleKeydown = React.useCallback(
  ($_, $_) => {
    $$$
    isOpen
    $$$
  },
  $$$
)'

Length of output: 119

.changeset/serious-feet-hide.md (1)

1-6: LGTM! Clear and concise changeset.

The changeset accurately describes the package upgrade and test additions.

packages/tools/package.json (1)

30-31: LGTM! Good addition of vitest-react configuration.

The addition of the vitest-react export supports the PR objective of adding combobox tests.

packages/ui-components/package.json (2)

94-97: LGTM! Good addition of testing dependencies.

The addition of React Testing Library dependencies aligns with the PR objective of adding combobox tests.


71-71: Verify cmdk upgrade compatibility.

Please verify that the upgrade from cmdk 1.0.0 to 1.0.4 doesn't introduce breaking changes.

✅ Verification successful

Cmdk Upgrade Compatibility Verification

The cmdk upgrade from 1.0.0 to 1.0.4 does not introduce any additional breaking changes. All the breaking changes were established in the v1.0.0 release (such as case sensitivity for the value prop, mandatory wrapping with <Command.List>, and updated CSS attribute selectors). Versions 1.0.1 through 1.0.4 focus on bug fixes and dependency updates.

No further modifications are required beyond what was addressed for v1.0.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Web query:

What are the breaking changes between cmdk versions 1.0.0 and 1.0.4?

Length of output: 3747

@kingston kingston merged commit 76f4247 into main Feb 4, 2025
4 checks passed
@kingston kingston deleted the kingston/eng-493-combobox-design-update branch February 4, 2025 16:36
@github-actions github-actions bot mentioned this pull request Feb 4, 2025
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.

2 participants