Skip to content

Commit

Permalink
rename SerializedMapState to ParsedMapStateJSON and SerializedUiState…
Browse files Browse the repository at this point in the history
… to ParsedUiStateJSON (elastic#182185)

Part of elastic#174960

elastic#178158 creates a new type
`MapSerializeState`. This new type name is very confusing with existing
`SerializedMapState` type name. This PR renames `SerializedMapState` to
`ParsedMapStateJSON` to avoid this confusion. Breaking this change out
of elastic#174960 to make things
clearer and avoid confusion during reviewing
elastic#174960
  • Loading branch information
nreese authored Apr 30, 2024
1 parent a0e269c commit daf81a6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
24 changes: 12 additions & 12 deletions x-pack/plugins/maps/public/routes/map_page/map_app/map_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {
unsavedChangesWarning,
} from '../saved_map';
import { waitUntilTimeLayersLoad$ } from './wait_until_time_layers_load';
import { RefreshConfig as MapRefreshConfig, SerializedMapState } from '../saved_map';
import { RefreshConfig as MapRefreshConfig, ParsedMapStateJSON } from '../saved_map';

export interface Props {
savedMap: SavedMap;
Expand Down Expand Up @@ -310,24 +310,24 @@ export class MapApp extends React.Component<Props, State> {
this._updateGlobalState(updatedGlobalState);
};

_getInitialTime(serializedMapState?: SerializedMapState) {
_getInitialTime(mapState?: ParsedMapStateJSON) {
if (this._initialTimeFromUrl) {
return this._initialTimeFromUrl;
}

return !this.props.savedMap.hasSaveAndReturnConfig() && serializedMapState?.timeFilters
? serializedMapState.timeFilters
return !this.props.savedMap.hasSaveAndReturnConfig() && mapState?.timeFilters
? mapState.timeFilters
: getTimeFilter().getTime();
}

_initMapAndLayerSettings(serializedMapState?: SerializedMapState) {
_initMapAndLayerSettings(mapState?: ParsedMapStateJSON) {
const globalState = this._getGlobalState();

const savedObjectFilters = serializedMapState?.filters ? serializedMapState.filters : [];
const savedObjectFilters = mapState?.filters ? mapState.filters : [];
const appFilters = this._appStateManager.getFilters() || [];

const query = getInitialQuery({
serializedMapState,
mapState,
appState: this._appStateManager.getAppState(),
});
if (query) {
Expand All @@ -337,12 +337,12 @@ export class MapApp extends React.Component<Props, State> {
this._onQueryChange({
filters: [..._.get(globalState, 'filters', []), ...appFilters, ...savedObjectFilters],
query,
time: this._getInitialTime(serializedMapState),
time: this._getInitialTime(mapState),
});

this._onRefreshConfigChange(
getInitialRefreshConfig({
serializedMapState,
mapState,
globalState,
})
);
Expand Down Expand Up @@ -453,16 +453,16 @@ export class MapApp extends React.Component<Props, State> {
);
}

let serializedMapState: SerializedMapState | undefined;
let mapState: ParsedMapStateJSON | undefined;
try {
const attributes = this.props.savedMap.getAttributes();
if (attributes.mapStateJSON) {
serializedMapState = JSON.parse(attributes.mapStateJSON);
mapState = JSON.parse(attributes.mapStateJSON);
}
} catch (e) {
// ignore malformed mapStateJSON, not a critical error for viewing map - map will just use defaults
}
this._initMapAndLayerSettings(serializedMapState);
this._initMapAndLayerSettings(mapState);

this.setState({ initialized: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

import { getData } from '../../../kibana_services';
import { MapsAppState } from '../url_state';
import { SerializedMapState } from './types';
import { ParsedMapStateJSON } from './types';

export function getInitialQuery({
serializedMapState,
mapState,
appState = {},
}: {
serializedMapState?: SerializedMapState;
mapState?: ParsedMapStateJSON;
appState: MapsAppState;
}) {
if (appState.query) {
return appState.query;
}

if (serializedMapState?.query) {
return serializedMapState.query;
if (mapState?.query) {
return mapState.query;
}

return getData().query.queryString.getDefaultQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
import { getUiSettings } from '../../../kibana_services';
import { SerializedMapState } from './types';
import { ParsedMapStateJSON } from './types';

export function getInitialRefreshConfig({
serializedMapState,
mapState,
globalState = {},
}: {
serializedMapState?: SerializedMapState;
mapState?: ParsedMapStateJSON;
globalState: GlobalQueryStateFromUrl;
}) {
const uiSettings = getUiSettings();

if (serializedMapState?.refreshConfig) {
return serializedMapState.refreshConfig;
if (mapState?.refreshConfig) {
return mapState.refreshConfig;
}

const defaultRefreshConfig = uiSettings.get(UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

export type { RefreshConfig, SerializedMapState, SerializedUiState } from './types';
export type { RefreshConfig, ParsedMapStateJSON, ParsedUiStateJSON } from './types';
export { SavedMap } from './saved_map';
export { getInitialLayersFromUrlParam } from './get_initial_layers_from_url_param';
export { getInitialQuery } from './get_initial_query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { getBreadcrumbs } from './get_breadcrumbs';
import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui';
import { createBasemapLayerDescriptor } from '../../../classes/layers/create_basemap_layer_descriptor';
import { whenLicenseInitialized } from '../../../licensed_features';
import { SerializedMapState, SerializedUiState } from './types';
import { ParsedMapStateJSON, ParsedUiStateJSON } from './types';
import { setAutoOpenLayerWizardId } from '../../../actions/ui_actions';
import { LayerStatsCollector, MapSettingsCollector } from '../../../../common/telemetry';
import { getIndexPatternsFromIds } from '../../../index_pattern_util';
Expand Down Expand Up @@ -150,7 +150,7 @@ export class SavedMap {

if (this._attributes?.mapStateJSON) {
try {
const mapState = JSON.parse(this._attributes.mapStateJSON) as SerializedMapState;
const mapState = JSON.parse(this._attributes.mapStateJSON) as ParsedMapStateJSON;
if (mapState.adHocDataViews && mapState.adHocDataViews.length > 0) {
const dataViewService = getIndexPatternService();
const promises = mapState.adHocDataViews.map((spec) => {
Expand All @@ -167,7 +167,7 @@ export class SavedMap {
this._store.dispatch(setMapSettingsFromEncodedState(this._mapEmbeddableInput.mapSettings));
} else if (this._attributes?.mapStateJSON) {
try {
const mapState = JSON.parse(this._attributes.mapStateJSON) as SerializedMapState;
const mapState = JSON.parse(this._attributes.mapStateJSON) as ParsedMapStateJSON;
if (mapState.settings) {
this._store.dispatch(setMapSettingsFromEncodedState(mapState.settings));
}
Expand All @@ -181,7 +181,7 @@ export class SavedMap {
isLayerTOCOpen = this._mapEmbeddableInput.isLayerTOCOpen;
} else if (this._attributes?.uiStateJSON) {
try {
const uiState = JSON.parse(this._attributes.uiStateJSON) as SerializedUiState;
const uiState = JSON.parse(this._attributes.uiStateJSON) as ParsedUiStateJSON;
if ('isLayerTOCOpen' in uiState) {
isLayerTOCOpen = uiState.isLayerTOCOpen;
}
Expand All @@ -196,7 +196,7 @@ export class SavedMap {
openTOCDetails = this._mapEmbeddableInput.openTOCDetails;
} else if (this._attributes?.uiStateJSON) {
try {
const uiState = JSON.parse(this._attributes.uiStateJSON) as SerializedUiState;
const uiState = JSON.parse(this._attributes.uiStateJSON) as ParsedUiStateJSON;
if ('openTOCDetails' in uiState) {
openTOCDetails = uiState.openTOCDetails;
}
Expand All @@ -216,7 +216,7 @@ export class SavedMap {
);
} else if (this._attributes?.mapStateJSON) {
try {
const mapState = JSON.parse(this._attributes.mapStateJSON) as SerializedMapState;
const mapState = JSON.parse(this._attributes.mapStateJSON) as ParsedMapStateJSON;
this._store.dispatch(
setGotoWithCenter({
lat: mapState.center.lat,
Expand Down Expand Up @@ -418,7 +418,7 @@ export class SavedMap {
}

try {
const mapState = JSON.parse(this._attributes.mapStateJSON) as SerializedMapState;
const mapState = JSON.parse(this._attributes.mapStateJSON) as ParsedMapStateJSON;
if (mapState?.settings.autoFitToDataBounds !== undefined) {
return mapState.settings.autoFitToDataBounds;
}
Expand Down Expand Up @@ -580,12 +580,12 @@ export class SavedMap {
return { ...icon, svg: Buffer.from(icon.svg).toString('base64') };
}),
},
} as SerializedMapState);
} as ParsedMapStateJSON);

this._attributes!.uiStateJSON = JSON.stringify({
isLayerTOCOpen: getIsLayerTOCOpen(state),
openTOCDetails: getOpenTOCDetails(state),
} as SerializedUiState);
} as ParsedUiStateJSON);
}

private async _getAdHocDataViews() {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/routes/map_page/saved_map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface RefreshConfig {
}

// parsed contents of mapStateJSON
export interface SerializedMapState {
export interface ParsedMapStateJSON {
adHocDataViews?: DataViewSpec[];
zoom: number;
center: MapCenter;
Expand All @@ -28,7 +28,7 @@ export interface SerializedMapState {
}

// parsed contents of uiStateJSON
export interface SerializedUiState {
export interface ParsedUiStateJSON {
isLayerTOCOpen: boolean;
openTOCDetails: string[];
}

0 comments on commit daf81a6

Please sign in to comment.