@intellegens/cornerstone-client 0.0.9999-alpha-21 → 0.0.9999-alpha-23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/CollectionViewAdapter/index.d.ts +34 -0
- package/dist/adapters/CollectionViewAdapter/index.js +73 -0
- package/dist/adapters/SearchAdapter/index.d.ts +10 -9
- package/dist/adapters/SearchAdapter/index.js +11 -8
- package/package.json +1 -1
- package/src/adapters/CollectionViewAdapter/index.ts +80 -0
- package/src/adapters/SearchAdapter/index.ts +25 -18
|
@@ -51,6 +51,7 @@ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey
|
|
|
51
51
|
private _readClient;
|
|
52
52
|
private _isLoading;
|
|
53
53
|
private _pageData;
|
|
54
|
+
private _selectedItems;
|
|
54
55
|
private _defaultOptions;
|
|
55
56
|
private _initialOptions;
|
|
56
57
|
private _currentOptions;
|
|
@@ -157,4 +158,37 @@ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey
|
|
|
157
158
|
* @returns The computed total item count
|
|
158
159
|
*/
|
|
159
160
|
private _calculateTotal;
|
|
161
|
+
/**
|
|
162
|
+
* Selects or deselects an item based on its ID.
|
|
163
|
+
* @param item - The item to select or deselect.
|
|
164
|
+
*/
|
|
165
|
+
toggleItemSelected(item: TDto): void;
|
|
166
|
+
clearSelectedItems(): void;
|
|
167
|
+
selectItems(item: TDto): void;
|
|
168
|
+
deselectItem(item: TDto): void;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the currently selected items
|
|
171
|
+
*/
|
|
172
|
+
get selectedItems(): TDto[];
|
|
173
|
+
/**
|
|
174
|
+
* Checks if an item is currently selected
|
|
175
|
+
* @param item - The item to check
|
|
176
|
+
*/
|
|
177
|
+
isItemSelected(item: TDto): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Selects all items on the current page
|
|
180
|
+
*/
|
|
181
|
+
selectAllItemsOnCurrentPage(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Deselects all items on the current page
|
|
184
|
+
*/
|
|
185
|
+
deselectAllItemsOnCurrentPage(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Checks if all items on the current page are selected
|
|
188
|
+
*/
|
|
189
|
+
areAllItemsOnCurrentPageSelected(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Checks if some (but not all) items on the current page are selected
|
|
192
|
+
*/
|
|
193
|
+
areSomeItemsOnCurrentPageSelected(): boolean;
|
|
160
194
|
}
|
|
@@ -12,6 +12,7 @@ export class CollectionViewAdapter {
|
|
|
12
12
|
_readClient;
|
|
13
13
|
_isLoading = false;
|
|
14
14
|
_pageData = [];
|
|
15
|
+
_selectedItems = [];
|
|
15
16
|
_defaultOptions = {
|
|
16
17
|
pagination: {
|
|
17
18
|
useTotalItemCount: false,
|
|
@@ -299,4 +300,76 @@ export class CollectionViewAdapter {
|
|
|
299
300
|
}
|
|
300
301
|
return previousTotal;
|
|
301
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Selects or deselects an item based on its ID.
|
|
305
|
+
* @param item - The item to select or deselect.
|
|
306
|
+
*/
|
|
307
|
+
toggleItemSelected(item) {
|
|
308
|
+
// if item with the same id is not already selected, add it
|
|
309
|
+
// if item with the same id is already selected, remove it
|
|
310
|
+
if (this._selectedItems.find(x => x.id === item.id)) {
|
|
311
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
this._selectedItems.push(item);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
clearSelectedItems() {
|
|
318
|
+
this._selectedItems = [];
|
|
319
|
+
}
|
|
320
|
+
selectItems(item) {
|
|
321
|
+
if (!this._selectedItems.find(x => x.id === item.id)) {
|
|
322
|
+
this._selectedItems.push(item);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
deselectItem(item) {
|
|
326
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Returns the currently selected items
|
|
330
|
+
*/
|
|
331
|
+
get selectedItems() {
|
|
332
|
+
return this._selectedItems;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Checks if an item is currently selected
|
|
336
|
+
* @param item - The item to check
|
|
337
|
+
*/
|
|
338
|
+
isItemSelected(item) {
|
|
339
|
+
return this._selectedItems.some(x => x.id === item.id);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Selects all items on the current page
|
|
343
|
+
*/
|
|
344
|
+
selectAllItemsOnCurrentPage() {
|
|
345
|
+
for (const item of this._pageData) {
|
|
346
|
+
if (!this.isItemSelected(item)) {
|
|
347
|
+
this._selectedItems.push(item);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Deselects all items on the current page
|
|
353
|
+
*/
|
|
354
|
+
deselectAllItemsOnCurrentPage() {
|
|
355
|
+
const pageItemIds = this._pageData.map(item => item.id);
|
|
356
|
+
this._selectedItems = this._selectedItems.filter(item => !pageItemIds.includes(item.id));
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Checks if all items on the current page are selected
|
|
360
|
+
*/
|
|
361
|
+
areAllItemsOnCurrentPageSelected() {
|
|
362
|
+
if (this._pageData.length === 0)
|
|
363
|
+
return false;
|
|
364
|
+
return this._pageData.every(item => this.isItemSelected(item));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Checks if some (but not all) items on the current page are selected
|
|
368
|
+
*/
|
|
369
|
+
areSomeItemsOnCurrentPageSelected() {
|
|
370
|
+
if (this._pageData.length === 0)
|
|
371
|
+
return false;
|
|
372
|
+
const selectedCount = this._pageData.filter(item => this.isItemSelected(item)).length;
|
|
373
|
+
return selectedCount > 0 && selectedCount < this._pageData.length;
|
|
374
|
+
}
|
|
302
375
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IIdentifiable } from '../../data';
|
|
2
|
-
export type SearchAdapterOptions = {
|
|
1
|
+
import { IIdentifiable, ReadSelectedSearchDefinitionDto } from '../../data';
|
|
2
|
+
export type SearchAdapterOptions<T> = {
|
|
3
3
|
controllerName: string;
|
|
4
4
|
typesToSearch: string[];
|
|
5
5
|
multiselect: boolean;
|
|
@@ -7,6 +7,7 @@ export type SearchAdapterOptions = {
|
|
|
7
7
|
searchDebounceDelay: number;
|
|
8
8
|
limitSearchToSelectedType: boolean;
|
|
9
9
|
resultsLimit: number;
|
|
10
|
+
additionalSearchDefinitions?: ReadSelectedSearchDefinitionDto<T>[];
|
|
10
11
|
};
|
|
11
12
|
declare class SingularEventTarget<T> {
|
|
12
13
|
private _target;
|
|
@@ -17,13 +18,16 @@ export interface IGlobalSearchable<TKey> extends IIdentifiable<TKey> {
|
|
|
17
18
|
type: string;
|
|
18
19
|
}
|
|
19
20
|
export declare class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
21
|
+
onChange: SingularEventTarget<string>;
|
|
20
22
|
private _readClient;
|
|
21
23
|
private _options;
|
|
22
24
|
private _isLoading;
|
|
23
25
|
private _currentAbortController?;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private
|
|
26
|
+
private _lastSearchedValue;
|
|
27
|
+
private _typesToSearch;
|
|
28
|
+
private _fetchResultsDataTimeout?;
|
|
29
|
+
private _fetchResultsPromises;
|
|
30
|
+
constructor(options: SearchAdapterOptions<TDto>);
|
|
27
31
|
get multiselect(): boolean;
|
|
28
32
|
private _searchText;
|
|
29
33
|
get searchText(): string;
|
|
@@ -36,11 +40,8 @@ export declare class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
|
36
40
|
set selectedItems(selectedItems: TDto[]);
|
|
37
41
|
addToSelection(item: TDto): void;
|
|
38
42
|
removeFromSelection(item: TDto): void;
|
|
39
|
-
private
|
|
40
|
-
private _typesToSearch;
|
|
43
|
+
private _emitChange;
|
|
41
44
|
private _trySearch;
|
|
42
|
-
private _fetchResultsDataTimeout?;
|
|
43
|
-
private _fetchResultsPromises;
|
|
44
45
|
private _fetchResults;
|
|
45
46
|
private _fetchResultsDebounced;
|
|
46
47
|
private _parseToSearchDefinition;
|
|
@@ -10,19 +10,20 @@ class SingularEventTarget {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export class SearchAdapter {
|
|
13
|
+
onChange = new SingularEventTarget();
|
|
13
14
|
// inputs
|
|
14
15
|
_readClient;
|
|
15
16
|
_options;
|
|
16
17
|
_isLoading = false;
|
|
17
18
|
_currentAbortController;
|
|
19
|
+
_lastSearchedValue = '';
|
|
20
|
+
_typesToSearch = [];
|
|
21
|
+
_fetchResultsDataTimeout;
|
|
22
|
+
_fetchResultsPromises = [];
|
|
18
23
|
constructor(options) {
|
|
19
24
|
this._options = options;
|
|
20
25
|
this._readClient = new ApiReadControllerClient(options.controllerName);
|
|
21
26
|
}
|
|
22
|
-
onChange = new SingularEventTarget();
|
|
23
|
-
_emitChange() {
|
|
24
|
-
this.onChange.dispatchEvent('onChange');
|
|
25
|
-
}
|
|
26
27
|
get multiselect() {
|
|
27
28
|
return this._options.multiselect;
|
|
28
29
|
}
|
|
@@ -78,8 +79,9 @@ export class SearchAdapter {
|
|
|
78
79
|
this.selectedItems = this._selectedItems.filter(s => s.id !== item.id);
|
|
79
80
|
this.searchResults = this._sortByName([...this._searchResults, item]);
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
_emitChange() {
|
|
83
|
+
this.onChange.dispatchEvent('onChange');
|
|
84
|
+
}
|
|
83
85
|
async _trySearch() {
|
|
84
86
|
const options = this._options;
|
|
85
87
|
this.searchResults = [];
|
|
@@ -92,8 +94,6 @@ export class SearchAdapter {
|
|
|
92
94
|
options.limitSearchToSelectedType && this._selectedItems.length ? [this._selectedItems[0].type] : this._options.typesToSearch;
|
|
93
95
|
this.searchResults = this._sortByName(await this._fetchResults(options.searchDebounceDelay));
|
|
94
96
|
}
|
|
95
|
-
_fetchResultsDataTimeout;
|
|
96
|
-
_fetchResultsPromises = [];
|
|
97
97
|
async _fetchResults(debounceDelay) {
|
|
98
98
|
return new Promise((resolve, reject) => {
|
|
99
99
|
this._fetchResultsPromises.push({ resolve, reject });
|
|
@@ -203,6 +203,9 @@ export class SearchAdapter {
|
|
|
203
203
|
},
|
|
204
204
|
];
|
|
205
205
|
}
|
|
206
|
+
if (this._options.additionalSearchDefinitions && this._options.additionalSearchDefinitions.length > 0) {
|
|
207
|
+
definition.searchDefinition.searches = [...(definition.searchDefinition.searches ?? []), ...this._options.additionalSearchDefinitions];
|
|
208
|
+
}
|
|
206
209
|
return definition;
|
|
207
210
|
}
|
|
208
211
|
_sortByName(array) {
|
package/package.json
CHANGED
|
@@ -56,6 +56,7 @@ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDeta
|
|
|
56
56
|
|
|
57
57
|
private _isLoading = false;
|
|
58
58
|
private _pageData: TDto[] = [];
|
|
59
|
+
private _selectedItems: TDto[] = [];
|
|
59
60
|
|
|
60
61
|
private _defaultOptions: CollectionViewAdapterOptions<TDto> = {
|
|
61
62
|
pagination: {
|
|
@@ -387,4 +388,83 @@ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDeta
|
|
|
387
388
|
}
|
|
388
389
|
return previousTotal;
|
|
389
390
|
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Selects or deselects an item based on its ID.
|
|
394
|
+
* @param item - The item to select or deselect.
|
|
395
|
+
*/
|
|
396
|
+
public toggleItemSelected(item: TDto) {
|
|
397
|
+
// if item with the same id is not already selected, add it
|
|
398
|
+
// if item with the same id is already selected, remove it
|
|
399
|
+
if (this._selectedItems.find(x => x.id === item.id)) {
|
|
400
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
401
|
+
} else {
|
|
402
|
+
this._selectedItems.push(item);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
public clearSelectedItems() {
|
|
407
|
+
this._selectedItems = [];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
public selectItems(item: TDto) {
|
|
411
|
+
if (!this._selectedItems.find(x => x.id === item.id)) {
|
|
412
|
+
this._selectedItems.push(item);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
public deselectItem(item: TDto) {
|
|
417
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Returns the currently selected items
|
|
422
|
+
*/
|
|
423
|
+
public get selectedItems(): TDto[] {
|
|
424
|
+
return this._selectedItems;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Checks if an item is currently selected
|
|
429
|
+
* @param item - The item to check
|
|
430
|
+
*/
|
|
431
|
+
public isItemSelected(item: TDto): boolean {
|
|
432
|
+
return this._selectedItems.some(x => x.id === item.id);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Selects all items on the current page
|
|
437
|
+
*/
|
|
438
|
+
public selectAllItemsOnCurrentPage() {
|
|
439
|
+
for (const item of this._pageData) {
|
|
440
|
+
if (!this.isItemSelected(item)) {
|
|
441
|
+
this._selectedItems.push(item);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Deselects all items on the current page
|
|
448
|
+
*/
|
|
449
|
+
public deselectAllItemsOnCurrentPage() {
|
|
450
|
+
const pageItemIds = this._pageData.map(item => item.id);
|
|
451
|
+
this._selectedItems = this._selectedItems.filter(item => !pageItemIds.includes(item.id));
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Checks if all items on the current page are selected
|
|
456
|
+
*/
|
|
457
|
+
public areAllItemsOnCurrentPageSelected(): boolean {
|
|
458
|
+
if (this._pageData.length === 0) return false;
|
|
459
|
+
return this._pageData.every(item => this.isItemSelected(item));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Checks if some (but not all) items on the current page are selected
|
|
464
|
+
*/
|
|
465
|
+
public areSomeItemsOnCurrentPageSelected(): boolean {
|
|
466
|
+
if (this._pageData.length === 0) return false;
|
|
467
|
+
const selectedCount = this._pageData.filter(item => this.isItemSelected(item)).length;
|
|
468
|
+
return selectedCount > 0 && selectedCount < this._pageData.length;
|
|
469
|
+
}
|
|
390
470
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@data';
|
|
11
11
|
import { ApiReadControllerClient } from '@services';
|
|
12
12
|
|
|
13
|
-
export type SearchAdapterOptions = {
|
|
13
|
+
export type SearchAdapterOptions<T> = {
|
|
14
14
|
controllerName: string;
|
|
15
15
|
typesToSearch: string[]; // provide known searchable types
|
|
16
16
|
multiselect: boolean;
|
|
@@ -18,6 +18,7 @@ export type SearchAdapterOptions = {
|
|
|
18
18
|
searchDebounceDelay: number;
|
|
19
19
|
limitSearchToSelectedType: boolean; // when item is selected, limit results to items of same type
|
|
20
20
|
resultsLimit: number;
|
|
21
|
+
additionalSearchDefinitions?: ReadSelectedSearchDefinitionDto<T>[];
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
class SingularEventTarget<T> {
|
|
@@ -37,31 +38,35 @@ export interface IGlobalSearchable<TKey> extends IIdentifiable<TKey> {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
41
|
+
public onChange = new SingularEventTarget<string>();
|
|
40
42
|
// inputs
|
|
41
43
|
private _readClient!: ApiReadControllerClient<TKey, TDto, TDto>;
|
|
42
|
-
private _options!: SearchAdapterOptions
|
|
43
|
-
|
|
44
|
+
private _options!: SearchAdapterOptions<TDto>;
|
|
44
45
|
private _isLoading = false;
|
|
45
46
|
private _currentAbortController?: AbortController;
|
|
47
|
+
private _lastSearchedValue = '';
|
|
48
|
+
private _typesToSearch: string[] = [];
|
|
49
|
+
private _fetchResultsDataTimeout?: any;
|
|
50
|
+
private _fetchResultsPromises: {
|
|
51
|
+
resolve: (value: TDto[] | PromiseLike<TDto[]>) => void;
|
|
52
|
+
reject: (reason?: unknown) => void;
|
|
53
|
+
}[] = [];
|
|
46
54
|
|
|
47
|
-
constructor(options: SearchAdapterOptions) {
|
|
55
|
+
constructor(options: SearchAdapterOptions<TDto>) {
|
|
48
56
|
this._options = options;
|
|
49
57
|
this._readClient = new ApiReadControllerClient<TKey, TDto, TDto>(options.controllerName);
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
public onChange = new SingularEventTarget<string>();
|
|
53
|
-
private _emitChange() {
|
|
54
|
-
this.onChange.dispatchEvent('onChange');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
60
|
public get multiselect() {
|
|
58
61
|
return this._options.multiselect;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
private _searchText: string = '';
|
|
65
|
+
|
|
62
66
|
public get searchText() {
|
|
63
67
|
return this._searchText;
|
|
64
68
|
}
|
|
69
|
+
|
|
65
70
|
public set searchText(searchText: string) {
|
|
66
71
|
this._searchText = searchText;
|
|
67
72
|
this._trySearch();
|
|
@@ -69,18 +74,22 @@ export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
private _searchResults: TDto[] = [];
|
|
77
|
+
|
|
72
78
|
public get searchResults() {
|
|
73
79
|
return this._searchResults;
|
|
74
80
|
}
|
|
81
|
+
|
|
75
82
|
protected set searchResults(searchResults: TDto[]) {
|
|
76
83
|
this._searchResults = [...searchResults];
|
|
77
84
|
this._emitChange();
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
private _selectedItems: TDto[] = [];
|
|
88
|
+
|
|
81
89
|
public get selectedItems() {
|
|
82
90
|
return this._selectedItems;
|
|
83
91
|
}
|
|
92
|
+
|
|
84
93
|
public set selectedItems(selectedItems: TDto[]) {
|
|
85
94
|
this._selectedItems = [...selectedItems];
|
|
86
95
|
this._emitChange();
|
|
@@ -116,8 +125,9 @@ export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
|
116
125
|
this.searchResults = this._sortByName([...this._searchResults, item]);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
private
|
|
120
|
-
|
|
128
|
+
private _emitChange() {
|
|
129
|
+
this.onChange.dispatchEvent('onChange');
|
|
130
|
+
}
|
|
121
131
|
|
|
122
132
|
private async _trySearch() {
|
|
123
133
|
const options = this._options;
|
|
@@ -133,13 +143,6 @@ export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
|
133
143
|
this.searchResults = this._sortByName(await this._fetchResults(options.searchDebounceDelay));
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
private _fetchResultsDataTimeout?: any;
|
|
137
|
-
|
|
138
|
-
private _fetchResultsPromises: {
|
|
139
|
-
resolve: (value: TDto[] | PromiseLike<TDto[]>) => void;
|
|
140
|
-
reject: (reason?: unknown) => void;
|
|
141
|
-
}[] = [];
|
|
142
|
-
|
|
143
146
|
private async _fetchResults(debounceDelay: number): Promise<TDto[]> {
|
|
144
147
|
return new Promise((resolve, reject) => {
|
|
145
148
|
this._fetchResultsPromises.push({ resolve, reject });
|
|
@@ -261,6 +264,10 @@ export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
|
261
264
|
];
|
|
262
265
|
}
|
|
263
266
|
|
|
267
|
+
if (this._options.additionalSearchDefinitions && this._options.additionalSearchDefinitions.length > 0) {
|
|
268
|
+
definition.searchDefinition.searches = [...(definition.searchDefinition.searches ?? []), ...this._options.additionalSearchDefinitions];
|
|
269
|
+
}
|
|
270
|
+
|
|
264
271
|
return definition;
|
|
265
272
|
}
|
|
266
273
|
|