@furystack/shades-common-components 7.0.0 → 8.0.0
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/esm/components/data-grid/body.d.ts.map +1 -1
- package/esm/components/data-grid/body.js +0 -5
- package/esm/components/data-grid/body.js.map +1 -1
- package/esm/components/data-grid/data-grid-row.d.ts.map +1 -1
- package/esm/components/data-grid/data-grid-row.js +40 -37
- package/esm/components/data-grid/data-grid-row.js.map +1 -1
- package/esm/components/data-grid/data-grid.d.ts +7 -1
- package/esm/components/data-grid/data-grid.d.ts.map +1 -1
- package/esm/components/data-grid/data-grid.js +7 -6
- package/esm/components/data-grid/data-grid.js.map +1 -1
- package/esm/components/data-grid/footer.d.ts +3 -0
- package/esm/components/data-grid/footer.d.ts.map +1 -1
- package/esm/components/data-grid/footer.js +13 -11
- package/esm/components/data-grid/footer.js.map +1 -1
- package/esm/components/data-grid/header.d.ts +6 -6
- package/esm/components/data-grid/header.d.ts.map +1 -1
- package/esm/components/data-grid/header.js +39 -33
- package/esm/components/data-grid/header.js.map +1 -1
- package/esm/services/collection-service.d.ts +2 -21
- package/esm/services/collection-service.d.ts.map +1 -1
- package/esm/services/collection-service.js +7 -36
- package/esm/services/collection-service.js.map +1 -1
- package/esm/services/collection-service.spec.js +2 -5
- package/esm/services/collection-service.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/components/data-grid/body.tsx +0 -11
- package/src/components/data-grid/data-grid-row.tsx +42 -39
- package/src/components/data-grid/data-grid.tsx +25 -13
- package/src/components/data-grid/footer.tsx +19 -13
- package/src/components/data-grid/header.tsx +59 -45
- package/src/services/collection-service.spec.ts +14 -20
- package/src/services/collection-service.ts +7 -62
|
@@ -7,31 +7,25 @@ const testEntries = [{ foo: 1 }, { foo: 2 }, { foo: 3 }]
|
|
|
7
7
|
describe('CollectionService', () => {
|
|
8
8
|
describe('Selection', () => {
|
|
9
9
|
it('Should add and remove selection', async () => {
|
|
10
|
-
await usingAsync(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
async (collectionService) => {
|
|
16
|
-
await collectionService.getEntries({})
|
|
17
|
-
testEntries.forEach((entry) => {
|
|
18
|
-
expect(collectionService.isSelected(entry)).toBe(false)
|
|
19
|
-
})
|
|
10
|
+
await usingAsync(new CollectionService({}), async (collectionService) => {
|
|
11
|
+
collectionService.data.setValue({ count: 3, entries: testEntries })
|
|
12
|
+
testEntries.forEach((entry) => {
|
|
13
|
+
expect(collectionService.isSelected(entry)).toBe(false)
|
|
14
|
+
})
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
collectionService.addToSelection(testEntries[0])
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
expect(collectionService.isSelected(testEntries[0])).toBe(true)
|
|
19
|
+
expect(collectionService.isSelected(testEntries[1])).toBe(false)
|
|
20
|
+
expect(collectionService.isSelected(testEntries[2])).toBe(false)
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
collectionService.removeFromSelection(testEntries[0])
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
expect(collectionService.isSelected(testEntries[0])).toBe(false)
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
26
|
+
collectionService.toggleSelection(testEntries[1])
|
|
27
|
+
expect(collectionService.isSelected(testEntries[1])).toBe(true)
|
|
28
|
+
})
|
|
35
29
|
})
|
|
36
30
|
})
|
|
37
31
|
})
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import type { PartialResult, FindOptions } from '@furystack/core'
|
|
2
|
-
import { Lock } from 'semaphore-async-await'
|
|
3
1
|
import type { Disposable } from '@furystack/utils'
|
|
4
|
-
import {
|
|
2
|
+
import { ObservableValue } from '@furystack/utils'
|
|
5
3
|
|
|
6
4
|
export interface CollectionData<T> {
|
|
7
5
|
entries: T[]
|
|
8
6
|
count: number
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
export type EntryLoader<T> = <TFields extends Array<keyof T>>(
|
|
12
|
-
searchOptions: FindOptions<T, TFields>,
|
|
13
|
-
) => Promise<CollectionData<PartialResult<T, TFields>>>
|
|
14
|
-
|
|
15
9
|
export interface CollectionServiceOptions<T> {
|
|
16
|
-
/**
|
|
17
|
-
* A method used to retrieve the entries from the data source
|
|
18
|
-
*/
|
|
19
|
-
loader: EntryLoader<T>
|
|
20
|
-
/**
|
|
21
|
-
* The default filter / top / skip / etc... options
|
|
22
|
-
*/
|
|
23
|
-
defaultSettings: FindOptions<T, Array<keyof T>>
|
|
24
10
|
/**
|
|
25
11
|
* An optional field that can be used for quick search
|
|
26
12
|
*/
|
|
27
13
|
searchField?: keyof T
|
|
28
|
-
|
|
29
14
|
/**
|
|
30
15
|
* @param entry The clicked entry
|
|
31
16
|
* optional callback for row clicks
|
|
@@ -38,19 +23,15 @@ export interface CollectionServiceOptions<T> {
|
|
|
38
23
|
*/
|
|
39
24
|
|
|
40
25
|
onRowDoubleClick?: (entry: T) => void
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* An optional debounce interval in milliseconds
|
|
44
|
-
*/
|
|
45
|
-
debounceMs?: number
|
|
46
26
|
}
|
|
47
27
|
|
|
48
28
|
export class CollectionService<T> implements Disposable {
|
|
49
29
|
public dispose() {
|
|
50
|
-
this.querySettings.dispose()
|
|
51
30
|
this.data.dispose()
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
31
|
+
this.selection.dispose()
|
|
32
|
+
this.searchTerm.dispose()
|
|
33
|
+
this.hasFocus.dispose()
|
|
34
|
+
this.focusedEntry.dispose()
|
|
54
35
|
}
|
|
55
36
|
|
|
56
37
|
public isSelected = (entry: T) => this.selection.getValue().includes(entry)
|
|
@@ -67,18 +48,8 @@ export class CollectionService<T> implements Disposable {
|
|
|
67
48
|
this.isSelected(entry) ? this.removeFromSelection(entry) : this.addToSelection(entry)
|
|
68
49
|
}
|
|
69
50
|
|
|
70
|
-
private readonly loadLock = new Lock()
|
|
71
|
-
|
|
72
|
-
public getEntries: EntryLoader<T>
|
|
73
|
-
|
|
74
51
|
public data = new ObservableValue<CollectionData<T>>({ count: 0, entries: [] })
|
|
75
52
|
|
|
76
|
-
public error = new ObservableValue<unknown | undefined>(undefined)
|
|
77
|
-
|
|
78
|
-
public isLoading = new ObservableValue<boolean>(false)
|
|
79
|
-
|
|
80
|
-
public querySettings: ObservableValue<FindOptions<T, Array<keyof T>>>
|
|
81
|
-
|
|
82
53
|
public focusedEntry = new ObservableValue<T | undefined>(undefined)
|
|
83
54
|
|
|
84
55
|
public selection = new ObservableValue<T[]>([])
|
|
@@ -193,35 +164,9 @@ export class CollectionService<T> implements Disposable {
|
|
|
193
164
|
this.focusedEntry.setValue(entry)
|
|
194
165
|
}
|
|
195
166
|
|
|
196
|
-
constructor(private options: CollectionServiceOptions<T>) {
|
|
197
|
-
this.querySettings = new ObservableValue<FindOptions<T, Array<keyof T>>>(this.options.defaultSettings)
|
|
198
|
-
|
|
199
|
-
const loader = this.options.debounceMs
|
|
200
|
-
? debounce(this.options.loader, this.options.debounceMs)
|
|
201
|
-
: this.options.loader
|
|
202
|
-
|
|
203
|
-
this.getEntries = async (opt) => {
|
|
204
|
-
await this.loadLock.acquire()
|
|
205
|
-
try {
|
|
206
|
-
this.error.setValue(undefined)
|
|
207
|
-
this.isLoading.setValue(true)
|
|
208
|
-
const result = await loader(opt)
|
|
209
|
-
this.data.setValue(result)
|
|
210
|
-
return result
|
|
211
|
-
} catch (error) {
|
|
212
|
-
this.error.setValue(error)
|
|
213
|
-
throw error
|
|
214
|
-
} finally {
|
|
215
|
-
this.loadLock.release()
|
|
216
|
-
this.isLoading.setValue(false)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
this.querySettings.subscribe((val) => this.getEntries(val))
|
|
221
|
-
this.getEntries(this.querySettings.getValue())
|
|
222
|
-
}
|
|
167
|
+
constructor(private options: CollectionServiceOptions<T> = {}) {}
|
|
223
168
|
|
|
224
|
-
public
|
|
169
|
+
public handleRowDoubleClick(entry: T) {
|
|
225
170
|
this.options.onRowDoubleClick?.(entry)
|
|
226
171
|
}
|
|
227
172
|
}
|