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

[Tableau de bord] Correction d'un défaut de marge des panneaux (AMP, zones reg, ZDV) au changement d'onglet #1792

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function Amps({

return (
<div>
{openPanel && <StyledPanel $marginLeft={columnWidth ?? 0} layerId={openPanel.id} />}
{openPanel && !!columnWidth && <StyledPanel $marginLeft={columnWidth} layerId={openPanel.id} />}
<Accordion isExpanded={isExpanded} setExpandedAccordion={setExpandedAccordion} title="Zones AMP">
<StyledLayerList
$baseLayersLength={Object.values(ampsByLayerName).length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function DashboardForm({ dashboardForm: [key, dashboard], isActive }: Das

const { data: controlUnits } = useGetControlUnitsQuery(undefined, RTK_DEFAULT_QUERY_OPTIONS)
const activeControlUnits = useMemo(() => controlUnits?.filter(isNotArchived), [controlUnits])
const [firstColumnWidth, setFirstColumnWidth] = useState<number | undefined>(undefined)

const firstColumnRef = useRef<HTMLDivElement>(null)
const firstColumnWidth = firstColumnRef.current?.clientWidth ?? 0

const toolbarRef = useRef<HTMLDivElement>(null)
const toolbarHeight = toolbarRef.current?.clientHeight ?? 0
Expand Down Expand Up @@ -70,6 +70,12 @@ export function DashboardForm({ dashboardForm: [key, dashboard], isActive }: Das
}
}

useEffect(() => {
if (isActive) {
setFirstColumnWidth(firstColumnRef.current?.clientWidth)
}
}, [isActive])

useEffect(() => {
// remove openedPanel on mount
dispatch(dashboardActions.setDashboardPanel())
Expand Down Expand Up @@ -98,7 +104,7 @@ export function DashboardForm({ dashboardForm: [key, dashboard], isActive }: Das
<Container>
<Column ref={firstColumnRef} $filterHeight={toolbarHeight}>
<RegulatoryAreas
columnWidth={firstColumnWidth}
columnWidth={firstColumnWidth ?? 0}
isExpanded={expandedAccordionFirstColumn === Dashboard.Block.REGULATORY_AREAS}
isSelectedAccordionOpen={previewSelectionFilter}
regulatoryAreas={dashboard.extractedArea?.regulatoryAreas}
Expand All @@ -108,14 +114,14 @@ export function DashboardForm({ dashboardForm: [key, dashboard], isActive }: Das

<Amps
amps={dashboard.extractedArea?.amps}
columnWidth={firstColumnWidth}
columnWidth={firstColumnWidth ?? 0}
isExpanded={expandedAccordionFirstColumn === Dashboard.Block.AMP}
isSelectedAccordionOpen={previewSelectionFilter}
selectedAmpIds={dashboard.dashboard.amps}
setExpandedAccordion={() => handleAccordionClick(Dashboard.Block.AMP)}
/>
<VigilanceAreas
columnWidth={firstColumnWidth}
columnWidth={firstColumnWidth ?? 0}
isExpanded={expandedAccordionFirstColumn === Dashboard.Block.VIGILANCE_AREAS}
isSelectedAccordionOpen={previewSelectionFilter}
selectedVigilanceAreaIds={dashboard.dashboard.vigilanceAreas}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function RegulatoryAreas({

return (
<div>
{openPanel && <StyledPanel $marginLeft={columnWidth ?? 0} layerId={openPanel.id} />}
{openPanel && !!columnWidth && <StyledPanel $marginLeft={columnWidth} layerId={openPanel.id} />}

<Accordion isExpanded={isExpanded} setExpandedAccordion={setExpandedAccordion} title="Zones réglementaires">
<StyledLayerList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function VigilanceAreas({

return (
<div>
{openPanel && <StyledPanel $marginLeft={columnWidth ?? 0} layerId={openPanel.id} />}
{openPanel && !!columnWidth && <StyledPanel $marginLeft={columnWidth} layerId={openPanel.id} />}

<Accordion isExpanded={isExpanded} setExpandedAccordion={setExpandedAccordion} title="Zones de vigilance">
<StyledLayerList
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/features/Dashboard/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export const dashboardSlice = createSlice({

state.dashboards[id].regulatoryIdsToDisplay = []
state.dashboards[id].ampIdsToDisplay = []
state.dashboards[id].reportingToDisplay = undefined
state.dashboards[id].openPanel = undefined
},
removeAllRegulatoryIdToDisplay(state) {
const id = state.activeDashboardId
Expand Down
Loading