Skip to content

Commit d4dcdff

Browse files
authored
Merge pull request #42 from bci-oss/fix/#40-41
Improve Schematic Table remote data loading functionality
2 parents 6b200b2 + ac4b8e3 commit d4dcdff

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/ng-generate/components/card/generators/components/card/files/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit<% i
106106

107107
dataToShow: Array<<%= options.aspectModelTypeName %>> = [];
108108
totalItems: number = 0;
109+
dataLoadError = false;
109110

110111
<% if (options.enableRemoteDataHandling) { %>
111112
rqlString: string = '';
@@ -115,6 +116,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit<% i
115116

116117
<% if (options.hasSearchBar || options.enableRemoteDataHandling) { %>
117118
private readonly destroy$ = new Subject<void>();
119+
private requestSubscription: Subscription;
118120
<% } %>
119121

120122
<% if (options.enableRemoteDataHandling) { %>

src/ng-generate/components/shared/methods/remote-handling/requestData.ts.template

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ private requestData() {
7373

7474
this.rqlString = rqlStringTemp;
7575

76-
this.<%= camelize((options.customRemoteService ? 'custom' : '') + '-' + options.name) %>Service.requestData(this.remoteAPI, {query: rqlStringTemp})
76+
if (this.requestSubscription && !this.requestSubscription.closed) {
77+
this.requestSubscription.unsubscribe();
78+
}
79+
80+
this.requestSubscription = this.<%= camelize((options.customRemoteService ? 'custom' : '') + '-' + options.name) %>Service.requestData(this.remoteAPI, {query: rqlStringTemp})
7781
.pipe(
7882
tap((movementResponse: <%= classify(options.aspectModel.name) %>Response) => {
83+
this.dataLoadError = false;
7984
this.totalItems =
8085
movementResponse.totalItems !== null && movementResponse.totalItems !== undefined
8186
? movementResponse.totalItems
@@ -95,7 +100,14 @@ private requestData() {
95100
this.dataSource.paginator = this.paginator;
96101
}),
97102
catchError((error: any) => {
98-
throw new Error(error.message);
103+
this.dataLoadError = true;
104+
<% if (options.componentType === 'card') { %>
105+
this.dataToShow = [];
106+
this.dataSource.data = [];
107+
<% } else { %>
108+
const dataToShow = [];
109+
this.dataSource.setData([]);
110+
<% } %>
99111
}),
100112
finalize(() => this.<% if (options.componentType === 'card') { %>card<% } else { %>table<% } %>UpdateFinishedEvent.emit()))
101113
.subscribe();

src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.html.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
<!-- Row shown when there is no matching data that will be provided to the wrapper table. -->
5151
<tr data-test="no-data-table-row" class="mat-row" *matNoDataRow>
5252
<td data-test="no-data-table-cell" class="mat-cell" [colSpan]="displayedColumns.length" *ngIf="!dataSource.data.length">
53-
<span data-test="no-data-message">{{noDataMessage || 'No data'}}</span>
53+
<span *ngIf="!dataLoadError" data-test="no-data-message">{{ noDataMessage || 'No data' }}</span>
54+
<span *ngIf="dataLoadError"
55+
data-test="no-data-message">{{ dataLoadErrorMessage || 'Unable to load data' }}</span>
56+
5457
</td>
5558
</tr>
5659

src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.ts.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
126126
@Input() highlightColor = 'rgba(127, 198, 231, 0.3)';
127127
@Input() isMultipleSelectionEnabled = true;
128128
@Input() noDataMessage: string = '';
129+
@Input() dataLoadErrorMessage: string = '';
129130
@Input() visibleRowActionsIcons: number = 3;
130131
@Input() headerTooltipsOff: boolean = false;
131132
@Input() setStickRowActions: boolean = true;
@@ -207,6 +208,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
207208
closeColumnMenu: boolean = false;
208209
rqlString: string = '';
209210
searchFocused: boolean = false;
211+
dataLoadError = false;
210212

211213
<% if (options.hasSearchBar) { %>
212214
highlightString: string[] = [];
@@ -220,6 +222,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
220222

221223
<% if (options.hasSearchBar || options.enableRemoteDataHandling) { %>
222224
private readonly ngUnsubscribe = new Subject<void>();
225+
private requestSubscription: Subscription;
223226
<% } %>
224227

225228
<% if (options.enableRemoteDataHandling) { %>

0 commit comments

Comments
 (0)