Skip to content

Commit

Permalink
feat(vehicles): Add operator to lookup screen (#16119)
Browse files Browse the repository at this point in the history
* Add operator to lookup screen

* Markup fix

* Update operator on vehicle search

* Fix

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thordurhhh and kodiakhq[bot] authored Sep 30, 2024
1 parent 2197961 commit 29a1854
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Field, ObjectType } from '@nestjs/graphql'
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql'

export enum OperatorAnonymityStatus {
ALL = 'all',
SOME = 'some',
UNKNOWN = 'unknown',
}

registerEnumType(OperatorAnonymityStatus, { name: 'OperatorAnonymityStatus' })

@ObjectType()
export class VehiclesVehicleSearchNextInspection {
Expand Down Expand Up @@ -76,4 +84,16 @@ export class VehiclesVehicleSearch {

@Field(() => Boolean, { nullable: true })
canRegisterMileage?: boolean | null

@Field({ nullable: true })
engine?: string

@Field(() => [String], {
nullable: true,
description: 'Basic operator array, names only.',
})
operatorNames?: string[]

@Field(() => OperatorAnonymityStatus)
operatorAnonymityStatus!: OperatorAnonymityStatus
}
28 changes: 24 additions & 4 deletions libs/api/domains/vehicles/src/lib/services/vehicles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
BasicVehicleInformationGetRequest,
PublicVehicleSearchApi,
VehicleDtoListPagedResponse,
VehicleSearchDto,
PersidnoLookupResultDto,
CurrentVehiclesWithMilageAndNextInspDtoListPagedResponse,
} from '@island.is/clients/vehicles'
Expand Down Expand Up @@ -38,6 +37,8 @@ import { VehicleMileageOverview } from '../models/getVehicleMileage.model'
import isSameDay from 'date-fns/isSameDay'
import { mileageDetailConstructor } from '../utils/helpers'
import { handle404 } from '@island.is/clients/middlewares'
import { VehicleSearchCustomDto } from '../vehicles.type'
import { operatorStatusMapper } from '../utils/operatorStatusMapper'
import { VehiclesListInputV3 } from '../dto/vehiclesListInputV3'
import { VehiclesCurrentListResponse } from '../models/v3/currentVehicleListResponse.model'
import { isDefined } from '@island.is/shared/utils'
Expand Down Expand Up @@ -301,13 +302,32 @@ export class VehiclesService {
async getVehiclesSearch(
auth: User,
search: string,
): Promise<VehicleSearchDto | null> {
): Promise<VehicleSearchCustomDto | null> {
const res = await this.getVehiclesWithAuth(auth).vehicleSearchGet({
search,
})
const { data } = res
if (!data) return null
return data[0]
if (!data || !data.length) return null

const vehicle = data[0]

const operatorNames = vehicle.operators
?.map((operator) => operator.fullname)
.filter(isDefined)

const operatorAnonymityStatus = operatorStatusMapper(
operatorNames,
!!vehicle.allOperatorsAreAnonymous,
!!vehicle.someOperatorsAreAnonymous,
)

return {
...data[0],

operatorNames:
operatorNames && operatorNames.length ? operatorNames : undefined,
operatorAnonymityStatus,
}
}

async getVehicleMileage(
Expand Down
17 changes: 17 additions & 0 deletions libs/api/domains/vehicles/src/lib/utils/operatorStatusMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { OperatorAnonymityStatus } from '../models/getVehicleSearch.model'

export const operatorStatusMapper = (
names: string[] | undefined | null,
allOperatorsAreAnonymous: boolean,
someOperatorsAreAnonymous: boolean,
): OperatorAnonymityStatus => {
if (allOperatorsAreAnonymous) {
return OperatorAnonymityStatus.ALL
}

if (someOperatorsAreAnonymous && names?.length) {
return OperatorAnonymityStatus.SOME
}

return OperatorAnonymityStatus.UNKNOWN
}
11 changes: 11 additions & 0 deletions libs/api/domains/vehicles/src/lib/vehicles.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VehicleSearchDto } from '@island.is/clients/vehicles'
import { OperatorAnonymityStatus } from './models/getVehicleSearch.model'

export interface VehicleSearchOperatorDto {
operatorNames?: Array<string> | null
operatorAnonymityStatus?: OperatorAnonymityStatus
}

export interface VehicleSearchCustomDto
extends VehicleSearchDto,
VehicleSearchOperatorDto {}
56 changes: 56 additions & 0 deletions libs/clients/vehicles/src/clientConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3381,6 +3381,62 @@
},
"requiresMileageRegistration": {
"type": "boolean"
},
"operators": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VehicleSearchOperatorDto"
},
"nullable": true
},
"engine": {
"type": "string",
"nullable": true
},
"allOperatorsAreAnonymous": {
"type": "boolean"
},
"someOperatorsAreAnonymous": {
"type": "boolean"
}
},
"additionalProperties": false
},
"VehicleSearchOperatorDto": {
"type": "object",
"properties": {
"mainoperator": {
"type": "boolean",
"nullable": true
},
"startdate": {
"type": "string",
"format": "date-time"
},
"enddate": {
"type": "string",
"format": "date-time",
"nullable": true
},
"persidno": {
"type": "string",
"nullable": true
},
"fullname": {
"type": "string",
"nullable": true
},
"address": {
"type": "string",
"nullable": true
},
"postalcode": {
"type": "string",
"nullable": true
},
"city": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
Expand Down
44 changes: 44 additions & 0 deletions libs/service-portal/assets/src/components/LookupOperator/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import { Box, Text } from '@island.is/island-ui/core'
import { useLocale, useNamespaces } from '@island.is/localization'

import { vehicleMessage as messages } from '../../lib/messages'
import { OperatorAnonymityStatus } from '@island.is/api/schema'

interface PropTypes {
names?: string[]
operatorAnonymityStatus?: OperatorAnonymityStatus
}

const LookupOperator = ({ names, operatorAnonymityStatus }: PropTypes) => {
useNamespaces('sp.vehicles')
const { formatMessage } = useLocale()

if (operatorAnonymityStatus === OperatorAnonymityStatus.ALL) {
return <span>{formatMessage(messages.anonymous)}</span>
}

if (names?.length) {
return (
<div>
{names?.map((name, i) => (
<React.Fragment key={i}>
{i + 1}. {name}
<br />
</React.Fragment>
))}
{operatorAnonymityStatus === OperatorAnonymityStatus.SOME ? (
<Box marginTop={1}>
<Text variant="small">
{formatMessage(messages.anonymousPartial)}
</Text>
</Box>
) : undefined}
</div>
)
}

return ''
}

export default LookupOperator
8 changes: 8 additions & 0 deletions libs/service-portal/assets/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ export const vehicleMessage = defineMessages({
id: 'sp.vehicles:name',
defaultMessage: 'Nafn',
},
anonymous: {
id: 'sp.vehicles:anonymous',
defaultMessage: 'Nafnlaus',
},
anonymousPartial: {
id: 'sp.vehicles:anonymous-partial',
defaultMessage: 'Hluti umráðamanna er nafnlaus',
},
nationalId: {
id: 'sp.vehicles:national-id',
defaultMessage: 'Kennitala',
Expand Down
3 changes: 3 additions & 0 deletions libs/service-portal/assets/src/screens/Lookup/Lookup.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ query GetVehiclesSearch($input: GetVehicleSearchInput!) {
co
co2Wltp
weightedco2Wltp
engine
operatorNames
operatorAnonymityStatus
}
}

Expand Down
25 changes: 23 additions & 2 deletions libs/service-portal/assets/src/screens/Lookup/Lookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
m,
TableGrid,
formatDate,
ErrorScreen,
ExcludesFalse,
FootNote,
SAMGONGUSTOFA_SLUG,
Expand All @@ -31,6 +30,8 @@ import {
useGetVehiclesSearchLazyQuery,
} from './Lookup.generated'
import { Problem } from '@island.is/react-spa/shared'
import LookupOperator from '../../components/LookupOperator'
import { OperatorAnonymityStatus } from '@island.is/api/schema'

const Lookup = () => {
useNamespaces('sp.vehicles')
Expand Down Expand Up @@ -78,9 +79,11 @@ const Lookup = () => {
mass,
massLaden,
vehicleStatus,
co,
co2Wltp,
weightedco2Wltp,
operatorNames,
engine,
operatorAnonymityStatus,
} = vehicleSearch.data?.vehiclesSearch || {}

const noInfo =
Expand Down Expand Up @@ -114,6 +117,8 @@ const Lookup = () => {

const limit = searchLimitData?.data?.vehiclesSearchLimit || 0
const limitExceeded = limit === 0
const operatorNamesArray =
operatorNames && operatorNames?.length > 0 ? operatorNames : []

return (
<>
Expand Down Expand Up @@ -320,6 +325,22 @@ const Lookup = () => {
title: formatMessage(messages.weightedWLTPCo2),
value: String(weightedco2Wltp),
},
engine && {
title: formatMessage(messages.engineType),
value: engine,
},
operatorAnonymityStatus === OperatorAnonymityStatus.ALL ||
operatorNamesArray.length > 0
? {
title: formatMessage(messages.operator),
value: (
<LookupOperator
names={operatorNamesArray}
operatorAnonymityStatus={operatorAnonymityStatus}
/>
),
}
: undefined,
].filter(Boolean as unknown as ExcludesFalse),
2,
)}
Expand Down
14 changes: 11 additions & 3 deletions libs/service-portal/core/src/components/TableGrid/TableGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tableStyles } from '../../utils/utils'

interface TableItem {
title: string
value: string
value: string | React.ReactNode
detail?: string
}

Expand Down Expand Up @@ -46,7 +46,7 @@ export const TableGrid: FC<React.PropsWithChildren<Props>> = ({
colSpan={2}
style={tableStyles}
>
<Columns collapseBelow="lg" space={2}>
<Columns alignY="center" collapseBelow="lg" space={2}>
<Column>
<Text
title={rowitem.detail}
Expand All @@ -58,7 +58,15 @@ export const TableGrid: FC<React.PropsWithChildren<Props>> = ({
</Text>
</Column>
<Column>
<Text variant="medium" title={rowitem.detail}>
<Text
as={
typeof rowitem.value === 'string'
? undefined
: 'span'
}
variant="medium"
title={rowitem.detail}
>
{rowitem.value}
</Text>
</Column>
Expand Down

0 comments on commit 29a1854

Please sign in to comment.