Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload geojson feature for use in search #200

Merged
merged 16 commits into from
Jul 14, 2023
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added Config feature flags for Advanced Search Options and Cart
- Added draw boundary feature to allow user to draw polygon on map (WIP)
- When polygon drawn, use as search intersects param instead of map viewport bbox
- Added upload geojson feature to allow users to select a geojson file to add to map
- Reusable System Message component for showing app alerts

### Removed

Expand Down
65 changes: 61 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"leaflet-geosearch": "^3.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-leaflet": "^4.2.1",
"react-redux": "^8.0.7",
"react-tooltip": "^5.16.1"
Expand Down
12 changes: 12 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import PageHeader from './components/Layout/PageHeader/PageHeader'
import PublishModal from './components/PublishModal/PublishModal'
import LaunchModal from './components/LaunchModal/LaunchModal'
import LaunchImageModal from './components/LaunchModal/LaunchImageModal'
import UploadGeojsonModal from './components/UploadGeojsonModal/UploadGeojsonModal'
import SystemMessage from './components/SystemMessage/SystemMessage'

import { GetCollectionsService } from './services/get-collections-service'
import { useSelector } from 'react-redux'
Expand All @@ -21,6 +23,12 @@ function App() {
const _showLaunchImageModal = useSelector(
(state) => state.mainSlice.showLaunchImageModal
)
const _showUploadGeojsonModal = useSelector(
(state) => state.mainSlice.showUploadGeojsonModal
)
const _showApplicationAlert = useSelector(
(state) => state.mainSlice.showApplicationAlert
)
useEffect(() => {
GetCollectionsService()
}, [])
Expand All @@ -33,6 +41,10 @@ function App() {
{_showPublishModal ? <PublishModal /> : null}
{_showLaunchModal ? <LaunchModal /> : null}
{_showLaunchImageModal ? <LaunchImageModal /> : null}
{_showUploadGeojsonModal ? (
<UploadGeojsonModal></UploadGeojsonModal>
) : null}
{_showApplicationAlert ? <SystemMessage></SystemMessage> : null}
</div>
</React.StrictMode>
)
Expand Down
34 changes: 33 additions & 1 deletion src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { store } from './redux/store'
import {
setShowPublishModal,
setShowLaunchModal,
setShowLaunchImageModal
setShowLaunchImageModal,
setshowUploadGeojsonModal,
setshowApplicationAlert
} from './redux/slices/mainSlice'
import { vi } from 'vitest'
import * as CollectionsService from './services/get-collections-service'
Expand Down Expand Up @@ -81,5 +83,35 @@ describe('App', () => {
expect(LaunchImageModalComponent).not.toBeNull()
})
})
describe('when conditionally rendering UploadGeojsonModal', () => {
it('should not render UploadGeojsonModal if showUploadGeojsonModal in state is false', () => {
setup()
const UploadGeojsonModalComponent = screen.queryByTestId(
'testUploadGeojsonModal'
)
expect(UploadGeojsonModalComponent).toBeNull()
})
it('should render UploadGeojsonModal if showUploadGeojsonModal in state is true', () => {
store.dispatch(setshowUploadGeojsonModal(true))
setup()
const UploadGeojsonModalComponent = screen.queryByTestId(
'testUploadGeojsonModal'
)
expect(UploadGeojsonModalComponent).not.toBeNull()
})
})
describe('when conditionally rendering SystemMessage', () => {
it('should not render SystemMessage if showApplicationAlert in state is false', () => {
setup()
const SystemMessageComponent = screen.queryByTestId('testSystemMessage')
expect(SystemMessageComponent).toBeNull()
})
it('should render SystemMessage if showApplicationAlert in state is true', () => {
store.dispatch(setshowApplicationAlert(true))
setup()
const SystemMessageComponent = screen.queryByTestId('testSystemMessage')
expect(SystemMessageComponent).not.toBeNull()
})
})
})
})
5 changes: 3 additions & 2 deletions src/components/Layout/Content/BottomContent/BottomContent.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.BottomContent {
width: 100%;
height: calc(100% - 103px);
height: calc(100% - 100px);
background-color: #12171a;
display: flex;
position: relative;
position: absolute;
top: 100px;
}

