Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { array } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
Expand Down Expand Up @@ -29,6 +30,7 @@ export default class AiSummaryModal extends Component {
@service currentUser;
@service site;
@service modal;
@service appEvents;

@tracked text = "";
@tracked summarizedOn = null;
Expand Down Expand Up @@ -208,6 +210,18 @@ export default class AiSummaryModal extends Component {
this.args.closeModal();
}

@action
onSummaryTextClick(event) {
// Check if the clicked element is an anchor tag
if (event.target.tagName === "A" && event.target.href) {
this.appEvents.trigger("ai_summary_link_clicked", {
topic_id: this.args.model.topic.id,
user_id: this.currentUser.id,
link: event.target.href,
});
}
}

<template>
<DModal
@title={{i18n "discourse_ai.summarization.topic.title"}}
Expand All @@ -221,7 +235,12 @@ export default class AiSummaryModal extends Component {
>
<:body>
{{htmlClass "scrollable-modal"}}
<div class="ai-summary-container" {{didInsert this.generateSummary}}>
<div
class="ai-summary-container"
{{didInsert this.generateSummary}}
{{on "click" this.onSummaryTextClick}}
role="button"
>
<article
class={{concatClass
"ai-summary-box"
Expand Down
10 changes: 10 additions & 0 deletions test/javascripts/acceptance/topic-summary-test.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Test looks good. Can you please add a test for the inverse?

  • A user clicks a non a element, and no appEvent is triggered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good! Will add that!

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from "@ember/owner";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { cloneJSON } from "discourse/lib/object";
Expand Down Expand Up @@ -97,10 +98,19 @@ acceptance("Topic - Summary", function (needs) {
},
});

let appEventTriggered = 0;
const appEvents = getOwner(this).lookup("service:app-events");
appEvents.on("ai_summary_link_clicked", this, () => appEventTriggered++);

await click(".generated-summary a");
assert
.dom(".ai-summary-box .generated-summary p")
.hasText(finalSummaryResult, "Retains final summary after clicking link");
assert.equal(
appEventTriggered,
1,
"ai_summary_link_clicked appEvent triggered once"
);
});
});

Expand Down