Skip to content

Commit

Permalink
Merge pull request #7322 from TheThingsNetwork/fix/console-redesign-i…
Browse files Browse the repository at this point in the history
…ssues

Fix console redesign issues
  • Loading branch information
PavelJankoski authored Oct 10, 2024
2 parents b16c4c1 + 017e134 commit 569c2cc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions pkg/webui/components/link/link.styl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
&:visited
color: var(--c-text-neutral-heavy)

// stylelint-disable declaration-no-important
&:disabled
cursor: not-allowed !important
background: transparent
Expand Down
28 changes: 21 additions & 7 deletions pkg/webui/components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import React, { useEffect } from 'react'
import React, { useEffect, useState } from 'react'
import {
MapContainer,
Marker,
Expand Down Expand Up @@ -108,6 +108,7 @@ const MarkerRenderer = ({ marker }) => {

const Controller = ({ onClick, centerOnMarkers, markers, bounds }) => {
const map = useMap()
const [useManualZoom, setUseManualZoom] = useState(false)

useEffect(() => {
const handleWheel = e => {
Expand All @@ -118,23 +119,36 @@ const Controller = ({ onClick, centerOnMarkers, markers, bounds }) => {
const zoomLevel = map.getZoom() - delta // Calculate the new zoom level

map.setZoom(zoomLevel)
setUseManualZoom(true) // Mark user interaction
}
}

const handleUserInteracted = () => {
setUseManualZoom(true) // Mark user interaction on zoom
}

// Ensure the map resizes correctly when the container changes size
map.invalidateSize()

map.getContainer().addEventListener('wheel', handleWheel)
map.on('zoomend', handleUserInteracted)
map.on('moveend', handleUserInteracted)

return () => {
map.getContainer().removeEventListener('wheel', handleWheel)
map.off('zoomend', handleUserInteracted)
map.off('moveend', handleUserInteracted)
}
}, [map])

useEffect(() => {
if (centerOnMarkers && markers.length > 1 && !useManualZoom) {
map.fitBounds(bounds, { padding: [50, 50], maxZoom: 14 })
}
}, [map, centerOnMarkers, markers, bounds, useManualZoom])

useMapEvent('click', onClick)
// Fix incomplete tile loading in some rare cases.
map.invalidateSize()
// Attach click handler.
if (centerOnMarkers && markers.length > 1) {
map.fitBounds(bounds, { padding: [50, 50], maxZoom: 14 })
}

return markers.map(marker => (
<MarkerRenderer
key={`${marker.position.latitude}-${marker.position.longitude}`}
Expand Down
9 changes: 6 additions & 3 deletions pkg/webui/components/scroll-fader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import React, { useCallback, useEffect, useRef } from 'react'
import React, { useCallback, useLayoutEffect, useRef } from 'react'
import classnames from 'classnames'

import PropTypes from '@ttn-lw/lib/prop-types'
Expand Down Expand Up @@ -49,18 +49,21 @@ const ScrollFader = React.forwardRef(
}
}, [fadeHeight])

useEffect(() => {
useLayoutEffect(() => {
const container = internalRef.current
if (!container) return

// Perform initial fader calculation
handleScroll()

// Observe mutations in the DOM to recalculate faders if content changes
const mutationObserver = new MutationObserver(() => {
handleScroll()
})

// Run the calculation whenever the children change.
mutationObserver.observe(container, { attributes: false, childList: true, subtree: true })

handleScroll() // Call once on mount if needed
container.addEventListener('scroll', handleScroll)
window.addEventListener('resize', handleScroll)

Expand Down
2 changes: 1 addition & 1 deletion pkg/webui/components/table/tabular.styl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

.container
overflow: visible
overflow: auto
scrollbar-width: none

.pagination
Expand Down
34 changes: 18 additions & 16 deletions pkg/webui/console/containers/sidebar/sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
left: 0
height: 100vh
sidebar-transition(left)
// Stylus has trouble adding multiple properties to a function
// so we have to overwrite it like this.
transition-property: left, width
+media-query-min($bp.xl)
// Stylus has trouble adding multiple properties to a function
// so we have to overwrite it like this.
transition-property: left, width
+media-query($bp.xxl)
--sidebar-width: 22rem
+media-query($bp.lg-xl)
Expand Down Expand Up @@ -60,18 +61,19 @@
z-index: $zi.mobile-menu - 1
cursor: pointer

&-minimized
position: absolute
top: 3.8rem
left: calc(-1 * var(--sidebar-width))
bottom: 0
height: calc(100vh - 3.8rem)
z-index: $zi.mobile-menu
+media-query-min($bp.lg-xl)
&-minimized
position: absolute
top: 3.8rem
left: calc(-1 * var(--sidebar-width))
bottom: 0
height: calc(100vh - 3.8rem)
z-index: $zi.mobile-menu

&-open&.sidebar-minimized
left: 0
box-shadow: 0 0 2rem 0 rgba(0,0,0,.05)
&-open&.sidebar-minimized
left: 0
box-shadow: 0 0 2rem 0 rgba(0,0,0,.05)

& + .sidebar-backdrop
opacity: .05
visibility: visible
& + .sidebar-backdrop
opacity: .05
visibility: visible

0 comments on commit 569c2cc

Please sign in to comment.