From b25bcae0b9e24641228b00cb5c5f8edd9912743e Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 28 Apr 2021 20:29:34 -0600 Subject: [PATCH] Review feedback. Mostly clean up --- .../public/actions/map_action_constants.ts | 1 - .../layers/new_vector_layer_wizard/config.tsx | 3 +- .../utils/indexing_service.ts | 49 +------------------ .../layers/new_vector_layer_wizard/wizard.tsx | 17 +++++-- .../plugins/maps/public/reducers/map/map.ts | 2 - .../plugins/maps/public/reducers/map/types.ts | 2 - 6 files changed, 16 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/maps/public/actions/map_action_constants.ts b/x-pack/plugins/maps/public/actions/map_action_constants.ts index 26a186f873613b..b9951af71154d2 100644 --- a/x-pack/plugins/maps/public/actions/map_action_constants.ts +++ b/x-pack/plugins/maps/public/actions/map_action_constants.ts @@ -44,4 +44,3 @@ export const SET_MAP_SETTINGS = 'SET_MAP_SETTINGS'; export const ROLLBACK_MAP_SETTINGS = 'ROLLBACK_MAP_SETTINGS'; export const TRACK_MAP_SETTINGS = 'TRACK_MAP_SETTINGS'; export const UPDATE_MAP_SETTING = 'UPDATE_MAP_SETTING'; -export const SET_VECTOR_LAYER_INDEX_NAME = 'SET_VECTOR_LAYER_INDEX_NAME'; diff --git a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/config.tsx b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/config.tsx index 5d6916c33ae560..531834e79e73d2 100644 --- a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/config.tsx +++ b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/config.tsx @@ -9,10 +9,11 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry'; import { NewVectorLayerEditor } from './index'; -import { ADD_VECTOR_DRAWING_LAYER } from './wizard'; import { DrawLayerIcon } from '../../layers/icons/draw_layer_icon'; import { getFileUpload } from '../../../kibana_services'; +const ADD_VECTOR_DRAWING_LAYER = 'ADD_VECTOR_DRAWING_LAYER'; + export const newVectorLayerWizardConfig: LayerWizard = { categories: [], description: i18n.translate('xpack.maps.newVectorLayerWizard.description', { diff --git a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/utils/indexing_service.ts b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/utils/indexing_service.ts index be5c0b57a509d0..95afb71ffbd547 100644 --- a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/utils/indexing_service.ts +++ b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/utils/indexing_service.ts @@ -5,16 +5,8 @@ * 2.0. */ -import { getSavedObjectsClient, getHttp } from '../../../../kibana_services'; -import { INDEX_FEATURE_PATH, INDEX_SOURCE_API_PATH } from '../../../../../common'; - -export const getExistingIndexNames = async () => { - const indexes = await getHttp().fetch({ - path: `/api/index_management/indices`, - method: 'GET', - }); - return indexes ? indexes.map(({ name }: { name: string }) => name) : []; -}; +import { getHttp } from '../../../../kibana_services'; +import { INDEX_SOURCE_API_PATH } from '../../../../../common'; export const createNewIndexAndPattern = async (indexName: string) => { return await getHttp().fetch({ @@ -34,43 +26,6 @@ export const createNewIndexAndPattern = async (indexName: string) => { }); }; -export const addFeatureToIndex = async (indexName: string, geometry: unknown) => { - return await getHttp().fetch({ - path: `/${INDEX_FEATURE_PATH}`, - method: 'POST', - body: convertObjectToBlob({ - index: indexName, - data: { - coordinates: geometry, - }, - }), - }); -}; - const convertObjectToBlob = (obj: unknown) => { return new Blob([JSON.stringify(obj)], { type: 'application/json' }); }; - -export const getExistingIndexPatternNames = async () => { - const indexPatterns = await getSavedObjectsClient() - .find({ - type: 'index-pattern', - fields: ['id', 'title', 'type', 'fields'], - perPage: 10000, - }) - .then(({ savedObjects }) => savedObjects.map((savedObject) => savedObject.get('title'))); - return indexPatterns ? indexPatterns.map(({ name }) => name) : []; -}; - -export function checkIndexPatternValid(name: string) { - const byteLength = encodeURI(name).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1; - const reg = new RegExp('[\\\\/*?"<>|\\s,#]+'); - const indexPatternInvalid = - byteLength > 255 || // name can't be greater than 255 bytes - name !== name.toLowerCase() || // name should be lowercase - name === '.' || - name === '..' || // name can't be . or .. - name.match(/^[-_+]/) !== null || // name can't start with these chars - name.match(reg) !== null; // name can't contain these chars - return !indexPatternInvalid; -} diff --git a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/wizard.tsx b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/wizard.tsx index f71e41a699422f..9b734638bfa1c1 100644 --- a/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/wizard.tsx +++ b/x-pack/plugins/maps/public/classes/layers/new_vector_layer_wizard/wizard.tsx @@ -16,8 +16,6 @@ import { ESSearchSource } from '../../sources/es_search_source'; import { ADD_LAYER_STEP_ID } from '../../../connected_components/add_layer_panel/view'; import { IndexNameFormProps } from '../../../../../file_upload/public'; -export const ADD_VECTOR_DRAWING_LAYER = 'ADD_VECTOR_DRAWING_LAYER'; - interface State { indexName: string; indexError: string; @@ -27,6 +25,8 @@ interface State { } export class NewVectorLayerEditor extends Component { + private _isMounted: boolean = false; + state: State = { indexName: '', indexError: '', @@ -36,13 +36,20 @@ export class NewVectorLayerEditor extends Component