Skip to content

Commit

Permalink
update redux state and removed widget over lay hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Nov 20, 2019
1 parent 9442ece commit b4cb029
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
5 changes: 5 additions & 0 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const SET_SCROLL_ZOOM = 'SET_SCROLL_ZOOM';
export const SET_MAP_INIT_ERROR = 'SET_MAP_INIT_ERROR';
export const SET_INTERACTIVE = 'SET_INTERACTIVE';
export const DISABLE_TOOLTIP_CONTROL = 'DISABLE_TOOLTIP_CONTROL';
export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY';

function getLayerLoadingCallbacks(dispatch, layerId) {
return {
Expand Down Expand Up @@ -826,3 +827,7 @@ export function disableInteractive() {
export function disableTooltipControl() {
return { type: DISABLE_TOOLTIP_CONTROL, disableTooltipControl: true };
}

export function hideToolbarOverlay() {
return { type: HIDE_TOOLBAR_OVERLAY, hideToolbarOverlay: true };
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
areLayersLoaded,
getRefreshConfig,
getMapInitError,
getQueryableUniqueIndexPatternIds
getQueryableUniqueIndexPatternIds,
isToolbarOverlayHidden,
} from '../../selectors/map_selectors';

function mapStateToProps(state = {}) {
Expand All @@ -28,6 +29,7 @@ function mapStateToProps(state = {}) {
refreshConfig: getRefreshConfig(state),
mapInitError: getMapInitError(state),
indexPatternIds: getQueryableUniqueIndexPatternIds(state),
hideToolbarOverlay: isToolbarOverlayHidden(state),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class GisMap extends Component {
{!this.props.hideToolbarOverlay && (
<ToolbarOverlay addFilters={addFilters} geoFields={this.state.geoFields} />
)}
{!this.props.hideWidgetOverlay && <WidgetOverlay />}
<WidgetOverlay/>
</EuiFlexItem>

<EuiFlexItem className={`mapMapLayerPanel ${currentPanelClassName}`} grow={false}>
Expand Down
11 changes: 7 additions & 4 deletions x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
disableScrollZoom,
disableInteractive,
disableTooltipControl,
hideToolbarOverlay,
} from '../actions/map_actions';
import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors';
Expand Down Expand Up @@ -119,14 +120,18 @@ export class MapEmbeddable extends Embeddable {
this._store.dispatch(setOpenTOCDetails(this.input.openTOCDetails));
}

if (_.has(this.input, 'disableInteractive')) {
if (_.has(this.input, 'disableInteractive') && this.input.disableInteractive) {
this._store.dispatch(disableInteractive(this.input.disableInteractive));
}

if (_.has(this.input, 'disableTooltipControl')) {
if (_.has(this.input, 'disableTooltipControl') && this.input.disableTooltipControl) {
this._store.dispatch(disableTooltipControl(this.input.disableTooltipControl));
}

if (_.has(this.input, 'hideToolbarOverlay') && this.input.hideToolbarOverlay) {
this._store.dispatch(hideToolbarOverlay(this.input.hideToolbarOverlay));
}

if (this.input.mapCenter) {
this._store.dispatch(
setGotoWithCenter({
Expand All @@ -149,8 +154,6 @@ export class MapEmbeddable extends Embeddable {
<GisMap
addFilters={this.input.hideFilterActions ? null : this.addFilters}
renderTooltipContent={this._renderTooltipContent}
hideToolbarOverlay={this.input.hideToolbarOverlay}
hideWidgetOverlay={this.input.hideWidgetOverlay}
/>
</I18nContext>
</Provider>,
Expand Down
49 changes: 30 additions & 19 deletions x-pack/legacy/plugins/maps/public/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
SET_MAP_INIT_ERROR,
UPDATE_DRAW_STATE,
SET_INTERACTIVE,
DISABLE_TOOLTIP_CONTROL
DISABLE_TOOLTIP_CONTROL,
HIDE_TOOLBAR_OVERLAY,
} from '../actions/map_actions';

import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from './util';
Expand All @@ -60,12 +61,13 @@ const updateLayerInList = (state, layerId, attribute, newValue) => {
...layerList[layerIdx],
// Update layer w/ new value. If no value provided, toggle boolean value
// allow empty strings, 0-value
[attribute]: (newValue || newValue === '' || newValue === 0) ? newValue : !layerList[layerIdx][attribute]
[attribute]:
newValue || newValue === '' || newValue === 0 ? newValue : !layerList[layerIdx][attribute],
};
const updatedList = [
...layerList.slice(0, layerIdx),
updatedLayer,
...layerList.slice(layerIdx + 1)
...layerList.slice(layerIdx + 1),
];
return { ...state, layerList: updatedList };
};
Expand All @@ -78,12 +80,12 @@ const updateLayerSourceDescriptorProp = (state, layerId, propName, value) => {
sourceDescriptor: {
...layerList[layerIdx].sourceDescriptor,
[propName]: value,
}
},
};
const updatedList = [
...layerList.slice(0, layerIdx),
updatedLayer,
...layerList.slice(layerIdx + 1)
...layerList.slice(layerIdx + 1),
];
return { ...state, layerList: updatedList };
};
Expand All @@ -110,14 +112,14 @@ const INITIAL_STATE = {
drawState: null,
disableInteractive: false,
disableTooltipControl: false,
hideToolbarOverlay: false
},
selectedLayerId: null,
__transientLayerId: null,
layerList: [],
waitingForMapReadyLayerList: [],
};


export function map(state = INITIAL_STATE, action) {
switch (action.type) {
case UPDATE_DRAW_STATE:
Expand Down Expand Up @@ -346,13 +348,20 @@ export function map(state = INITIAL_STATE, action) {
disableTooltipControl: action.disableTooltipControl,
},
};
case HIDE_TOOLBAR_OVERLAY:
return {
...state,
mapState: {
...state.mapState,
hideToolbarOverlay: action.hideToolbarOverlay,
},
};
default:
return state;
}
}

function findDataRequest(layerDescriptor, dataRequestAction) {

if (!layerDescriptor.__dataRequests) {
return;
}
Expand All @@ -362,32 +371,31 @@ function findDataRequest(layerDescriptor, dataRequestAction) {
});
}


function updateWithDataRequest(state, action) {
let dataRequest = getValidDataRequest(state, action, false);
const layerRequestingData = findLayerById(state, action.layerId);

if (!dataRequest) {
dataRequest = {
dataId: action.dataId
dataId: action.dataId,
};
layerRequestingData.__dataRequests = [
...(layerRequestingData.__dataRequests
? layerRequestingData.__dataRequests : []), dataRequest ];
...(layerRequestingData.__dataRequests ? layerRequestingData.__dataRequests : []),
dataRequest,
];
}
dataRequest.dataMetaAtStart = action.meta;
dataRequest.dataRequestToken = action.requestToken;
const layerList = [...state.layerList];
return { ...state, layerList };
}


function updateSourceDataRequest(state, action) {
const layerDescriptor = findLayerById(state, action.layerId);
if (!layerDescriptor) {
return state;
}
const dataRequest = layerDescriptor.__dataRequests.find(dataRequest => {
const dataRequest = layerDescriptor.__dataRequests.find(dataRequest => {
return dataRequest.dataId === SOURCE_DATA_ID_ORIGIN;
});
if (!dataRequest) {
Expand All @@ -398,10 +406,11 @@ function updateSourceDataRequest(state, action) {
return resetDataRequest(state, action, dataRequest);
}


function updateWithDataResponse(state, action) {
const dataRequest = getValidDataRequest(state, action);
if (!dataRequest) { return state; }
if (!dataRequest) {
return state;
}

dataRequest.data = action.data;
dataRequest.dataMeta = { ...dataRequest.dataMetaAtStart, ...action.meta };
Expand All @@ -411,7 +420,9 @@ function updateWithDataResponse(state, action) {

function resetDataRequest(state, action, request) {
const dataRequest = request || getValidDataRequest(state, action);
if (!dataRequest) { return state; }
if (!dataRequest) {
return state;
}

dataRequest.dataRequestToken = null;
dataRequest.dataId = action.dataId;
Expand Down Expand Up @@ -452,7 +463,7 @@ function trackCurrentLayerState(state, layerId) {
}

function removeTrackedLayerState(state, layerId) {
const layer = findLayerById(state, layerId);
const layer = findLayerById(state, layerId);
if (!layer) {
return state;
}
Expand All @@ -462,7 +473,7 @@ function removeTrackedLayerState(state, layerId) {

return {
...state,
layerList: replaceInLayerList(state.layerList, layerId, copyLayer)
layerList: replaceInLayerList(state.layerList, layerId, copyLayer),
};
}

Expand All @@ -482,7 +493,7 @@ function rollbackTrackedLayerState(state, layerId) {

return {
...state,
layerList: replaceInLayerList(state.layerList, layerId, rolledbackLayer)
layerList: replaceInLayerList(state.layerList, layerId, rolledbackLayer),
};
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/maps/public/selectors/map_selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const isInteractiveDisabled = ({ map }) => map.mapState.disableInteractiv

export const isTooltipControlDisabled = ({ map }) => map.mapState.disableTooltipControl;

export const isToolbarOverlayHidden = ({ map }) => map.mapState.hideToolbarOverlay;

export const getMapExtent = ({ map }) => map.mapState.extent ?
map.mapState.extent : {};

Expand Down

0 comments on commit b4cb029

Please sign in to comment.