Skip to content

Commit

Permalink
move settings button to top map chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Apr 20, 2020
1 parent 1abe6b9 commit 71e7d7a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 68 deletions.
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { AnyAction } from 'redux';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui';

export function updateFlyout(display: FLYOUT_STATE): AnyAction;
Expand Down
15 changes: 15 additions & 0 deletions x-pack/legacy/plugins/maps/public/actions/ui_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
} from '../../../../../plugins/maps/public/actions/ui_actions';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export * from '../../../../../plugins/maps/public/actions/ui_actions';
import { getFlyoutDisplay } from '../selectors/ui_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui';
import { setSelectedLayer, trackMapSettings } from './map_actions';

export function exitFullScreen() {
return {
Expand All @@ -33,6 +37,17 @@ export function updateFlyout(display) {
display,
};
}
export function openMapSettings() {
return (dispatch, getState) => {
const flyoutDisplay = getFlyoutDisplay(getState());
if (flyoutDisplay === FLYOUT_STATE.MAP_SETTINGS_PANEL) {
return;
}
dispatch(setSelectedLayer(null));
dispatch(trackMapSettings());
dispatch(updateFlyout(FLYOUT_STATE.MAP_SETTINGS_PANEL));
};
}
export function closeSetView() {
return {
type: CLOSE_SET_VIEW,
Expand Down
28 changes: 27 additions & 1 deletion x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import {
setReadOnly,
setIsLayerTOCOpen,
setOpenTOCDetails,
openMapSettings,
} from '../actions/ui_actions';
import { getIsFullScreen } from '../selectors/ui_selectors';
import { getIsFullScreen, getFlyoutDisplay } from '../selectors/ui_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util';
import {
Expand Down Expand Up @@ -447,6 +448,7 @@ app.controller(

$scope.isFullScreen = false;
$scope.isSaveDisabled = false;
$scope.isOpenSettingsDisabled = false;
function handleStoreChanges(store) {
const nextIsFullScreen = getIsFullScreen(store.getState());
if (nextIsFullScreen !== $scope.isFullScreen) {
Expand All @@ -468,6 +470,14 @@ app.controller(
$scope.isSaveDisabled = nextIsSaveDisabled;
});
}

const flyoutDisplay = getFlyoutDisplay(store.getState());
const nextIsOpenSettingsDisabled = flyoutDisplay !== FLYOUT_STATE.NONE;
if (nextIsOpenSettingsDisabled !== $scope.isOpenSettingsDisabled) {
$scope.$evalAsync(() => {
$scope.isOpenSettingsDisabled = nextIsOpenSettingsDisabled;
});
}
}

$scope.$on('$destroy', () => {
Expand Down Expand Up @@ -645,6 +655,22 @@ app.controller(
},
]
: []),
{
id: 'mapSettings',
label: i18n.translate('xpack.maps.mapController.openSettingsButtonLabel', {
defaultMessage: `Settings`,
}),
description: i18n.translate('xpack.maps.mapController.openSettingsDescription', {
defaultMessage: `Open settings`,
}),
testId: 'openSettingsButton',
disableButton() {
return $scope.isOpenSettingsDisabled;
},
run() {
store.dispatch(openMapSettings());
},
},
];
}
);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LayerControl } from './view';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui';
import { updateFlyout, setIsLayerTOCOpen } from '../../../actions/ui_actions';
import { setSelectedLayer, trackMapSettings } from '../../../actions/map_actions';
import { setSelectedLayer } from '../../../actions/map_actions';
import {
getIsReadOnly,
getIsLayerTOCOpen,
Expand Down Expand Up @@ -38,11 +38,6 @@ function mapDispatchToProps(dispatch) {
openLayerTOC: () => {
dispatch(setIsLayerTOCOpen(true));
},
openMapSettings: async () => {
await dispatch(setSelectedLayer(null));
dispatch(trackMapSettings());
dispatch(updateFlyout(FLYOUT_STATE.MAP_SETTINGS_PANEL));
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function LayerControl({
openLayerTOC,
layerList,
isFlyoutOpen,
openMapSettings,
}) {
if (!isLayerTOCOpen) {
const hasErrors = layerList.some(layer => {
Expand All @@ -81,12 +80,7 @@ export function LayerControl({
);
}

const openMapSettingsLabel = i18n.translate('xpack.maps.layerControl.openMapSettingsLabel', {
defaultMessage: 'Edit map settings',
});

let addLayer;
let mapSettingsBtn;
if (!isReadOnly) {
addLayer = (
<Fragment>
Expand All @@ -106,21 +100,6 @@ export function LayerControl({
</EuiButton>
</Fragment>
);
mapSettingsBtn = (
<EuiFlexItem grow={false}>
<EuiToolTip delay="long" content={openMapSettingsLabel}>
<EuiButtonIcon
isDisabled={isFlyoutOpen}
className="mapLayerControl__openMapSettingsButton"
onClick={openMapSettings}
iconType="gear"
color="text"
aria-label={openMapSettingsLabel}
data-test-subj="mapOpenMapSettingsButton"
/>
</EuiToolTip>
</EuiFlexItem>
);
}

return (
Expand All @@ -147,7 +126,6 @@ export function LayerControl({
</h2>
</EuiTitle>
</EuiFlexItem>
{mapSettingsBtn}
<EuiFlexItem grow={false}>
<EuiToolTip
delay="long"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const defaultProps = {
showAddLayerWizard: () => {},
closeLayerTOC: () => {},
openLayerTOC: () => {},
openMapSettings: () => {},
isLayerTOCOpen: true,
layerList: [],
isFlyoutOpen: false,
Expand Down

0 comments on commit 71e7d7a

Please sign in to comment.