Skip to content

[WEB-4748] chore: placement helper fn added and code refactor#7627

Merged
sriramveeraghanta merged 2 commits intopreviewfrom
chore-propel-placement-helper-fn
Aug 22, 2025
Merged

[WEB-4748] chore: placement helper fn added and code refactor#7627
sriramveeraghanta merged 2 commits intopreviewfrom
chore-propel-placement-helper-fn

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Aug 22, 2025

Description

This PR adds a placement helper utility function to the Propel package.

Type of Change

  • Code refactoring

Summary by CodeRabbit

  • New Features

    • Unified placement options across Popover and Tooltip, with consistent support for top/bottom/left/right, start/end variants, and auto.
    • More predictable alignment behavior when using placement values.
  • Refactor

    • Centralized placement logic into a shared utility for consistency and reduced duplication.
    • Popover and Tooltip now reference the same placement/side/align value set; no visual or behavioral changes expected for users.
    • Existing usage should continue to work with standardized option names.

@anmolsinghbhatia anmolsinghbhatia self-assigned this Aug 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

Centralizes placement types and conversion into a new shared utility (utils/placement.ts). Popover and Tooltip components remove local types/mappings and now import TPlacement/TSide/TAlign and convertPlacementToSideAndAlign. Public prop types are updated to reference shared types; local exports for placement types/functions are removed.

Changes

Cohort / File(s) Summary of changes
Placement utility centralization in components
packages/propel/src/popover/root.tsx, packages/propel/src/tooltip/root.tsx
Removed local placement types/mapping/converter; imported TPlacement, TSide, TAlign, convertPlacementToSideAndAlign from ../utils/placement. Updated prop types (placement/position, side, align) to shared types. Removed local exports for placement-related types/functions. Logic delegates conversion to utility.
New shared placement utility
packages/propel/src/utils/placement.ts
Added shared types TPlacement, TSide, TAlign. Added PLACEMENT_MAP and convertPlacementToSideAndAlign(placement) returning { side, align } with a default fallback.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Component as Popover/Tooltip
  participant Utility as utils/placement.convertPlacementToSideAndAlign

  User->>Component: render({ placement? / position?, side?, align? })
  alt placement/position provided
    Component->>Utility: convertPlacementToSideAndAlign(placement)
    Utility-->>Component: { side, align }
    Component->>Component: use returned side/align
  else explicit side/align provided
    Component->>Component: use provided side/align
  end
  Component-->>User: UI rendered with computed side/align
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • vamsikrishnamathala
  • sriramveeraghanta

Poem

A bunny maps the breeze to sides,
Aligns the stars where logic guides.
No more crumbs in every nook—
One shared warren for the book.
Popovers, tips, now hop in line,
With placements neat and all divine. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore-propel-placement-helper-fn

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@makeplane
Copy link

makeplane bot commented Aug 22, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/propel/src/tooltip/root.tsx (1)

26-33: Side/align are effectively ignored due to position = "top" default; fix precedence detection.

Because position has a default, if (position) is always true, so side/align can never take effect. This silently changes behavior for callers who only set side/align.

Use prop-presence detection to prefer:

  • position when explicitly provided, OR when neither side nor align is provided (preserve “top” default),
  • otherwise use side/align.
   const {
     tooltipHeading,
     tooltipContent,
-    position = "top",
+    position = "top",
     children,
     disabled = false,
     className = "",
     openDelay = 200,
-    side = "bottom",
-    align = "center",
+    side = "bottom",
+    align = "center",
     sideOffset = 10,
     closeDelay,
     isMobile = false,
   } = props;
