-
Notifications
You must be signed in to change notification settings - Fork 0
IM-224 setStyle and setSubLayerStyle use mappedDatasets #243
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3683c9
IM-224 added mappedDatasetsReducer tests
markfee 5e51a1e
IM-224 changed signature parameter name on getPatternImageId
markfee cc5ea0c
IM-224 Temp console.log effect in Layers.jsx
markfee c93aed7
IM-224 added some timeout changes to styles/visibility to test state …
markfee a196518
IM-224 WIP - attempt to refactor setStyle to use mappedDatasets
markfee 70a9442
Revert IM-224 changed signature parameter name on getPatternImageId
markfee 4f6ac31
IM-224 added a demo timeout change of style
markfee e2f7014
IM-224 setStyle and setSubLayerStyle use mappedDatasets
markfee 3334c9c
IM-224 fixed tests after change to setSublayerStyle
markfee 319bf65
IM-224 simplified setStyle
markfee 04a79c3
IM-224 altered test to cover new sublayer format too
markfee 1a56e73
IM-224 removed BUILD_MAPPED_DATASETS listener
markfee 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 +1,10 @@ | ||
| export const setStyle = ({ pluginState, mapState }, style, { datasetId, sublayerId } = {}) => { | ||
| export const setStyle = ({ pluginState, mapState }, styleChanges, { datasetId, sublayerId } = {}) => { | ||
| const dataset = pluginState.datasets?.find(d => d.id === datasetId) | ||
| if (!dataset) { | ||
| return | ||
| } | ||
|
|
||
| if (sublayerId) { | ||
| pluginState.dispatch({ type: 'SET_SUBLAYER_STYLE', payload: { datasetId, sublayerId, styleChanges: style } }) | ||
| const updatedSublayerDataset = { | ||
| ...dataset, | ||
| sublayers: dataset.sublayers?.map(sublayer => | ||
| sublayer.id === sublayerId ? { ...sublayer, style: { ...sublayer.style, ...style } } : sublayer | ||
| ) | ||
| } | ||
| pluginState.layerAdapter?.setSublayerStyle(updatedSublayerDataset, sublayerId, mapState.mapStyle) | ||
| return | ||
| } | ||
|
|
||
| pluginState.dispatch({ type: 'SET_DATASET_STYLE', payload: { datasetId, styleChanges: style } }) | ||
| const updatedDataset = { ...dataset, ...style } | ||
| pluginState.layerAdapter?.setStyle(updatedDataset, mapState.mapStyle) | ||
| const mapStyle = mapState.mapStyle | ||
| const type = sublayerId ? 'SET_SUBLAYER_STYLE' : 'SET_DATASET_STYLE' | ||
| const payload = { datasetId, styleChanges, mapStyle, sublayerId } | ||
| pluginState.dispatch({ type, payload }) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
116 changes: 116 additions & 0 deletions
116
plugins/beta/datasets/src/reducers/mappedDatasetsReducer.test.js
This file contains hidden or 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,116 @@ | ||
| import { mappedDatasetsReducer } from './mappedDatasetsReducer' | ||
|
|
||
| describe('mappedDatasetsReducer', () => { | ||
| it('handles empty datasets', () => { | ||
| const result = mappedDatasetsReducer({ datasets: [] }) | ||
| expect(result.mappedDatasets).toEqual({}) | ||
| expect(result.orderedDatasets).toEqual([]) | ||
| }) | ||
|
|
||
| it('handles missing datasets', () => { | ||
| const result = mappedDatasetsReducer({}) | ||
| expect(result.mappedDatasets).toEqual({}) | ||
| expect(result.orderedDatasets).toEqual([]) | ||
| }) | ||
|
|
||
| it('maps a single dataset with no sublayers', () => { | ||
| const state = { | ||
| datasets: [{ id: 'roads', label: 'Roads', minZoom: 10 }] | ||
| } | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets).toEqual({ | ||
| roads: { id: 'roads', label: 'Roads', minZoom: 10 } | ||
| }) | ||
| expect(result.orderedDatasets).toEqual(['roads']) | ||
| }) | ||
|
|
||
| it('maps multiple datasets preserving order', () => { | ||
| const state = { | ||
| datasets: [ | ||
| { id: 'alpha', label: 'Alpha' }, | ||
| { id: 'beta', label: 'Beta' }, | ||
| { id: 'gamma', label: 'Gamma' } | ||
| ] | ||
| } | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.orderedDatasets).toEqual(['alpha', 'beta', 'gamma']) | ||
| expect(Object.keys(result.mappedDatasets)).toEqual(['alpha', 'beta', 'gamma']) | ||
| }) | ||
|
|
||
| it('preserves other state properties', () => { | ||
| const state = { | ||
| datasets: [], | ||
| someOtherProp: 'value', | ||
| nested: { foo: 'bar' } | ||
| } | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.someOtherProp).toBe('value') | ||
| expect(result.nested).toEqual({ foo: 'bar' }) | ||
| }) | ||
|
|
||
| describe('with sublayers', () => { | ||
| const state = { | ||
| datasets: [{ | ||
| id: 'land-covers', | ||
| label: 'Land covers', | ||
| sublayers: [ | ||
| { id: 'grassland', label: 'Grassland' }, | ||
| { id: 'woodland', label: 'Woodland', visibility: 'hidden' } | ||
| ] | ||
| }] | ||
| } | ||
|
|
||
| it('removes the sublayers property from the parent dataset', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers'].sublayers).toBeUndefined() | ||
| }) | ||
|
|
||
| it('adds sublayerIds to the parent dataset', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers'].sublayerIds).toEqual([ | ||
| 'land-covers-grassland', | ||
| 'land-covers-woodland' | ||
| ]) | ||
| }) | ||
|
|
||
| it('adds flattened sublayers to mappedDatasets', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-grassland']).toBeDefined() | ||
| expect(result.mappedDatasets['land-covers-woodland']).toBeDefined() | ||
| }) | ||
|
|
||
| it('sets compound id on flattened sublayer', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-grassland'].id).toBe('land-covers-grassland') | ||
| }) | ||
|
|
||
| it('sets parentId on flattened sublayer', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-grassland'].parentId).toBe('land-covers') | ||
| }) | ||
|
|
||
| it('sets sublayerId to the original sublayer id', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-grassland'].sublayerId).toBe('grassland') | ||
| }) | ||
|
|
||
| it('sets visibility to visible for sublayers without explicit visibility', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-grassland'].visibility).toBe('visible') | ||
| }) | ||
|
|
||
| it('preserves hidden visibility on sublayers', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.mappedDatasets['land-covers-woodland'].visibility).toBe('hidden') | ||
| }) | ||
|
|
||
| it('includes sublayers in orderedDatasets after their parent', () => { | ||
| const result = mappedDatasetsReducer(state) | ||
| expect(result.orderedDatasets).toEqual([ | ||
| 'land-covers', | ||
| 'land-covers-grassland', | ||
| 'land-covers-woodland' | ||
| ]) | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.