Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat: add errors API #28192

Open
wants to merge 7 commits into
base: 24_2
Choose a base branch
from
Open
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
52 changes: 51 additions & 1 deletion packages/devextreme-angular/src/ui/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {

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 { ChatError, DisposingEvent, InitializedEvent, Message, MessageSendEvent, OptionChangedEvent, User } from 'devextreme/ui/chat';

import DxChat from 'devextreme/ui/chat';

Expand All @@ -39,16 +39,20 @@ import {
WatcherHelper
} from 'devextreme-angular/core';

import { DxiErrorModule } from 'devextreme-angular/ui/nested';
import { DxiItemModule } from 'devextreme-angular/ui/nested';
import { DxoAuthorModule } from 'devextreme-angular/ui/nested';
import { DxoUserModule } from 'devextreme-angular/ui/nested';

import { DxiChatErrorModule } from 'devextreme-angular/ui/chat/nested';
import { DxiChatItemModule } from 'devextreme-angular/ui/chat/nested';
import { DxoChatAuthorModule } from 'devextreme-angular/ui/chat/nested';
import { DxoChatUserModule } from 'devextreme-angular/ui/chat/nested';

import { DxiErrorComponent } from 'devextreme-angular/ui/nested';
import { DxiItemComponent } from 'devextreme-angular/ui/nested';

import { DxiChatErrorComponent } from 'devextreme-angular/ui/chat/nested';
import { DxiChatItemComponent } from 'devextreme-angular/ui/chat/nested';


Expand Down Expand Up @@ -134,6 +138,19 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
}


/**
* [descr:dxChatOptions.errors]

*/
@Input()
get errors(): Array<ChatError> {
return this._getOption('errors');
}
set errors(value: Array<ChatError>) {
this._setOption('errors', value);
}


/**
* [descr:dxChatOptions.focusStateEnabled]

Expand Down Expand Up @@ -317,6 +334,13 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
*/
@Output() elementAttrChange: EventEmitter<any>;

/**

* This member supports the internal infrastructure and is not intended to be used directly from your code.

*/
@Output() errorsChange: EventEmitter<Array<ChatError>>;

/**

* This member supports the internal infrastructure and is not intended to be used directly from your code.
Expand Down Expand Up @@ -383,6 +407,15 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges



@ContentChildren(DxiChatErrorComponent)
get errorsChildren(): QueryList<DxiChatErrorComponent> {
return this._getOption('errors');
}
set errorsChildren(value) {
this.setContentChildren('errors', value, 'DxiChatErrorComponent');
this.setChildren('errors', value);
}

@ContentChildren(DxiChatItemComponent)
get itemsChildren(): QueryList<DxiChatItemComponent> {
return this._getOption('items');
Expand All @@ -393,6 +426,16 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
}


@ContentChildren(DxiErrorComponent)
get errorsLegacyChildren(): QueryList<DxiErrorComponent> {
return this._getOption('errors');
}
set errorsLegacyChildren(value) {
if (this.checkContentChildren('errors', value, 'DxiErrorComponent')) {
this.setChildren('errors', value);
}
}

@ContentChildren(DxiItemComponent)
get itemsLegacyChildren(): QueryList<DxiItemComponent> {
return this._getOption('items');
Expand Down Expand Up @@ -425,6 +468,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
{ emit: 'dataSourceChange' },
{ emit: 'disabledChange' },
{ emit: 'elementAttrChange' },
{ emit: 'errorsChange' },
{ emit: 'focusStateEnabledChange' },
{ emit: 'heightChange' },
{ emit: 'hintChange' },
Expand Down Expand Up @@ -453,6 +497,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
this.setupChanges('dataSource', changes);
this.setupChanges('errors', changes);
this.setupChanges('items', changes);
}

Expand All @@ -464,6 +509,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges

ngDoCheck() {
this._idh.doCheck('dataSource');
this._idh.doCheck('errors');
this._idh.doCheck('items');
this._watcherHelper.checkWatchers();
super.ngDoCheck();
Expand All @@ -482,9 +528,11 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges

@NgModule({
imports: [
DxiErrorModule,
DxiItemModule,
DxoAuthorModule,
DxoUserModule,
DxiChatErrorModule,
DxiChatItemModule,
DxoChatAuthorModule,
DxoChatUserModule,
Expand All @@ -496,9 +544,11 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
],
exports: [
DxChatComponent,
DxiErrorModule,
DxiItemModule,
DxoAuthorModule,
DxoUserModule,
DxiChatErrorModule,
DxiChatItemModule,
DxoChatAuthorModule,
DxoChatUserModule,
Expand Down
74 changes: 74 additions & 0 deletions packages/devextreme-angular/src/ui/chat/nested/error-dxi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* tslint:disable:max-line-length */


import {
Component,
NgModule,
Host,
SkipSelf,
Input
} from '@angular/core';





