Skip to content

Commit f9510c9

Browse files
authored
Extra slots plus search transformRequest fix (#160)
* Four extra slots added, inset slot replaced with left-top * Safe zone calculation improvements * Search plugin transformRequest options fix
1 parent 154e36d commit f9510c9

25 files changed

Lines changed: 600 additions & 366 deletions

demo/js/planning.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,22 @@ interactiveMap.on('app:ready', function (e) {
131131
label: 'Key',
132132
html: renderKeyHTML(),
133133
mobile: { slot: 'bottom', open: false, exclusive: true },
134-
tablet: { slot: 'inset', width: '260px', open: false, exclusive: true },
135-
desktop: { slot: 'inset', width: '280px', open: false, exclusive: true }
134+
tablet: { slot: 'left-top', width: '260px', open: false, exclusive: true },
135+
desktop: { slot: 'left-top', width: '280px', open: false, exclusive: true }
136+
})
137+
// interactiveMap.addPanel('test1', {
138+
// label: 'Test1',
139+
// html: '<p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p>',
140+
// mobile: { slot: 'bottom', open: true },
141+
// tablet: { slot: 'left-top', open: true },
142+
// desktop: { slot: 'left-top', open: true, width: '200px' },
143+
// })
144+
interactiveMap.addPanel('test2', {
145+
label: 'Test2',
146+
html: '<p>Test</p><p>Test</p>',
147+
mobile: { slot: 'bottom', open: true },
148+
tablet: { slot: 'left-top', open: true },
149+
desktop: { slot: 'left-top', open: true, width: '400px' },
136150
})
137151
})
138152

