diff --git a/packages/devextreme-angular/src/ui/chat/index.ts b/packages/devextreme-angular/src/ui/chat/index.ts index 3b12df31c558..9b32cfefc9bc 100644 --- a/packages/devextreme-angular/src/ui/chat/index.ts +++ b/packages/devextreme-angular/src/ui/chat/index.ts @@ -22,6 +22,8 @@ import { } from '@angular/core'; +import { Store } from 'devextreme/data'; +import DataSource, { Options as DataSourceOptions } from 'devextreme/data/data_source'; import { DisposingEvent, InitializedEvent, Message, MessageSendEvent, OptionChangedEvent, User } from 'devextreme/ui/chat'; import DxChat from 'devextreme/ui/chat'; @@ -88,6 +90,19 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges } + /** + * [descr:dxChatOptions.dataSource] + + */ + @Input() + get dataSource(): Store | DataSource | DataSourceOptions | null | string | Array { + return this._getOption('dataSource'); + } + set dataSource(value: Store | DataSource | DataSourceOptions | null | string | Array) { + this._setOption('dataSource', value); + } + + /** * [descr:WidgetOptions.disabled] @@ -276,6 +291,13 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges */ @Output() activeStateEnabledChange: EventEmitter; + /** + + * This member supports the internal infrastructure and is not intended to be used directly from your code. + + */ + @Output() dataSourceChange: EventEmitter>; + /** * This member supports the internal infrastructure and is not intended to be used directly from your code. @@ -383,6 +405,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges { subscribe: 'optionChanged', emit: 'onOptionChanged' }, { emit: 'accessKeyChange' }, { emit: 'activeStateEnabledChange' }, + { emit: 'dataSourceChange' }, { emit: 'disabledChange' }, { emit: 'elementAttrChange' }, { emit: 'focusStateEnabledChange' }, @@ -412,6 +435,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges ngOnChanges(changes: SimpleChanges) { super.ngOnChanges(changes); + this.setupChanges('dataSource', changes); this.setupChanges('items', changes); } @@ -422,6 +446,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges } ngDoCheck() { + this._idh.doCheck('dataSource'); this._idh.doCheck('items'); this._watcherHelper.checkWatchers(); super.ngDoCheck(); diff --git a/packages/devextreme-vue/src/chat.ts b/packages/devextreme-vue/src/chat.ts index a8ef6d018abc..ca9626be8229 100644 --- a/packages/devextreme-vue/src/chat.ts +++ b/packages/devextreme-vue/src/chat.ts @@ -5,6 +5,7 @@ import { createConfigurationComponent } from "./core/index"; type AccessibleOptions = Pick { hoverStateEnabled: true, title: '', items: [], + dataSource: null, user: { id: new Guid().toString() }, onMessageSend: undefined, }; @@ -138,7 +140,7 @@ class Chat extends Widget { case 'activeStateEnabled': case 'focusStateEnabled': case 'hoverStateEnabled': - this._messageBox.option({ [name]: value }); + this._messageBox.option(name, value as Properties[typeof name]); break; case 'title': { if (value) { @@ -154,10 +156,11 @@ class Chat extends Widget { break; } case 'user': - this._messageList.option('currentUserId', (value as Properties['user'])?.id); + this._messageList.option('currentUserId', (value as Properties[typeof name])?.id); break; case 'items': - this._messageList.option('items', (value as Properties['items']) ?? []); + case 'dataSource': + this._messageList.option(name, value as Properties[typeof name]); break; case 'onMessageSend': this._createMessageSendAction(); @@ -176,7 +179,6 @@ class Chat extends Widget { } } -// @ts-expect-error ts-error -registerComponent('dxChat', Chat); +registerComponent('dxChat', Chat as unknown as ComponentFactory); export default Chat; diff --git a/packages/devextreme/js/core/component_registrator.d.ts b/packages/devextreme/js/core/component_registrator.d.ts index c9637a60890d..3676d7fcc739 100644 --- a/packages/devextreme/js/core/component_registrator.d.ts +++ b/packages/devextreme/js/core/component_registrator.d.ts @@ -1,7 +1,7 @@ import DOMComponent from './dom_component'; import { UserDefinedElement } from './element'; -type ComponentFactory = { +export type ComponentFactory = { new(element: UserDefinedElement, options?: Record): TComponent; getInstance(element: UserDefinedElement): TComponent; }; diff --git a/packages/devextreme/js/ui/chat.d.ts b/packages/devextreme/js/ui/chat.d.ts index 46ba1998c99c..b2481f188c32 100644 --- a/packages/devextreme/js/ui/chat.d.ts +++ b/packages/devextreme/js/ui/chat.d.ts @@ -5,6 +5,7 @@ import { InitializedEventInfo, ChangedOptionInfo, } from '../events/index'; +import DataSource, { DataSourceLike } from '../data/data_source'; /** * @docid _ui_chat_DisposingEvent @@ -138,6 +139,13 @@ export interface dxChatOptions extends WidgetOptions { * @public */ items?: Array; + /** + * @docid + * @type string | Array | Store | DataSource | DataSourceOptions | null + * @default null + * @public + */ + dataSource?: DataSourceLike | null; /** * @docid * @default null @@ -150,7 +158,7 @@ export interface dxChatOptions extends WidgetOptions { /** * @docid - * @inherits Widget + * @inherits Widget, DataHelperMixin * @namespace DevExpress.ui * @public */ @@ -161,6 +169,8 @@ export default class dxChat extends Widget { * @public */ renderMessage(message: Message): void; + + getDataSource(): DataSource; } /** @public */ diff --git a/packages/devextreme/testing/tests/DevExpress.ui/defaultOptions.tests.js b/packages/devextreme/testing/tests/DevExpress.ui/defaultOptions.tests.js index f7ec1185cd1c..66fae23c6e33 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui/defaultOptions.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui/defaultOptions.tests.js @@ -1347,6 +1347,7 @@ testComponentDefaults(Chat, hoverStateEnabled: true, title: '', onMessageSend: undefined, + dataSource: undefined, } ); diff --git a/packages/devextreme/ts/dx.all.d.ts b/packages/devextreme/ts/dx.all.d.ts index a4f5f5676ff0..337e5aa6a125 100644 --- a/packages/devextreme/ts/dx.all.d.ts +++ b/packages/devextreme/ts/dx.all.d.ts @@ -4837,7 +4837,7 @@ declare module DevExpress.core { /** * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */ - type ComponentFactory = { + export type ComponentFactory = { new ( element: UserDefinedElement, options?: Record @@ -9420,6 +9420,8 @@ declare module DevExpress.ui { * [descr:dxChat.renderMessage(message)] */ renderMessage(message: DevExpress.ui.dxChat.Message): void; + + getDataSource(): DevExpress.data.DataSource; } module dxChat { /** @@ -9481,6 +9483,10 @@ declare module DevExpress.ui { * [descr:dxChatOptions.items] */ items?: Array; + /** + * [descr:dxChatOptions.dataSource] + */ + dataSource?: DevExpress.data.DataSource.DataSourceLike | null; /** * [descr:dxChatOptions.onMessageSend] */