Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Feb 3, 2025
1 parent 80bcf37 commit e2c341d
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 82 deletions.
2 changes: 1 addition & 1 deletion frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = {
}
},
{
files: ['src/domain/types/*.ts', 'src/domain/**/types.ts', 'src/domain/shared_slices/**/*.ts', 'src/**/slice.ts'],
files: ['src/domain/schemas/*.ts', 'src/domain/**/schemas.ts', 'src/domain/shared_slices/**/*.ts', 'src/**/slice.ts'],
plugins: ['no-null'],
rules: {
'no-param-reassign': 'off'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('BackOffice > Regulation Table > Table', () => {
cy.wait(1000)
})

it('regulatory zones are displayed by layer name and law types', () => {
it('regulatory zones are displayed by layer name and law schemas', () => {
cy.get('[data-cy="backoffice-search-regulation"]').type('dra')
cy.get('[data-cy="Reg. NAMO"]').eq(0).click()
cy.get('[data-cy="backoffice-search-regulation"]').type('{backspace}{backspace}{backspace}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
cy.contains('Créer le préavis').should('be.enabled')
})

it('Should calculate and display manual prior notification fleet segments, risk factor & types', () => {
it('Should calculate and display manual prior notification fleet segments, risk factor & schemas', () => {
// -------------------------------------------------------------------------
// Add

Expand Down Expand Up @@ -402,7 +402,7 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
})
})

it('Should only recalculate manual prior notification fleet segments, risk factor & types when necessary (creation)', () => {
it('Should only recalculate manual prior notification fleet segments, risk factor & schemas when necessary (creation)', () => {
cy.intercept('POST', '/bff/v1/prior_notifications/manual/compute').as('computePriorNotification')
cy.resetCountRequestsByAlias('@computePriorNotification')

Expand Down Expand Up @@ -446,7 +446,7 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
cy.countRequestsByAlias('@computePriorNotification', 1500).should('be.equal', 1)
})

it('Should only recalculate manual prior notification fleet segments, risk factor & types when necessary (edition)', () => {
it('Should only recalculate manual prior notification fleet segments, risk factor & schemas when necessary (edition)', () => {
cy.intercept('POST', '/bff/v1/prior_notifications/manual/compute').as('computePriorNotification')
cy.resetCountRequestsByAlias('@computePriorNotification')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ context('Side Window > Prior Notification List > VesselFilter Bar', () => {
cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)
})

it('Should filter prior notifications by types', () => {
it('Should filter prior notifications by schemas', () => {
openSideWindowPriorNotificationListAsSuperUser()

cy.intercept('GET', `${apiPathBase}*priorNotificationTypes=${encodeURI('Préavis type A,Préavis type C')}*`).as(
Expand Down
2 changes: 1 addition & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/domain/entities/vessel/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO This should be moved to `entities/vessel/mission.types.ts`
// TODO This should be moved to `entities/vessel/mission.schemas.ts`

import type { VesselTrackDepth } from '../vesselTrackDepth'
import type { SelectableVesselTrackDepth } from '@features/Vessel/components/VesselSidebar/actions/TrackRequest/types'
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/domain/types/GeoJSON.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Typescript types for the GeoJSON RFC7946 specification. This is not fully RFC-compliant due to lack of support for
* ranged number data types.
* Typescript schemas for the GeoJSON RFC7946 specification. This is not fully RFC-compliant due to lack of support for
* ranged number data schemas.
*
* See https://tools.ietf.org/html/rfc7946
*/
Expand All @@ -13,13 +13,13 @@ export declare namespace GeoJSON {
export type GeometryType = Geometry['type']

/**
* ...the term "GeoJSON types" refers to nine case-sensitive strings: "Feature", "FeatureCollection", and the
* geometry types listed above.
* ...the term "GeoJSON schemas" refers to nine case-sensitive strings: "Feature", "FeatureCollection", and the
* geometry schemas listed above.
*/
export type GeoJson = Geometry | Feature | FeatureCollection
export type GeoJsonType = GeoJson['type']

// types
// schemas

/**
* A position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and
Expand All @@ -34,7 +34,7 @@ export declare namespace GeoJSON {
export type Record = { [key in string | number]: unknown }

/**
* Properties inherit to all GeoJSON types
* Properties inherit to all GeoJSON schemas
*/
export interface GeometryBase extends Record {
/**
Expand All @@ -55,7 +55,7 @@ export declare namespace GeoJSON {
*/
}

// geometry types
// geometry schemas

export interface Point extends GeometryBase {
/**
Expand Down Expand Up @@ -132,7 +132,7 @@ export declare namespace GeoJSON {
type: 'GeometryCollection'
}

// GeoJSON types
// GeoJSON schemas

export interface Feature<Properties extends Record = Record, Id = string | number> {
/**
Expand Down
1 change: 0 additions & 1 deletion frontend/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// https://vitejs.dev/guide/env-and-mode#intellisense-for-typescript
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly FRONTEND_GEOSERVER_LOCAL_URL: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ListFilter } from './components/PriorNotificationList/types'
import type { Logbook } from '@features/Logbook/Logbook.types'

const COMPUTE_PRIOR_NOTIFICATION_ERROR_MESSAGE =
"Nous n'avons pas pu calculer note de risque, segments ou types pour ce préavis."
"Nous n'avons pas pu calculer note de risque, segments ou schemas pour ce préavis."
const CREATE_PRIOR_NOTIFICATION_ERROR_MESSAGE = "Nous n'avons pas pu créé le préavis."
const DELETE_PRIOR_NOTIFICATION_UPLOAD_ERROR_MESSAGE = "Nous n'avons pas pu supprimer ce document attaché."
const GET_PRIOR_NOTIFICATION_UPLOADS_ERROR_MESSAGE =
Expand All @@ -21,7 +21,7 @@ const GET_PRIOR_NOTIFICATION_SENT_MESSAGES_ERROR_MESSAGE =
const UPDATE_PRIOR_NOTIFICATION_ERROR_MESSAGE = "Nous n'avons pas pu modifier le préavis."
const GET_PRIOR_NOTIFICATION_DETAIL_ERROR_MESSAGE = "Nous n'avons pas pu récupérer le préavis."
const GET_PRIOR_NOTIFICATIONS_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des préavis."
const GET_PRIOR_NOTIFICATION_TYPES_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des types de préavis."
const GET_PRIOR_NOTIFICATION_TYPES_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des schemas de préavis."
const GET_PRIOR_NOTIFICATION_PDF_ERROR_MESSAGE = "Nous n'avons pas pu récupérer le PDF du préavis."
const VERIFY_AND_SEND_PRIOR_NOTIFICATION_ERROR_MESSAGE = "Nous n'avons pas pu vérifier et envoyer le préavis."
const INVALIDATE_PRIOR_NOTIFICATION_ERROR_MESSAGE = "Nous n'avons pas pu invalider et envoyer le préavis."
Expand Down Expand Up @@ -139,7 +139,7 @@ export const priorNotificationApi = monitorfishApi.injectEndpoints({

getPriorNotificationTypes: builder.query<string[], void>({
providesTags: () => [{ type: RtkCacheTagType.PriorNotificationTypes }],
query: () => '/prior_notifications/types',
query: () => '/prior_notifications/schemas',
transformErrorResponse: response => new FrontendApiError(GET_PRIOR_NOTIFICATION_TYPES_ERROR_MESSAGE, response)
}),

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/Regulation/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const regulationSlice = createSlice({
}
},

// TODO Fix these types and find a cleaner way to achieve that. Proposal: pass a partial `RegulatoryZoneDraft` as param and use a "deepMerge" function.
// TODO Fix these schemas and find a cleaner way to achieve that. Proposal: pass a partial `RegulatoryZoneDraft` as param and use a "deepMerge" function.
updateProcessingRegulationByKeyAndSubKey(
state,
action: PayloadAction<{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/Regulation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type TimeInterval = {
to: Date | undefined
}

// TODO It would be safer to use strict array types: `DateRange[]` and `DateAsStringRange[]`.
// TODO It would be safer to use strict array schemas: `DateRange[]` and `DateAsStringRange[]`.
export type FishingPeriod<DateType extends string | Date = string> = {
always: boolean | undefined
annualRecurrence: boolean | undefined
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/Reporting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Infraction } from '../../domain/types/infraction'
import type { PendingAlertValue } from '../Alert/types'
import type { LegacyControlUnit } from '../ControlUnit/legacyControlUnit'

// TODO Move other types into new `Reporting` namespace.
// TODO Move other schemas into new `Reporting` namespace.
export namespace Reporting {
export type Reporting = InfractionSuspicionReporting | ObservationReporting | PendingAlertReporting
export type EditableReporting = InfractionSuspicionReporting | ObservationReporting
Expand Down Expand Up @@ -125,7 +125,7 @@ export type Observation = {
}

type ReportingTypeCharacteristic = {
// TODO It should be useless now that types are discriminated.
// TODO It should be useless now that schemas are discriminated.
code: ReportingType
displayName: string
// TODO This should be named differently to avoid confusion with `ReportingType.INFRACTION_SUSPICION` type.
Expand Down
53 changes: 2 additions & 51 deletions frontend/src/features/Vessel/Vessel.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { PendingAlertValueType } from '@features/Alert/types'
import { ReportingType } from '@features/Reporting/types'
import { z } from 'zod'

import { booleanOrUndefined, numberOrUndefined, stringOrUndefined } from '../../types'
import { numberOrUndefined, stringOrUndefined } from '../../types'

import type { ProducerOrganizationMembership } from '@features/ProducerOrganizationMembership/types'
import type { RiskFactor } from '@features/RiskFactor/types'
import type { VesselLastPositionSchema } from '@features/Vessel/schemas/VesselLastPositionSchema'
import type Feature from 'ol/Feature'
import type LineString from 'ol/geom/LineString'
import type Point from 'ol/geom/Point'
Expand Down Expand Up @@ -155,54 +154,6 @@ export namespace Vessel {
})
export type DeclaredLogbookSpecies = z.infer<typeof DeclaredLogbookSpeciesSchema>

// TODO Check which of these types are nullable or not
export const VesselLastPositionSchema = z.strictObject({
alerts: z.array(z.union([z.nativeEnum(PendingAlertValueType), z.literal('PNO_LAN_WEIGHT_TOLERANCE_ALERT')])),
beaconMalfunctionId: numberOrUndefined,
beaconNumber: numberOrUndefined,
course: numberOrUndefined,
dateTime: z.string(),
departureDateTime: stringOrUndefined,
destination: stringOrUndefined,
detectabilityRiskFactor: numberOrUndefined,
district: stringOrUndefined,
districtCode: stringOrUndefined,
emissionPeriod: numberOrUndefined,
estimatedCurrentLatitude: numberOrUndefined,
estimatedCurrentLongitude: numberOrUndefined,
externalReferenceNumber: stringOrUndefined,
flagState: z.string(),
from: stringOrUndefined,
gearOnboard: z.array(DeclaredLogbookGearSchema),
impactRiskFactor: numberOrUndefined,
internalReferenceNumber: stringOrUndefined,
ircs: stringOrUndefined,
isAtPort: booleanOrUndefined,
lastControlDateTime: stringOrUndefined,
lastControlInfraction: booleanOrUndefined,
lastLogbookMessageDateTime: stringOrUndefined,
latitude: z.number(),
length: numberOrUndefined,
longitude: z.number(),
mmsi: stringOrUndefined,
positionType: z.string(),
postControlComment: stringOrUndefined,
probabilityRiskFactor: numberOrUndefined,
registryPortLocode: stringOrUndefined,
registryPortName: stringOrUndefined,
reportings: z.array(z.nativeEnum(ReportingType)),
riskFactor: numberOrUndefined,
segments: z.array(z.string()),
speciesOnboard: z.array(DeclaredLogbookSpeciesSchema),
speed: numberOrUndefined,
totalWeightOnboard: numberOrUndefined,
tripNumber: stringOrUndefined,
underCharter: booleanOrUndefined,
vesselId: numberOrUndefined,
vesselIdentifier: z.nativeEnum(VesselIdentifier),
vesselName: stringOrUndefined,
width: numberOrUndefined
})
export type VesselLastPosition = z.infer<typeof VesselLastPositionSchema>

export type VesselPosition = {
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/features/Vessel/schemas/VesselLastPositionSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PendingAlertValueType } from '@features/Alert/types'
import { ReportingType } from '@features/Reporting/types'
import { Vessel } from '@features/Vessel/Vessel.types'
import { z } from 'zod'

import { booleanOrUndefined, numberOrUndefined, stringOrUndefined } from '../../../types'

import DeclaredLogbookSpeciesSchema = Vessel.DeclaredLogbookSpeciesSchema
import DeclaredLogbookGearSchema = Vessel.DeclaredLogbookGearSchema
import VesselIdentifier = Vessel.VesselIdentifier

// TODO Check which of these schemas are nullable or not
export const VesselLastPositionSchema = z.strictObject({
alerts: z.array(z.union([z.nativeEnum(PendingAlertValueType), z.literal('PNO_LAN_WEIGHT_TOLERANCE_ALERT')])),
beaconMalfunctionId: numberOrUndefined,
beaconNumber: numberOrUndefined,
course: numberOrUndefined,
dateTime: z.string(),
departureDateTime: stringOrUndefined,
destination: stringOrUndefined,
detectabilityRiskFactor: numberOrUndefined,
district: stringOrUndefined,
districtCode: stringOrUndefined,
emissionPeriod: numberOrUndefined,
estimatedCurrentLatitude: numberOrUndefined,
estimatedCurrentLongitude: numberOrUndefined,
externalReferenceNumber: stringOrUndefined,
flagState: z.string(),
from: stringOrUndefined,
gearOnboard: z.array(DeclaredLogbookGearSchema),
impactRiskFactor: numberOrUndefined,
internalReferenceNumber: stringOrUndefined,
ircs: stringOrUndefined,
isAtPort: booleanOrUndefined,
lastControlDateTime: stringOrUndefined,
lastControlInfraction: booleanOrUndefined,
lastLogbookMessageDateTime: stringOrUndefined,
latitude: z.number(),
length: numberOrUndefined,
longitude: z.number(),
mmsi: stringOrUndefined,
positionType: z.string(),
postControlComment: stringOrUndefined,
probabilityRiskFactor: numberOrUndefined,
registryPortLocode: stringOrUndefined,
registryPortName: stringOrUndefined,
reportings: z.array(z.nativeEnum(ReportingType)),
riskFactor: numberOrUndefined,
segments: z.array(z.string()),
speciesOnboard: z.array(DeclaredLogbookSpeciesSchema),
speed: numberOrUndefined,
totalWeightOnboard: numberOrUndefined,
tripNumber: stringOrUndefined,
underCharter: booleanOrUndefined,
vesselId: numberOrUndefined,
vesselIdentifier: z.nativeEnum(VesselIdentifier),
vesselName: stringOrUndefined,
width: numberOrUndefined
})
3 changes: 2 additions & 1 deletion frontend/src/features/Vessel/vesselApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { monitorfishApi } from '@api/api'
import { HttpStatusCode, RtkCacheTagType } from '@api/constants'
import { VesselLastPositionSchema } from '@features/Vessel/schemas/VesselLastPositionSchema'
import { DisplayedErrorKey } from '@libs/DisplayedError/constants'
import { FrontendApiError } from '@libs/FrontendApiError'
import { getUrlOrPathWithQueryParams } from '@utils/getUrlOrPathWithQueryParams'
Expand Down Expand Up @@ -140,7 +141,7 @@ export const vesselApi = monitorfishApi.injectEndpoints({
getVesselsLastPositions: builder.query<Vessel.VesselLastPosition[], void>({
query: () => `/vessels`,
transformResponse: (baseQueryReturnValue: Vessel.VesselLastPosition[]) =>
baseQueryReturnValue.map(LastPosition => Vessel.VesselLastPositionSchema.parse(LastPosition))
baseQueryReturnValue.map(LastPosition => VesselLastPositionSchema.parse(LastPosition))
}),

searchVessels: builder.query<Vessel.VesselIdentity[], Vessel.ApiSearchFilter>({
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/features/Vessel/vesselNavApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { monitorfishLightApi } from '@api/api'
import { VesselLastPositionSchema } from '@features/Vessel/schemas/VesselLastPositionSchema'
import { Vessel } from '@features/Vessel/Vessel.types'

export const vesselNavApi = monitorfishLightApi.injectEndpoints({
endpoints: builder => ({
getVesselsLastPositions: builder.query<Vessel.VesselLastPosition[], void>({
query: () => `/v1/vessels`,
transformResponse: (baseQueryReturnValue: Vessel.VesselLastPosition[]) =>
baseQueryReturnValue.map(LastPosition => Vessel.VesselLastPositionSchema.parse(LastPosition))
baseQueryReturnValue.map(LastPosition => VesselLastPositionSchema.parse(LastPosition))
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ setupListeners(mainStore.dispatch)
export const mainStorePersistor = persistStore(mainStore)

// https://react-redux.js.org/using-react-redux/usage-with-typescript#define-root-state-and-dispatch-types
// Infer the `MainRootState` and `AppDispatch` types from the store itself
// Infer the `MainRootState` and `AppDispatch` schemas from the store itself
export type MainAppDispatch = typeof mainStore.dispatch
export type MainAppGetState = () => MainRootState
export type MainAppThunk<ReturnType = void> = ThunkAction<ReturnType, MainRootState, undefined, AnyAction>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BackofficeAppDispatch, BackofficeAppThunk, MainAppDispatch, MainAppThunk } from '@store'

// These types are used for store-hybrid thunks (use cases)
// These schemas are used for store-hybrid thunks (use cases)
export type HybridAppDispatch = BackofficeAppDispatch | MainAppDispatch
export type HybridAppThunk<T extends HybridAppDispatch, R = void> = T extends BackofficeAppDispatch
? BackofficeAppThunk<R>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('types', () => {
/**
* This test is required by jest to pass the error : "Your test suite must contain at least one test."
*
* The actual tests are running when checkin TS types (by `npm run test:type`):
* The actual tests are running when checkin TS schemas (by `npm run test:type`):
* - undefinableTestInterface
* - undefinableTestInterfaceWithMissingProp
*/
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/nullify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const nullifyObjectPropPair = ([key, value]: [string, NativeAny]) => [key, nulli
* Transform all `undefined` values into `null` ones in any type of value
*
* @description
* The value must be of native type and only contains native types.
* The value must be of native type and only contains native schemas.
*/
export function nullify<T extends NativeAny>(value: T): Nullify<T> | null {
if (value === null || value === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/undefinedize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const undefinedizeObjectPropPair = ([key, value]: [string, NativeAny]) => [key,
* Transform all `null` values into `undefined` ones in any type of value
*
* @description
* The value must be of native type and only contains native types.
* The value must be of native type and only contains native schemas.
*/
export function undefinedize<T extends NativeAny>(value: T): Undefinedized<T> | undefined {
if (value === null || value === undefined) {
Expand Down

0 comments on commit e2c341d

Please sign in to comment.