plugins/beta/datasets/src/manifest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export const manifest = {
2727
dismissible: true
2828
},
2929
tablet: {
30-
slot: 'inset',
30+
slot: 'left-top',
3131
dismissible: true,
3232
exclusive: true,
3333
width: '300px'
3434
},
3535
desktop: {
36-
slot: 'inset',
36+
slot: 'left-top',
3737
modal: false,
3838
dismissible: true,
3939
exclusive: true,
@@ -48,11 +48,11 @@ export const manifest = {
4848
modal: true
4949
},
5050
tablet: {
51-
slot: 'inset',
51+
slot: 'left-top',
5252
width: '300px'
5353
},
5454
desktop: {
55-
slot: 'inset',
55+
slot: 'left-top',
5656
width: '320px'
5757
},
5858
render: Key

plugins/beta/map-styles/src/manifest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const manifest = {
1414
dismissible: true
1515
},
1616
tablet: {
17-
slot: 'inset',
17+
slot: 'left-top',
1818
modal: true,
1919
width: '400px',
2020
dismissible: true
2121
},
2222
desktop: {
23-
slot: 'inset',
23+
slot: 'left-top',
2424
modal: true,
2525
width: '400px',
2626
dismissible: true

plugins/search/src/events/fetchSuggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const getRequestConfig = async (ds, query, transformRequest) => {
2626
*/
2727
const fetchDatasetResults = async (ds, request, query) => {
2828
try {
29-
const response = await fetch(request.url, request.options)
29+
const response = await fetch(request)
3030

3131
if (!response.ok) {
3232
console.error(`Fetch error for ${ds.label || 'dataset'}: ${response.status}`)

plugins/search/src/events/fetchSuggestions.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('fetchSuggestions', () => {
3535

3636
const result = await fetchSuggestions('test', datasets, dispatch)
3737

38-
expect(fetch).toHaveBeenCalledWith('/api?q=test', { method: 'GET' })
38+
expect(fetch).toHaveBeenCalledWith({ url: '/api?q=test', options: { method: 'GET' } })
3939
expect(result.results).toEqual(['a', 'b'])
4040
expect(dispatch).toHaveBeenCalledWith({
4141
type: 'UPDATE_SUGGESTIONS',
@@ -77,7 +77,7 @@ describe('fetchSuggestions', () => {
7777

7878
const result = await fetchSuggestions('abc', datasets, dispatch)
7979

80-
expect(fetch).toHaveBeenCalledWith('/custom/abc', { method: 'POST' })
80+
expect(fetch).toHaveBeenCalledWith({ url: '/custom/abc', options: { method: 'POST' } })
8181
expect(result.results).toEqual(['y'])
8282
})
8383

@@ -101,7 +101,7 @@ describe('fetchSuggestions', () => {
101101

102102
await fetchSuggestions('x', datasets, dispatch, transformRequest)
103103

104-
expect(fetch).toHaveBeenCalledWith('/t?q=x', { method: 'PUT' })
104+
expect(fetch).toHaveBeenCalledWith({ url: '/t?q=x', options: { method: 'PUT' } })
105105
})
106106

107107
test('handles fetch HTTP error', async () => {
@@ -206,7 +206,7 @@ describe('fetchSuggestions', () => {
206206

207207
const result = await fetchSuggestions('hi', datasets, dispatch)
208208

209-
expect(fetch).toHaveBeenCalledWith('/default?q=hi', { method: 'GET' })
209+
expect(fetch).toHaveBeenCalledWith({ url: '/default?q=hi', options: { method: 'GET' } })
210210
expect(result.results).toEqual(['ok'])
211211
})
212212
})

plugins/search/src/search.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,14 @@
8484
opacity: 0;
8585
z-index: -1;
8686
}
87-
.im-o-app__inset .im-c-panel {
88-
opacity: 0;
89-
z-index: -1;
87+
.im-o-app__left-top,
88+
.im-o-app__left-bottom,
89+
.im-o-app__right-top,
90+
.im-o-app__right-bottom {
91+
.im-c-panel {
92+
opacity: 0;
93+
z-index: -1;
94+
}
9095
}
9196
}
9297

src/App/components/Panel/Panel.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
display: flex;
1515
flex-direction: column;
1616
max-height: 100vh;
17+
min-height: 0;
1718
min-width: var(--min-panel-width);
1819
pointer-events: auto;
1920
background-color: var(--background-color);

src/App/hooks/useLayoutMeasurements.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ const topColWidth = (left, right) =>
1212
const subSlotMaxHeight = (columnHeight, siblingButtons, gap) =>
1313
columnHeight - (siblingButtons ? siblingButtons + gap : 0)
1414

15-
const calcOffsetLeft = (bottomOffsetTop, gap, insetBottom, inset) =>
16-
bottomOffsetTop - gap > insetBottom ? 0 : inset.offsetLeft + inset.offsetWidth
17-
1815
export function useLayoutMeasurements () {
1916
const { dispatch, breakpoint, layoutRefs } = useApp()
2017
const { mapSize, isMapReady } = useMap()
@@ -26,7 +23,6 @@ export function useLayoutMeasurements () {
2623
topRef,
2724
topLeftColRef,
2825
topRightColRef,
29-
insetRef,
3026
footerRef,
3127
actionsRef,
3228
leftTopRef,
@@ -44,11 +40,9 @@ export function useLayoutMeasurements () {
4440
const top = topRef.current
4541
const topLeftCol = topLeftColRef.current
4642
const topRightCol = topRightColRef.current
47-
const inset = insetRef.current
4843
const bottom = footerRef.current
49-
const actions = actionsRef.current
5044

51-
if ([main, top, inset, bottom].some(r => !r)) {
45+
if ([main, top, bottom].some(r => !r)) {
5246
return
5347
}
5448

@@ -77,9 +71,6 @@ export function useLayoutMeasurements () {
7771
appContainer.style.setProperty('--left-bottom-panel-max-height', `${subSlotMaxHeight(leftColumnHeight, buttonHeight(leftTopRef), dividerGap)}px`)
7872
appContainer.style.setProperty('--right-top-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightBottomRef), dividerGap)}px`)
7973
appContainer.style.setProperty('--right-bottom-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightTopRef), dividerGap)}px`)
80-
81-
// === Bottom left offset ===
82-
appContainer.style.setProperty('--offset-left', `${calcOffsetLeft(Math.min(bottom.offsetTop, actions.offsetTop), dividerGap, inset.offsetHeight + leftOffsetTop, inset)}px`)
8374
}
8475

8576
// --------------------------------

src/App/hooks/useLayoutMeasurements.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const refs = (o = {}) => ({
2424
topRef: { current: o.top === null ? null : el({ offsetTop: 10, ...o.top }) },
2525
topLeftColRef: { current: el({ offsetHeight: 50, offsetWidth: 200, ...o.topLeftCol }) },
2626
topRightColRef: { current: el({ offsetHeight: 40, offsetWidth: 180, ...o.topRightCol }) },
27-
insetRef: { current: o.inset === null ? null : el({ offsetHeight: 100, offsetLeft: 20, offsetWidth: 300, ...o.inset }) },
2827
footerRef: { current: o.footer === null ? null : el({ offsetTop: 400, ...o.footer }) },
2928
actionsRef: { current: el({ offsetTop: 450, ...o.actions }) },
3029
leftTopRef: { current: el({ offsetHeight: 0, ...o.leftTop }) },
@@ -57,7 +56,7 @@ describe('useLayoutMeasurements', () => {
5756
})
5857

5958
test('early return when required refs are null', () => {
60-
const { layoutRefs } = setup({ refs: { main: null, top: null, inset: null, footer: null } })
59+
const { layoutRefs } = setup({ refs: { main: null, top: null, footer: null } })
6160
renderHook(() => useLayoutMeasurements())
6261
expect(layoutRefs.appContainerRef.current.style.setProperty).not.toHaveBeenCalled()
6362
})
@@ -66,13 +65,11 @@ describe('useLayoutMeasurements', () => {
6665
const { layoutRefs } = setup()
6766
renderHook(() => useLayoutMeasurements())
6867
const spy = layoutRefs.appContainerRef.current.style.setProperty
69-
;['--offset-left', '--right-offset-top', '--right-offset-bottom', '--top-col-width']
68+
;['--right-offset-top', '--right-offset-bottom', '--top-col-width']
7069
.forEach(prop => expect(spy).toHaveBeenCalledWith(prop, expect.any(String)))
7170
})
7271

7372
test.each([
74-
['offset-left with overlap', { inset: { offsetHeight: 200, offsetLeft: 30, offsetWidth: 150 }, footer: { offsetTop: 100 }, actions: { offsetTop: 120 }, topLeftCol: { offsetHeight: 50 }, top: { offsetTop: 10 } }, '180px'],
75-
['offset-left without overlap', { inset: { offsetHeight: 50, offsetLeft: 30, offsetWidth: 150 }, footer: { offsetTop: 200 }, actions: { offsetTop: 220 }, topLeftCol: { offsetHeight: 50 }, top: { offsetTop: 10 } }, '0px'],
7673
['right-offset-top', { topRightCol: { offsetHeight: 80 }, top: { offsetTop: 15 } }, '95px'],
7774
['right-offset-bottom', { main: { offsetHeight: 600 }, footer: { offsetTop: 500 } }, '108px'],
7875
// leftColumnHeight = 400 - (50+10) - 8 = 332; rightColumnHeight = 400 - (40+10) - 8 = 342

src/App/hooks/useVisibleGeometry.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ export const getPointCoordinates = (geojson) => {
3131
return null
3232
}
3333

34-
const SLOT_REFS = {
35-
inset: 'insetRef',
36-
bottom: 'bottomRef',
37-
side: 'sideRef'
38-
}
39-
4034
export const useVisibleGeometry = () => {
41-
const { mapProvider, eventBus } = useConfig()
35+
const { id, mapProvider, eventBus } = useConfig()
4236
const { layoutRefs, panelConfig, panelRegistry, breakpoint } = useApp()
4337

4438
const latestRef = useRef({ layoutRefs, panelConfig, panelRegistry, breakpoint })
@@ -49,22 +43,22 @@ export const useVisibleGeometry = () => {
4943
return undefined
5044
}
5145

52-
const handlePanelOpened = ({ panelId, slot: eventSlot, visibleGeometry: eventVisibleGeometry }) => {
53-
const { panelConfig: config, panelRegistry: registry, layoutRefs: refs, breakpoint: bp } = latestRef.current
46+
const handlePanelOpened = ({ panelId, visibleGeometry: eventVisibleGeometry }) => {
47+
const { panelConfig: config, panelRegistry: registry } = latestRef.current
5448
const resolvedConfig = config?.[panelId] ? config : (registry?.getPanelConfig() ?? config)
5549
const visibleGeometry = eventVisibleGeometry ?? resolvedConfig?.[panelId]?.visibleGeometry
56-
const slot = eventSlot ?? resolvedConfig?.[panelId]?.[bp]?.slot
57-
const slotRef = refs[SLOT_REFS[slot]]
50+
const panel = layoutRefs.appContainerRef.current?.querySelector(`#${id}-panel-${panelId}`)
5851

59-
if (!visibleGeometry || !slotRef) {
52+
if (!visibleGeometry) {
6053
return
6154
}
6255
if (typeof mapProvider.isGeometryObscured !== 'function') {
6356
return
6457
}
6558

6659
const waitForPanel = () => {
67-
const panelRect = slotRef.current?.getBoundingClientRect()
60+
if (!panel) { return }
61+
const panelRect = panel.getBoundingClientRect()
6862

6963
if (!panelRect || panelRect.width === 0 || panelRect.height === 0) {
7064
// Not ready yet, check on the next animation frame

0 commit comments

Comments
 (0)