@@ -42,7 +42,6 @@ import { getEditBreadcrumbs } from '../breadcrumbs';
4242import {
4343 createStore ,
4444 syncState ,
45- InitialTruthSource , SyncStrategy ,
4645} from '../../../../../../../../plugins/kibana_utils/public' ;
4746
4847const REACT_SOURCE_FILTERS_DOM_ELEMENT_ID = 'reactSourceFiltersTable' ;
@@ -213,34 +212,76 @@ uiModules.get('apps/management')
213212 } ) ;
214213 handleTabChange ( $scope , store . get ( ) . tab ) ;
215214
215+ $scope . crazyBatchUpdate = ( ) => {
216+ store . set ( { ...store . get ( ) , tab : 'indexedFiles' } ) ;
217+ store . set ( { ...store . get ( ) } ) ;
218+ store . set ( { ...store . get ( ) , fieldFilter : 'BATCH!' } ) ;
219+ } ;
220+
216221 $scope . $$postDigest ( ( ) => {
217- // just an artificial example of advanced syncState util setup
218- // 1. different strategies are used for different slices
219- // 2. to/from storage mappers are used to shorten state keys
220- $scope . destroyStateSync = syncState ( [
221- {
222- syncKey : '_a' ,
223- store,
224- initialTruthSource : InitialTruthSource . Storage ,
225- syncStrategy : SyncStrategy . Url ,
226- toStorageMapper : state => ( { t : state . tab } ) ,
227- fromStorageMapper : storageState => ( { tab : storageState . t || 'indexedFields' } ) ,
228- } ,
229- {
230- syncKey : '_b' ,
231- store,
232- initialTruthSource : InitialTruthSource . Storage ,
233- syncStrategy : config . get ( 'state:storeInSessionStorage' ) ? SyncStrategy . HashedUrl : SyncStrategy . Url ,
234- toStorageMapper : state => ( { f : state . fieldFilter , i : state . indexedFieldTypeFilter , l : state . scriptedFieldLanguageFilter } ) ,
235- fromStorageMapper : storageState => (
236- {
237- fieldFilter : storageState . f || '' ,
238- indexedFieldTypeFilter : storageState . i || '' ,
239- scriptedFieldLanguageFilter : storageState . l || ''
240- }
241- ) ,
242- } ,
243- ] ) ;
222+ // 1. the simplest use case
223+ $scope . destroyStateSync = syncState ( {
224+ syncKey : '_s' ,
225+ store,
226+ } ) ;
227+
228+ // 2. conditionally picking sync strategy
229+ // $scope.destroyStateSync = syncState({
230+ // syncKey: '_s',
231+ // store,
232+ // syncStrategy: config.get('state:storeInSessionStorage') ? SyncStrategy.HashedUrl : SyncStrategy.Url
233+ // });
234+
235+ // 3. implementing custom sync strategy
236+ // const localStorageSyncStrategy = {
237+ // toStorage: (syncKey, state) => localStorage.setItem(syncKey, JSON.stringify(state)),
238+ // fromStorage: (syncKey) => localStorage.getItem(syncKey) ? JSON.parse(localStorage.getItem(syncKey)) : null
239+ // };
240+ // $scope.destroyStateSync = syncState({
241+ // syncKey: '_s',
242+ // store,
243+ // syncStrategy: localStorageSyncStrategy
244+ // });
245+
246+ // 4. syncing only part of state
247+ // $scope.destroyStateSync = syncState({
248+ // syncKey: '_s',
249+ // store,
250+ // toStorageMapper: s => ({ tab: s.tab })
251+ // });
252+
253+ // 5. transform state before serialising
254+ // this could be super useful for backward compatibility
255+ // $scope.destroyStateSync = syncState({
256+ // syncKey: '_s',
257+ // store,
258+ // toStorageMapper: s => ({ t: s.tab }),
259+ // fromStorageMapper: s => ({ tab: s.t })
260+ // });
261+
262+ // 6. multiple different sync configs
263+ // $scope.destroyStateSync = syncState([
264+ // {
265+ // syncKey: '_a',
266+ // store,
267+ // syncStrategy: SyncStrategy.Url,
268+ // toStorageMapper: s => ({ t: s.tab }),
269+ // fromStorageMapper: s => ({ tab: s.t })
270+ // },
271+ // {
272+ // syncKey: '_b',
273+ // store,
274+ // syncStrategy: SyncStrategy.HashedUrl,
275+ // toStorageMapper: state => ({ f: state.fieldFilter, i: state.indexedFieldTypeFilter, l: state.scriptedFieldLanguageFilter }),
276+ // fromStorageMapper: storageState => (
277+ // {
278+ // fieldFilter: storageState.f || '',
279+ // indexedFieldTypeFilter: storageState.i || '',
280+ // scriptedFieldLanguageFilter: storageState.l || ''
281+ // }
282+ // ),
283+ // },
284+ // ]);
244285 } ) ;
245286
246287 const indexPatternListProvider = Private ( IndexPatternListFactory ) ( ) ;
0 commit comments