-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from MTES-MCT/feature/241-refactor-architectu…
…re-react-pour-module-partager-components-features Feature/241 refactor architecture react pour module partager components features
- Loading branch information
Showing
173 changed files
with
7,722 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Suspense } from 'react' | ||
import { Navigate } from 'react-router-dom' | ||
import useAuth from '../hooks/use-auth' | ||
|
||
type AuthGuardProps = { | ||
children: JSX.Element | ||
} | ||
|
||
export default function AuthGuard(props: AuthGuardProps): JSX.Element | null { | ||
const { isAuthenticated } = useAuth() | ||
|
||
const denied = () => { | ||
return <Navigate to={`/login`} replace /> | ||
} | ||
|
||
const allow = () => { | ||
return <Suspense>{props.children}</Suspense> | ||
} | ||
return !isAuthenticated ? denied() : allow() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Action } from '@common/types/action-types' | ||
import { MissionSourceEnum } from '@common/types/env-mission-types' | ||
|
||
export function isEnvAction(action: Action): boolean { | ||
return action !== null && action.source === MissionSourceEnum.MONITORENV | ||
} | ||
|
||
export function isFishAction(action: Action): boolean { | ||
return action !== null && action.source === MissionSourceEnum.MONITORFISH | ||
} | ||
|
||
export function isNavAction(action: Action): boolean { | ||
return action !== null && action.source === MissionSourceEnum.RAPPORTNAV | ||
} | ||
|
||
export const vesselNameOrUnknown = (name?: string): string | undefined => { | ||
if (!name) { | ||
return | ||
} else if (name === 'UNKNOWN') { | ||
return 'Navire inconnu' | ||
} else { | ||
return name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('control utils', () => { | ||
it('dummy', () => { | ||
expect(false).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { ControlMethod, ControlType } from '@common/types/control-types' | ||
import { VesselSizeEnum, VesselTypeEnum } from '@common/types/mission-types' | ||
|
||
export const controlMethodToHumanString = (controlMethod?: ControlMethod | null): string => { | ||
switch (controlMethod) { | ||
case ControlMethod.AIR: | ||
return 'aérien' | ||
case ControlMethod.LAND: | ||
return 'à Terre' | ||
case ControlMethod.SEA: | ||
return 'en Mer' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
export const vesselTypeToHumanString = (vesselType?: VesselTypeEnum | null): string => { | ||
switch (vesselType) { | ||
case VesselTypeEnum.FISHING: | ||
return 'Navire de pêche professionnelle' | ||
case VesselTypeEnum.COMMERCIAL: | ||
return 'Navire de commerce' | ||
case VesselTypeEnum.MOTOR: | ||
return 'Navire de service' | ||
case VesselTypeEnum.SAILING: | ||
return 'Navire de plaisance professionnelle' | ||
case VesselTypeEnum.SAILING_LEISURE: | ||
return 'Navire de plaisance de loisir' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
export const VESSEL_TYPE_OPTIONS = [ | ||
{ | ||
label: vesselTypeToHumanString(VesselTypeEnum.FISHING), | ||
value: VesselTypeEnum.FISHING | ||
}, | ||
{ | ||
label: vesselTypeToHumanString(VesselTypeEnum.SAILING), | ||
value: VesselTypeEnum.SAILING | ||
}, | ||
{ | ||
label: vesselTypeToHumanString(VesselTypeEnum.MOTOR), | ||
value: VesselTypeEnum.MOTOR | ||
}, | ||
{ | ||
label: vesselTypeToHumanString(VesselTypeEnum.COMMERCIAL), | ||
value: VesselTypeEnum.COMMERCIAL | ||
}, | ||
{ | ||
label: vesselTypeToHumanString(VesselTypeEnum.SAILING_LEISURE), | ||
value: VesselTypeEnum.SAILING_LEISURE | ||
} | ||
] | ||
|
||
export const vesselSizeToHumanString = (vesselSize?: VesselSizeEnum | null): string => { | ||
switch (vesselSize) { | ||
case VesselSizeEnum.LESS_THAN_12m: | ||
return 'Moins de 12m' | ||
case VesselSizeEnum.FROM_12_TO_24m: | ||
return 'Entre 12m et 24m' | ||
case VesselSizeEnum.FROM_24_TO_46m: | ||
return 'Entre 24m et 46m' | ||
case VesselSizeEnum.MORE_THAN_46m: | ||
return 'Plus de 46m' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
export const VESSEL_SIZE_OPTIONS = [ | ||
{ | ||
label: 'Moins de 12m', | ||
value: VesselSizeEnum.LESS_THAN_12m | ||
}, | ||
{ | ||
label: 'Entre 12m et 24m', | ||
value: VesselSizeEnum.FROM_12_TO_24m | ||
}, | ||
{ | ||
label: 'Entre 24m et 46m', | ||
value: VesselSizeEnum.FROM_24_TO_46m | ||
}, | ||
{ | ||
label: 'Plus de 46m', | ||
value: VesselSizeEnum.MORE_THAN_46m | ||
} | ||
] | ||
|
||
export const RESCUE_TYPE_OPTIONS = [ | ||
{ | ||
label: 'Assistance de navire en difficulté', | ||
value: true | ||
}, | ||
{ | ||
label: 'Sauvegarde de la vie humaine', | ||
value: false | ||
} | ||
] | ||
|
||
export const controlTitle = (controlType: ControlType) => { | ||
switch (controlType) { | ||
case ControlType.ADMINISTRATIVE: | ||
return 'Contrôle administratif navire' | ||
case ControlType.GENS_DE_MER: | ||
return 'Contrôle administratif gens de mer' | ||
case ControlType.SECURITY: | ||
return 'Equipements et respect des normes de sécurité' | ||
case ControlType.NAVIGATION: | ||
return 'Respect des règles de navigation' | ||
} | ||
} | ||
|
||
export function getDisabledControlTypes(enabledControlTypes?: ControlType[]): ControlType[] { | ||
const allControlTypes = Object.values(ControlType) | ||
if (!enabledControlTypes) { | ||
return allControlTypes | ||
} | ||
const disabledControlTypes = allControlTypes.filter(controlType => !enabledControlTypes.includes(controlType)) | ||
return disabledControlTypes | ||
} | ||
|
||
export const CONTROL_TYPE_OPTIONS = [ | ||
{ | ||
label: `Infraction - ${controlTitle(ControlType.ADMINISTRATIVE)}`, | ||
value: ControlType.ADMINISTRATIVE | ||
}, | ||
{ | ||
label: `Infraction - ${controlTitle(ControlType.SECURITY)}`, | ||
value: ControlType.SECURITY | ||
}, | ||
{ | ||
label: `Infraction - ${controlTitle(ControlType.NAVIGATION)}`, | ||
value: ControlType.NAVIGATION | ||
}, | ||
{ | ||
label: `Infraction - ${controlTitle(ControlType.GENS_DE_MER)}`, | ||
value: ControlType.GENS_DE_MER | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ControlType } from '../../../common/types/control-types.ts' | ||
|
||
export const infractionTitleForControlType = (controlType: ControlType): string => { | ||
switch (controlType) { | ||
case ControlType.ADMINISTRATIVE: | ||
return 'Infraction administrative' | ||
case ControlType.NAVIGATION: | ||
return 'Infraction règles de navigation' | ||
case ControlType.SECURITY: | ||
return 'Infraction équipements et respect des normes de sécurité' | ||
case ControlType.GENS_DE_MER: | ||
return 'Infraction administrative gens de mer' | ||
default: | ||
return '' | ||
} | ||
} | ||
export const infractionButtonTitle = (controlType: ControlType): string => { | ||
switch (controlType) { | ||
case ControlType.ADMINISTRATIVE: | ||
return 'Ajouter une infraction administrative' | ||
case ControlType.NAVIGATION: | ||
return 'Ajouter une infraction règle de navigation' | ||
case ControlType.SECURITY: | ||
return 'Ajouter une infraction sécurité' | ||
case ControlType.GENS_DE_MER: | ||
return 'Ajouter une infraction administrative' | ||
default: | ||
return '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ActionStatusReason, ActionStatusType } from '@common/types/action-types' | ||
import { THEME } from '@mtes-mct/monitor-ui' | ||
|
||
export const getColorForStatus = (status: ActionStatusType) => { | ||
switch (status) { | ||
case ActionStatusType.NAVIGATING: | ||
return THEME.color.blueGray | ||
case ActionStatusType.ANCHORED: | ||
return THEME.color.blueYonder | ||
case ActionStatusType.DOCKED: | ||
return THEME.color.goldenPoppy | ||
case ActionStatusType.UNAVAILABLE: | ||
return THEME.color.maximumRed | ||
case ActionStatusType.UNKNOWN: | ||
default: | ||
return 'transparent' | ||
} | ||
} | ||
|
||
export const mapStatusToText = (status: ActionStatusType) => { | ||
switch (status) { | ||
case ActionStatusType.NAVIGATING: | ||
return 'Navigation' | ||
case ActionStatusType.ANCHORED: | ||
return 'Mouillage' | ||
case ActionStatusType.DOCKED: | ||
return 'Présence à quai' | ||
case ActionStatusType.UNAVAILABLE: | ||
return 'Indisponibilité' | ||
case ActionStatusType.UNKNOWN: | ||
default: | ||
return 'Inconnu' | ||
} | ||
} | ||
|
||
export const statusReasonToHumanString = (reason?: ActionStatusReason): string | undefined => { | ||
switch (reason) { | ||
case ActionStatusReason.MAINTENANCE: | ||
return 'Maintenance' | ||
case ActionStatusReason.WEATHER: | ||
return 'Météo' | ||
case ActionStatusReason.REPRESENTATION: | ||
return 'Représentation' | ||
case ActionStatusReason.ADMINISTRATION: | ||
return 'Administration' | ||
case ActionStatusReason.HARBOUR_CONTROL: | ||
return 'Contrôle portuaire' | ||
case ActionStatusReason.TECHNICAL: | ||
return 'Technique' | ||
case ActionStatusReason.PERSONNEL: | ||
return 'Personnel' | ||
case ActionStatusReason.OTHER: | ||
return 'Autre' | ||
default: | ||
return undefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.