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

chore(weave): add highlight state when editing filters #3889

Merged
merged 2 commits into from
Mar 18, 2025

Conversation

gtarpenning
Copy link
Member

@gtarpenning gtarpenning commented Mar 17, 2025

Description

WB-23846

Add highlight state when editing filter.

Testing

Screenshot 2025-03-17 at 4 56 49 PM Screenshot 2025-03-17 at 4 56 58 PM

Summary by CodeRabbit

  • New Features

    • Enhanced filter editing experience with clear visual feedback when a filter is actively being edited.
    • The editing state now automatically resets when a filter is removed or editing is exited, ensuring seamless interactions.
  • Style

    • Updated filter tag presentation with distinct color cues to differentiate between editing and default states.

Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request introduces a new state variable activeEditId in the FilterBar component to track the filter currently being edited. The component’s update, removal, and popover closure methods have been modified to manage this state correctly. In addition, the FilterTag and FilterTagItem components now accept an optional isEditing prop (defaulting to false) to reflect an editing state in their rendering logic.

Changes

File(s) Summary
weave-js/src/.../FilterBar.tsx Added activeEditId state; updated onUpdateFilter, onRemoveFilter, and onSetSelected to manage filter editing state; updated dependencies.
weave-js/src/.../FilterTag.tsx
weave-js/src/.../FilterTagItem.tsx
Introduced optional isEditing prop (default false) in both components; adjusted tag color and passed the prop from FilterTagItem to FilterTag.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant FB as FilterBar
    participant FTI as FilterTagItem
    participant FT as FilterTag

    U->>FB: Triggers filter edit (onUpdateFilter)
    FB-->>FB: Sets activeEditId to filter ID
    FB->>FTI: Passes isEditing prop based on activeEditId
    FTI->>FT: Forwards isEditing to adjust display

    U->>FB: Removes a filter (onRemoveFilter)
    FB-->>FB: Resets activeEditId if filter removed

    U->>FB: Closes popover (onSetSelected)
    FB-->>FB: Clears activeEditId
Loading

Possibly related PRs

Suggested reviewers

  • bcsherma
  • nicholaspun-wandb

Poem

Oh what a hop in the code today,
A rabbit's delight in a clever display.
With activeEditId set to guide the edit,
And isEditing flags keeping the mode legit.
Carrots and code, in sync we play,
Bounding along the path of a bright new day!
🐇🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.
  • @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.

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

@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 comments (1)
weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterBar.tsx (1)

211-212: ⚠️ Potential issue

Include activeEditId in dependency array.

The onUpdateFilter callback references activeEditId but it's not included in the dependency array, which could lead to stale closures.

  },
-  [localFilterModel, updateLocalAndDebouncedFilterModel]
+  [localFilterModel, updateLocalAndDebouncedFilterModel, activeEditId]
);
🧹 Nitpick comments (1)
weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterBar.tsx (1)

253-254: Avoid duplicate state cleanup logic.

The activeEditId is cleared in both onSetSelected and the Popover's onClose handler. This is redundant as setAnchorEl(null) will trigger the onClose event.

  setAnchorEl(null);

-  // Clear active edit when popover is closed
-  setActiveEditId(null);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11526fb and d6e65d1.

📒 Files selected for processing (3)
  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterBar.tsx (6 hunks)
  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTag.tsx (1 hunks)
  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTagItem.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,jsx,ts,tsx}`: Focus on architectural and logical i...

**/*.{js,jsx,ts,tsx}: Focus on architectural and logical issues rather than style (assuming ESLint is in place).
Flag potential memory leaks and performance bottlenecks.
Check for proper error handling and async/await usage.
Avoid strict enforcement of try/catch blocks - accept Promise chains, early returns, and other clear error handling patterns. These are acceptable as long as they maintain clarity and predictability.
Ensure proper type usage in TypeScript files.
Look for security vulnerabilities in data handling.
Don't comment on formatting if prettier is configured.
Verify proper React hooks usage and component lifecycle.
Check for proper state management patterns.

  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTagItem.tsx
  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTag.tsx
  • weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterBar.tsx
⏰ Context from checks skipped due to timeout of 90000ms (90)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
🔇 Additional comments (11)
weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTag.tsx (2)

9-9: Well structured TypeScript prop definition.

The optional boolean prop is correctly typed with the TypeScript optional modifier.


12-20: Good implementation of the highlight state feature.

The component correctly:

  1. Destructures the new isEditing prop with a proper default value
  2. Uses a conditional to set the tag color based on the editing state

This provides clear visual feedback to users when they're editing a filter.

weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterTagItem.tsx (3)

29-29: Consistent prop typing pattern.

The optional isEditing prop is correctly defined with the TypeScript optional modifier, maintaining consistency with the parent component.


39-43: Clean prop destructuring with default value.

The function signature properly destructures the props including the new isEditing prop with a default value of false.


72-72: Proper prop forwarding.

The isEditing prop is correctly passed to the child FilterTag component, ensuring the visual state is properly propagated.

weave-js/src/components/PagePanelComponents/Home/Browse3/filters/FilterBar.tsx (6)

67-67: Good state management with clear typing.

The new state variable activeEditId is correctly initialized with null and properly typed as FilterId | null.


194-196: Good implementation of active filter tracking.

Setting the active edit ID when a filter is updated provides the foundation for the highlight state feature.


221-225: Properly clean up editing state.

Good handling of the edge case where the active filter is removed, ensuring the UI state remains consistent.


226-226: Correctly updated dependency array.

The dependency array properly includes activeEditId, ensuring the callback has access to the latest state.


286-286: Proper prop passing to child component.

The isEditing prop is correctly passed to the FilterTagItem component based on comparison with the activeEditId.


311-314: Consolidated state management.

Good implementation of the onClose handler to clear both the anchor element and the active edit ID when the popover is closed.

@circle-job-mirror
Copy link

circle-job-mirror bot commented Mar 18, 2025

@gtarpenning gtarpenning marked this pull request as ready for review March 18, 2025 02:07
@gtarpenning gtarpenning requested review from a team as code owners March 18, 2025 02:07
Copy link
Contributor

@neutralino1 neutralino1 left a comment

Choose a reason for hiding this comment

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

I wonder if we can leverage the :focus pseudo-class instead of a React state to do this. It would be more minimal, lower level, and more centralized (meaning we wouldn't have to do this for each individual field).

Alternatively, what about the focus and blur events?

@gtarpenning
Copy link
Member Author

I wonder if we can leverage the :focus pseudo-class instead of a React state to do this. It would be more minimal, lower level, and more centralized (meaning we wouldn't have to do this for each individual field).

Alternatively, what about the focus and blur events?
@neutralino1

Played around with this, afaict using focus is going to be hard, because we want to update a totally different component. we want the children to light up when selecting the filter in the edit window, only while actively editing. Maybe i'm misunderstanding though.

@neutralino1
Copy link
Contributor

Ah yeah, I see we're using a div around the actual elements. So can't use :focus on that. Thanks!

@gtarpenning gtarpenning enabled auto-merge (squash) March 18, 2025 20:18
@gtarpenning gtarpenning merged commit 22b8ba1 into master Mar 18, 2025
129 of 131 checks passed
@gtarpenning gtarpenning deleted the griffin/highlight-editing-filter branch March 18, 2025 20:45
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants