Skip to content
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

[Tech] Fixe les problèmes de style après suppression de mini.css #2722

Merged
merged 12 commits into from
Dec 1, 2023
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { memo, useCallback, useEffect, useRef, useState } from 'react'
import styled from 'styled-components'

import { RegulatoryZone } from './RegulatoryZone'
Expand Down Expand Up @@ -73,12 +73,6 @@ function UnmemoizedRegulatoryTopic({
const onMouseEnter = () => !isOver && setIsOver(true)
const onMouseLeave = () => isOver && setIsOver(false)

useLayoutEffect(() => {
if (ref.current && regulatoryTopicsOpened[regulatoryTopicsOpened.length - 1] === regulatoryTopic) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Attention à ce changement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On n'a plus cette fonctonnalité de scroll ? C'était ce qui causait le bandeau blanc ?

Copy link
Member Author

@ivangabriele ivangabriele Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est en effet ça qui produit un blanc. J'ai expérimenté de le mettre dans un setTimeout que j'ai même monté jusqu'à 250 et ça ne changeait rien. Je pense que ça a un rapport avec le temps d'animation d'ouverture de la liste des couches mais je n'en suis pas sûr. Sur Env aussi c'était un soucis de scoll mais le fix est différent (et Env n'a pas d'animation d'ouverture je crois) : MTES-MCT/monitorenv#993.

ref.current.scrollIntoView({ block: 'start', inline: 'nearest' })
}
}, [regulatoryTopic, regulatoryTopicsOpened])

useEffect(() => {
if (showedLayers && regulatoryTopic) {
const topicFoundInShowedLayers = showedLayers.some(layer => layer.topic === regulatoryTopic)
Expand Down Expand Up @@ -217,32 +211,32 @@ const Text = styled.span`
`

const Name = styled.span`
line-height: 2.7em;
display: inline-block;
font-size: 13px;
line-height: 2.7em;
overflow: hidden;
padding: 2px 10px;
width: 79%;
display: inline-block;
text-overflow: ellipsis;
overflow: hidden;
width: 79%;
`

const ZonesNumber = styled.span`
font-size: 11px;
color: ${COLORS.slateGray};
font-size: 11px;
margin-right: 10px;
`

const Zone = styled.span<{
$isLastItem: boolean
$isOpen: boolean
}>`
width: 100%;
align-items: center;
border-bottom: 1px solid ${p => (!p.$isOpen && p.$isLastItem ? p.theme.color.white : p.theme.color.lightGray)};
display: flex;
font-weight: 500;
justify-content: space-between;
align-items: center;
user-select: none;
font-weight: 500;
${p => (!p.$isOpen && p.$isLastItem ? null : `border-bottom: 1px solid ${p.theme.color.lightGray};`)}
width: 100%;

:hover {
background: ${p => p.theme.color.blueGray25};
Expand All @@ -259,20 +253,18 @@ const List = styled.div<{
`

const Row = styled.li`
padding: 0px 5px 0px 0px;
margin: 0;
cursor: pointer;
display: block;
font-size: 13px;
text-align: left;
line-height: 1.9em;
list-style-type: none;
width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden !important;
cursor: pointer;

margin: 0;
line-height: 1.9em;
display: block;
overflow: hidden !important;
padding: 0px 5px 0px 0px;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
`

export const RegulatoryTopic = memo(UnmemoizedRegulatoryTopic)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function RegulatoryZones({
const dispatch = useMainAppDispatch()
const { setLayersSideBarOpenedLayerType } = layer[namespace].actions

const { selectedRegulatoryLayers } = useMainAppSelector(state => state.regulatory)
const selectedRegulatoryLayers = useMainAppSelector(state => state.regulatory.selectedRegulatoryLayers)
const advancedSearchIsOpen = useMainAppSelector(state => state.regulatoryLayerSearch.advancedSearchIsOpen)

const { layersSidebarOpenedLayerType } = useMainAppSelector(state => state.layer)
Expand Down Expand Up @@ -100,27 +100,23 @@ export function RegulatoryZones({
>
Mes zones réglementaires <ChevronIcon $isOpen={showRegulatoryLayers} />
</RegulatoryLayersTitle>
{selectedRegulatoryLayers && (
{selectedRegulatoryLayers && isOpen && (
<RegulatoryLayersList $advancedSearchIsOpen={advancedSearchIsOpen} className="smooth-scroll">
{isOpen && (
<>
{Object.keys(selectedRegulatoryLayers).length > 0 ? (
Object.keys(selectedRegulatoryLayers).map((regulatoryTopic, index) => (
<RegulatoryTopic
key={regulatoryTopic}
allowRemoveZone
isEditable={false}
isLastItem={Object.keys(selectedRegulatoryLayers).length === index + 1}
onRemoveById={removeById}
onRemoveByTopic={removeByTopic}
regulatoryTopic={regulatoryTopic}
regulatoryZones={selectedRegulatoryLayers[regulatoryTopic]}
/>
))
) : (
<NoLayerSelected>Aucune zone sélectionnée</NoLayerSelected>
)}
</>
{Object.keys(selectedRegulatoryLayers).length > 0 ? (
Object.keys(selectedRegulatoryLayers).map((regulatoryTopic, index) => (
<RegulatoryTopic
key={regulatoryTopic}
allowRemoveZone
isEditable={false}
isLastItem={Object.keys(selectedRegulatoryLayers).length === index + 1}
onRemoveById={removeById}
onRemoveByTopic={removeByTopic}
regulatoryTopic={regulatoryTopic}
regulatoryZones={selectedRegulatoryLayers[regulatoryTopic]}
/>
))
) : (
<NoLayerSelected>Aucune zone sélectionnée</NoLayerSelected>
)}
</RegulatoryLayersList>
)}
Expand All @@ -138,16 +134,21 @@ const RegulatoryLayersTitle = styled.div<{
$regulatoryLayersAddedToMySelection: boolean
$showRegulatoryLayers: boolean
}>`
height: 30px;
padding-top: 5px;
animation: ${p => (p.$regulatoryLayersAddedToMySelection ? 'blink' : '')} 0.3s ease forwards;
background: ${p => p.theme.color.charcoal};
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
border-top-left-radius: 2px;
border-top-right-radius: 2px;
border-bottom-left-radius: ${p => (p.$showRegulatoryLayers ? '0' : '2px')};
border-bottom-right-radius: ${p => (p.$showRegulatoryLayers ? '0' : '2px')};
background: ${p => p.theme.color.charcoal};

animation: ${p => (p.$regulatoryLayersAddedToMySelection ? 'blink' : '')} 0.3s ease forwards;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
color: ${p => p.theme.color.gainsboro};
cursor: pointer;
font-size: 16px;
height: 30px;
padding-left: 20px;
padding-top: 5px;
text-align: left;
user-select: none;

@keyframes blink {
0% {
Expand All @@ -170,13 +171,6 @@ const RegulatoryLayersTitle = styled.div<{
}
}

color: ${p => p.theme.color.gainsboro};
font-size: 16px;
cursor: pointer;
text-align: left;
padding-left: 20px;
user-select: none;

> div {
float: right;
margin-top: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function UnmemoizedRegulatoryLayerSearchResultTopic({
}: RegulatoryLayerSearchResultTopicProps) {
const dispatch = useMainAppDispatch()

const regulatory = useMainAppSelector(state => state.regulatory)
const selectedRegulatoryLayers = useMainAppSelector(state => state.regulatory.selectedRegulatoryLayers)
const regulatoryLayerSearch = useMainAppSelector(state => state.regulatoryLayerSearch)

const { regulatoryZonesChecked, searchResultZones, searchResultZonesLength } = useMemo<{
Expand Down Expand Up @@ -63,21 +63,21 @@ function UnmemoizedRegulatoryLayerSearchResultTopic({
}, [regulatoryLayerSearch, regulatoryLayerLawType, regulatoryLayerTopic])

const numberOfTotalZones = useMemo(() => {
if (!regulatory.selectedRegulatoryLayers || !regulatoryLayerLawType || !regulatoryLayerTopic) {
if (!selectedRegulatoryLayers || !regulatoryLayerLawType || !regulatoryLayerTopic) {
return 0
}

const regulatoryLayer = regulatory.selectedRegulatoryLayers[regulatoryLayerLawType]
const regulatoryLayer = selectedRegulatoryLayers[regulatoryLayerLawType]
if (!regulatoryLayer) {
return 0
}

return regulatoryLayer[regulatoryLayerTopic]?.length || 0
}, [regulatory, regulatoryLayerLawType, regulatoryLayerTopic])
}, [regulatoryLayerLawType, regulatoryLayerTopic, selectedRegulatoryLayers])

const allZonesAreAlreadySelected =
regulatory.selectedRegulatoryLayers && regulatoryLayerTopic
? regulatory.selectedRegulatoryLayers[regulatoryLayerTopic]?.length === searchResultZonesLength
selectedRegulatoryLayers && regulatoryLayerTopic
? selectedRegulatoryLayers[regulatoryLayerTopic]?.length === searchResultZonesLength
: false

const [zonesAreOpen, setZonesAreOpen] = useState(false)
Expand Down Expand Up @@ -128,9 +128,9 @@ function UnmemoizedRegulatoryLayerSearchResultTopic({
<Checkbox
key={regulatoryLayerTopic}
disabled={
(regulatory.selectedRegulatoryLayers &&
(selectedRegulatoryLayers &&
regulatoryLayerTopic &&
regulatory.selectedRegulatoryLayers[regulatoryLayerTopic]?.length === searchResultZonesLength) ||
selectedRegulatoryLayers[regulatoryLayerTopic]?.length === searchResultZonesLength) ||
false
}
title={allZonesAreAlreadySelected ? 'zones déjà ajoutées à mes zones réglementaires' : ''}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import { Checkbox, CheckboxGroup } from 'rsuite'
import styled, { css } from 'styled-components'

Expand All @@ -24,8 +24,9 @@ export function RegulatoryLayerSearchResultZone({ isOpen, regulatoryZone }: Regu
const zoneIsChecked = useMainAppSelector(
state => !!state.regulatoryLayerSearch.regulatoryZonesChecked?.find(zone => zone.id === regulatoryZone.id)
)
const zoneIsAlreadySelected = useMainAppSelector(state => {
const { selectedRegulatoryLayers } = state.regulatory
const selectedRegulatoryLayers = useMainAppSelector(state => state.regulatory.selectedRegulatoryLayers)

const zoneIsAlreadySelected = useMemo(() => {
if (!selectedRegulatoryLayers) {
return false
}
Expand All @@ -36,7 +37,7 @@ export function RegulatoryLayerSearchResultZone({ isOpen, regulatoryZone }: Regu
}

return selectedRegulatoryLayersZone.find(zone => zone.id === regulatoryZone.id)
})
}, [regulatoryZone.id, regulatoryZone.topic, selectedRegulatoryLayers])

const zoneStyle = getRegulatoryLayerStyle(undefined, regulatoryZone)
const [metadataIsShown, setMetadataIsShown] = useState(false)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/Regulation/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ const regulatorySlice = createSlice({
*/
addRegulatoryZonesToMyLayers(state, action) {
const myRegulatoryLayers = { ...state.selectedRegulatoryLayers }
// TODO Use Redux Persist.
const myRegulatoryLayerIds = getLocalStorageState([], SELECTED_REG_ZONES_IDS_LOCAL_STORAGE_KEY)

// TODO Make that functional.
action.payload.forEach(regulatoryZone => {
const myTopicRegulatoryLayer = myRegulatoryLayers[regulatoryZone.topic]

if (!myTopicRegulatoryLayer || !myTopicRegulatoryLayer.length) {
// TODO Make that functional.
myRegulatoryLayers[regulatoryZone.topic] = [regulatoryZone]
} else if (myTopicRegulatoryLayer && !myTopicRegulatoryLayer.some(zone => zone.id === regulatoryZone.id)) {
// TODO Make that functional.
myRegulatoryLayers[regulatoryZone.topic] = myTopicRegulatoryLayer.concat(regulatoryZone)
}

Expand Down
Loading