Skip to content

Commit

Permalink
[FEAT-5438]: fixes for tonen objecten lijstweergave (#2767)
Browse files Browse the repository at this point in the history
* Fixes

Stop flickering when reverse address search gets new address.
Put a delay on icon list on click handler. Capitalize assetlist titles.
Change drawer top position logic.
Fix scroll, rearrange DrawerOverlay.tsx, resize icon list image.
Add padding objecten title for desktop.
Add paddings and fit scrollbar.
Change pdokInput.
  • Loading branch information
OscarBakker authored Nov 29, 2023
1 parent 8a6c4d8 commit d3a433b
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 78 deletions.
3 changes: 1 addition & 2 deletions src/components/DrawerOverlay/DrawerOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Drawer,
DrawerContainer,
DrawerContent,
DrawerContentWrapper,
DrawerHandleDesktop,
DrawerHandleMiniDesktop,
DrawerHandleMobile,
Expand Down Expand Up @@ -115,7 +114,7 @@ export const DrawerOverlay = ({
)}

<DrawerContent style={drawerContentStyle} data-testid="drawerContent">
<DrawerContentWrapper>{children}</DrawerContentWrapper>
{children}
</DrawerContent>
</Drawer>
</DrawerContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DrawerOverlay/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const DrawerContent = styled.div`
flex-grow: 1;
max-width: 100%;
min-height: 0;
overflow-y: auto;
height: 100%;
@media screen and ${breakpoint('min-width', 'tabletM')} {
width: ${MENU_WIDTH}px;
Expand Down
36 changes: 35 additions & 1 deletion src/components/IconList/IconList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2021 - 2022 Gemeente Amsterdam
import { render, screen } from '@testing-library/react'
import { act, render, screen } from '@testing-library/react'

import type configurationType from 'shared/services/configuration/__mocks__/configuration'
import configuration from 'shared/services/configuration/configuration'
Expand All @@ -13,9 +13,14 @@ jest.mock('shared/services/configuration/configuration')
const mockConfiguration = configuration as typeof configurationType

describe('IconList', () => {
beforeEach(() => {
jest.useFakeTimers()
})
afterEach(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
mockConfiguration.__reset()

jest.useRealTimers()
})

it('renders correctly', () => {
Expand All @@ -40,4 +45,33 @@ describe('IconList', () => {
expect(screen.getByRole('list')).toBeInTheDocument()
expect(screen.queryAllByRole('listitem').length).toBe(0)
})

it('click checkbox', () => {
const onClickMock = jest.fn()
render(
withAppContext(
<IconList>
<IconListItem
iconUrl=""
item={{
id: '1',
name: 'test',
featureStatusType: 'test',
}}
onClick={onClickMock}
>
Icon
</IconListItem>
</IconList>
)
)

screen.getByRole('checkbox').click()

act(() => {
jest.runAllTimers()
})

expect(onClickMock).toHaveBeenCalledTimes(1)
})
})
75 changes: 49 additions & 26 deletions src/components/IconList/IconList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2021-2023 Gemeente Amsterdam
import type { ReactNode } from 'react'
import { useCallback, useState } from 'react'

import { List } from '@amsterdam/asc-ui'
import styled from 'styled-components'
Expand All @@ -20,10 +21,10 @@ export interface IconListItemProps {
iconSize?: number
featureStatusType?: FeatureStatusType
children: ReactNode
remove?: (item: Item) => void
onClick?: (item: Item) => void
item?: Item
checked?: boolean
checkboxDisabled?: boolean
checked?: boolean
}

export const IconListItem = ({
Expand All @@ -33,32 +34,54 @@ export const IconListItem = ({
iconSize = 40,
id,
featureStatusType,
remove,
onClick,
item,
checked,
checkboxDisabled,
}: IconListItemProps) => (
<StyledListItem data-testid={id} className={className}>
{!checkboxDisabled && (
<Checkbox
onClick={() => remove && item && remove(item)}
checked={checked}
/>
)}
{iconUrl && (
<StyledImg alt="" height={iconSize} src={iconUrl} width={iconSize} />
)}
{featureStatusType && (
<StatusIcon
alt=""
height={20}
src={featureStatusType.icon.iconUrl}
width={20}
/>
)}
{children}
</StyledListItem>
)
checked,
}: IconListItemProps) => {
const [checkedState, setCheckedState] = useState<boolean | undefined>(
undefined
)
const [disabled, setDisabled] = useState<boolean>(false)

const onClickWithDelay = useCallback(
(item) => {
if (onClick && !disabled) {
setDisabled(true)
setCheckedState(!checked)
const timeout = setTimeout(() => {
onClick(item)
setDisabled(false)
}, 600)
return () => clearTimeout(timeout)
}
},
[checked, disabled, onClick]
)

return (
<StyledListItem data-testid={id} className={className}>
{!checkboxDisabled && (
<Checkbox
onClick={() => onClickWithDelay(item)}
checked={checkedState === undefined ? checked : checkedState}
/>
)}
{iconUrl && (
<StyledImg alt="" height={iconSize} src={iconUrl} width={iconSize} />
)}
{featureStatusType && (
<StatusIcon
alt=""
height={20}
src={featureStatusType.icon.iconUrl}
width={20}
/>
)}
{children}
</StyledListItem>
)
}

const StyledList = styled(List)`
margin: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/IconList/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const StyledListItem = styled(ListItem)`
padding: 0;
${Checkbox} {
margin-right: ${themeSpacing(0.5)};
cursor: pointer;
}
`

export const StyledImg = styled.img`
margin-right: ${themeSpacing(2)};
flex-shrink: 0;
`

Expand Down
37 changes: 20 additions & 17 deletions src/signals/IncidentMap/components/IncidentMap/IncidentMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
StyledViewerContainer,
TopLeftWrapper,
Wrapper,
DrawerContentWrapper,
} from './styled'
import usePaginatedIncidents from './usePaginatedIncidents'
import { getFlyToZoom } from './utils'
Expand Down Expand Up @@ -227,24 +228,26 @@ export const IncidentMap = () => {
incident={selectedIncident}
DetailPanel={DetailPanel}
>
<StyledParagraph>
Op deze kaart staan meldingen in de openbare ruimte waarmee we aan
het werk zijn. Vanwege privacy staat een klein deel van de meldingen
niet op de kaart.
</StyledParagraph>

{!isMobile(deviceMode) && (
<AddressLocation
setCoordinates={setCoordinates}
address={address}
<DrawerContentWrapper>
<StyledParagraph>
Op deze kaart staan meldingen in de openbare ruimte waarmee we aan
het werk zijn. Vanwege privacy staat een klein deel van de
meldingen niet op de kaart.
</StyledParagraph>

{!isMobile(deviceMode) && (
<AddressLocation
setCoordinates={setCoordinates}
address={address}
/>
)}

<FilterPanel
filters={filters}
setFilters={setFilters}
setMapMessage={setMapMessage}
/>
)}

<FilterPanel
filters={filters}
setFilters={setFilters}
setMapMessage={setMapMessage}
/>
</DrawerContentWrapper>
</DrawerOverlay>

<StyledViewerContainer
Expand Down
11 changes: 11 additions & 0 deletions src/signals/IncidentMap/components/IncidentMap/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,14 @@ export const StyledViewerContainer = styled(ViewerContainer)<{
margin-left: ${themeSpacing(4)};
}
`

export const DrawerContentWrapper = styled('div')`
width: 100%;
height: 100%;
padding: ${themeSpacing(5)};
overflow-y: auto;
@media screen and ${breakpoint('max-width', 'tabletM')} {
padding-top: 0;
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jest.mock('components/IconList/IconList', () => ({
iconUrl,
featureStatusType,
id,
onClick,
...props
}: PropsWithChildren<IconListItemProps>) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { FunctionComponent } from 'react'
import type { FeatureCollection } from 'geojson'

import IconList from 'components/IconList/IconList'
import { capitalize } from 'shared/services/date-utils'

import { AssetListItem } from './AssetListItem'
import { AssetListItemSelectable } from './AssetListItemSelectable'
Expand Down Expand Up @@ -51,10 +52,12 @@ const AssetList: FunctionComponent<AssetListProps> = ({
(zoomLevel && zoomLevel >= 13) || (selection && selection.length > 0)

return (
<div>
<>
{renderAssetListHeading && (
<>
<ListHeading>{objectTypePlural || 'Objecten'}</ListHeading>
<ListHeading>
{(objectTypePlural && capitalize(objectTypePlural)) || 'Objecten'}
</ListHeading>
{featureTypes.length > 0 &&
!(
(selectableComponents && selectableComponents?.length > 0) ||
Expand All @@ -75,20 +78,20 @@ const AssetList: FunctionComponent<AssetListProps> = ({
selection.length > 0 &&
selection
.filter(({ id }) => id)
.map((item, index) => (
.map((item) => (
<AssetListItem
key={index}
key={item.id}
item={item}
featureTypes={featureTypes}
featureStatusTypes={featureStatusTypes}
remove={() => remove && remove(item)}
remove={remove}
/>
))}
{Array.isArray(selectableComponents) &&
selectableComponents.length > 0 &&
selectableComponents}
</IconList>
</div>
</>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const AssetListItem: FunctionComponent<ItemType> = ({
id={extendedId}
iconUrl={icon?.iconUrl}
featureStatusType={featureStatusType}
remove={remove}
onClick={remove}
item={item}
checked
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const AssetListItemSelectable = ({
id={`${id}`}
iconUrl={icon?.iconUrl}
featureStatusType={featureStatusType}
remove={onClick}
onClick={onClick}
item={item}
checked={false}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, themeColor, themeSpacing } from '@amsterdam/asc-ui'
import { breakpoint, Button, themeColor, themeSpacing } from '@amsterdam/asc-ui'
import styled from 'styled-components'

import { FeatureStatus } from '../../types'
Expand Down Expand Up @@ -35,7 +35,12 @@ export const SelectionNearby = styled.div`

export const ListHeading = styled.p`
font-weight: 700;
margin-top: 0;
margin-bottom: ${themeSpacing(2)};
@media only screen and ${breakpoint('min-width', 'tabletM')} {
margin-top: ${themeSpacing(4)};
}
`

export const ListDescription = styled.p`
Expand Down
Loading

0 comments on commit d3a433b

Please sign in to comment.