55 */
66
77import _ from 'lodash' ;
8- import { createSavedObjectClass } from '../../../../../../../src/plugins/saved_objects/public' ;
8+ import { SavedObjectReference } from 'kibana/public' ;
9+ import { i18n } from '@kbn/i18n' ;
10+ import {
11+ createSavedObjectClass ,
12+ SavedObject ,
13+ SavedObjectKibanaServices ,
14+ } from '../../../../../../../src/plugins/saved_objects/public' ;
915import {
1016 getTimeFilters ,
1117 getMapZoom ,
@@ -18,73 +24,82 @@ import {
1824} from '../../../selectors/map_selectors' ;
1925import { getIsLayerTOCOpen , getOpenTOCDetails } from '../../../selectors/ui_selectors' ;
2026import { copyPersistentState } from '../../../reducers/util' ;
27+ // @ts -expect-error
2128import { extractReferences , injectReferences } from '../../../../common/migrations/references' ;
2229import { getExistingMapPath , MAP_SAVED_OBJECT_TYPE } from '../../../../common/constants' ;
30+ // @ts -expect-error
2331import { getStore } from '../../store_operations' ;
32+ import { MapStoreState } from '../../../reducers/store' ;
33+ import { LayerDescriptor } from '../../../../common/descriptor_types' ;
34+
35+ export interface ISavedGisMap extends SavedObject {
36+ layerListJSON ?: string ;
37+ mapStateJSON ?: string ;
38+ uiStateJSON ?: string ;
39+ getLayerList ( ) : LayerDescriptor [ ] ;
40+ syncWithStore ( ) : void ;
41+ }
2442
25- export function createSavedGisMapClass ( services ) {
43+ export function createSavedGisMapClass ( services : SavedObjectKibanaServices ) {
2644 const SavedObjectClass = createSavedObjectClass ( services ) ;
2745
28- class SavedGisMap extends SavedObjectClass {
29- static type = MAP_SAVED_OBJECT_TYPE ;
46+ class SavedGisMap extends SavedObjectClass implements ISavedGisMap {
47+ public static type = MAP_SAVED_OBJECT_TYPE ;
3048
3149 // Mappings are used to place object properties into saved object _source
32- static mapping = {
50+ public static mapping = {
3351 title : 'text' ,
3452 description : 'text' ,
3553 mapStateJSON : 'text' ,
3654 layerListJSON : 'text' ,
3755 uiStateJSON : 'text' ,
3856 } ;
39- static fieldOrder = [ 'title' , 'description' ] ;
40- static searchSource = false ;
57+ public static fieldOrder = [ 'title' , 'description' ] ;
58+ public static searchSource = false ;
4159
42- constructor ( id ) {
60+ public showInRecentlyAccessed = true ;
61+ public layerListJSON ?: string ;
62+ public mapStateJSON ?: string ;
63+ public uiStateJSON ?: string ;
64+
65+ constructor ( id : string ) {
4366 super ( {
4467 type : SavedGisMap . type ,
4568 mapping : SavedGisMap . mapping ,
4669 searchSource : SavedGisMap . searchSource ,
4770 extractReferences,
48- injectReferences : ( savedObject , references ) => {
71+ injectReferences : ( savedObject : ISavedGisMap , references : SavedObjectReference [ ] ) => {
4972 const { attributes } = injectReferences ( {
5073 attributes : { layerListJSON : savedObject . layerListJSON } ,
5174 references,
5275 } ) ;
5376
5477 savedObject . layerListJSON = attributes . layerListJSON ;
55-
56- const indexPatternIds = references
57- . filter ( ( reference ) => {
58- return reference . type === 'index-pattern' ;
59- } )
60- . map ( ( reference ) => {
61- return reference . id ;
62- } ) ;
63- savedObject . indexPatternIds = _ . uniq ( indexPatternIds ) ;
6478 } ,
6579
6680 // if this is null/undefined then the SavedObject will be assigned the defaults
67- id : id ,
81+ id,
6882
6983 // default values that will get assigned if the doc is new
7084 defaults : {
71- title : 'New Map' ,
85+ title : i18n . translate ( 'xpack.maps.newMapTitle' , {
86+ defaultMessage : 'New Map' ,
87+ } ) ,
7288 description : '' ,
7389 } ,
7490 } ) ;
75- this . showInRecentlyAccessed = true ;
76- }
7791
78- getFullPath ( ) {
79- return getExistingMapPath ( this . id ) ;
92+ this . getFullPath = ( ) => {
93+ return getExistingMapPath ( this . id ! ) ;
94+ } ;
8095 }
8196
8297 getLayerList ( ) {
8398 return this . layerListJSON ? JSON . parse ( this . layerListJSON ) : null ;
8499 }
85100
86101 syncWithStore ( ) {
87- const state = getStore ( ) . getState ( ) ;
102+ const state : MapStoreState = getStore ( ) . getState ( ) ;
88103 const layerList = getLayerListRaw ( state ) ;
89104 const layerListConfigOnly = copyPersistentState ( layerList ) ;
90105 this . layerListJSON = JSON . stringify ( layerListConfigOnly ) ;
0 commit comments