Skip to content

Commit

Permalink
Add number of species
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Jun 12, 2024
1 parent 02565e0 commit f75a50e
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package fr.gouv.cnsp.monitorfish.domain.entities.logbook

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonTypeName

@JsonTypeName("catch")
data class LogbookFishingCatch(
var weight: Double? = null,
@JsonProperty("nbFish")
var numberFish: Double? = null,
var nbFish: Double? = null,
/** Species FAO code. */
var species: String? = null,
var speciesName: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class LogbookFishingCatchInput(
fun fromLogbookFishingCatch(logbookFishingCatch: LogbookFishingCatch): LogbookFishingCatchInput {
return LogbookFishingCatchInput(
isIncidentalCatch = false,
quantity = logbookFishingCatch.numberFish,
quantity = logbookFishingCatch.nbFish,
specyCode = requireNotNull(logbookFishingCatch.species),
specyName = requireNotNull(logbookFishingCatch.speciesName),
weight = requireNotNull(logbookFishingCatch.weight),
Expand All @@ -29,7 +29,7 @@ data class LogbookFishingCatchInput(
effortZone = null,
faoZone = null,
freshness = null,
numberFish = quantity,
nbFish = quantity,
packaging = null,
presentation = null,
preservationState = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookFishingCatch

class LogbookMessageCatchDataOutput(
var weight: Double?,
var numberFish: Double?,
var nbFish: Double?,
var species: String?,
var speciesName: String?,
var faoZone: String?,
Expand All @@ -21,7 +21,7 @@ class LogbookMessageCatchDataOutput(
fun fromCatch(catch: LogbookFishingCatch): LogbookMessageCatchDataOutput {
return LogbookMessageCatchDataOutput(
weight = catch.weight,
numberFish = catch.numberFish,
nbFish = catch.nbFish,
species = catch.species,
speciesName = catch.speciesName,
faoZone = catch.faoZone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() {
assertThat(pnoMessage.purpose).isEqualTo("LAN")
assertThat(pnoMessage.catchOnboard).hasSize(4)
assertThat(pnoMessage.catchOnboard.first().weight).isEqualTo(20.0)
assertThat(pnoMessage.catchOnboard.first().numberFish).isEqualTo(null)
assertThat(pnoMessage.catchOnboard.first().nbFish).isEqualTo(null)
assertThat(pnoMessage.catchOnboard.first().species).isEqualTo("SLS")
assertThat(pnoMessage.catchOnboard.first().faoZone).isEqualTo("27.8.a")
assertThat(pnoMessage.catchOnboard.first().effortZone).isEqualTo("C")
assertThat(pnoMessage.catchOnboard.first().economicZone).isEqualTo("FRA")
assertThat(pnoMessage.catchOnboard.first().statisticalRectangle).isEqualTo("23E6")
assertThat(pnoMessage.catchToLand).hasSize(4)
assertThat(pnoMessage.catchToLand.first().weight).isEqualTo(15.0)
assertThat(pnoMessage.catchToLand.first().numberFish).isEqualTo(null)
assertThat(pnoMessage.catchToLand.first().nbFish).isEqualTo(null)
assertThat(pnoMessage.catchToLand.first().species).isEqualTo("SLS")
assertThat(pnoMessage.catchToLand.first().faoZone).isEqualTo("27.8.a")
assertThat(pnoMessage.catchToLand.first().effortZone).isEqualTo("C")
Expand All @@ -278,7 +278,7 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() {
val disMessage = messages[4].message as DIS
assertThat(disMessage.catches).hasSize(2)
assertThat(disMessage.catches.first().weight).isEqualTo(5.0)
assertThat(disMessage.catches.first().numberFish).isEqualTo(1.0)
assertThat(disMessage.catches.first().nbFish).isEqualTo(1.0)
assertThat(disMessage.catches.first().species).isEqualTo("NEP")

// INS
Expand All @@ -299,7 +299,7 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() {

assertThat(farMessageOneCorrectedHaul.catches).hasSize(20)
assertThat(farMessageOneCorrectedHaul.catches.first().weight).isEqualTo(1500.0)
assertThat(farMessageOneCorrectedHaul.catches.first().numberFish).isEqualTo(null)
assertThat(farMessageOneCorrectedHaul.catches.first().nbFish).isEqualTo(null)
assertThat(farMessageOneCorrectedHaul.catches.first().species).isEqualTo("BON")
assertThat(farMessageOneCorrectedHaul.catches.first().faoZone).isEqualTo("27.8.a")
assertThat(farMessageOneCorrectedHaul.catches.first().effortZone).isEqualTo("C")
Expand All @@ -318,7 +318,7 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() {
assertThat(farMessageOneHaul.catchDateTime.toString()).isEqualTo("2019-10-17T11:32Z")
assertThat(farMessageOneHaul.catches).hasSize(4)
assertThat(farMessageOneHaul.catches.first().weight).isEqualTo(1500.0)
assertThat(farMessageOneHaul.catches.first().numberFish).isEqualTo(null)
assertThat(farMessageOneHaul.catches.first().nbFish).isEqualTo(null)
assertThat(farMessageOneHaul.catches.first().species).isEqualTo("BON")
assertThat(farMessageOneHaul.catches.first().faoZone).isEqualTo("27.8.a")
assertThat(farMessageOneHaul.catches.first().effortZone).isEqualTo("C")
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/Logbook/Logbook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type LogbookCatch = {
effortZone: string | null
faoZone: string | null
freshness: string | null
numberFish: number | null
nbFish: number | null
packaging: string | null
presentation: string | null
preservationState: string | null
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/Logbook/LogbookMessage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export namespace LogbookMessage {
effortZone: string | undefined
faoZone: string | undefined
freshness: string | undefined
numberFish: number | undefined
nbFish: number | undefined
packaging: string | undefined
presentation: string | undefined
preservationState: string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export function LogbookMessage({
}
case LogbookMessageTypeEnum.PNO.code.toString(): {
if (isLessThanTwelveMetersVessel) {
return 'Préavis (notification de retour au port) – navire sans JPE'
return (
<>
Préavis (notification de retour au port) – <i>navire sans JPE</i>
</>
)
}

return LogbookMessageTypeEnum[logbookMessage.messageType].fullName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useGetGearsQuery } from '@api/gear'
import { PriorNotification } from '@features/PriorNotification/PriorNotification.types'
import { FlatKeyValue } from '@features/VesselSidebar/common/FlatKeyValue'
import { uniq } from 'lodash'
Expand All @@ -19,6 +20,20 @@ type PNOMessageProps = Readonly<{
tripGears: Gear[] | undefined
}>
export function PNOMessage({ isLessThanTwelveMetersVessel, message, tripGears }: PNOMessageProps) {
const getGearsApiQuery = useGetGearsQuery()

const gearsWithName: Array<Gear> = useMemo(() => {
if (!getGearsApiQuery.data || !tripGears) {
return []
}

return tripGears.map(tripGear => {
const gearName = getGearsApiQuery.data?.find(gear => gear.code === tripGear.gear)?.name || null

return { ...tripGear, gearName }
})
}, [getGearsApiQuery.data, tripGears])

const catchesWithProperties = useMemo(() => {
if (!message?.catchOnboard) {
return []
Expand Down Expand Up @@ -84,7 +99,9 @@ export function PNOMessage({ isLessThanTwelveMetersVessel, message, tripGears }:
column={[
{
key: 'Engins utilisés',
value: tripGears?.map(gear => gear.gear).join(', ')
value: gearsWithName
.map(gear => (gear.gearName ? `${gear.gearName} (${gear.gear})` : gear.gear))
.join(', ')
},
{
key: 'Zones de pêche',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export function SpecyCatch({
<SpecyWeightLabel>Poids total ({weightType})</SpecyWeightLabel>
<SpecyWeightValue>{specyCatch.weight || <NoValue>-</NoValue>} kg</SpecyWeightValue>
</SpecyWeight>
{specyCatch.nbFish > 0 && (
<SpecyWeight title={`${specyCatch.nbFish} pièces`}>
<SpecyWeightLabel>Pc.</SpecyWeightLabel>
<SpecyWeightValue>{specyCatch.nbFish || <NoValue>-</NoValue>}</SpecyWeightValue>
</SpecyWeight>
)}
{isOpenable && <ChevronIcon $isOpen={isOpen} />}
</Title>
<Content $isOpen={isOpen} $isProtectedSpecy={isProtectedSpecy} $length={specyCatch.properties.length || 1}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export type LogbookTripSummary = {
}

export type CatchWithProperties = {
nbFish: number
properties: CatchProperty[]
species: string
speciesName: string | undefined
weight: number
}

export type ProtectedCatchWithProperties = {
nbFish: number
properties: ProtectedSpeciesCatch[]
species: string
speciesName: string | undefined
Expand All @@ -56,6 +58,7 @@ export type CatchProperty = {
economicZone: string | undefined
effortZone: string | undefined
faoZone: string | undefined
nbFish: number | undefined
packaging: string | undefined
presentation: string | undefined
preservationState: string | undefined
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/features/Logbook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function getCatchPropertiesObject(logbookCatch: LogbookCatch): CatchProperty {
economicZone: undefinedize(logbookCatch.economicZone),
effortZone: undefinedize(logbookCatch.effortZone),
faoZone: undefinedize(logbookCatch.faoZone),
nbFish: undefinedize(logbookCatch.nbFish),
packaging: undefinedize(logbookCatch.packaging),
presentation: undefinedize(logbookCatch.presentation),
preservationState: undefinedize(logbookCatch.preservationState),
Expand All @@ -36,6 +37,7 @@ export function buildCatchArray(catches: LogbookCatch[]): CatchWithProperties[]

if (sameSpeciesIndex === NOT_FOUND) {
return accumulator.concat({
nbFish: logbookCatch.nbFish ? logbookCatch.nbFish : 0,
properties: [logbookCatchProperties],
species: logbookCatch.species,
speciesName: undefinedize(logbookCatch.speciesName),
Expand All @@ -46,6 +48,7 @@ export function buildCatchArray(catches: LogbookCatch[]): CatchWithProperties[]
const nextCatch = accumulator[sameSpeciesIndex] as CatchWithProperties
nextCatch.properties = nextCatch.properties.concat(logbookCatchProperties)
nextCatch.weight += logbookCatch.weight ?? 0
nextCatch.nbFish += logbookCatch.nbFish ?? 0

accumulator[sameSpeciesIndex] = nextCatch

Expand All @@ -63,6 +66,7 @@ export function buildProtectedCatchArray(catches: ProtectedSpeciesCatch[]): Prot

if (sameSpeciesIndex === NOT_FOUND) {
return accumulator.concat({
nbFish: logbookCatch.nbFish ? logbookCatch.nbFish : 0,
properties: [logbookCatch],
species: logbookCatch.species,
speciesName: undefinedize(logbookCatch.speciesName),
Expand All @@ -73,6 +77,7 @@ export function buildProtectedCatchArray(catches: ProtectedSpeciesCatch[]): Prot
const nextCatch = accumulator[sameSpeciesIndex] as ProtectedCatchWithProperties
nextCatch.properties = nextCatch.properties.concat(logbookCatch)
nextCatch.weight += logbookCatch.weight ?? 0
nextCatch.nbFish += logbookCatch.nbFish ?? 0

accumulator[sameSpeciesIndex] = nextCatch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function EquipmentResume({ setIsCurrentBeaconMalfunctionDetails }: Beacon
!!selectedVessel?.beacon.loggingDatetimeUtc && getDateTime(selectedVessel.beacon.loggingDatetimeUtc)
}
]}
valueEllipsisedForWidth={100}
/>
<StyledFlatKeyValue
column={[
Expand Down
35 changes: 26 additions & 9 deletions frontend/src/features/VesselSidebar/common/FlatKeyValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ type KeyValue = {
type KeyValueTableProps = {
className?: string | undefined
column: Array<KeyValue>
valueEllipsisedForWidth?: number | undefined
}
export function FlatKeyValue({ className, column }: KeyValueTableProps) {
export function FlatKeyValue({ className, column, valueEllipsisedForWidth }: KeyValueTableProps) {
return (
<Zone className={className}>
<Fields>
<TableBody>
{column.map(({ key, value }) => (
<Field>
<Field key={key}>
<Key>{key}</Key>
{value ? <Value title={value?.toString()}>{value}</Value> : <NoValue>-</NoValue>}
{value ? (
<Value title={value?.toString()} valueEllipsisedForWidth={valueEllipsisedForWidth}>
{value}
</Value>
) : (
<NoValue>-</NoValue>
)}
</Field>
))}
</TableBody>
Expand Down Expand Up @@ -58,16 +65,26 @@ const Key = styled.th`
font-weight: normal;
`

const Value = styled.td`
const Value = styled.td<{
valueEllipsisedForWidth: number | undefined
}>`
color: ${p => p.theme.color.gunMetal};
padding: 1px 5px 5px 5px;
line-height: normal;
text-overflow: ellipsis;
overflow: hidden !important;
white-space: nowrap;
${p => {
if (p.valueEllipsisedForWidth === undefined) {
return null
}
return (
`text-overflow: ellipsis;` +
`overflow: hidden !important;` +
`white-space: nowrap;` +
`max-width: ${p.valueEllipsisedForWidth}px;`
)
}}
height: 19px;
max-width: 100px;
font-weight: 500;
font-weight: 400;
`

const NoValue = styled.td`
Expand Down

0 comments on commit f75a50e

Please sign in to comment.