forked from opensearch-project/dashboards-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move zoom and coordinates as separate component (opensearch-project#309…
…) (opensearch-project#311) We don't have to render zoom/coordiantes if there is no change in maps movement. Added unit test to check render Signed-off-by: Vijayan Balasubramanian <[email protected]> (cherry picked from commit 90acbc6)
- Loading branch information
1 parent
0ed051e
commit 34e2d11
Showing
4 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"last_github_commit": "35319613bf79479c3133b75ddc370c651288da66", | ||
"last_gitfarm_commit": "c40e41190aaa9a2e23e6467cdfdc1a4daad2cc43" | ||
"last_github_commit": "90acbc6458a66550dc2f24b49020302a5707fc2b", | ||
"last_gitfarm_commit": "5b1b0197c8f4c2ccffbce9d28208f53f60f1e901" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { MapsFooter } from './mapsFooter'; | ||
import { LngLat } from 'maplibre-gl'; | ||
|
||
let container: Element | null; | ||
beforeEach(() => { | ||
// setup a DOM element as a render target | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
// cleanup on exiting | ||
unmountComponentAtNode(container!); | ||
container?.remove(); | ||
container = null; | ||
}); | ||
|
||
it('renders with or without coordinates', () => { | ||
act(() => { | ||
render(<MapsFooter zoom={3} />, container); | ||
}); | ||
expect(container?.textContent).toBe('zoom: 3'); | ||
|
||
act(() => { | ||
const coordinates: LngLat = new LngLat(-73.974912, 40.773654); | ||
render(<MapsFooter zoom={3} coordinates={coordinates} />, container); | ||
}); | ||
expect(container?.textContent).toBe('lat: 40.7737, lon: -73.9749, zoom: 3'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiPanel } from '@elastic/eui'; | ||
import { isEqual } from 'lodash'; | ||
import React, { memo } from 'react'; | ||
import { LngLat } from 'maplibre-gl'; | ||
|
||
const coordinatesRoundOffDigit = 4; | ||
interface MapFooterProps { | ||
coordinates?: LngLat; | ||
zoom: number; | ||
} | ||
|
||
export const MapsFooter = memo(({ coordinates, zoom }: MapFooterProps) => { | ||
return ( | ||
<EuiPanel | ||
hasShadow={false} | ||
hasBorder={false} | ||
color="transparent" | ||
className="zoombar" | ||
data-test-subj="mapStatusBar" | ||
> | ||
<small> | ||
{coordinates && | ||
`lat: ${coordinates.lat.toFixed( | ||
coordinatesRoundOffDigit | ||
)}, lon: ${coordinates.lng.toFixed(coordinatesRoundOffDigit)}, `} | ||
zoom: {zoom} | ||
</small> | ||
</EuiPanel> | ||
); | ||
}, isEqual); |