Skip to content

Commit

Permalink
Refactor delete layer modal (#242) (#266)
Browse files Browse the repository at this point in the history
Signed-off-by: Vijayan Balasubramanian <[email protected]>
(cherry picked from commit c688c23)

Co-authored-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and VijayanB authored Feb 21, 2023
1 parent d6aafcf commit 391bdb6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"wellknown": "^0.5.0"
},
"devDependencies": {
"@types/react-test-renderer": "^18.0.0",
"cypress": "9.5.4",
"cypress-multi-reporters": "^1.5.0",
"prettier": "^2.1.1"
Expand Down
23 changes: 23 additions & 0 deletions public/components/layer_control_panel/delete_layer_modal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { DeleteLayerModal } from './delete_layer_modal';
import React from 'react';
import { EuiConfirmModal } from '@elastic/eui';
import TestRenderer from 'react-test-renderer';

describe('test delete layer modal', function () {
it('should show modal', function () {
const deleteLayerModal = TestRenderer.create(
<DeleteLayerModal layerName={'test-layer'} onCancel={() => {}} onConfirm={() => {}} />
);
const testInstance = deleteLayerModal.root;
expect(testInstance.findByType(EuiConfirmModal).props.title).toBe('Delete layer');
expect(testInstance.findByType(EuiConfirmModal).props.confirmButtonText).toBe('Delete');
expect(testInstance.findByType(EuiConfirmModal).props.cancelButtonText).toBe('Cancel');
expect(testInstance.findByType(EuiConfirmModal).props.buttonColor).toBe('danger');
expect(testInstance.findByType(EuiConfirmModal).props.defaultFocusedButton).toBe('confirm');
});
});
30 changes: 30 additions & 0 deletions public/components/layer_control_panel/delete_layer_modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiConfirmModal } from '@elastic/eui';
import React from 'react';

interface DeleteLayerModalProps {
onCancel: () => void;
onConfirm: () => void;
layerName: string;
}
export const DeleteLayerModal = ({ onCancel, onConfirm, layerName }: DeleteLayerModalProps) => {
return (
<EuiConfirmModal
title="Delete layer"
onCancel={onCancel}
onConfirm={onConfirm}
cancelButtonText="Cancel"
confirmButtonText="Delete"
buttonColor="danger"
defaultFocusedButton="confirm"
>
<p>
Do you want to delete layer <strong>{layerName}</strong>?
</p>
</EuiConfirmModal>
);
};
28 changes: 8 additions & 20 deletions public/components/layer_control_panel/layer_control_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
import { MapState } from '../../model/mapState';
import { ConfigSchema } from '../../../common/config';
import { moveLayers, removeLayers, updateLayerVisibility } from '../../model/map/layer_operations';
import { DeleteLayerModal } from './delete_layer_modal';

interface MaplibreRef {
current: Maplibre | null;
Expand Down Expand Up @@ -309,25 +310,6 @@ export const LayerControlPanel = memo(
setSelectedDeleteLayer(undefined);
};

let deleteLayerModal;
if (isDeleteLayerModalVisible) {
deleteLayerModal = (
<EuiConfirmModal
title="Delete layer"
onCancel={onCancelDeleteLayer}
onConfirm={onDeleteLayerConfirm}
cancelButtonText="Cancel"
confirmButtonText="Delete"
buttonColor="danger"
defaultFocusedButton="confirm"
>
<p>
Do you want to delete layer <strong>{selectedDeleteLayer?.name}</strong>?
</p>
</EuiConfirmModal>
);
}

const getLayerTooltipContent = (layer: MapLayerSpecification) => {
if (zoom < layer.zoomRange[0] || zoom > layer.zoomRange[1]) {
return `Layer is not visible outside of zoom range ${layer.zoomRange[0]} - ${layer.zoomRange[1]}`;
Expand Down Expand Up @@ -510,7 +492,13 @@ export const LayerControlPanel = memo(
mapConfig={mapConfig}
layerCount={layers.length}
/>
{deleteLayerModal}
{isDeleteLayerModalVisible && (
<DeleteLayerModal
onCancel={onCancelDeleteLayer}
onConfirm={onDeleteLayerConfirm}
layerName={selectedDeleteLayer?.name!}
/>
)}
</EuiFlexGroup>
</EuiPanel>
</I18nProvider>
Expand Down

0 comments on commit 391bdb6

Please sign in to comment.