-  const { finalSide, finalAlign } = React.useMemo(() => {
-    if (position) {
-      const converted = convertPlacementToSideAndAlign(position);
-      return { finalSide: converted.side, finalAlign: converted.align };
-    }
-    return { finalSide: side, finalAlign: align };
-  }, [position, side, align]);
+  // Determine precedence: use `position` if explicitly provided, or when neither `side` nor `align` are provided.
+  const hasPositionProp = Object.prototype.hasOwnProperty.call(props, "position");
+  const hasSideProp = Object.prototype.hasOwnProperty.call(props, "side");
+  const hasAlignProp = Object.prototype.hasOwnProperty.call(props, "align");
+  const shouldUsePosition = hasPositionProp || (!hasSideProp && !hasAlignProp);
+
+  const { finalSide, finalAlign } = React.useMemo(() => {
+    if (shouldUsePosition) {
+      const converted = convertPlacementToSideAndAlign(position);
+      return { finalSide: converted.side, finalAlign: converted.align };
+    }
+    return { finalSide: side, finalAlign: align };
+  }, [position, side, align, shouldUsePosition]);

Also applies to: 37-43

🧹 Nitpick comments (6)
packages/propel/src/utils/placement.ts (3)

22-39: Prefer an exhaustive typed Record over Map for compile-time coverage.

Using a Record<TPlacement, {side; align}> with satisfies guarantees every union member is mapped and removes the need for a runtime fallback. It’s also simpler and more treeshake-friendly than Map.

Apply:

-// placement conversion map
-const PLACEMENT_MAP = new Map<TPlacement, { side: TSide; align: TAlign }>([
-  ["auto", { side: "bottom", align: "center" }],
-  ["auto-start", { side: "bottom", align: "start" }],
-  ["auto-end", { side: "bottom", align: "end" }],
-  ["top", { side: "top", align: "center" }],
-  ["bottom", { side: "bottom", align: "center" }],
-  ["left", { side: "left", align: "center" }],
-  ["right", { side: "right", align: "center" }],
-  ["top-start", { side: "top", align: "start" }],
-  ["top-end", { side: "top", align: "end" }],
-  ["bottom-start", { side: "bottom", align: "start" }],
-  ["bottom-end", { side: "bottom", align: "end" }],
-  ["left-start", { side: "left", align: "start" }],
-  ["left-end", { side: "left", align: "end" }],
-  ["right-start", { side: "right", align: "start" }],
-  ["right-end", { side: "right", align: "end" }],
-]);
+// placement conversion map (exhaustive over TPlacement)
+const PLACEMENT_MAP = {
+  "auto": { side: "bottom", align: "center" },
+  "auto-start": { side: "bottom", align: "start" },
+  "auto-end": { side: "bottom", align: "end" },
+  "top": { side: "top", align: "center" },
+  "bottom": { side: "bottom", align: "center" },
+  "left": { side: "left", align: "center" },
+  "right": { side: "right", align: "center" },
+  "top-start": { side: "top", align: "start" },
+  "top-end": { side: "top", align: "end" },
+  "bottom-start": { side: "bottom", align: "start" },
+  "bottom-end": { side: "bottom", align: "end" },
+  "left-start": { side: "left", align: "start" },
+  "left-end": { side: "left", align: "end" },
+  "right-start": { side: "right", align: "start" },
+  "right-end": { side: "right", align: "end" },
+} satisfies Record<TPlacement, { side: TSide; align: TAlign }>;

41-47: Remove unreachable fallback and use object index.

With the exhaustive Record approach, a fallback should never be needed; returning a default can mask missing mappings during future edits.

-export function convertPlacementToSideAndAlign(placement: TPlacement): {
-  side: TSide;
-  align: TAlign;
-} {
-  return PLACEMENT_MAP.get(placement) || { side: "bottom", align: "center" };
-}
+export function convertPlacementToSideAndAlign(placement: TPlacement): {
+  side: TSide;
+  align: TAlign;
+} {
+  return PLACEMENT_MAP[placement];
+}

2-20: Nit: Type names without “T” prefix are more idiomatic in TS.

Placement, Side, Align read cleaner and align with common style, but this is subjective. If you prefer the T prefix across the codebase, keep it consistent.

packages/propel/src/tooltip/root.tsx (2)

