Skip to content

Commit 40d38ef

Browse files
author
Aaron Caldwell
committed
Add snapshot tests, test fixes, misc. updates
1 parent 19e8186 commit 40d38ef

10 files changed

Lines changed: 88 additions & 22 deletions

File tree

x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface IVectorLayer extends ILayer {
9393
getPropertiesForTooltip(properties: GeoJsonProperties): Promise<ITooltipProperty[]>;
9494
hasJoins(): boolean;
9595
canShowTooltip(): boolean;
96-
isEditable(): boolean;
96+
supportsFeatureEditing(): boolean;
9797
getLeftJoinFields(): Promise<IField[]>;
9898
addFeature(geometry: Geometry | Position[]): Promise<void>;
9999
}
@@ -176,9 +176,10 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
176176
});
177177
}
178178

179-
isEditable(): boolean {
179+
supportsFeatureEditing(): boolean {
180180
const dataRequest = this.getDataRequest(IS_EDITABLE_REQUEST_ID);
181181
const data = dataRequest?.getData() as { isEditable: boolean } | undefined;
182+
182183
return data ? data.isEditable : false;
183184
}
184185

x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/action_labels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function getVisibilityToggleLabel(isVisible: boolean) {
2121
});
2222
}
2323

24-
export const LAYER_SETTINGS_LABEL = i18n.translate(
24+
export const EDIT_LAYER_SETTINGS_LABEL = i18n.translate(
2525
'xpack.maps.layerControl.layerTocActions.layerSettingsButtonLabel',
2626
{
2727
defaultMessage: 'Layer settings',

x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { TOCEntryActionsPopover } from './toc_entry_actions_popover';
1515
import {
1616
getVisibilityToggleIcon,
1717
getVisibilityToggleLabel,
18-
LAYER_SETTINGS_LABEL,
18+
EDIT_LAYER_SETTINGS_LABEL,
1919
FIT_TO_DATA_LABEL,
2020
} from './action_labels';
2121
import { ILayer } from '../../../../../classes/layers/layer';
@@ -200,8 +200,8 @@ export class TOCEntry extends Component<Props, State> {
200200
key="settings"
201201
isDisabled={this.props.isEditButtonDisabled}
202202
iconType="gear"
203-
aria-label={LAYER_SETTINGS_LABEL}
204-
title={LAYER_SETTINGS_LABEL}
203+
aria-label={EDIT_LAYER_SETTINGS_LABEL}
204+
title={EDIT_LAYER_SETTINGS_LABEL}
205205
onClick={this._openLayerPanelWithCheck}
206206
/>
207207
);

x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { TOCEntryButton } from '../toc_entry_button';
1313
import {
1414
getVisibilityToggleIcon,
1515
getVisibilityToggleLabel,
16-
LAYER_SETTINGS_LABEL,
16+
EDIT_LAYER_SETTINGS_LABEL,
1717
FIT_TO_DATA_LABEL,
1818
EDIT_FEATURES_LABEL,
1919
} from '../action_labels';
2020
import { ESSearchSource } from '../../../../../../classes/sources/es_search_source';
2121
import { VectorLayer } from '../../../../../../classes/layers/vector_layer';
22+
import { SCALING_TYPES } from '../../../../../../../common';
2223

2324
export interface Props {
2425
cloneLayer: (layerId: string) => void;
@@ -62,7 +63,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
6263
if (!(this.props.layer instanceof VectorLayer)) {
6364
return;
6465
}
65-
const isLayerEditable = await this.props.layer.isEditable();
66+
const isLayerEditable = this.props.layer.supportsFeatureEditing();
6667
const editModeEnabled = await this._getEditModeEnabled();
6768
if (
6869
!this._isMounted ||
@@ -76,8 +77,14 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
7677

7778
async _getEditModeEnabled(): Promise<boolean> {
7879
const vectorLayer = this.props.layer as VectorLayer;
80+
const layerSource = await this.props.layer.getSource();
81+
if (!(layerSource instanceof ESSearchSource)) {
82+
return false;
83+
}
84+
// @ts-ignore
85+
const isClustered = layerSource?.getSyncMeta()?.scalingType === SCALING_TYPES.CLUSTERS;
7986
if (
80-
!(await vectorLayer.isEditable()) ||
87+
isClustered ||
8188
(await vectorLayer.isFilteredByGlobalTime()) ||
8289
vectorLayer.isPreviewLayer() ||
8390
!vectorLayer.isVisible() ||
@@ -155,7 +162,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
155162
? null
156163
: i18n.translate('xpack.maps.layerTocActions.editLayerTooltip', {
157164
defaultMessage:
158-
'Only fully added document layers without clustering, joins or time filtering enabled can be modified',
165+
'Edit features only supported for document layers without clustering, joins, or time filtering',
159166
}),
160167
disabled: !this.state.editModeEnabled,
161168
onClick: async () => {
@@ -171,7 +178,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
171178
}
172179
actionItems.push({
173180
disabled: this.props.isEditButtonDisabled,
174-
name: LAYER_SETTINGS_LABEL,
181+
name: EDIT_LAYER_SETTINGS_LABEL,
175182
icon: <EuiIcon type="gear" size="m" />,
176183
'data-test-subj': 'layerSettingsButton',
177184
toolTipContent: null,

x-pack/plugins/maps/public/connected_components/toolbar_overlay/__snapshots__/toolbar_overlay.test.tsx.snap

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/maps/public/connected_components/toolbar_overlay/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import { getGeoFieldNames } from '../../selectors/map_selectors';
1313
import { DRAW_MODE } from '../../../common';
1414

1515
function mapStateToProps(state: MapStoreState) {
16-
const shapeDrawModeActive = getDrawMode(state) === DRAW_MODE.DRAW_SHAPES;
17-
const pointDrawModeActive = getDrawMode(state) === DRAW_MODE.DRAW_POINTS;
1816
return {
1917
showToolsControl: getGeoFieldNames(state).length !== 0,
20-
disableToolsControl: shapeDrawModeActive || pointDrawModeActive,
21-
shapeDrawModeActive,
22-
pointDrawModeActive,
18+
shapeDrawModeActive: getDrawMode(state) === DRAW_MODE.DRAW_SHAPES,
19+
pointDrawModeActive: getDrawMode(state) === DRAW_MODE.DRAW_POINTS,
2320
};
2421
}
2522

x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.test.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ test('Should only show set view control', async () => {
2727
pointDrawModeActive={false}
2828
showFitToBoundsButton={false}
2929
showTimesliderButton={false}
30-
disableToolsControl={false}
3130
/>
3231
);
3332
expect(component).toMatchSnapshot();
@@ -42,7 +41,32 @@ test('Should show all controls', async () => {
4241
showTimesliderButton={true}
4342
shapeDrawModeActive={false}
4443
pointDrawModeActive={false}
45-
disableToolsControl={false}
44+
/>
45+
);
46+
expect(component).toMatchSnapshot();
47+
});
48+
49+
test('Should show point layer edit tools', async () => {
50+
const component = shallow(
51+
<ToolbarOverlay
52+
showToolsControl={false}
53+
shapeDrawModeActive={false}
54+
pointDrawModeActive={true}
55+
showFitToBoundsButton={false}
56+
showTimesliderButton={false}
57+
/>
58+
);
59+
expect(component).toMatchSnapshot();
60+
});
61+
62+
test('Should show shape layer edit tools', async () => {
63+
const component = shallow(
64+
<ToolbarOverlay
65+
showToolsControl={false}
66+
shapeDrawModeActive={true}
67+
pointDrawModeActive={false}
68+
showFitToBoundsButton={false}
69+
showTimesliderButton={false}
4670
/>
4771
);
4872
expect(component).toMatchSnapshot();

x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { TimesliderToggleButton } from './timeslider_toggle_button';
1818
export interface Props {
1919
addFilters?: ((filters: Filter[], actionId: string) => Promise<void>) | null;
2020
showToolsControl: boolean;
21-
disableToolsControl: boolean;
2221
getFilterActions?: () => Promise<Action[]>;
2322
getActionContext?: () => ActionExecutionContext;
2423
shapeDrawModeActive: boolean;
@@ -34,7 +33,7 @@ export function ToolbarOverlay(props: Props) {
3433
<ToolsControl
3534
getFilterActions={props.getFilterActions}
3635
getActionContext={props.getActionContext}
37-
disableToolsControl={props.disableToolsControl}
36+
disableToolsControl={props.pointDrawModeActive || props.shapeDrawModeActive}
3837
/>
3938
</EuiFlexItem>
4039
) : null;

x-pack/plugins/maps/public/connected_components/toolbar_overlay/tools_control/__snapshots__/tools_control.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/maps/public/connected_components/toolbar_overlay/tools_control/tools_control.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('renders', async () => {
3333
});
3434

3535
test('Should render cancel button when drawing', async () => {
36-
const component = shallow(<ToolsControl {...defaultProps} />);
36+
const component = shallow(<ToolsControl {...defaultProps} disableToolsControl={true} />);
3737

3838
expect(component).toMatchSnapshot();
3939
});

0 commit comments

Comments
 (0)