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

[PAP] merge prio1 with ip adresses #3016

Merged
merged 1 commit into from
Jun 14, 2024
Merged
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
104 changes: 41 additions & 63 deletions src/components/DTD/DTDAddressMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BadgeCircle = styled('span')({
height: '10px',
})

const colors = ['#919EAB', '#EF000E', '#FF912B', '#FFC90A', '#29A6FF']
const colors = ['#919EAB', '#EF000E', '#FF912B', '#FFC90A']

const filterButtons = [
{
Expand All @@ -54,11 +54,6 @@ const filterButtons = [
value: 3,
badge: colors[3],
},
{
label: 'IP',
value: 100,
badge: colors[4],
},
{
label: 'Non prioritaire',
value: -1,
Expand All @@ -76,43 +71,38 @@ const DTDAddressMap = ({ userScope }) => {
const { handleError } = useErrorHandler()

const zoneCode = userScope.isAnimator() ? userScope.getAttributes()?.dpt : userScope.zones[0].code
const isNational = userScope.isNational()

const getFilter = useCallback(
(zoneCode, activePriority = null) => {
const filter = []
const getFilter = useCallback((zoneCode, activePriority = null) => {
const filter = []

if (zoneCode !== 'FR') {
filter.push(['==', ['get', 'dpt'], zoneCode.substring(0, 2)])
}
if (zoneCode !== 'FR') {
filter.push(['==', ['get', 'dpt'], zoneCode.substring(0, 2)])
}

if (activePriority) {
if (activePriority === -1) {
filter.push(['all', ['!', ['has', 'score']], ...(isNational ? [['!', ['has', 'ip_score']]] : [])])
} else if (activePriority === 100 && isNational) {
filter.push(['has', 'ip_score'])
} else {
filter.push([activePriority < 3 ? '==' : '>=', ['get', 'score'], activePriority])
}
if (activePriority) {
if (activePriority === -1) {
filter.push(['all', ['!', ['has', 'score']], ['!', ['has', 'ip_score']]])
} else if (activePriority === 1) {
filter.push(['any', ['==', ['get', 'score'], 1], ['has', 'ip_score']])
} else {
filter.push([activePriority < 3 ? '==' : '>=', ['get', 'score'], activePriority])
}
}

if (filter.length) {
return ['all', ...filter]
}
if (filter.length) {
return ['all', ...filter]
}

return null
},
[isNational]
)
return null
}, [])

const handlePriorityChange = priority => {
setActivePriority(priority)
map.current.setFilter('layer-addresses', getFilter(zoneCode, priority))
}

const onMapReady = useCallback(() => {
const ipPoint = ['has', 'ip_score']
const prio1 = ['==', ['get', 'score'], 1]
const prio1 = ['any', ['==', ['get', 'score'], 1], ['has', 'ip_score']]
const prio2 = ['==', ['get', 'score'], 2]
const prio3 = ['>=', ['to-number', ['get', 'score']], 3]

Expand All @@ -132,18 +122,8 @@ const DTDAddressMap = ({ userScope }) => {
...(filter ? { filter } : {}),
'circle-sort-key': ['case', ['has', 'score'], 100, ['has', 'ip_score'], 100, 0],
paint: {
'circle-color': [
'case',
...(isNational ? [ipPoint, colors[4]] : []),
prio1,
colors[1],
prio2,
colors[2],
prio3,
colors[3],
colors[0],
],
'circle-opacity': ['case', ['has', 'score'], 1, ...(isNational ? [['has', 'ip_score'], 1] : []), 0.6],
'circle-color': ['case', prio1, colors[1], prio2, colors[2], prio3, colors[3], colors[0]],
'circle-opacity': ['case', ['any', ['has', 'score'], ['has', 'ip_score']], 1, 0.6],
'circle-stroke-color': '#fff',
'circle-stroke-width': 1,
},
Expand All @@ -166,7 +146,7 @@ const DTDAddressMap = ({ userScope }) => {
}),
'top-right'
)
}, [zoneCode, isNational, getFilter])
}, [zoneCode, getFilter])

useEffect(() => {
map.current = createMap(mapContainer.current)
Expand Down Expand Up @@ -229,26 +209,24 @@ const DTDAddressMap = ({ userScope }) => {
<Grid container>
<Grid item xs={12}>
<Box sx={{ display: 'flex' }} gap={1}>
{filterButtons
.filter(filter => isNational || filter.value !== 100)
.map(({ label, value, badge }) => (
<UIChip
key={label}
label={
badge ? (
<Box component="span" sx={{ display: 'flex', alignItems: 'center' }} gap={0.5}>
<BadgeCircle sx={{ backgroundColor: badge }} /> {label}
</Box>
) : (
label
)
}
color="#0369a1"
bgcolor={activePriority === value ? '#f0f9ff' : '#fff'}
sx={{ cursor: 'pointer' }}
onClick={() => handlePriorityChange(value)}
/>
))}
{filterButtons.map(({ label, value, badge }) => (
<UIChip
key={label}
label={
badge ? (
<Box component="span" sx={{ display: 'flex', alignItems: 'center' }} gap={0.5}>
<BadgeCircle sx={{ backgroundColor: badge }} /> {label}
</Box>
) : (
label
)
}
color="#0369a1"
bgcolor={activePriority === value ? '#f0f9ff' : '#fff'}
sx={{ cursor: 'pointer' }}
onClick={() => handlePriorityChange(value)}
/>
))}
</Box>
</Grid>
<Grid item xs={12}>
Expand Down
Loading