@@ -11,6 +11,7 @@ import { useEffect } from "react";
11
11
import { times } from "remeda" ;
12
12
import { IncrementalLoaderState } from "@/components/List/model/loading/IncrementalLoaderState" ;
13
13
import { hash } from "object-code" ;
14
+ import type { PropertyName } from "@/components/List/model/types" ;
14
15
15
16
type AsyncResourceLoadingState = AsyncResource [ "state" ] [ "value" ] ;
16
17
@@ -23,6 +24,7 @@ export class IncrementalLoader<T> {
23
24
public readonly manualFiltering : boolean ;
24
25
public readonly manualPagination : boolean ;
25
26
public readonly loaderState : IncrementalLoaderState < T > ;
27
+ public readonly staticDataProperties : PropertyName < T > [ ] = [ ] ;
26
28
27
29
private constructor ( list : List < T > , shape : IncrementalLoaderShape < T > = { } ) {
28
30
const { source } = shape ;
@@ -52,6 +54,8 @@ export class IncrementalLoader<T> {
52
54
this . manualSorting = manualSorting ?? this . manualPagination ;
53
55
this . list . filters . forEach ( ( f ) => f . onFilterUpdated ( ( ) => this . reset ( ) ) ) ;
54
56
this . list . search ?. onUpdated ( ( ) => this . reset ( ) ) ;
57
+
58
+ this . initStaticDataProperties ( ) ;
55
59
}
56
60
57
61
public static useNew < T > (
@@ -61,6 +65,27 @@ export class IncrementalLoader<T> {
61
65
return new IncrementalLoader ( list , shape ) ;
62
66
}
63
67
68
+ private initStaticDataProperties ( ) {
69
+ const addPropertiesOfDataEntry = ( data : unknown ) => {
70
+ if ( typeof data !== "object" || data === null ) {
71
+ return ;
72
+ }
73
+
74
+ ( Object . keys ( data ) as PropertyName < T > [ ] )
75
+ . filter ( ( p ) => ! this . staticDataProperties . includes ( p ) )
76
+ . forEach ( ( p ) => {
77
+ this . staticDataProperties . push ( p ) ;
78
+ } ) ;
79
+ } ;
80
+
81
+ if ( "staticData" in this . dataSource ) {
82
+ this . dataSource . staticData
83
+ // collect properties from just the first 100 items
84
+ . slice ( 0 , 100 )
85
+ . forEach ( addPropertiesOfDataEntry ) ;
86
+ }
87
+ }
88
+
64
89
private reset ( ) : void {
65
90
this . loaderState . reset ( ) ;
66
91
}
0 commit comments