Skip to content

feat: add listener for share actions#24

Merged
javier-godoy merged 3 commits into
masterfrom
feature/12-share-listener
Jun 26, 2026
Merged

feat: add listener for share actions#24
javier-godoy merged 3 commits into
masterfrom
feature/12-share-listener

Conversation

@paodb

@paodb paodb commented Jun 4, 2026

Copy link
Copy Markdown
Member

Description

Adds the ability to listen for share actions, as requested in #12.

A new withShareListener(ShareEasyClickListener) builder method registers a
listener that is notified whenever a share driver is clicked. The
ShareEasyClickEvent exposes:

  • getDriverName() - the clicked driver's name (e.g. "telegram")
  • getDriver() - the resolved Driver for default drivers (Optional)
  • getLink() - the share link (the copied URL for the copy driver)
  • getSource() - the component the Share Easy instance is attached to

How it works

This builds on the upstream driver-clicked event added in sharee 1.1.24
(parsagholipour/sharee#6). The connector:

  • patches each default driver's getName so the event carries a stable
    driver key instead of the bundled (build-dependent) class name;
  • re-dispatches the event for the copy driver - whose onClick is fully
    overridden by the add-on - carrying the actual copied URL.

Additional changes

  • build: bump webdrivermanager to 5.9.2 so the integration tests can
    resolve a driver for current Chrome versions.
  • build: set version to 2.2.0-SNAPSHOT.

Testing

  • New integration test ShareEasyNormalModeIT.withShareListener_clickDriver_firesEvent.
  • New demo example ("With share listener") in the Normal mode demo.

Close #12

Summary by CodeRabbit

  • New Features
    • Added share-driver click listening with a new click event (includes clicked driver name and optional share link).
    • Added a fluent callback registration to react when a driver is clicked.
  • Behavior
    • Driver names are normalized so emitted events match the registered driver keys.
    • Copy now dispatches the click event early, and stops further handling if the event was prevented.
  • Documentation
    • Developer Guide adds “Listening to share actions” with a Java example; README lists the new driver-click tracking capability.
  • Tests / Demos
    • Added a demo and integration test verifying the listener fires and includes "copy".

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f610f1ba-5267-4ad5-85c6-89b187538883

📥 Commits

Reviewing files that changed from the base of the PR and between 6b80e26 and 3c0a5b9.

📒 Files selected for processing (10)
  • README.md
  • pom.xml
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
  • src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/NormalModeDemo.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java
✅ Files skipped from review due to trivial changes (2)
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java
  • README.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/NormalModeDemo.java
  • pom.xml
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
  • src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js

Walkthrough

Adds a share-action listener API and frontend event dispatch. Java exposes withShareListener(...) and a click event type; the frontend emits driver-clicked events; tests, demo code, README guidance, and build metadata were updated.

Changes

Share Listener Feature

Layer / File(s) Summary
Event classes and listener interface
src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java, src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
ShareEasyClickEvent stores source, driver name, and link; ShareEasyClickListener defines onShare(...) and bridges accept(...) to it.
Driver enum factory method
src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
Adds Driver.fromName(String) returning Optional<Driver> by matching the enum’s internal name field.
BaseShareEasy listener registration
src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
Adds listener state, withShareListener(...), startup registration, and "driver-clicked" handling that extracts detail.name and detail.link into ShareEasyClickEvent.
Frontend driver name patching
src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js
Patches default driver getName() values before Sharee creation, and the Copy driver dispatches a "driver-clicked" CustomEvent with {name, link, originalEvent}.
Demo and UI test validation
src/test/java/com/flowingcode/vaadin/addons/shareeasy/NormalModeDemo.java, src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java, src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java
Adds a demo example using withShareListener(...), updates selector helpers to descriptive driver class names, and adds an integration test that clicks the copy driver and checks the notification text.
Documentation and release updates
README.md, pom.xml
README documents listening for share actions; pom.xml bumps the project version, adds json-migration-helper, and updates webdrivermanager.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • javier-godoy
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.04% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding a listener for share actions.
Linked Issues check ✅ Passed The PR adds a share-action callback API, event payload, driver resolution, demo, and tests that satisfy #12.
Out of Scope Changes check ✅ Passed The docs, demo, tests, and dependency/version updates support the new listener feature and do not appear unrelated.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/12-share-listener

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java (1)

180-190: 💤 Low value

Consider validating driverName before dispatching the event.

The frontend should always provide a driver name, but if the event payload is malformed or a future change breaks this contract, driverName could be null. Consider adding a guard to skip calling the listener or log a warning when critical event data is missing.

🛡️ Optional defensive check
 private void registerShareListener() {
   if (shareListener == null) {
     return;
   }
   component.getElement().addEventListener("driver-clicked", event -> {
     JsonObject detail = event.getEventData();
     String driverName = getStringOrNull(detail, "event.detail.name");
     String link = getStringOrNull(detail, "event.detail.link");
+    if (driverName == null) {
+      // Log warning or skip event if critical data is missing
+      return;
+    }
     shareListener.onShare(new ShareEasyClickEvent(component, driverName, link));
   }).addEventData("event.detail.name").addEventData("event.detail.link");
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java`
around lines 180 - 190, The registerShareListener method currently dispatches a
ShareEasyClickEvent without checking that driverName is present; update
registerShareListener to validate driverName (using getStringOrNull result)
before calling shareListener.onShare — if driverName is null or empty, skip
calling shareListener (and optionally log a warning via a Logger) so malformed
events are ignored; keep the rest of the logic (link handling and adding event
data) unchanged and reference registerShareListener, shareListener,
getStringOrNull, driverName, and ShareEasyClickEvent when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java`:
- Around line 180-190: The registerShareListener method currently dispatches a
ShareEasyClickEvent without checking that driverName is present; update
registerShareListener to validate driverName (using getStringOrNull result)
before calling shareListener.onShare — if driverName is null or empty, skip
calling shareListener (and optionally log a warning via a Logger) so malformed
events are ignored; keep the rest of the logic (link handling and adding event
data) unchanged and reference registerShareListener, shareListener,
getStringOrNull, driverName, and ShareEasyClickEvent when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dce88ace-9ad6-4728-9cd7-bbfd2987df39

📥 Commits

Reviewing files that changed from the base of the PR and between bc83ef4 and 930d89a.

📒 Files selected for processing (10)
  • README.md
  • pom.xml
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
  • src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/NormalModeDemo.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java

@paodb paodb marked this pull request as draft June 4, 2026 19:31
@paodb

paodb commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@javier-godoy

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java`:
- Around line 49-53: The ShareEasyClickEvent constructor should validate
required params: in ShareEasyClickEvent(Component source, String driverName,
String link) add null checks (e.g., Objects.requireNonNull or explicit checks)
for driverName (and optionally source) and throw an IllegalArgumentException
with a clear message if missing so the event cannot be created with a null
driverName; update the constructor to perform these checks before assigning
fields so getDriverName() never returns null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7cc97a56-f4fc-483c-bba8-46ea9c196c9e

📥 Commits

Reviewing files that changed from the base of the PR and between bc83ef4 and 930d89a.

📒 Files selected for processing (10)
  • README.md
  • pom.xml
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickEvent.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
  • src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/NormalModeDemo.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java

@paodb paodb force-pushed the feature/12-share-listener branch from 930d89a to 278285f Compare June 4, 2026 20:29
@paodb paodb requested review from javier-godoy and scardanzan June 4, 2026 20:40
@paodb paodb marked this pull request as ready for review June 4, 2026 20:40

@javier-godoy javier-godoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code Review Findings

1. Event listeners accumulate on repeated forComponent() calls

File:
Line: 178

In , the is not stored, so if is called multiple times on the same instance, listeners accumulate without deduplication:

component.getElement().addEventListener("driver-clicked", event -> {
  // ...
}).addEventData("event.detail.name").addEventData("event.detail.link");
// Registration is discarded - no way to remove old listener

Failure scenario: Calling then leaves both listeners active. Subsequent clicks fire multiple times.

Fix: Store the and remove the previous listener before registering a new one.


2. JsonObject usage not compatible with Vaadin 24-25 json-migration-helper requirement

File:
Line: 185

The code uses and directly:

private static String getStringOrNull(JsonObject data, String key) {
    return data.hasKey(key) && data.get(key) instanceof JsonString ? data.getString(key) : null;
}

Vaadin 24-25 requires for JsonObject compatibility. This usage may not be properly migrated.

Fix: Verify the json-migration-helper is applied to this code path or refactor to use the migrated JSON API.

@github-project-automation github-project-automation Bot moved this from To Do to In Progress in Flowing Code Addons Jun 23, 2026

@javier-godoy javier-godoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code Review Findings

1. Event listeners accumulate on repeated forComponent() calls

File: src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
Line: 178

In registerShareListener(), the DomListenerRegistration is not stored, so if forComponent() is called multiple times on the same instance, listeners accumulate without deduplication.

The addEventListener call chain doesn't store the Registration, so the old listener can never be removed. Each call to forComponent() adds another listener.

Failure scenario: Calling forComponent(div1) then forComponent(div2) leaves both listeners active. Subsequent clicks fire multiple times.

Fix: Store the DomListenerRegistration and remove the previous listener before registering a new one.


2. JsonObject usage not compatible with Vaadin 24-25 json-migration-helper requirement

File: src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
Line: 185

The code uses elemental.json.JsonObject and elemental.json.JsonString directly. Vaadin 24-25 requires json-migration-helper for proper JsonObject compatibility. This usage may not be properly migrated for full compatibility.

Fix: Verify the json-migration-helper is applied to this code path or refactor to use the migrated JSON API.

@paodb paodb requested a review from javier-godoy June 24, 2026 23:42

@javier-godoy javier-godoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comments have been addressed, please squash WIP.

@paodb

paodb commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

Comments have been addressed, please squash WIP.

Done @javier-godoy

@paodb paodb force-pushed the feature/12-share-listener branch from 6b80e26 to 3c0a5b9 Compare June 25, 2026 18:14
@javier-godoy javier-godoy merged commit b4562b3 into master Jun 26, 2026
4 checks passed
@javier-godoy javier-godoy deleted the feature/12-share-listener branch June 26, 2026 17:38
@github-project-automation github-project-automation Bot moved this from In Progress to Pending release in Flowing Code Addons Jun 26, 2026
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

Status: Pending release

Development

Successfully merging this pull request may close these issues.

Add callback for share actions

2 participants