Skip to content

Commit

Permalink
[Maps] avoid using MAP_SAVED_OBJECT_TYPE constant when defining URL p…
Browse files Browse the repository at this point in the history
…aths (#69723)

* [Maps] avoid using MAP_SAVED_OBJECT_TYPE constant when defining URL paths

* rename methods

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
nreese and elasticmachine authored Jun 26, 2020
1 parent 0465e86 commit be3886b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
11 changes: 7 additions & 4 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ export const MAP_SAVED_OBJECT_TYPE = 'map';
export const APP_ID = 'maps';
export const APP_ICON = 'gisApp';

export const MAP_APP_PATH = `app/${APP_ID}`;
export const MAPS_APP_PATH = `app/${APP_ID}`;
export const MAP_PATH = 'map';
export const GIS_API_PATH = `api/${APP_ID}`;
export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`;
export const FONTS_API_PATH = `${GIS_API_PATH}/fonts`;

export const MAP_BASE_URL = `/${MAP_APP_PATH}/${MAP_SAVED_OBJECT_TYPE}`;

export function createMapPath(id: string) {
const MAP_BASE_URL = `/${MAPS_APP_PATH}/${MAP_PATH}`;
export function getNewMapPath() {
return MAP_BASE_URL;
}
export function getExistingMapPath(id: string) {
return `${MAP_BASE_URL}/${id}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IContainer,
} from '../../../../../src/plugins/embeddable/public';
import '../index.scss';
import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants';
import { getExistingMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants';
import { LayerDescriptor } from '../../common/descriptor_types';
import { MapEmbeddableInput } from './types';
import { lazyLoadMapModules } from '../lazy_load_bundle';
Expand Down Expand Up @@ -113,7 +113,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
{
layerList,
title: savedMap.title,
editUrl: getHttp().basePath.prepend(createMapPath(savedObjectId)),
editUrl: getHttp().basePath.prepend(getExistingMapPath(savedObjectId)),
indexPatterns,
editable: await this.isEditable(),
settings,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/maps_vis_type_alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { i18n } from '@kbn/i18n';
import { APP_ID, APP_ICON, MAP_SAVED_OBJECT_TYPE } from '../common/constants';
import { APP_ID, APP_ICON, MAP_PATH } from '../common/constants';
import { getShowMapVisualizationTypes, getVisualizations } from './kibana_services';

export function getMapsVisTypeAlias() {
Expand All @@ -28,7 +28,7 @@ The Maps app offers more functionality and is easier to use.`,

return {
aliasApp: APP_ID,
aliasPath: `/${MAP_SAVED_OBJECT_TYPE}`,
aliasPath: `/${MAP_PATH}`,
name: APP_ID,
title: i18n.translate('xpack.maps.visTypeAlias.title', {
defaultMessage: 'Maps',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../../../selectors/ui_selectors';
import { copyPersistentState } from '../../../reducers/util';
import { extractReferences, injectReferences } from '../../../../common/migrations/references';
import { MAP_BASE_URL, MAP_SAVED_OBJECT_TYPE } from '../../../../common/constants';
import { getExistingMapPath, MAP_SAVED_OBJECT_TYPE } from '../../../../common/constants';
import { getStore } from '../../store_operations';

export function createSavedGisMapClass(services) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function createSavedGisMapClass(services) {
}

getFullPath() {
return `${MAP_BASE_URL}/${this.id}`;
return getExistingMapPath(this.id);
}

getLayerList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { getCoreChrome } from '../../kibana_services';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
import { MAP_PATH } from '../../../common/constants';
import _ from 'lodash';
import { getLayerListRaw } from '../../selectors/map_selectors';
import { copyPersistentState } from '../../reducers/util';
Expand All @@ -31,7 +31,7 @@ function hasUnsavedChanges(savedMap, initialLayerListConfig) {
}

export const updateBreadcrumbs = (savedMap, initialLayerListConfig, currentPath = '') => {
const isOnMapNow = currentPath.startsWith(`/${MAP_SAVED_OBJECT_TYPE}`);
const isOnMapNow = currentPath.startsWith(`/${MAP_PATH}`);
const breadCrumbs = isOnMapNow
? [
{
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getFlightsSavedObjects } from './sample_data/flights_saved_objects.js';
// @ts-ignore
import { getWebLogsSavedObjects } from './sample_data/web_logs_saved_objects.js';
import { registerMapsUsageCollector } from './maps_telemetry/collectors/register';
import { APP_ID, APP_ICON, MAP_SAVED_OBJECT_TYPE, createMapPath } from '../common/constants';
import { APP_ID, APP_ICON, MAP_SAVED_OBJECT_TYPE, getExistingMapPath } from '../common/constants';
import { mapSavedObjects } from './saved_objects';
import { MapsXPackConfig } from '../config';
// @ts-ignore
Expand Down Expand Up @@ -58,7 +58,7 @@ export class MapsPlugin implements Plugin {

home.sampleData.addAppLinksToSampleDataset('ecommerce', [
{
path: createMapPath('2c9c1f60-1909-11e9-919b-ffe5949a18d2'),
path: getExistingMapPath('2c9c1f60-1909-11e9-919b-ffe5949a18d2'),
label: sampleDataLinkLabel,
icon: APP_ICON,
},
Expand All @@ -80,7 +80,7 @@ export class MapsPlugin implements Plugin {

home.sampleData.addAppLinksToSampleDataset('flights', [
{
path: createMapPath('5dd88580-1906-11e9-919b-ffe5949a18d2'),
path: getExistingMapPath('5dd88580-1906-11e9-919b-ffe5949a18d2'),
label: sampleDataLinkLabel,
icon: APP_ICON,
},
Expand All @@ -101,7 +101,7 @@ export class MapsPlugin implements Plugin {
home.sampleData.addSavedObjectsToSampleDataset('logs', getWebLogsSavedObjects());
home.sampleData.addAppLinksToSampleDataset('logs', [
{
path: createMapPath('de71f4f0-1902-11e9-919b-ffe5949a18d2'),
path: getExistingMapPath('de71f4f0-1902-11e9-919b-ffe5949a18d2'),
label: sampleDataLinkLabel,
icon: APP_ICON,
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/server/saved_objects/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { SavedObjectsType } from 'src/core/server';
import { APP_ICON, createMapPath } from '../../common/constants';
import { APP_ICON, getExistingMapPath } from '../../common/constants';
// @ts-ignore
import { migrations } from './migrations';

Expand All @@ -31,7 +31,7 @@ export const mapSavedObjects: SavedObjectsType = {
},
getInAppUrl(obj) {
return {
path: createMapPath(obj.id),
path: getExistingMapPath(obj.id),
uiCapabilitiesPath: 'maps.show',
};
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/server/tutorials/ems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { TutorialsCategory } from '../../../../../../src/plugins/home/server';
import { MAP_BASE_URL } from '../../../common/constants';
import { getNewMapPath } from '../../../common/constants';

export function emsBoundariesSpecProvider({
emsLandingPageUrl,
Expand Down Expand Up @@ -64,7 +64,7 @@ Indexing EMS administrative boundaries in Elasticsearch allows for search on bou
2. Click `Add layer`, then select `Upload GeoJSON`.\n\
3. Upload the GeoJSON file and click `Import file`.',
values: {
newMapUrl: prependBasePath(MAP_BASE_URL),
newMapUrl: prependBasePath(getNewMapPath()),
},
}),
},
Expand Down

0 comments on commit be3886b

Please sign in to comment.