-
Notifications
You must be signed in to change notification settings - Fork 1
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
Integrate STAC Catalog and Bbox field on Databrowser #72
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d8a0af
initial commit, added dynamic and static catalog alog with the existi…
mo-dkrz 8568ffc
removed the redundent configuration from local.py
mo-dkrz d22e72c
updated makefile, added newly added js script regarding the catalog
mo-dkrz bb1f17d
added bbox
mo-dkrz e9b532c
added bboxSelector
mo-dkrz d33f56b
ran prettier to make the code prettier
mo-dkrz 02b9057
update the auth APIs
mo-dkrz d71a691
fixed the issue in width of catalog button
mo-dkrz 05d5ee6
made it prettier and correct makefile
mo-dkrz 18fad9d
adding a condition to block the apply when the fields are empty
mo-dkrz 9a93b57
resolve the request changes
mo-dkrz f7201ff
add clear all
mo-dkrz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -26,4 +26,4 @@ static/* | |
assets/bundles/* | ||
webpack-stats.json | ||
base/migrations/* | ||
|
||
stac-browser/ |
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,267 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { connect } from "react-redux"; | ||
import { withRouter } from "react-router"; | ||
import queryString from "query-string"; | ||
import { | ||
BsRecordCircleFill, | ||
BsRecordCircle, | ||
BsCircleSquare, | ||
} from "react-icons/bs"; | ||
import { | ||
Button, | ||
InputGroup, | ||
Form, | ||
OverlayTrigger, | ||
Tooltip, | ||
Dropdown, | ||
DropdownButton, | ||
} from "react-bootstrap"; | ||
|
||
import { | ||
BBOX_RANGE_FILE, | ||
BBOX_RANGE_FLEXIBLE, | ||
BBOX_RANGE_STRICT, | ||
} from "./constants"; | ||
|
||
function BBoxSelector({ databrowser, router, location }) { | ||
const [selector, setSelector] = useState(BBOX_RANGE_FLEXIBLE); | ||
const [minLon, setMinLon] = useState(""); | ||
const [maxLon, setMaxLon] = useState(""); | ||
const [minLat, setMinLat] = useState(""); | ||
const [maxLat, setMaxLat] = useState(""); | ||
|
||
useEffect(() => { | ||
setMinLon(databrowser.minLon || ""); | ||
setMaxLon(databrowser.maxLon || ""); | ||
setMinLat(databrowser.minLat || ""); | ||
setMaxLat(databrowser.maxLat || ""); | ||
setSelector(databrowser.bboxSelector || BBOX_RANGE_FLEXIBLE); | ||
}, [databrowser]); | ||
|
||
function applyChanges() { | ||
const currentLocation = location.pathname; | ||
const { | ||
bboxSelector: ignore1, | ||
minLon: ignore2, | ||
maxLon: ignore3, | ||
minLat: ignore4, | ||
maxLat: ignore5, | ||
...queryObject | ||
} = location.query; | ||
|
||
const query = queryString.stringify({ | ||
...queryObject, | ||
minLon, | ||
maxLon, | ||
minLat, | ||
maxLat, | ||
bboxSelector: selector, | ||
}); | ||
router.push(currentLocation + "?" + query); | ||
} | ||
|
||
function onKeyPress(errorMessage, e) { | ||
const enterKey = 13; | ||
if (!errorMessage && e.charCode === enterKey) { | ||
applyChanges(); | ||
} | ||
} | ||
|
||
const isValidLongitude = (value) => { | ||
const num = Number(value); | ||
return Number.isFinite(num) && num >= -180 && num <= 180; | ||
}; | ||
|
||
const isValidLatitude = (value) => { | ||
const num = Number(value); | ||
return Number.isFinite(num) && num >= -90 && num <= 90; | ||
}; | ||
|
||
const minLonError = | ||
minLon && !isValidLongitude(minLon) | ||
? "Invalid longitude (-180 to 180)" | ||
: minLon && maxLon && parseFloat(minLon) > parseFloat(maxLon) | ||
? "Max longitude must be greater than min longitude" | ||
: ""; | ||
|
||
const maxLonError = | ||
maxLon && !isValidLongitude(maxLon) | ||
? "Invalid longitude (-180 to 180)" | ||
: minLon && maxLon && parseFloat(minLon) > parseFloat(maxLon) | ||
? "Max longitude must be greater than min longitude" | ||
: ""; | ||
const minLatError = | ||
minLat && !isValidLatitude(minLat) | ||
? "Invalid latitude (-90 to 90)" | ||
: minLat && maxLat && parseFloat(minLat) > parseFloat(maxLat) | ||
? "Max latitude must be greater than min latitude" | ||
: ""; | ||
|
||
const maxLatError = | ||
maxLat && !isValidLatitude(maxLat) | ||
? "Invalid latitude (-90 to 90)" | ||
: minLat && maxLat && parseFloat(minLat) > parseFloat(maxLat) | ||
? "Max latitude must be greater than min latitude" | ||
: ""; | ||
|
||
let errorMessage = minLonError || maxLonError || minLatError || maxLatError; | ||
|
||
if (!minLon || !maxLon || !minLat || !maxLat) { | ||
errorMessage = "All coordinates are required"; | ||
} | ||
if ( | ||
!errorMessage && | ||
minLon && | ||
maxLon && | ||
parseFloat(minLon) > parseFloat(maxLon) | ||
) { | ||
errorMessage = "Max longitude must be greater than min longitude"; | ||
} | ||
if ( | ||
!errorMessage && | ||
minLat && | ||
maxLat && | ||
parseFloat(minLat) > parseFloat(maxLat) | ||
) { | ||
errorMessage = "Max latitude must be greater than min latitude"; | ||
} | ||
|
||
let applyButton; | ||
if (errorMessage) { | ||
const tooltip = <Tooltip id="boxWarning">{errorMessage}</Tooltip>; | ||
applyButton = ( | ||
<OverlayTrigger overlay={tooltip} placement="top"> | ||
<span> | ||
<Button variant="danger" disabled> | ||
Apply | ||
</Button> | ||
</span> | ||
</OverlayTrigger> | ||
); | ||
} else { | ||
applyButton = ( | ||
<Button variant="primary" onClick={applyChanges.bind(this)}> | ||
Apply | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<div onKeyPress={onKeyPress.bind(this, errorMessage)}> | ||
<InputGroup className="mb-4"> | ||
<InputGroup.Text id="bbox-text">Operator</InputGroup.Text> | ||
<DropdownButton | ||
className="selector-button" | ||
variant="outline-secondary" | ||
title={selector} | ||
id="time-operator-dropdown" | ||
> | ||
<Dropdown.Item | ||
onClick={() => setSelector(BBOX_RANGE_FLEXIBLE)} | ||
href="#" | ||
> | ||
<BsCircleSquare /> {BBOX_RANGE_FLEXIBLE} | ||
</Dropdown.Item> | ||
<Dropdown.Item | ||
onClick={() => setSelector(BBOX_RANGE_STRICT)} | ||
href="#" | ||
> | ||
<BsRecordCircleFill /> {BBOX_RANGE_STRICT} | ||
</Dropdown.Item> | ||
<Dropdown.Item onClick={() => setSelector(BBOX_RANGE_FILE)} href="#"> | ||
<BsRecordCircle /> {BBOX_RANGE_FILE} | ||
</Dropdown.Item> | ||
</DropdownButton> | ||
</InputGroup> | ||
|
||
<div | ||
style={{ | ||
display: "grid", | ||
gridTemplateColumns: "repeat(2, 1fr)", | ||
gap: "1rem", | ||
marginBottom: "1rem", | ||
}} | ||
> | ||
<div> | ||
<InputGroup> | ||
<InputGroup.Text>Min Lon</InputGroup.Text> | ||
<Form.Control | ||
value={minLon} | ||
placeholder="-180" | ||
onChange={(e) => setMinLon(e.target.value)} | ||
isInvalid={!!minLonError} | ||
/> | ||
</InputGroup> | ||
<div className="text-danger small">{minLonError} </div> | ||
</div> | ||
<div> | ||
<InputGroup> | ||
<InputGroup.Text>Max Lon</InputGroup.Text> | ||
<Form.Control | ||
value={maxLon} | ||
placeholder="180" | ||
onChange={(e) => setMaxLon(e.target.value)} | ||
isInvalid={!!maxLonError} | ||
/> | ||
</InputGroup> | ||
<div className="text-danger small">{maxLonError} </div> | ||
</div> | ||
</div> | ||
<div | ||
style={{ | ||
display: "grid", | ||
gridTemplateColumns: "repeat(2, 1fr)", | ||
gap: "1rem", | ||
marginBottom: "1.5rem", | ||
}} | ||
> | ||
<div> | ||
<InputGroup> | ||
<InputGroup.Text>Min Lat</InputGroup.Text> | ||
<Form.Control | ||
value={minLat} | ||
placeholder="-90" | ||
onChange={(e) => setMinLat(e.target.value)} | ||
isInvalid={!!minLatError} | ||
/> | ||
</InputGroup> | ||
<div className="text-danger small">{minLatError} </div> | ||
</div> | ||
<div> | ||
<InputGroup> | ||
<InputGroup.Text>Max Lat</InputGroup.Text> | ||
<Form.Control | ||
value={maxLat} | ||
placeholder="90" | ||
onChange={(e) => setMaxLat(e.target.value)} | ||
isInvalid={!!maxLatError} | ||
/> | ||
</InputGroup> | ||
<div className="text-danger small">{maxLatError} </div> | ||
</div> | ||
</div> | ||
|
||
{applyButton} | ||
</div> | ||
); | ||
} | ||
|
||
BBoxSelector.propTypes = { | ||
databrowser: PropTypes.shape({ | ||
minLon: PropTypes.string, | ||
maxLon: PropTypes.string, | ||
minLat: PropTypes.string, | ||
maxLat: PropTypes.string, | ||
bboxSelector: PropTypes.string, | ||
}), | ||
location: PropTypes.object.isRequired, | ||
router: PropTypes.object.isRequired, | ||
dispatch: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = (state) => ({ | ||
databrowser: state.databrowserReducer, | ||
}); | ||
|
||
export default withRouter(connect(mapStateToProps)(BBoxSelector)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like it if error messages like this would also appear in the
minLatError
or themaxLatError
(one is enough I guess) and not only in the tooltip.