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

fix(platform): update items on new event #8650

Merged
merged 2 commits into from
Sep 15, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<fdp-list [navigated]="true">
<fdp-list-group-header grpheaderTitle="Vegetables Group"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Vegetables Group"></fdp-list-group-header>
<fdp-display-list-item title="Green Vegetables"> </fdp-display-list-item>
<fdp-display-list-item title="Dry Vegetables"> </fdp-display-list-item>
<fdp-list-footer>List footer</fdp-list-footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<fdp-list [navigated]="true">
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item title="List item 1"> </fdp-standard-list-item>
<fdp-standard-list-item title="List item 2"> </fdp-standard-list-item>
<fdp-list-footer>List footer</fdp-list-footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h5>Cozy</h5>
<fdp-list>
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item title="Title1"></fdp-standard-list-item>
<fdp-standard-list-item title="Title2"></fdp-standard-list-item>
<fdp-standard-list-item title="Title3"></fdp-standard-list-item>
<fdp-list-group-header grpheaderTitle="Group header 2"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 2"></fdp-list-group-header>
<fdp-standard-list-item title="Title1"></fdp-standard-list-item>
<fdp-standard-list-item title="Title2"></fdp-standard-list-item>
<fdp-standard-list-item title="Title3"></fdp-standard-list-item>
Expand All @@ -14,11 +14,11 @@ <h5>Cozy</h5>

<h5>Compact</h5>
<fdp-list fdCompact>
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item title="Title1"></fdp-standard-list-item>
<fdp-standard-list-item title="Title2"></fdp-standard-list-item>
<fdp-standard-list-item title="Title3"></fdp-standard-list-item>
<fdp-list-group-header grpheaderTitle="Group header 2"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 2"></fdp-list-group-header>
<fdp-standard-list-item title="Title1"></fdp-standard-list-item>
<fdp-standard-list-item title="Title2"></fdp-standard-list-item>
<fdp-standard-list-item title="Title3"></fdp-standard-list-item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3>Cozy Mode</h3>
<fdp-list [hasByLine]="true" [navigated]="true">
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item
[title]="'List item 1'"
avatarSrc="https://placeimg.com/400/400/nature"
Expand All @@ -19,7 +19,7 @@ <h3>Cozy Mode</h3>
</fdp-list>
<h3>Compact Mode</h3>
<fdp-list fdCompact [noBorder]="true" [hasByLine]="true" [navigated]="true">
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item
[title]="'List item 1'"
avatarSrc="https://placeimg.com/400/400/nature"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h5>Declarative Approach</h5>
<fdp-list [hasByLine]="true">
<fdp-list-group-header grpheaderTitle="Group header 1"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 1"></fdp-list-group-header>
<fdp-standard-list-item
[title]="'Title 1'"
avatarSrc="https://placeimg.com/400/400/nature"
Expand All @@ -22,7 +22,7 @@ <h5>Declarative Approach</h5>
description="Third text item in Byline (Standard text item)"
>
</fdp-standard-list-item>
<fdp-list-group-header grpheaderTitle="Group header 2"></fdp-list-group-header>
<fdp-list-group-header groupHeaderTitle="Group header 2"></fdp-list-group-header>
<fdp-standard-list-item
[title]="'Title 6'"
avatarSrc="https://placeimg.com/400/400/nature"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<ng-container *ngIf="isGroup">
<ng-container *ngFor="let group of _suggestions">
<ng-container *ngIf="!groupItemTemplate">
<fdp-list-group-header [grpheaderTitle]="group.label"></fdp-list-group-header>
<fdp-list-group-header [groupHeaderTitle]="group.label"></fdp-list-group-header>
</ng-container>

