Skip to content

Commit

Permalink
review: remove useless function and replace null from properties by u…
Browse files Browse the repository at this point in the history
…ndefined
  • Loading branch information
maximeperrault authored and claire2212 committed Dec 6, 2024
1 parent 08d6ea7 commit 74a6474
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 65 deletions.
6 changes: 3 additions & 3 deletions frontend/src/domain/entities/AMPs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export type AMPFromAPI = {
geom: GeoJSON.MultiPolygon
id: number
name: string
ref_reg: string | null
type: string | null
url_legicem: string | null
ref_reg: string | undefined
type: string | undefined
url_legicem: string | undefined
}
export type AMP = AMPFromAPI & { bbox: Extent }

Expand Down
17 changes: 0 additions & 17 deletions frontend/src/domain/entities/administrative.ts

This file was deleted.

10 changes: 0 additions & 10 deletions frontend/src/domain/entities/layers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import type { GeoJSON as GeoJSONType } from '../../types/GeoJSON'
import type { MultiPoint, Point, MultiPolygon, Polygon } from 'ol/geom'
import type Geometry from 'ol/geom/Geometry'

/**
*
* @param {Object} layer
* @param { String } layer.type
* @param { String | null } layer.topic
* @param { String | null } layer.zone
* @returns String
*/
export const getLayerNameNormalized = layer => [layer.type, layer.topic, layer.zone].filter(Boolean).join(':')

export function convertToGeoJSONGeometryObject(feature: Geometry): GeoJSONType.Geometry {
const format = new GeoJSON()

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/entities/layers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { VigilanceArea } from '@features/VigilanceArea/types'
import type { AMPProperties } from 'domain/entities/AMPs'
import type { RegulatoryLayerCompactProperties } from 'domain/entities/regulatory'

export const getTitle = (name?: string | undefined | null) => (name ? `${name?.replace(/[_]/g, ' ')}` : '')
export const getTitle = (name?: string | undefined) => (name ? `${name?.replace(/[_]/g, ' ')}` : '')

type GenericLayerType = AMPProperties | RegulatoryLayerCompactProperties | VigilanceArea.VigilanceAreaProperties

Expand Down
16 changes: 8 additions & 8 deletions frontend/src/domain/entities/semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { InteractionType } from './map/constants'

export type Semaphore = {
administration: string | undefined | null
base: string | undefined | null
department: string | undefined | null
email: string | undefined | null
facade: string | undefined | null
administration: string | undefined
base: string | undefined
department: string | undefined
email: string | undefined
facade: string | undefined
geom: { coordinates: number[]; type: InteractionType.POINT }
id: number
name: string
phoneNumber: string | undefined | null
unit: string | undefined | null
url: string | undefined | null
phoneNumber: string | undefined
unit: string | undefined
url: string | undefined
}
8 changes: 0 additions & 8 deletions frontend/src/domain/types/layer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import type VectorLayer from 'ol/layer/Vector'
import type VectorSource from 'ol/source/Vector'

export type AdministrativeOrRegulatoryLayerIdentity = {
id: string
namespace: string
topic: string | null
type: string
zone: string | null
}

export type LayerToFeatures = {
area: number
center: number[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ListLayerGroup({ groupName, isSelected = false, layerIds, select
data-cy={`dashboard-${isSelected ? 'selected-' : ''}amp-result-group`}
title={groupName}
>
{getTitle(groupName) ?? ''}
{getTitle(groupName)}
</LayerSelector.GroupName>
<LayerSelector.IconGroup>
<LayerSelector.ZonesNumber>{`${layerIds.length}/${totalNumberOfZones}`}</LayerSelector.ZonesNumber>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function ListLayerGroup({
data-cy={`dashboard-${isSelected ? 'selected-' : ''}regulatory-result-group`}
title={groupName}
>
{getTitle(groupName) ?? ''}
{getTitle(groupName)}
</LayerSelector.GroupName>
<LayerSelector.IconGroup>
<LayerSelector.ZonesNumber>{`${layerIds.length}/${totalNumberOfZones}`}</LayerSelector.ZonesNumber>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/InterestPoint/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface InterestPointState {
isEditing: boolean
}

const newInterestPoint = () => ({ coordinates: null, name: null, observations: null, uuid: uuidv4() })
const newInterestPoint = () => ({ coordinates: undefined, name: undefined, observations: undefined, uuid: uuidv4() })

const INITIAL_STATE: InterestPointState = {
currentInterestPoint: newInterestPoint(),
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/InterestPoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export type InterestPoint = {
}

export type NewInterestPoint = {
coordinates: Coordinate | null
coordinates: Coordinate | undefined
feature?: Feature<LineString>
name: string | null
observations: string | null
name: string | undefined
observations: string | undefined
uuid: string
}

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/features/InterestPoint/useCases/updateName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export const updateNameAction =
const { currentInterestPoint }: InterestPointState = getState().interestPoint

if (currentInterestPoint?.name !== name) {
const updatedName = name === undefined ? null : name

const { name: currentName, ...currentInterestPointWithoutName } = currentInterestPoint

dispatch(updateCurrentInterestPoint({ name: updatedName, ...currentInterestPointWithoutName }))
dispatch(updateCurrentInterestPoint({ name, ...currentInterestPointWithoutName }))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ export const updateObservationsAction =
const { currentInterestPoint }: InterestPointState = getState().interestPoint

if (currentInterestPoint?.observations !== observations) {
const updatedObservations = observations === undefined ? null : observations
const { observations: currentObservations, ...currentInterestPointWithoutObservations } = currentInterestPoint

dispatch(
updateCurrentInterestPoint({ observations: updatedObservations, ...currentInterestPointWithoutObservations })
)
dispatch(updateCurrentInterestPoint({ observations, ...currentInterestPointWithoutObservations }))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function MyAMPLayerZone({ amp, isDisplayed }: { amp: AMP; isDisplayed: bo

const handleRemoveZone = () => dispatch(removeAmpZonesFromMyLayers([amp.id]))

const displayedName = getTitle(amp?.type) ?? 'AUNCUN NOM'
const displayedName = getTitle(amp?.type) || 'AUCUN NOM'

const toggleAmpZoneMetadata = () => {
if (metadataIsShown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function RegulatoryLayerZone({ regulatoryZone }: RegulatoryLayerZoneProps

const handleRemoveZone = () => dispatch(removeRegulatoryZonesFromMyLayers([regulatoryZone.id]))

const displayedName = getTitle(regulatoryZone?.entity_name) ?? 'AUNCUN NOM'
const displayedName = getTitle(regulatoryZone?.entity_name) || 'AUCUN NOM'

const toggleRegulatoryZoneMetadata = () => {
if (metadataIsShown) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/layersSelector/utils/MyLayerZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type MyLayerZoneProps = {
removeZone: () => void
showLayer: () => void
toggleZoneMetadata?: () => void
type: string | null
type: string | undefined
}

export function MyLayerZone({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/getDateAsLocalizedString.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function formatDateLabel(dateLabel: string) {
)
}

export function getDateAsLocalizedStringExpanded(date: string | undefined | null) {
export function getDateAsLocalizedStringExpanded(date: string | undefined) {
if (!date || date.trim() === '') {
return undefined
}
Expand All @@ -20,7 +20,7 @@ export function getDateAsLocalizedStringExpanded(date: string | undefined | null
)
}

export function getDateAsLocalizedStringCompact(date: string | undefined | null, withUtc = false) {
export function getDateAsLocalizedStringCompact(date: string | undefined, withUtc = false) {
if (!date || date.trim() === '') {
return undefined
}
Expand Down

0 comments on commit 74a6474

Please sign in to comment.