@@ -2,7 +2,7 @@ import isEqual from 'lodash/isEqual'
22import cloneDeep from 'lodash/cloneDeep'
33
44export function toList ( state ) {
5- return state . filter ( ( { visible } ) => visible ) . map ( ( { attribute } ) => attribute )
5+ return state . filter ( ( { visible} ) => visible ) . map ( ( { attribute} ) => attribute )
66}
77
88export function encode ( state ) {
@@ -13,9 +13,9 @@ export function decode(state) {
1313 return state ? JSON . parse ( decodeURIComponent ( escape ( atob ( state ) ) ) ) : null
1414}
1515
16- export function getStateFromLocalStorage ( cacheKey ) {
16+ export async function getStateFromLocalStorage ( cacheKey ) {
1717
18- const value = localStorage . getItem ( generateCacheKey ( cacheKey ) )
18+ const value = localStorage . getItem ( await generateCacheKey ( cacheKey ) )
1919
2020 if ( value === null ) {
2121 return true
@@ -25,23 +25,24 @@ export function getStateFromLocalStorage(cacheKey) {
2525
2626}
2727
28- export function saveStateToLocalStorage ( state , cacheKey ) {
29- localStorage . setItem ( generateCacheKey ( cacheKey ) , encode ( state ) )
28+ export async function saveStateToLocalStorage ( state , cacheKey ) {
29+ localStorage . setItem ( await generateCacheKey ( cacheKey ) , encode ( state ) )
3030}
3131
32- export function generateCacheKey ( cacheKey ) {
32+
33+ export async function generateCacheKey ( cacheKey ) {
3334 return [
3435 'column-toggler' ,
3536 cacheKey ,
36- Nova . $router . page . component ,
37+ ( await Nova . $router . decryptHistory ( ) ) . props ?. lens ,
3738 Nova . config ( 'column_toggler' ) . enable_sorting ,
3839 ] . join ( '/' )
3940}
4041
4142export function registerMixin ( component ) {
4243
4344 if ( component . computed . resourceRequestQueryString === undefined ) {
44- component = component . mixins . find ( ( { computed } ) => typeof computed . resourceRequestQueryString === 'function' )
45+ component = component . mixins . find ( ( { computed} ) => typeof computed . resourceRequestQueryString === 'function' )
4546 }
4647
4748 const originalResourceRequestQueryString = component . computed . resourceRequestQueryString
@@ -53,19 +54,22 @@ export function registerMixin(component) {
5354 unmounted ( ) {
5455 Nova . $off ( this . columnTogglerEventKey , this . columnTogglerOnStateChange )
5556 } ,
57+ async beforeMount ( ) {
58+ this . columnTogglerState = await getStateFromLocalStorage ( this . resourceName )
59+ } ,
5660 data ( ) {
5761 return {
58- columnTogglerState : getStateFromLocalStorage ( this . resourceName ) ,
62+ columnTogglerState : true ,
5963 }
6064 } ,
6165 methods : {
62- columnTogglerOnStateChange ( state ) {
66+ async columnTogglerOnStateChange ( state ) {
6367
6468 const currentState = this . columnTogglerState
6569
6670 if ( isEqual ( state , currentState ) === false ) {
6771
68- saveStateToLocalStorage ( state , this . resourceName )
72+ await saveStateToLocalStorage ( state , this . resourceName )
6973
7074 this . columnTogglerState = cloneDeep ( state )
7175
@@ -79,14 +83,13 @@ export function registerMixin(component) {
7983 } ,
8084 computed : {
8185 columnTogglerEventKey ( ) {
82- return `column-toggler:state-changed:${ [ this . resourceName , this . lens , this . actionQueryString ?. viaRelationship ] . filter ( Boolean ) . join ( '/' ) } `
86+ return `column-toggler:state-changed:${ [ this . resourceName , this . lens , this . actionQueryString ?. viaRelationship ] . filter ( Boolean ) . join ( '/' ) } `
8387 } ,
8488 columnTogglerEncodedColumns ( ) {
8589
8690 if ( typeof this . columnTogglerState === 'boolean' ) {
8791 return this . columnTogglerState
8892 }
89-
9093 const columns = toList ( this . columnTogglerState )
9194
9295 if ( columns . length === 0 ) {
0 commit comments