.ZoomNotice {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Layout/Content/TopContent/TopContent.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
width: 100%;
height: 100px;
background-color: #353d4f;
position: relative;
z-index: 5;
position: absolute;
z-index: 6;
}

.TopContent .mobileMenu {
Expand Down
30 changes: 30 additions & 0 deletions src/components/Search/Search.Advanced.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ describe('Search', () => {
expect(store.getState().mainSlice.showAdvancedSearchOptions).toBeFalsy()
})
})
describe('when upload geojson button clicked', () => {
it('should not call dispatch functions if geom already exists', async () => {
store.dispatch(
setsearchGeojsonBoundary({
type: 'Polygon',
coordinates: [[]]
})
)
setup()
const advancedButton = screen.getByText(/advanced/i)
await user.click(advancedButton)
const uploadGeojsonButton = screen.getByRole('button', {
name: /upload geojson/i
})
await user.click(uploadGeojsonButton)
expect(store.getState().mainSlice.showUploadGeojsonModal).toBeFalsy()
})
it('should call dispatch functions if geom does not exists', async () => {
store.dispatch(setshowAdvancedSearchOptions(true))
setup()
const advancedButton = screen.getByText(/advanced/i)
await user.click(advancedButton)
const uploadGeojsonButton = screen.getByRole('button', {
name: /upload geojson/i
})
await user.click(uploadGeojsonButton)
expect(store.getState().mainSlice.showAdvancedSearchOptions).toBeFalsy()
expect(store.getState().mainSlice.showUploadGeojsonModal).toBeTruthy()
})
})
describe('when drawing mode enabled', () => {
it('should render disabled search bar overlay div', async () => {
setup()
Expand Down
12 changes: 11 additions & 1 deletion src/components/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
setIsAutoSearchSet,
setshowAdvancedSearchOptions,
setisDrawingEnabled,
setsearchGeojsonBoundary
setsearchGeojsonBoundary,
setshowUploadGeojsonModal
} from '../../redux/slices/mainSlice'
import 'react-tooltip/dist/react-tooltip.css'
import Switch from '@mui/material/Switch'
Expand Down Expand Up @@ -79,6 +80,14 @@ const Search = () => {
enableMapPolyDrawing()
}

function onUploadGeojsonButtonClicked() {
if (_searchGeojsonBoundary) {
return
}
dispatch(setshowAdvancedSearchOptions(false))
dispatch(setshowUploadGeojsonModal(true))
}

function onClearButtonClicked() {
if (!_searchGeojsonBoundary) {
return
Expand Down Expand Up @@ -164,6 +173,7 @@ const Search = () => {
: 'advancedSearchOptionsButton ' +
'advancedSearchOptionsButtonDisabled'
}
onClick={onUploadGeojsonButtonClicked}
>
Upload GeoJSON
</button>
Expand Down
6 changes: 6 additions & 0 deletions src/components/SystemMessage/SystemMessage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.SystemMessage {
position: absolute;
bottom: 40px;
right: 10px;
z-index: 500;
}
36 changes: 36 additions & 0 deletions src/components/SystemMessage/SystemMessage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import Alert from '@mui/material/Alert'
import './SystemMessage.css'

import { useSelector } from 'react-redux'
import { store } from '../../redux/store'
import { setshowApplicationAlert } from '../../redux/slices/mainSlice'

const SystemMessage = () => {
const _applicationAlertMessage = useSelector(
(state) => state.mainSlice.applicationAlertMessage
)
const _applicationAlertSeverity = useSelector(
(state) => state.mainSlice.applicationAlertSeverity
)

return (
<div className="SystemMessage" data-testid="testSystemMessage">
<Alert
onClose={() => {
store.dispatch(setshowApplicationAlert(false))
}}
severity={_applicationAlertSeverity}
sx={{
'& .MuiAlert-message': {
fontSize: 14
}
}}
>
{_applicationAlertMessage}
</Alert>
</div>
)
}

export default SystemMessage
Loading