Skip to content

Commit

Permalink
Clear out old drawing data on cancel. Update action names
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Apr 8, 2021
1 parent ceae6d2 commit bee0fd5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/maps/public/actions/layer_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
UPDATE_LAYER_PROP,
UPDATE_LAYER_STYLE,
UPDATE_SOURCE_PROP,
INDEX_DRAWN_LAYERS,
CLEAR_DRAWING_DATA,
} from './map_action_constants';
import { clearDataRequests, syncDataForLayerId, updateStyleMeta } from './data_request_actions';
import { cleanTooltipStateForLayer } from './tooltip_actions';
Expand Down Expand Up @@ -555,8 +555,8 @@ export function setAreTilesLoaded(layerId: string, areTilesLoaded: boolean) {
};
}

export function indexDrawnLayers() {
export function clearDrawingData() {
return {
type: INDEX_DRAWN_LAYERS,
type: CLEAR_DRAWING_DATA,
};
}
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/map_action_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export const UPDATE_MAP_SETTING = 'UPDATE_MAP_SETTING';
export const ADD_FEATURES_TO_INDEX_QUEUE = 'ADD_FEATURES_TO_INDEX_QUEUE';
export const REMOVE_FEATURES_FROM_INDEX_QUEUE = 'REMOVE_FEATURES_FROM_INDEX_QUEUE';
export const SET_VECTOR_LAYER_INDEX_NAME = 'SET_VECTOR_LAYER_INDEX_NAME';
export const INDEX_DRAWN_LAYERS = 'INDEX_DRAWN_LAYERS';
export const CLEAR_DRAWING_DATA = 'CLEAR_DRAWING_DATA';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MapStoreState } from '../../../reducers/store';
import { NewVectorLayerEditor } from './wizard';
import {
addLayer,
indexDrawnLayers,
clearDrawingData,
setSelectedLayer,
setVectorLayerIndexName,
updateEditMode,
Expand All @@ -31,10 +31,13 @@ function mapStateToProps(state: MapStoreState) {
function mapDispatchToProps(dispatch: ThunkDispatch<MapStoreState, void, AnyAction>) {
return {
setEditModeActive: () => dispatch(updateEditMode(true)),
setEditModeInActive: () => dispatch(updateEditMode(false)),
setEditModeInActive: () => {
dispatch(updateEditMode(false))
dispatch(clearDrawingData());
},
setIndexName: (indexName: string) => dispatch(setVectorLayerIndexName(indexName)),
indexDrawnLayers: () => {
dispatch(indexDrawnLayers());
clearDrawingData: () => {
dispatch(clearDrawingData());
},
addNewLayer: async (layerDescriptor: LayerDescriptor) => {
await dispatch(addLayer(layerDescriptor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface NewVectorLayerProps extends RenderWizardArguments {
setEditModeActive: () => void;
setEditModeInActive: () => void;
setIndexName: (indexName: string) => void;
indexDrawnLayers: () => void;
clearDrawingData: () => void;
addNewLayer: (layerDescriptor: LayerDescriptor) => void;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export class NewVectorLayerEditor extends Component<NewVectorLayerProps, State>
}
if (!this.state.indexingTriggered && currentStepId === ADD_DRAWN_FEATURES_TO_INDEX_STEP_ID) {
await this._addFeaturesToNewIndex();
this.props.indexDrawnLayers();
this.props.clearDrawingData();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class DrawFeatureControl extends Component<Props, {}> {
this.props.addFeaturesToIndexQueue(e.features);
} catch (error) {
getToasts().addWarning(
i18n.translate('xpack.maps.drawFeatureControl.unableToCreatFilter', {
i18n.translate('xpack.maps.drawFeatureControl.unableToCreateFeature', {
defaultMessage: `Unable to create feature, error: '{errorMsg}'.`,
values: {
errorMsg: error.message,
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/maps/public/reducers/map/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
UPDATE_EDIT_MODE,
ADD_FEATURES_TO_INDEX_QUEUE,
SET_VECTOR_LAYER_INDEX_NAME,
INDEX_DRAWN_LAYERS,
CLEAR_DRAWING_DATA,
REMOVE_FEATURES_FROM_INDEX_QUEUE,
} from '../../actions';

Expand Down Expand Up @@ -84,7 +84,7 @@ export const DEFAULT_MAP_STATE: MapState = {
vectorLayerIndexName: '',
drawState: undefined,
drawFeatureState: undefined,
editModeActive: undefined,
editModeActive: false,
featuresToIndexQueue: [],
},
selectedLayerId: null,
Expand Down Expand Up @@ -145,11 +145,14 @@ export function map(state: MapState = DEFAULT_MAP_STATE, action: any) {
vectorLayerIndexName: action.indexName,
},
};
case INDEX_DRAWN_LAYERS:
case CLEAR_DRAWING_DATA:
return {
...state,
mapState: {
...state.mapState,
drawState: undefined,
drawFeatureState: undefined,
editModeActive: false,
featuresToIndexQueue: [],
},
};
Expand Down

0 comments on commit bee0fd5

Please sign in to comment.