Skip to content

Commit

Permalink
Review feedback. Mostly clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Apr 29, 2021
1 parent 4162876 commit b25bcae
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 58 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/maps/public/actions/map_action_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +25,8 @@ interface State {
}

export class NewVectorLayerEditor extends Component<RenderWizardArguments, State> {
private _isMounted: boolean = false;

state: State = {
indexName: '',
indexError: '',
Expand All @@ -36,13 +36,20 @@ export class NewVectorLayerEditor extends Component<RenderWizardArguments, State
};

componentDidMount() {
this._isMounted = true;
this._loadIndexNameFormComponent();
}

componentWillUnmount() {
this._isMounted = false;
}

async _loadIndexNameFormComponent() {
this.setState({
indexNameFormComponent: await getFileUpload().getIndexNameFormComponent(),
});
if (this._isMounted) {
this.setState({
indexNameFormComponent: await getFileUpload().getIndexNameFormComponent(),
});
}
}

async componentDidUpdate() {
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/maps/public/reducers/map/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export const DEFAULT_MAP_STATE: MapState = {
filters: [],
refreshConfig: undefined,
refreshTimerLastTriggeredAt: undefined,
vectorLayerIndexName: '',
drawState: undefined,
editModeActive: false,
},
selectedLayerId: null,
layerList: [],
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/maps/public/reducers/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export type MapContext = {
filters: Filter[];
refreshConfig?: MapRefreshConfig;
refreshTimerLastTriggeredAt?: string;
vectorLayerIndexName: string;
drawState?: DrawState;
editModeActive: boolean;
searchSessionId?: string;
searchSessionMapBuffer?: MapExtent;
};
Expand Down

0 comments on commit b25bcae

Please sign in to comment.