Skip to content

Commit 2d0a6af

Browse files
authored
HtmlEditor: implement canceled state in aiDialog
1 parent d1101d3 commit 2d0a6af

File tree

35 files changed

+147
-12
lines changed

35 files changed

+147
-12
lines changed
Loading
Loading
Loading

packages/devextreme/js/__internal/ui/html_editor/ui/aiDialog.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ enum DialogState {
7272
Generating = 'generating',
7373
ResultReady = 'resultReady',
7474
Error = 'error',
75+
InitialCanceled = 'initialCanceled',
76+
AskingCanceled = 'askingCanceled',
7577
}
7678

7779
enum ReplaceButtonActions {
@@ -321,12 +323,10 @@ export default class AIDialog extends BaseDialog<AIDialogResult> {
321323

322324
private _renderInformer($container: dxElementWrapper): void {
323325
const $informer = $('<div>').appendTo($container);
324-
const text = localizationMessage.format('dxHtmlEditor-aiDialogError');
325326

326327
const options: InformerProperties = {
327328
contentAlignment: 'center',
328329
showBackground: true,
329-
text,
330330
};
331331
// @ts-expect-error no .d.ts for private component
332332
this._informer = new Informer($informer.get(0), options);
@@ -478,10 +478,12 @@ export default class AIDialog extends BaseDialog<AIDialogResult> {
478478

479479
switch (this._dialogState) {
480480
case DialogState.Initial:
481+
case DialogState.InitialCanceled:
481482
case DialogState.ResultReady:
482483
items.push(...this._getInitialToolbarItems());
483484
break;
484485
case DialogState.Asking:
486+
case DialogState.AskingCanceled:
485487
items.push(this._getGenerateButtonItem());
486488
break;
487489
case DialogState.Generating:
@@ -599,7 +601,7 @@ export default class AIDialog extends BaseDialog<AIDialogResult> {
599601
}
600602

601603
private _cancelAICommandExecution(): void {
602-
this._processCommandCompletion(this._getInitialDialogState());
604+
this._processCommandCompletion(this._getInitialDialogState(true));
603605
}
604606

605607
private _isCommandWithOptionsSelected(): boolean {
@@ -672,9 +674,11 @@ export default class AIDialog extends BaseDialog<AIDialogResult> {
672674
private _refreshTextAreas(): void {
673675
switch (this._dialogState) {
674676
case DialogState.Initial:
677+
case DialogState.InitialCanceled:
675678
this._setTextAreasInitialState();
676679
break;
677680
case DialogState.Asking:
681+
case DialogState.AskingCanceled:
678682
this._setTextAreasAskingState();
679683
break;
680684
case DialogState.Generating:
@@ -726,13 +730,41 @@ export default class AIDialog extends BaseDialog<AIDialogResult> {
726730
}
727731

728732
private _refreshInformer(): void {
729-
const visible = this._dialogState === DialogState.Error;
733+
const errorText = localizationMessage.format('dxHtmlEditor-aiDialogError');
734+
const cancelText = localizationMessage.format('dxHtmlEditor-aiDialogCanceled');
730735

731-
this._informer.option('visible', visible);
736+
switch (this._dialogState) {
737+
case DialogState.Error:
738+
this._informer.option({
739+
visible: true,
740+
text: errorText,
741+
icon: '',
742+
type: 'error',
743+
});
744+
break;
745+
case DialogState.InitialCanceled:
746+
case DialogState.AskingCanceled:
747+
this._informer.option({
748+
visible: true,
749+
text: cancelText,
750+
icon: 'errorcircle',
751+
type: 'info',
752+
});
753+
break;
754+
default:
755+
this._informer.option('visible', false);
756+
break;
757+
}
732758
}
733759

734-
private _getInitialDialogState(): DialogState {
735-
return this._isAskAICommandSelected ? DialogState.Asking : DialogState.Initial;
760+
private _getInitialDialogState(canceled?: boolean): DialogState {
761+
const isAskingCommand = this._isAskAICommandSelected;
762+
763+
if (canceled) {
764+
return isAskingCommand ? DialogState.AskingCanceled : DialogState.InitialCanceled;
765+
}
766+
767+
return isAskingCommand ? DialogState.Asking : DialogState.Initial;
736768
}
737769

738770
private _replaceButtonAction(event: AIDialogResult['event']): void {

packages/devextreme/js/localization/messages/ar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "outset",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

packages/devextreme/js/localization/messages/bg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "outset",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

packages/devextreme/js/localization/messages/ca.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "outset",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

packages/devextreme/js/localization/messages/cs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "outset",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

packages/devextreme/js/localization/messages/da.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "udsat",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

packages/devextreme/js/localization/messages/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
"dxHtmlEditor-borderStyleOutset": "outset",
547547
"dxHtmlEditor-aiDialogTitle": "AI Assistant",
548548
"dxHtmlEditor-aiDialogError": "Something went wrong. Please try again.",
549+
"dxHtmlEditor-aiDialogCanceled": "Generation canceled",
549550
"dxHtmlEditor-aiReplace": "Replace",
550551
"dxHtmlEditor-aiInsertAbove": "Insert above",
551552
"dxHtmlEditor-aiInsertBelow": "Insert below",

0 commit comments

Comments
 (0)