Skip to content

Conversation

@kyrapieterse
Copy link
Contributor

@kyrapieterse kyrapieterse commented Sep 28, 2025

Fixes #5783

Summary by CodeRabbit

  • New Features

    • Adds inline-block reset support and propagates block attributes so color controls resolve resets from the correct source.
    • Reset events now include an explicit flag so controls can distinguish resets from regular edits.
  • Bug Fixes

    • Reset now prioritizes actual block attribute values (preferring hover when present) and avoids inheriting earlier breakpoint values.
    • Hover no longer contaminates default/reset values; palette and non-palette resets behave consistently across breakpoints.

@kyrapieterse kyrapieterse self-assigned this Sep 28, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 28, 2025

Walkthrough

Adds blockAttributes support and an isReset flag to color layer reset logic; enhances getResetValue to resolve IB (inline block) and non-IB reset values (preferring the block's actual attribute values and previous-breakpoint non-hover values), and threads isReset through onChangeColor emissions.

Changes

Cohort / File(s) Summary
Color layer logic & API
src/components/background-control/colorLayer.js
Added blockAttributes prop; onChangeColor gains isReset = false param and emits isReset: true when resetting. getResetValue updated to handle IB path (read target block's attributes, prefer hover values) and non-IB path (use prevBreakpoint or current breakpoint with isHover=false). Reset flow now uses blockAttributes where appropriate.
Background layers control plumbing
src/components/background-control/backgroundLayersControl.js
blockAttributes prop threaded into getLayerCardContent and BackgroundLayersControl; added getBlockLayer helper to locate matching layer in blockAttributes['background-layers'] (by order/type) and pass it into ColorLayer. onChange handling extended to accept and re-attach isReset.
Block-level propagation
src/components/background-control/blockBackgroundControl.js
Propagates blockAttributes from BlockBackgroundControl down to BackgroundLayersControl (props signature updated).
Relation control attributes
src/components/relation-control/index.js
Adds isHover property to attributes passed into relation-setting UI (derived from `item.effects?.hoverStatus

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as BackgroundLayersControl / Color UI
  participant CL as ColorLayer.getResetValue
  participant BlockAttrs as Block Attributes (IB)
  participant Store as Breakpoint Data (non-IB)

  User->>UI: Click "Reset" on a color layer (maybe in hover)
  UI->>CL: onReset() -> getResetValue(isLayer, isHover, breakpoint, prevBreakpoint, blockAttributes)
  alt isLayer (IB) path
    CL->>BlockAttrs: Read target layer attributes (prefer hover value)
    BlockAttrs-->>CL: Resolved attribute(s)
  else non-IB path
    alt prevBreakpoint exists
      CL->>Store: Query prevBreakpoint data with isHover=false
      Store-->>CL: Prev breakpoint color
    else
      CL->>Store: Query current breakpoint data with isHover=false
      Store-->>CL: Current non-hover color
    end
  end
  CL-->>UI: return reset value (includes isReset: true)
  UI->>UI: Emit onChangeColor(payload including isReset)
  UI-->>User: UI updates color control
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

bug 🐛, Final code review, lgtm, size:XS

Suggested reviewers

  • Olekrut

Poem

A rabbit nudges pigment back in line,
Hover hops retreat to the normal sign.
I fetch the block, I check the past,
Restore the hue that holds and lasts.
Little paws, precise and spry — reset complete, oh my! 🐰🎨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The addition of an isHover property in src/components/relation-control/index.js is unrelated to restoring background colours on hover reset and does not pertain to the linked issue’s objectives. Please remove or isolate the unrelated isHover changes in relation-control/index.js into a separate pull request to keep this fix focused solely on the hover-state background colour reset.
Description Check ⚠️ Warning The pull request description only contains a link to the issue and does not include a summary of the changes, motivation or context, a “How Has This Been Tested?” section, or the required test checklist, so it does not follow the repository’s description template. Please expand the description to include a concise summary of the changes, related motivation and context, a “How Has This Been Tested?” section detailing your testing steps, and a completed test checklist as specified by the template.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly describes the primary change, focusing on adding reset behavior for background colours in the hover state, which directly aligns with the pull request’s main objective of fixing the hover-state reset functionality. It is specific to the background colour reset feature without extra noise or unrelated details.
Linked Issues Check ✅ Passed The changes introduce an isReset flag and enhanced getResetValue logic that correctly retrieves the normal-state colour when resetting hover state, directly addressing the issue requirement that the hover reset returns the normal-state background colour.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Reset-for-colours-of-BG-colour-on-hover-state

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Sep 28, 2025
@elzadj elzadj requested a review from Olekrut September 29, 2025 09:56
Copy link
Collaborator

@Olekrut Olekrut left a comment

Choose a reason for hiding this comment

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

kyrapieterse and others added 3 commits October 8, 2025 12:25
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Oct 13, 2025
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 944e629 and b0b6dea.

📒 Files selected for processing (4)
  • src/components/background-control/backgroundLayersControl.js (6 hunks)
  • src/components/background-control/blockBackgroundControl.js (2 hunks)
  • src/components/background-control/colorLayer.js (6 hunks)
  • src/components/relation-control/index.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/background-control/colorLayer.js (2)
src/components/color-control/index.js (1)
  • showPalette (133-133)
src/extensions/style-cards/getSCVariablesObject.js (1)
  • paletteOpacity (23-23)
src/components/background-control/backgroundLayersControl.js (1)
src/components/background-control/utils.js (4)
  • layer (81-81)
  • layer (123-123)
  • handleOnChangeLayer (148-160)
  • handleOnChangeLayer (148-160)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: e2e-js
  • GitHub Check: unit-js
🔇 Additional comments (7)
src/components/relation-control/index.js (1)

223-223: Pass isHover flag—ensure downstream consumption
The new isHover: item.effects?.hoverStatus || false prop correctly surfaces hover state. Verify that the settings components receiving this prop explicitly destructure and use isHover in their reset handlers to restore the normal-state background color.

src/components/background-control/blockBackgroundControl.js (1)

40-40: LGTM!

The propagation of blockAttributes through to BackgroundLayersControl is correct and necessary for enabling IB (inline block) reset functionality downstream.

Also applies to: 88-88

src/components/background-control/backgroundLayersControl.js (3)

73-82: LGTM!

The helper function correctly locates the matching background layer from the target block's attributes by order and type. Returning null for non-IB cases or when no match is found is handled safely downstream.


100-106: LGTM!

The destructuring pattern correctly strips isReset before passing the change object to handleOnChangeLayer (which expects layer attribute updates only), then reattaches it to preserve the reset flag for the final change emission.


117-117: LGTM!

Passing blockAttributes={getBlockLayer()} to ColorLayer provides the necessary context for IB reset resolution. Only color layers receive this prop, which is appropriate since the reset behavior is specific to color layers.

src/components/background-control/colorLayer.js (2)

152-172: LGTM!

The non-IB reset logic correctly resolves hover mode reset to the current breakpoint's normal state value (lines 152-158), and non-hover mode reset to the previous breakpoint or current breakpoint's normal state (lines 159-171). This matches the expected behavior described in the issue.


225-253: LGTM!

The onReset function correctly propagates isReset: true in both palette-enabled (lines 225-233) and palette-disabled (lines 234-253) code paths, ensuring the reset flag is properly threaded through the change emission.

Comment on lines +111 to +122
if (isHover) {
const blockHoverValue = getLastBreakpointAttribute({
target,
breakpoint,
attributes: blockAttributes,
isHover: true,
});

if (blockHoverValue !== undefined) {
return blockHoverValue;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify hover reset behavior matches issue requirements.

The IB hover reset logic first attempts to retrieve the target block's hover value (lines 111-122), then falls back to the normal value (lines 124-134). However, the issue description states: "Clicking the reset button in hover state should revert the hover colour to the colour selected for the normal state."

This suggests the reset should always revert to the normal state color, not the hover state color. The non-IB logic (lines 152-158) correctly implements this by getting isHover=false when in hover mode.

Please verify the intended behavior:

  • Should IB hover reset always use the target block's normal state color (matching the issue description)?
  • Or should it prefer the target block's hover color if defined (current implementation)?

If the former, apply this diff to skip the hover value check:

 		if (isIB) {
 			// For IB reset, we want to reset to the target block's actual background color
 			// NOT the IB override values - we're clearing the IB override!
 
 			// First, get the value from the target block's actual attributes
-			// If we're in hover mode, check for the block's hover value first
 			if (blockAttributes) {
-				// Try to get the hover value if we're in hover mode
-				if (isHover) {
-					const blockHoverValue = getLastBreakpointAttribute({
-						target,
-						breakpoint,
-						attributes: blockAttributes,
-						isHover: true,
-					});
-
-					if (blockHoverValue !== undefined) {
-						return blockHoverValue;
-					}
-				}
-
-				// If not in hover mode, or no hover value exists, get non-hover value
+				// Get non-hover value (normal state)
 				const blockValue = getLastBreakpointAttribute({
 					target,
 					breakpoint,
 					attributes: blockAttributes,
 					isHover: false,
 				});

🏁 Script executed:

#!/bin/bash
set -e
FILE="src/components/background-control/colorLayer.js"
echo "Showing lines 80–180 of $FILE"
sed -n '80,180p' "$FILE"

Length of output: 2811


Remove hover-first check in IB reset logic

The IB reset path must always revert to the normal-state color. Remove the hover-value lookup (lines 111–122) so getResetValue only fetches isHover: false.

🤖 Prompt for AI Agents
In src/components/background-control/colorLayer.js around lines 111 to 122, the
IB reset logic currently checks for and returns a hover-state value; remove that
hover-value lookup so the reset path always reverts to the normal state. Delete
the if (isHover) { ... getLastBreakpointAttribute(... isHover: true) ... } block
and ensure getResetValue only calls getLastBreakpointAttribute with isHover:
false (or omits isHover/sets to false) so the reset always fetches the non-hover
color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reset for colours of BG colour on hover state

4 participants