Skip to content

Commit 6ed3731

Browse files
authored
fix(ui5-ai-textarea): apply feedback and suggestions
* fix(ui5-ai-textarea): apply feedback and improvements Added "Stop Generating" tooltip to button during generation. Improved version history management in the test sample. Other minor fixes and improvements.
1 parent fa59293 commit 6ed3731

File tree

6 files changed

+67
-27
lines changed

6 files changed

+67
-27
lines changed

packages/ai/cypress/specs/WritingAssistant.cy.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,46 @@ describe("WritingAssistant Component", () => {
869869
.should("have.attr", "tooltip", "Writing Assistant (Shift + F4)");
870870
});
871871

872+
it("should have stop tooltip when loading", () => {
873+
cy.mount(<WritingAssistant loading={true} />);
874+
875+
cy.get("[ui5-ai-writing-assistant]")
876+
.shadow()
877+
.find("#ai-menu-btn")
878+
.should("have.attr", "tooltip", "Stop Generating (Esc)");
879+
});
880+
881+
it("should change tooltip based on loading state", () => {
882+
cy.mount(<WritingAssistant loading={false} />);
883+
884+
cy.get("[ui5-ai-writing-assistant]")
885+
.as("writingAssistant");
886+
887+
// Verify initial button tooltip
888+
cy.get("@writingAssistant")
889+
.shadow()
890+
.find("#ai-menu-btn")
891+
.should("have.attr", "tooltip", "Writing Assistant (Shift + F4)");
892+
893+
// Change to loading state
894+
cy.get("@writingAssistant").invoke("prop", "loading", true);
895+
896+
// Verify stop tooltip
897+
cy.get("@writingAssistant")
898+
.shadow()
899+
.find("#ai-menu-btn")
900+
.should("have.attr", "tooltip", "Stop Generating (Esc)");
901+
902+
// Change back to non-loading state
903+
cy.get("@writingAssistant").invoke("prop", "loading", false);
904+
905+
// Verify button tooltip is restored
906+
cy.get("@writingAssistant")
907+
.shadow()
908+
.find("#ai-menu-btn")
909+
.should("have.attr", "tooltip", "Writing Assistant (Shift + F4)");
910+
});
911+
872912
it("should maintain accessibility attributes when loading state changes", () => {
873913
cy.mount(<WritingAssistant loading={false} />);
874914

@@ -923,7 +963,7 @@ describe("WritingAssistant Component", () => {
923963
.find("#ai-menu-btn")
924964
.should("have.attr", "data-state", "generating")
925965
.should("have.attr", "accessible-name", "Writing Assistant")
926-
.should("have.attr", "tooltip", "Writing Assistant (Shift + F4)")
966+
.should("have.attr", "tooltip", "Stop Generating (Esc)")
927967
.should("have.attr", "icon", "stop");
928968
});
929969

packages/ai/src/TextArea.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
55
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
66

77
import { BaseTextArea } from "@ui5/webcomponents/dist/TextArea.js";
8-
import BusyIndicator from "@ui5/webcomponents/dist/BusyIndicator.js";
98
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
109
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
1110
import {
@@ -18,7 +17,6 @@ import valueStateMessageStyles from "@ui5/webcomponents/dist/generated/themes/Va
1817

1918
// Templates
2019
import TextAreaTemplate from "./TextAreaTemplate.js";
21-
import WritingAssistant from "./WritingAssistant.js";
2220

2321
/**
2422
* @class
@@ -56,10 +54,6 @@ import WritingAssistant from "./WritingAssistant.js";
5654
valueStateMessageStyles,
5755
TextAreaCss,
5856
],
59-
dependencies: [
60-
WritingAssistant,
61-
BusyIndicator,
62-
],
6357
})
6458

6559
/**

packages/ai/src/WritingAssistant.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { i18n } from "@ui5/webcomponents-base/dist/decorators.js";
55
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
66
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
77
import announce from "@ui5/webcomponents-base/dist/util/InvisibleMessage.js";
8+
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
89
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
910
import {
1011
WRITING_ASSISTANT_LABEL,
@@ -14,6 +15,7 @@ import {
1415
WRITING_ASSISTANT_TOOLBAR_ACCESSIBLE_NAME,
1516
WRITING_ASSISTANT_BUTTON_ACCESSIBLE_NAME,
1617
WRITING_ASSISTANT_BUTTON_TOOLTIP,
18+
WRITING_ASSISTANT_STOP_TOOLTIP,
1719
} from "./generated/i18n/i18n-defaults.js";
1820

1921
// Styles
@@ -153,6 +155,10 @@ class WritingAssistant extends UI5Element {
153155
@i18n("@ui5/webcomponents-ai")
154156
static i18nBundleAi: I18nBundle;
155157

158+
static async onDefine() {
159+
WritingAssistant.i18nBundleAi = await getI18nBundle("@ui5/webcomponents-ai");
160+
}
161+
156162
/**
157163
* Handles the version change event from the versioning component.
158164
*/
@@ -198,6 +204,10 @@ class WritingAssistant extends UI5Element {
198204
get _buttonTooltip() {
199205
return WritingAssistant.i18nBundleAi.getText(WRITING_ASSISTANT_BUTTON_TOOLTIP);
200206
}
207+
208+
get _stopTooltip() {
209+
return WritingAssistant.i18nBundleAi.getText(WRITING_ASSISTANT_STOP_TOOLTIP);
210+
}
201211
}
202212

203213
WritingAssistant.define();

packages/ai/src/WritingAssistantTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function WritingAssistantTemplate(this: WritingAssistant) {
3939
icon={this.loading ? "stop" : "ai"}
4040
data-state={this.loading ? "generating" : "generate"}
4141
onClick={this.handleButtonClick}
42-
tooltip={this._buttonTooltip}
42+
tooltip={this.loading ? this._stopTooltip : this._buttonTooltip}
4343
accessibilityAttributes={{ hasPopup: this.loading ? "false" : "menu" }}
4444
accessibleName={this._buttonAccessibleName}
4545
overflowPriority="NeverOverflow"

packages/ai/src/i18n/messagebundle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ WRITING_ASSISTANT_TOOLBAR_ACCESSIBLE_NAME=Writing Assistant Toolbar
3737
#XFLD: Accessible name for the Writing Assistant button
3838
WRITING_ASSISTANT_BUTTON_ACCESSIBLE_NAME=Writing Assistant
3939

40-
#XFLD: Tooltip for the Writing Assistant button
40+
#XTOL: Tooltip for the Writing Assistant button
4141
WRITING_ASSISTANT_BUTTON_TOOLTIP=Writing Assistant (Shift + F4)
4242

43+
#XTOL: Writing Assistant stop generating button tooltip
44+
WRITING_ASSISTANT_STOP_TOOLTIP=Stop Generating (Esc)
45+
4346
#XFLD: Tooltip for the Previous Version button
4447
VERSIONING_PREVIOUS_BUTTON_TOOLTIP=Previous Version
4548

packages/ai/test/pages/TextArea.html

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
9292

9393
<strong>Generation Behavior:</strong><br>
9494
• Selecting a new action while generating will stop current generation<br>
95-
Stopped generations are saved as versions with "(stopped)" suffix<br>
95+
Cancelled generations restore previous content and are not saved to history<br>
9696
• History is limited to 50 versions to prevent memory issues
9797
</div>
9898
</div>
@@ -169,6 +169,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
169169
let currentActionInProgress = null;
170170
let typingInterval = null;
171171
let currentGenerationIndex = 0;
172+
let contentBeforeGeneration = "";
172173

173174
const textarea = document.getElementById('ai-textarea');
174175
const menu = document.getElementById('ai-menu');
@@ -234,14 +235,13 @@ <h1 class="demo-title">AI TextArea Component</h1>
234235

235236
menu.innerHTML = '';
236237

237-
// Add initial "Generate text" option if no history
238238
if (!hasHistory) {
239239
const generateItem = document.createElement('ui5-menu-item');
240240
generateItem.setAttribute('text', 'Generate text');
241241
generateItem.dataset.action = 'generate';
242-
generateItem.dataset.processingLabel = 'Generating text...';
242+
generateItem.dataset.processingLabel = 'Generating...';
243243
generateItem.dataset.completedLabel = 'Generated text';
244-
generateItem.dataset.textKey = 'en';
244+
generateItem.dataset.textKey = 'generateText';
245245
menu.appendChild(generateItem);
246246
}
247247

@@ -339,6 +339,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
339339
const textKey = menuItem.dataset.textKey || 'en';
340340

341341
saveCurrentVersion();
342+
contentBeforeGeneration = textarea.value;
342343
currentActionInProgress = action;
343344
currentGenerationIndex += 1;
344345
const generationIdForThisRun = currentGenerationIndex;
@@ -364,23 +365,14 @@ <h1 class="demo-title">AI TextArea Component</h1>
364365

365366
stopTypingAnimation();
366367
currentGenerationIndex += 1;
367-
const action = currentActionInProgress || 'generate';
368-
const menuItem = findMenuItemByAction(action);
369-
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';
370-
371-
versionHistory.push({
372-
value: textarea.value,
373-
action,
374-
endAction: completedLabel + " (stopped)",
375-
timestamp: new Date().toISOString()
376-
});
377-
378-
currentIndexHistory = versionHistory.length - 1;
368+
369+
// Restore the previous content instead of saving the cancelled action
370+
textarea.value = contentBeforeGeneration;
379371
currentActionInProgress = null;
372+
textarea.loading = false;
373+
textarea.promptDescription = "";
380374

381-
buildMenuFromConfig();
382375
updateComponentState();
383-
textarea.loading = false;
384376
}
385377

386378
function handleVersionChange(event) {
@@ -423,6 +415,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
423415
currentIndexHistory = 0;
424416
currentGenerationIndex = 0;
425417
currentActionInProgress = null;
418+
contentBeforeGeneration = "";
426419

427420
textarea.value = "Innovation managers operate with both creativity and business acumen, driving initiatives that cultivate an innovation-friendly culture.";
428421
textarea.loading = false;

0 commit comments

Comments
 (0)