Skip to content

Commit 4df9dd6

Browse files
marker-daomarker dao ®
andauthored
Chat Prompt Suggestions: Support nested option path for suggestions updates (DevExpress#33312)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 38bc2ef commit 4df9dd6

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

  • packages/devextreme

packages/devextreme/js/__internal/ui/chat/chat.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,11 @@ class Chat extends Widget<ChatProperties> {
786786
this._createSendButtonAction();
787787
this._messageBox.option(name, this._getSendButtonOptionsWithAction());
788788
break;
789-
case 'suggestions':
790-
this._suggestions?.updateOptions(value as ChatProperties['suggestions']);
789+
case 'suggestions': {
790+
const { suggestions } = this.option();
791+
this._suggestions?.updateOptions(suggestions);
791792
break;
793+
}
792794
default:
793795
super._optionChanged(args);
794796
}

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/chat.tests.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,36 @@ QUnit.module('Chat', () => {
28212821
assert.strictEqual(this.getSuggestionsElement().length, 1, 'suggestions container remains in DOM');
28222822
assert.strictEqual(this.getSuggestionItems().length, 0, 'items are removed');
28232823
});
2824+
2825+
QUnit.test('suggestions items should be updated via nested option path', function(assert) {
2826+
this.reinit({
2827+
suggestions: { items: [{ text: 'Item 1' }] },
2828+
});
2829+
2830+
this.instance.option('suggestions.items', [{ text: 'New 1' }, { text: 'New 2' }]);
2831+
2832+
assert.strictEqual(this.getSuggestionItems().length, 2, 'items count updated via nested path');
2833+
assert.strictEqual(this.getSuggestionItems().eq(0).text(), 'New 1', 'first item text updated');
2834+
});
2835+
2836+
QUnit.test('nested option update should not drop other suggestions options', function(assert) {
2837+
assert.expect(1);
2838+
2839+
const clickedText = 'Item 1';
2840+
2841+
this.reinit({
2842+
suggestions: {
2843+
items: [{ text: clickedText }],
2844+
onItemClick: (e) => {
2845+
assert.strictEqual(e.itemData.text, clickedText, 'onItemClick preserved after nested update');
2846+
},
2847+
},
2848+
});
2849+
2850+
this.instance.option('suggestions.items', [{ text: clickedText }, { text: 'Item 2' }]);
2851+
2852+
this.getSuggestionItems().first().trigger('dxclick');
2853+
});
28242854
});
28252855

28262856
QUnit.module('Data Layer Integration', {

0 commit comments

Comments
 (0)