<ng-container *ngIf="groupItemTemplate">
Expand Down
2 changes: 1 addition & 1 deletion libs/platform/src/lib/list/list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*ngIf="loadMore && !loadOnScroll"
(click)="_getMoreData()"
fd-list-item
(keydown)="_loadOnkeyPress($event)"
(keydown)="_loadOnKeyPress($event)"
class="fd-list__item fd-list__item--growing fd-list__item--action"
[tabindex]="0"
role="button"
Expand Down
52 changes: 32 additions & 20 deletions libs/platform/src/lib/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,10 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft

/**
* @hidden
* Instailization of list with selection mode
* Initialization of the lis component with selection mode
*/
ngOnInit(): void {
if (this._dsItems.length !== null && this.itemSize !== 0) {
this._startIndex = 0;
this._lastIndex = this.itemSize;
this._items = this._dsItems.slice(this._startIndex, this._lastIndex);
} else {
this._items = this._dsItems;
}
this._setItems();

this.stateChanges.next(this._items);
this.id = `fdp-list-${nextListId++}`;
Expand Down Expand Up @@ -487,7 +481,7 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft
* @hidden
* load more on enter or space press
*/
_loadOnkeyPress(event: KeyboardEvent): void {
_loadOnKeyPress(event: KeyboardEvent): void {
if (KeyUtil.isKeyCode(event, [ENTER, SPACE])) {
this._getMoreData();
}
Expand All @@ -503,15 +497,15 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft
this._loading = true;
of(this._loadNewItems())
.pipe(
tap((data) => {
tap(async (data) => {
if (isBlank(data)) {
console.error('===Invalid Response recived===');
}
this.loadingLabel = this._translationResolver.resolve(
this._language,
'platformList.loadingAriaLabel'
);
this._liveAnnouncer.announce(this.loadingLabel, 'assertive');
await this._liveAnnouncer.announce(this.loadingLabel, 'assertive');
}),
delay(this.delayTime),
takeUntil(this._destroyed)
Expand Down Expand Up @@ -588,6 +582,19 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft
this.stateChanges.next(item);
}

/** @hidden */
private _setItems(): void {
if (this._dsItems.length !== null && this.itemSize !== 0) {
this._startIndex = 0;
this._lastIndex = this.itemSize;
this._items = this._dsItems.slice(this._startIndex, this._lastIndex);
} else {
this._items = this._dsItems;
}

this.stateChanges.next(this._items);
}

/** @hidden */
private _initializeDS(ds: FdpListDataSource<T>): void {
this._dsItems = [];
Expand Down Expand Up @@ -638,6 +645,7 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft
.subscribe((data) => {
this._dsItems = data || [];
this.stateChanges.next(this._dsItems);
this._setItems();
this._cd.markForCheck();
});

Expand Down Expand Up @@ -814,30 +822,34 @@ export class ListComponent<T> extends CollectionBaseInput implements OnInit, Aft

@Component({
selector: 'fdp-list-footer',
template: ` <li #listfooter class="fd-list__footer" [attr.id]="id" role="option">
template: ` <li #listFooter class="fd-list__footer" [attr.id]="id" role="option">
<ng-content></ng-content>
</li>`
})
// eslint-disable-next-line @angular-eslint/component-class-suffix
export class ListFooter extends BaseComponent {}
export class ListFooterComponent extends BaseComponent {}

@Component({
selector: 'fdp-list-group-header',
template: ` <li #listItem fd-list-group-header [attr.id]="id" role="option" [tabindex]="0">
<span fd-list-title>{{ grpheaderTitle }}</span>
<span fd-list-title>{{ groupHeaderTitle }}</span>
<ng-content></ng-content>
</li>`,
providers: [{ provide: BaseListItem, useExisting: forwardRef(() => ListGroupHeader) }]
providers: [{ provide: BaseListItem, useExisting: forwardRef(() => ListGroupHeaderComponent) }]
})
// eslint-disable-next-line @angular-eslint/component-class-suffix
export class ListGroupHeader extends BaseListItem implements OnInit {
export class ListGroupHeaderComponent extends BaseListItem implements OnInit {
N1XUS marked this conversation as resolved.
Show resolved Hide resolved
/** Displays list goup header title */
@Input()
grpheaderTitle?: string;
N1XUS marked this conversation as resolved.
Show resolved Hide resolved
groupHeaderTitle?: string;

/** @deprecated Use `groupHeaderTitle` instead */
@Input()
set grpheaderTitle(value: string) {
this.groupHeaderTitle = value;
}

/**
* @hidden
* Instailization of list header
* Initialization of the list header component
*/
ngOnInit(): void {
this.id = `fdp-list-${nextListGrpHeaderId++}`;
Expand Down
26 changes: 19 additions & 7 deletions libs/platform/src/lib/list/list.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import { BusyIndicatorModule } from '@fundamental-ngx/core/busy-indicator';
import { InfiniteScrollModule } from '@fundamental-ngx/core/infinite-scroll';
import { ContentDensityModule } from '@fundamental-ngx/core/content-density';
import { PlatformContentDensityDeprecationsModule } from '@fundamental-ngx/platform/shared';
import { ListComponent, ListFooter, ListGroupHeader } from './list.component';
import { ListItemDef } from './base-list-item';
import { I18nModule } from '@fundamental-ngx/i18n';
import { ActionListItemModule } from './action-list-item/action-list-item.module';
import { DisplayListItemModule } from './display-list-item/display-list-item.module';
import { ListComponent, ListFooterComponent, ListGroupHeaderComponent } from './list.component';
import { ListItemDef } from './base-list-item';
import { ObjectListItemModule } from './object-list-item/object-list-item.module';
import { StandardListItemModule } from './standard-list-item/standard-list-item.module';

@NgModule({
declarations: [ListComponent, ListFooter, ListGroupHeader, ListItemDef],
declarations: [ListComponent, ListFooterComponent, ListGroupHeaderComponent, ListItemDef],
imports: [
CommonModule,
FormsModule,
Expand All @@ -27,15 +31,23 @@ import { I18nModule } from '@fundamental-ngx/i18n';
BusyIndicatorModule,
InfiniteScrollModule,
PlatformContentDensityDeprecationsModule,
ContentDensityModule
ContentDensityModule,
StandardListItemModule,
ObjectListItemModule,
DisplayListItemModule,
ActionListItemModule
],
exports: [
ListComponent,
ListFooter,
ListGroupHeader,
ListFooterComponent,
ListGroupHeaderComponent,
ListItemDef,
PlatformContentDensityDeprecationsModule,
ContentDensityModule
ContentDensityModule,
StandardListItemModule,
ObjectListItemModule,
DisplayListItemModule,
ActionListItemModule
]
})
export class PlatformListModule {}
6 changes: 3 additions & 3 deletions libs/platform/src/lib/shared/domain/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export abstract class DataProvider<T> {
protected _matchingStrategy: MatchingStrategy = MatchingStrategy.STARTS_WITH;
protected _matchingBy: MatchingBy | null = null;

abstract fetch(params: ProviderParams): Observable<T[]>;
abstract fetch(params: ProviderParams, start?: number, end?: number): Observable<T[]>;

/**
* Tells if this DataProvider supports INSERT, REMOVE
Expand Down Expand Up @@ -173,7 +173,7 @@ export class ComboBoxDataSource<T> implements DataSource<T> {

constructor(public dataProvider: DataProvider<any>) {}

match(predicate: string | Map<string, string> = new Map<string, string>()): void {
match(predicate: string | Map<string, string> = new Map<string, string>(), start = 0, end = Infinity): void {
this._onDataRequested$.next();
this._dataLoading = true;
const searchParam = new Map();
Expand All @@ -191,7 +191,7 @@ export class ComboBoxDataSource<T> implements DataSource<T> {
}

this.dataProvider
.fetch(searchParam)
.fetch(searchParam, start, end)
.pipe(takeUntil(this._onDestroy$))
.subscribe(
(result: T[]) => {
Expand Down