@intellegens/cornerstone-client 0.0.9999-alpha-22 → 0.0.9999-alpha-24

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.
@@ -98,6 +98,10 @@ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey
98
98
  * @param pageSize
99
99
  */
100
100
  setPageSize(pageSize: number): Promise<TDto[]>;
101
+ /**
102
+ * Refreshes the data by re-fetching the current page
103
+ */
104
+ refreshData(): Promise<TDto[]>;
101
105
  private _totalItemCount;
102
106
  /**
103
107
  * Returns the total count value of the collection.
@@ -133,6 +133,12 @@ export class CollectionViewAdapter {
133
133
  this._currentOptions.pagination.pageNumber = 1; // Reset to first page
134
134
  return this._fetchCurrentPageData();
135
135
  }
136
+ /**
137
+ * Refreshes the data by re-fetching the current page
138
+ */
139
+ refreshData() {
140
+ return this._fetchCurrentPageData();
141
+ }
136
142
  _totalItemCount = -1;
137
143
  /**
138
144
  * Returns the total count value of the collection.
@@ -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
- constructor(options: SearchAdapterOptions);
25
- onChange: SingularEventTarget<string>;
26
- private _emitChange;
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 _lastSearchedValue;
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
- _lastSearchedValue = '';
82
- _typesToSearch = [];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-client",
3
- "version": "0.0.9999-alpha-22",
3
+ "version": "0.0.9999-alpha-24",
4
4
  "private": false,
5
5
  "publishable": true,
6
6
  "main": "./dist/index.js",
@@ -204,6 +204,13 @@ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDeta
204
204
  return this._fetchCurrentPageData();
205
205
  }
206
206
 
207
+ /**
208
+ * Refreshes the data by re-fetching the current page
209
+ */
210
+ public refreshData() {
211
+ return this._fetchCurrentPageData();
212
+ }
213
+
207
214
  private _totalItemCount = -1;
208
215
 
209
216
  /**
@@ -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 _lastSearchedValue = '';
120
- private _typesToSearch: string[] = [];
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