Skip to content

feat: add listener for share actions#24

Open
paodb wants to merge 3 commits into
masterfrom
feature/12-share-listener
Open

feat: add listener for share actions#24
paodb wants to merge 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 a share listener so apps can capture driver click events, see which driver was clicked, and receive the share link.
  • Behavior

    • Share events are emitted consistently with normalized driver names; the copy action dispatches a driver-click event before its UI/clipboard flow.
  • Documentation

    • Developer Guide includes "Listening to share actions" with usage examples.
  • Tests / Demos

    • Demo and UI test added to illustrate and verify listener behavior.

@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: 2f65f988-08b0-4550-b121-f5b0fe5fbdf8

📥 Commits

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

📒 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 (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyElement.java
  • pom.xml
  • src/test/java/com/flowingcode/vaadin/addons/shareeasy/it/ShareEasyNormalModeIT.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/ShareEasyClickListener.java
  • src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
  • 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-listener callback feature: frontend dispatches named "driver-clicked" events; Java API accepts a ShareEasyClickListener via withShareListener(...); new event and listener types, Driver.fromName lookup, demo and UI test, README docs, and version/dependency bump.

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 holds source, driverName, and link; ShareEasyClickListener is a functional interface with onShare(...) and a SerializableConsumer-compatible accept(...).
Driver enum factory method
src/main/java/com/flowingcode/vaadin/addons/shareeasy/enums/Driver.java
Adds Driver.fromName(String) returning Optional<Driver> by scanning enum constants for a matching internal name.
BaseShareEasy listener registration
src/main/java/com/flowingcode/vaadin/addons/shareeasy/BaseShareEasy.java
Introduces shareListener field, fluent withShareListener(...), calls registerShareListener() during setup; registerShareListener() attaches a "driver-clicked" DOM handler, safely extracts detail.name/detail.link via getStringOrNull(...), and dispatches ShareEasyClickEvent.
Frontend driver name patching
src/main/resources/META-INF/resources/frontend/src/fc-sharee-connector.js
Adds _patchDriverNames() to override default drivers' getName() to return their registered keys; create() and createWithCustomDrivers() call it; Copy driver dispatches "driver-clicked" CustomEvent with {name,link,originalEvent} and respects defaultPrevented.
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 example8 demo using withShareListener(...) to show a Notification with event.getDriverName(); updates test helpers to descriptive CSS class checks; adds UI test that clicks copy driver and asserts notification text includes "copy".
Documentation and version release
README.md, pom.xml
README adds "Listening to share actions" Developer Guide with a Java example; pom.xml version bumped to 2.2.0-SNAPSHOT and test dependency webdrivermanager updated to 5.9.2.

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 PR title 'feat: add listener for share actions' accurately and concisely describes the main objective of the changeset.
Linked Issues check ✅ Passed The PR fully implements issue #12 requirements by providing a callback mechanism via withShareListener(), exposing driver name and platform data through ShareEasyClickEvent.
Out of Scope Changes check ✅ Passed All changes are in scope: listener implementation (BaseShareEasy, new listener/event classes), JavaScript connector patches, dependency updates for test compatibility, documentation, and tests.

✏️ 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 and usage tips.

@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
@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Do

Development

Successfully merging this pull request may close these issues.

Add callback for share actions

2 participants