import {
NestedOptionHost,
} from 'devextreme-angular/core';
import { CollectionNestedOption } from 'devextreme-angular/core';


@Component({
selector: 'dxi-chat-error',
template: '',
styles: [''],
providers: [NestedOptionHost]
})
export class DxiChatErrorComponent extends CollectionNestedOption {
@Input()
get id(): number | string {
return this._getOption('id');
}
set id(value: number | string) {
this._setOption('id', value);
}

@Input()
get message(): string {
return this._getOption('message');
}
set message(value: string) {
this._setOption('message', value);
}


protected get _optionPath() {
return 'errors';
}


constructor(@SkipSelf() @Host() parentOptionHost: NestedOptionHost,
@Host() optionHost: NestedOptionHost) {
super();
parentOptionHost.setNestedOption(this);
optionHost.setHost(this, this._fullOptionPath.bind(this));
}



ngOnDestroy() {
this._deleteRemovedOptions(this._fullOptionPath());
}

}

@NgModule({
declarations: [
DxiChatErrorComponent
],
exports: [
DxiChatErrorComponent
],
})
export class DxiChatErrorModule { }
1 change: 1 addition & 0 deletions packages/devextreme-angular/src/ui/chat/nested/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './author';
export * from './error-dxi';
export * from './item-dxi';
export * from './user';

26 changes: 26 additions & 0 deletions packages/devextreme-angular/src/ui/nested/base/chat-error-dxi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* tslint:disable:max-line-length */

import { CollectionNestedOption } from 'devextreme-angular/core';
import {
Component,
} from '@angular/core';


@Component({
template: ''
})
export abstract class DxiChatError extends CollectionNestedOption {
get id(): number | string {
return this._getOption('id');
}
set id(value: number | string) {
this._setOption('id', value);
}

get message(): string {
return this._getOption('message');
}
set message(value: string) {
this._setOption('message', value);
}
}
1 change: 1 addition & 0 deletions packages/devextreme-angular/src/ui/nested/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './chart-common-annotation-config';
export * from './chart-common-series-settings';
export * from './chart-series-dxi';
export * from './charts-color';
export * from './chat-error-dxi';
export * from './column-chooser-search-config';
export * from './column-chooser-selection-config';
export * from './data-change-dxi';
Expand Down
62 changes: 62 additions & 0 deletions packages/devextreme-angular/src/ui/nested/error-dxi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* tslint:disable:max-line-length */

/* tslint:disable:use-input-property-decorator */

import {
Component,
NgModule,
Host,
SkipSelf
} from '@angular/core';





import {
NestedOptionHost,
} from 'devextreme-angular/core';
import { DxiChatError } from './base/chat-error-dxi';


@Component({
selector: 'dxi-error',
template: '',
styles: [''],
providers: [NestedOptionHost],
inputs: [
'id',
'message'
]
})
export class DxiErrorComponent extends DxiChatError {

protected get _optionPath() {
return 'errors';
}


constructor(@SkipSelf() @Host() parentOptionHost: NestedOptionHost,
@Host() optionHost: NestedOptionHost) {
super();
parentOptionHost.setNestedOption(this);
optionHost.setHost(this, this._fullOptionPath.bind(this));
}



ngOnDestroy() {
this._deleteRemovedOptions(this._fullOptionPath());
}

}

@NgModule({
declarations: [
DxiErrorComponent
],
exports: [
DxiErrorComponent
],
})
export class DxiErrorModule { }
1 change: 1 addition & 0 deletions packages/devextreme-angular/src/ui/nested/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export * from './drag-box-style';
export * from './drop-down-options';
export * from './edges';
export * from './editing';
export * from './error-dxi';
export * from './export';
export * from './field-chooser';
export * from './field-dxi';
Expand Down
20 changes: 20 additions & 0 deletions packages/devextreme-react/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Chat = memo(
}), []);

const expectedChildren = useMemo(() => ({
error: { optionName: "errors", isCollectionItem: true },
item: { optionName: "items", isCollectionItem: true },
user: { optionName: "user", isCollectionItem: false }
}), []);
Expand Down Expand Up @@ -87,6 +88,23 @@ const Author: typeof _componentAuthor & IElementDescriptor = Object.assign(_comp
OptionName: "author",
})

// owners:
// Chat
type IErrorProps = React.PropsWithChildren<{
id?: number | string;
message?: string;
}>
const _componentError = memo(
(props: IErrorProps) => {
return React.createElement(NestedOption<IErrorProps>, { ...props });
}
);

const Error: typeof _componentError & IElementDescriptor = Object.assign(_componentError, {
OptionName: "errors",
IsCollectionItem: true,
})

// owners:
// Chat
type IItemProps = React.PropsWithChildren<{
Expand Down Expand Up @@ -133,6 +151,8 @@ export {
ChatRef,
Author,
IAuthorProps,
Error,
IErrorProps,
Item,
IItemProps,
User,
Expand Down
Loading
Loading