Skip to content

Commit

Permalink
Merge pull request #306 from Element84/ba/feature/define-collections-…
Browse files Browse the repository at this point in the history
…via-config

Allow defining collections via config
  • Loading branch information
bradleyandrick authored Dec 28, 2023
2 parents cebd9dd + 0d94d3e commit 54e80ca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added support for `COLLECTIONS` to be defined in the `config.json` file.

### Fixed

- Bug fix that made `DEFAULT_COLLECTION` required instead of optional, per the readme. It is now actually optional.

## 4.4.0 - 2023-12-01

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The file `./public/config/config.example.json` is included in this repository as
| SHOW_PUBLISH_BTN | Flag for displaying the Publish button at the bottom left of the UI. Setting to `true` will display the button, any other value will not display the button. Default is to not display the button. | Optional |
| API_MAX_ITEMS | Maximum number of items requested from API. If not set, the default max items will be 200. | Optional |
| DEFAULT_COLLECTION | Default collection option for collection dropdown | Optional |
| COLLECTIONS | Array of strings listing collections to show in dropdown. This is used to filter the collections endpoint from the list fetched from the `STAC_API_URL` defined in the config. Collection property of `id` must be used. If set, only the matched collections will show in the app. If not set, all collections in the STAC API will show in dropdown. | Optional |
| SCENE_TILER_URL | URL for map tiling | Optional |
| SCENE_TILER_PARAMS | Per-collection configuration of TiTiler `assets`, `color_formula`, `bidx`, `rescale`, `expression`, and `colormap_name` parameters. Example in [config.example.json](./public/config/config.example.json) | Optional |
| MOSAIC_MIN_ZOOM_LEVEL | Minimum zoom level for mosaic view search results. If not set, the default zoom level will be 7. | Optional |
Expand Down
3 changes: 2 additions & 1 deletion public/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@
}
]
}
]
],
"COLLECTIONS": ["naip", "cop-dem-glo-30", "sentinel-2-l2a"]
}
5 changes: 5 additions & 0 deletions src/components/CollectionDropdown/CollectionDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ const Dropdown = () => {

useEffect(() => {
if (_collectionsData.length > 0) {
if (!_appConfig.DEFAULT_COLLECTION) {
setCollectionId(_collectionsData[0].id)
return
}
const defaultCollectionFound = !!_collectionsData.find(
(o) => o.id === _appConfig.DEFAULT_COLLECTION
)
if (!defaultCollectionFound) {
console.log('Configuration Error: DEFAULT_COLLECTION not found in API')
setCollectionId(_collectionsData[0].id)
} else {
setCollectionId(_appConfig.DEFAULT_COLLECTION)
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/ViewSelector/ViewSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { newSearch } from '../../utils/searchHelper'
const ViewSelector = () => {
const _viewMode = useSelector((state) => state.mainSlice.viewMode)
const _showAppLoading = useSelector((state) => state.mainSlice.showAppLoading)
const _selectedCollectionData = useSelector(
(state) => state.mainSlice.selectedCollectionData
)

const dispatch = useDispatch()
const [selectedBtn, setSelectedBtn] = useState(_viewMode)
Expand All @@ -29,15 +32,15 @@ const ViewSelector = () => {

useEffect(() => {
dispatch(setViewMode(selectedBtn))
if (!_showAppLoading) {
if (!_showAppLoading && _selectedCollectionData) {
newSearch()
}
}, [selectedBtn])

return (
<ThemeProvider theme={theme}>
<Box sx={{ width: 165 }} className="viewSelector">
<label>View Mode</label>
<label htmlFor="ViewModeToggle">View Mode</label>
<Grid container spacing={2} alignItems="center">
<Grid item xs>
<ButtonGroup
Expand Down
25 changes: 22 additions & 3 deletions src/services/get-collections-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { store } from '../redux/store'
import {
setCollectionsData,
setShowAppLoading
setShowAppLoading,
setapplicationAlertMessage,
setshowApplicationAlert
} from '../redux/slices/mainSlice'
import { buildCollectionsData, loadLocalGridData } from '../utils/dataHelper'

Expand All @@ -19,10 +21,27 @@ export async function GetCollectionsService(searchParams) {
throw new Error()
})
.then((json) => {
const builtCollectionData = buildCollectionsData(json)
return builtCollectionData
if (!store.getState().mainSlice.appConfig.COLLECTIONS) {
const builtCollectionData = buildCollectionsData(json)
return builtCollectionData
}
if (json && json.collections && Array.isArray(json.collections)) {
json.collections = json.collections.filter((collection) => {
return store
.getState()
.mainSlice.appConfig.COLLECTIONS.includes(collection.id)
})
const builtCollectionData = buildCollectionsData(json)
return builtCollectionData
}
})
.then((formattedData) => {
if (Object.values(formattedData).length === 0) {
store.dispatch(
setapplicationAlertMessage('Error: No Collections Found')
)
store.dispatch(setshowApplicationAlert(true))
}
store.dispatch(setCollectionsData(formattedData))
store.dispatch(setShowAppLoading(false))
loadLocalGridData()
Expand Down

0 comments on commit 54e80ca

Please sign in to comment.