@@ -50,12 +50,7 @@ export class DatasourceParamsController implements ReactiveController {
5050 meta : FiltersMeta ;
5151 hash : string | null ;
5252 } {
53- // return and(compactArray(this.columns.conditions), compactArray(this.customFilters.conditions));
5453 return this . reduceFilters ( this . columns . conditions , this . customFilters . conditions ) ;
55-
56- // console.dir(...reduceArray(columns.conditions));
57-
58- // return [this.columns.conditions, this.customFilters.conditions];
5954 }
6055
6156 private get derivedSortOrder ( ) : SortInstruction [ ] | undefined {
@@ -108,24 +103,24 @@ export class DatasourceParamsController implements ReactiveController {
108103 return disposeAll ;
109104 }
110105
111- storageKey ( hash : string ) : string {
112- return ` ${ this . widgetName } :[ ${ hash } ]` ;
106+ dataKey ( hash : string ) : string {
107+ return DatasourceParamsController . storageKey ( this . widgetName , hash ) ;
113108 }
114109
115110 clearFilterMeta ( hash : string ) : void {
116- sessionStorage . removeItem ( this . storageKey ( hash ) ) ;
111+ sessionStorage . removeItem ( this . dataKey ( hash ) ) ;
117112 }
118113
119114 saveFilterMeta ( hash : string | null , meta : FiltersMeta ) : void {
120115 if ( ! hash ) {
121116 return ;
122117 }
123118
124- sessionStorage . setItem ( this . storageKey ( hash ) , JSON . stringify ( meta ) ) ;
119+ sessionStorage . setItem ( this . dataKey ( hash ) , JSON . stringify ( meta ) ) ;
125120 }
126121
127122 readFilterMeta ( hash : string ) : FiltersMeta | null {
128- const item = sessionStorage . getItem ( this . storageKey ( hash ) ) ;
123+ const item = sessionStorage . getItem ( this . dataKey ( hash ) ) ;
129124 if ( ! item ) {
130125 return null ;
131126 }
@@ -141,22 +136,35 @@ export class DatasourceParamsController implements ReactiveController {
141136 return fnv1aHash ( JSON . stringify ( filter ) ) . toString ( ) ;
142137 }
143138
139+ static storageKey ( widgetName : string , hash : string ) : string {
140+ return `${ widgetName } :[${ hash } ]` ;
141+ }
142+
143+ static restoreMeta ( filter : FilterCondition ) : FiltersMeta | null {
144+ const hash = this . filterHash ( filter ) ;
145+ const key = this . storageKey ( "dataKey" , hash ) ;
146+ const metaJson = sessionStorage . getItem ( key ) ;
147+ if ( ! metaJson ) {
148+ return null ;
149+ }
150+ return JSON . parse ( metaJson ) as FiltersMeta ;
151+ }
152+
144153 static unzipFilter (
145154 filter ?: FilterCondition ,
146- widgetName = "dataKey "
155+ widgetName = "DatasourceParamsController "
147156 ) : [ columnFilters : Array < FilterCondition | undefined > , customFilters : Array < FilterCondition | undefined > ] {
148157 if ( ! filter ) {
149158 return [ [ ] , [ ] ] ;
150159 }
151- const hash = this . filterHash ( filter ) ;
152- const metaJson = sessionStorage . getItem ( `${ widgetName } :[${ hash } ]` ) ;
153- if ( ! metaJson ) {
160+ const meta = this . restoreMeta ( filter ) ;
161+ if ( ! meta ) {
154162 return [ [ ] , [ ] ] ;
155163 }
156- const meta = JSON . parse ( metaJson ) as FiltersMeta ;
157- const [ x , y ] = restoreArray ( filter , meta . combined ) ;
158- const columnFilters = restoreArray ( x , meta . columnFilters ) ;
159- const customFilters = restoreArray ( y , meta . customFilters ) ;
164+
165+ const [ column , custom ] = restoreArray ( filter , meta . combined ) ;
166+ const columnFilters = restoreArray ( column , meta . columnFilters ) ;
167+ const customFilters = restoreArray ( custom , meta . customFilters ) ;
160168 return [ columnFilters , customFilters ] ;
161169 }
162170}
0 commit comments