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

Feat: show list of features inside Asset Select #100

Merged
merged 30 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9a6615b
Feat: show list of features inside Asset Select
justiandevs Nov 11, 2024
103d05e
Feat: show icons per feature, show error if more than maxSelectedFeat…
justiandevs Nov 12, 2024
bff8e16
todo: add comment
justiandevs Nov 12, 2024
19f1d12
Feat: add language fields in MapDialog for AssetSelect
justiandevs Nov 12, 2024
278f5d2
Fix: use <Icon> component wrapping <img> tag
justiandevs Nov 12, 2024
3effecc
Feat: show list of all features in view (AssetSelect) sync changes be…
justiandevs Nov 13, 2024
fc499fc
Feat: fly to selected asset when toggled in FeatureList
justiandevs Nov 13, 2024
e8b16fb
Fix: try to fix slowness
justiandevs Nov 13, 2024
0fefeb4
Fix: try to fix slowness
justiandevs Nov 14, 2024
253bbb4
refactor: remove featureIds set, moved everything to selectedFeatures…
justiandevs Nov 14, 2024
2d29e10
refactor: move set feature description to MapDialog
justiandevs Nov 14, 2024
b2d8d9c
Merge remote-tracking branch 'origin/main' into feat/7-asset-select
justiandevs Nov 18, 2024
18335b1
feat: submit selected features to API
justiandevs Nov 18, 2024
924240c
Feat: show selected features in basic Asset Select viewer step 2, kee…
justiandevs Nov 18, 2024
a47b8ad
refactor: remove old TODO comments
justiandevs Nov 18, 2024
dbac39e
feat: use flag "minimal_zoom" in config.json for minimal zoom level t…
justiandevs Nov 18, 2024
6dbd3da
feat: use flag "minimal_zoom" in config.json for minimal zoom level t…
justiandevs Nov 18, 2024
1286e61
Feat: show alert dialog if not enough zoomed in
justiandevs Nov 18, 2024
01c4486
Merge remote-tracking branch 'origin/main' into feat/7-asset-select
justiandevs Nov 18, 2024
3909c18
Feat: support multiple feature sorts
justiandevs Nov 19, 2024
a73ac16
fix: change scroll class
iehkaatee Nov 19, 2024
965c9ee
Fix: bug when maxFeatures is not set in field config
justiandevs Nov 19, 2024
e8c5480
Merge remote-tracking branch 'origin/feat/7-asset-select' into feat/7…
justiandevs Nov 19, 2024
063b44c
Fix: show shortLabel in admin interface if shortLabel exists on field
justiandevs Nov 19, 2024
4c32f71
Fix: don't require address
justiandevs Nov 19, 2024
0b77308
Refactor: rename value to checked
justiandevs Nov 19, 2024
55f2851
Refactor: move initialisation of index constance to else block
justiandevs Nov 19, 2024
f3f6f21
Refactor: add comments to make service and utils more clear
justiandevs Nov 19, 2024
09e5b76
Refactor: made comment more clear, about what useEffect in AssetSelec…
justiandevs Nov 19, 2024
cae0fef
Refactor: remove unneccessary code
justiandevs Nov 19, 2024
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
14 changes: 8 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"base": {
"municipality": "purmerend",
"assets_url": "https://meldingen.demo.meierijstad.delta10.cloud",
"style": {
"primaryColor": "#24578f"
},
"map": {
"find_address_in_distance": 30,
"minimal_zoom": 17,
"center": [
52.3731081,
4.8932945
51.6045656,
5.5342026
],
"maxBounds": [
[
4.8339104,
52.4703485
3.31497114423,
50.803721015
],
[
5.0247001,
52.6141075
7.09205325687,
53.5104033474
]
]
},
Expand Down
116 changes: 116 additions & 0 deletions src/app/[locale]/incident/add/components/FeatureListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { Dispatch, RefObject, SetStateAction, useMemo } from 'react'
import { getFeatureType } from '@/lib/utils/map'
import { Feature, FeatureCollection } from 'geojson'
import { PublicQuestion } from '@/types/form'
import { MapRef } from 'react-map-gl/maplibre'
import { FormField, FormFieldCheckbox, Icon } from '@/components/index'
import { useTranslations } from 'next-intl'
import { FeatureWithDescription } from '@/types/map'
import { useFormStore } from '@/store/form_store'

type FeatureListItemProps = {
feature: FeatureWithDescription
field: PublicQuestion
map: MapRef | undefined
setError: Dispatch<SetStateAction<string | null>>
dialogRef: RefObject<HTMLDialogElement>
configUrl?: string
}

export const FeatureListItem = ({
feature,
field,
map,
setError,
dialogRef,
configUrl,
}: FeatureListItemProps) => {
const t = useTranslations('describe-add.map')
const { formState, updateForm } = useFormStore()

const featureId = feature.id
const featureDescription = feature.description
const maxNumberOfAssets = field
? field.meta.maxNumberOfAssets
? field.meta.maxNumberOfAssets
: 1
: 1

// Get feature type of asset
const featureType = useMemo(() => {
return getFeatureType(field.meta.featureTypes, feature.properties)
}, [field.meta.featureTypes, feature.properties])

// Add or remove feature to / from the newSelectedFeature state declared in DialogMap
const addOrRemoveFeature = (checked: boolean) => {
const newSelectedFeatureArray = Array.from(
formState.selectedFeatures ? formState.selectedFeatures : []
)

if (checked) {
if (newSelectedFeatureArray.length >= maxNumberOfAssets) {
setError(t('max_number_of_assets_error', { max: maxNumberOfAssets }))
dialogRef.current?.showModal()

return
}

newSelectedFeatureArray.push(feature)

if (map && feature && feature.geometry) {
map.flyTo({
center: [
// @ts-ignore
feature.geometry.coordinates[0],
// @ts-ignore
feature.geometry.coordinates[1],
],
speed: 0.5,
zoom: 18,
})
}
} else {
const index = newSelectedFeatureArray.findIndex(
(feature) => feature.id === featureId
)

newSelectedFeatureArray.splice(index, 1) // Remove the feature at the found index
}

updateForm({
...formState,
selectedFeatures: newSelectedFeatureArray,
})
}

// TODO: iets van een label toevoegen zodat voor een SR duidelijk wordt om welke lantaarnpaal, adres etc het gaat?
return featureDescription ? (
<li className="py-4 border-t border-gray-200">
<FormField className="flex flex-row items-center gap-2">
{!formState.selectedFeatures.some(
(featureItem) => featureItem.id === featureId
) ? (
<Icon>
<img src={featureType?.icon.iconUrl} />
justiandevs marked this conversation as resolved.
Show resolved Hide resolved
</Icon>
justiandevs marked this conversation as resolved.
Show resolved Hide resolved
) : (
<Icon>
<img
src={configUrl + '/assets/images/feature-selected-marker.svg'}
/>
</Icon>
)}
<FormFieldCheckbox
label={featureDescription}
className="!mt-1"
checked={formState.selectedFeatures.some(
(featureItem) => featureItem.id === featureId
)}
id={featureId.toString()}
// @ts-ignore
onChange={(e) => addOrRemoveFeature(e.target.checked)}
/>
</FormField>
</li>
) : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ export const IncidentQuestionsLocationForm = () => {
? id.filter((value: any) => value !== false && value !== 'empty')
: []

// If checkboxAnswers has a length, map over them to return a list of answer objects
const answer =
checkboxAnswers.length > 0
const isFeature = checkboxAnswers.some(
(answer: any) => answer.type === 'Feature'
)

// If checkboxAnswers has a length, map over them to return a list of answer objects. If isFeature return list of already made answers
const answer = isFeature
? checkboxAnswers
: checkboxAnswers.length > 0
? checkboxAnswers.map((answerId) => ({
id: answerId,
label: question.meta.values[answerId],
Expand All @@ -102,7 +107,9 @@ export const IncidentQuestionsLocationForm = () => {

return {
id: question.key,
label: question.meta.label,
label: question.meta.shortLabel
? question.meta.shortLabel
: question.meta.label,
category_url: `/signals/v1/public/terms/categories/${formStoreState.sub_category}/sub_categories/${formStoreState.main_category}`,
answer,
}
Expand Down
Loading