6-20: Consider aligning prop naming: position vs placement.

Popover uses placement while Tooltip uses position. If feasible, consider aliasing placement in Tooltip props (with deprecation notice) for consistency.


26-33: Document precedence in props JSDoc.

A short note that position takes precedence over side/align (and defaults to "top" when neither is provided) will prevent confusion.

I can add JSDoc to ITooltipProps if you want.

packages/propel/src/popover/root.tsx (1)

33-41: Minor: Consider documenting precedence in the component props.

A brief comment in PopoverContentProps or component JSDoc about placement taking precedence over side/align would help usage clarity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d3b2699 and e594bac.

📒 Files selected for processing (3)
  • packages/propel/src/popover/root.tsx (1 hunks)
  • packages/propel/src/tooltip/root.tsx (1 hunks)
  • packages/propel/src/utils/placement.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/propel/src/tooltip/root.tsx (1)
packages/propel/src/utils/placement.ts (3)
  • TPlacement (2-17)
  • TSide (19-19)
  • TAlign (20-20)
packages/propel/src/popover/root.tsx (1)
packages/propel/src/utils/placement.ts (3)
  • TPlacement (2-17)
  • TAlign (20-20)
  • TSide (19-19)
🔇 Additional comments (7)
packages/propel/src/utils/placement.ts (1)

24-26: Confirm intent for “auto” placements mapping to bottom variants*

I attempted to locate any occurrences of placement="auto", placement="auto-start", or placement="auto-end" across our .ts and .tsx files and found none. It’s possible these variants aren’t used or may only appear in .js/.jsx examples or documentation. Since normalizing all “auto*” cases to bottom variants removes any viewport-aware flipping (a breaking change if consumers expected dynamic flips), please:

  • Manually verify that there are no existing uses of "auto", "auto-start", or "auto-end" in any .js/.jsx files, examples, or docs.
  • If the behavior change is intentional, update our documentation to note that auto* now maps to bottom-only placements (no flipping).
  • Otherwise, consider preserving the original “auto” semantics by routing dynamic flipping through the underlying Positioner’s collision/flip props rather than normalizing here.
packages/propel/src/tooltip/root.tsx (3)

4-4: Good move centralizing placement types/logic.

Importing shared TPlacement/TSide/TAlign and the converter reduces duplication and keeps Tooltip aligned with Popover.


50-67: LGTM on Positioner usage.

side, align, and sideOffset flow correctly into BaseTooltip.Positioner, and className merging is clean.


6-20: Verify removal of legacy placement exports

Please manually confirm that no consumer code is importing the now-removed placement-related types or helpers from the Tooltip package. Specifically, search for any references to the following identifiers in your application or other packages:

  • TPosition
  • Placement
  • Side
  • Align
  • convertPlacementToSideAndAlign

If any usages are found, they should be updated to use the new props on ITooltipProps (position?: TPlacement, side?: TSide, align?: TAlign) or those legacy types/functions should be re-exported where needed.

packages/propel/src/popover/root.tsx (3)

3-3: Nice consolidation of placement utilities.

Importing shared types and converter removes duplication and keeps Popover/Tooltip behavior in sync.


25-31: Precedence logic reads correctly.

Using placement when provided, otherwise falling back to side/align matches expected behavior and pairs well with the shared converter.


6-11: No downstream breakage detected from type name changes
A repository-wide search found no imports of the old Placement, Side, Align, or convertPlacementToSideAndAlign exports.

  • The only import from packages/propel/src/popover/root is Popover in packages/propel/src/combobox/combobox.tsx, which isn’t affected by the type renames.

@sriramveeraghanta
Copy link
Member

@anmolsinghbhatia Format check is failing. Can you look into it?

@sriramveeraghanta sriramveeraghanta merged commit 7060853 into preview Aug 22, 2025
6 of 7 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore-propel-placement-helper-fn branch August 22, 2025 19:12
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.

4 participants