Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ remove isDummyTypology and refactor guideFactice #480

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions frontend/src/components/ResultPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const img = computed(() => resultStore.img)
const typology = TYPOLOGIES[resultStore.typology]

const isDummy = computed(() => stepsStore.isDummy)
const isDummyTypology = computed(() => typology?.isDummyTypology === true)
const hasDummyOptions = typology?.dummyOptions !== undefined
const isCardDetected = computed(() => resultStore.gunLength !== null && resultStore.gunBarrelLength !== null)

const isUp = ref(false)
Expand Down Expand Up @@ -75,7 +75,7 @@ function sendFeedback (isCorrect: boolean) {
<div class="result-frame -mx-8 py-5 px-8">
<div class="result">
<h2
v-if="$route.name === 'IdentificationTypologyResult' && isDummyTypology === true"
v-if="$route.name === 'IdentificationTypologyResult' && hasDummyOptions"
class="typology-title bg-white py-4"
>
Typologie de l'arme
Expand Down Expand Up @@ -144,7 +144,7 @@ function sendFeedback (isCorrect: boolean) {
>
{{ label }}
</h3>
<template v-if="confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || isDummyTypology !== true)">
<template v-if="confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || !hasDummyOptions)">
<h3
class="fr-alert__title"
data-testid="arm-category"
Expand All @@ -157,14 +157,14 @@ function sendFeedback (isCorrect: boolean) {
</template>
</div>
<div
v-if="disclaimer && confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || isDummyTypology !== true)"
v-if="disclaimer && confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || !hasDummyOptions)"
class="fr-alert fr-alert--warning"
>
<p v-html="disclaimer" />
</div>
<MissingCardAlert v-if="MEASURED_GUNS_TYPOLOGIES.includes(typology) && isCardDetected === false && isDummy == false" />
<div
v-if="confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || isDummyTypology !== true)"
v-if="confidenceLevel !== 'low' && ($route.name !== 'IdentificationTypologyResult' || !hasDummyOptions)"
class="fr-callout mt-3"
>
<p class="fr-callout__text">
Expand All @@ -178,7 +178,7 @@ function sendFeedback (isCorrect: boolean) {
</p>
</div>
<div
v-if="confidenceLevel !== 'low' && $route.name === 'IdentificationTypologyResult' && isDummyTypology"
v-if="confidenceLevel !== 'low' && $route.name === 'IdentificationTypologyResult' && hasDummyOptions"
class="fr-alert fr-alert--warning"
>
<p>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/firearms-utils/autre-pistolet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const autre_pistolet = {
typologie: 'autre_pistolet',
displayLabel: 'Pistolet divers',
getCategory: () => 'A, B ou D',
isDummyTypology: false,
options_text: '',
securingSteps: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Armes d’épaule à levier de sous-garde
export const epaule_a_levier_sous_garde = {
displayLabel: "Arme d'épaule à levier de sous-garde",
getCategory: getCommonCategory,
isDummyTypology: false,
options_text: 'En manipulant l’arme avec précaution dans une <span class="font-bold">direction sans risque</span>, inspectez l’<span class="font-bold">extrémité du tube sous le canon</span>. Sélectionnez ce que vous voyez :',
securingSteps: [
{
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/firearms-utils/epaule-a-pompe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const epaule_a_pompe = {
getCategory: (gunLength: number, gunBarrelLength: number) => {
if (gunLength && gunBarrelLength) { return gunLength > 75 && gunBarrelLength > 55 ? 'C' : 'B' } else { return 'B ou C' }
},
isDummyTypology: false,
options_text: '',
securingSteps: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const epaule_a_un_coup_par_canon = {
getCategory: (gunLength: number, gunBarrelLength: number) => {
if (gunLength && gunBarrelLength) { return (gunLength > 75 && gunBarrelLength > 40) ? 'C' : 'B' } else { return 'B ou C' }
},
isDummyTypology: false,
options_text: 'Sélectionnez ce que vous voyez sur la <span class="font-bold">zone centrale de l’arme</span>',
securingSteps: [
{
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/utils/firearms-utils/epaule-a-verrou.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Armes d’épaule à verrou
export const epaule_a_verrou = {
displayLabel: 'Arme d’épaule à verrou',
getCategory: getCommonCategory,
isDummyTypology: true,
securingSteps: [
{
options: [
Expand All @@ -29,17 +28,17 @@ export const epaule_a_verrou = {
],
},
],
guideFactice: {
cartouches: {
dummyOptions: [
{
label: 'Balles',
value: 'cartouches',
img_ammo: epauleAVerrouCartridges,
},
billes: {
{
label: 'Billes ou trou pour billes',
value: 'billes',
img_ammo: epauleAVerrouBalls,
},
},
],
getDisclaimer: getEpaulLevierVerrouDisclaimer,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Armes d’épaule semi-automatiques ou automatiques type militaire milieu 20e
export const epaule_semi_auto_style_militaire_milieu_20e = {
displayLabel: 'Arme d’épaule semi-automatique ou automatique',
getCategory: () => 'A ou B',
isDummyTypology: false,
getDisclaimer: () => "<strong>Catégorie A</strong> si à l'origine l’arme était à <strong>répétition automatique</strong> puis a été <strong>transformée</strong> en arme <strong>semi automatique</strong>, ou si l’arme possède <strong>une crosse rétractable / pliable</strong> et qu’en configuration la plus courte elle <strong>mesure moins de 60 cm</strong>.",
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Armes d’épaule semi-automatiques ou automatiques type chasse
export const epaule_semi_auto_style_chasse = {
displayLabel: 'Arme d’épaule semi-automatique',
getCategory: getCommonCategory,
isDummyTypology: false,
getDisclaimer: (category: string, isCardDetected: boolean) => {
if (['B ou C', 'C'].includes(category)) {
if (isCardDetected === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Armes d’épaule à mécanisme ancien
export const epaule_mecanisme_ancien = {
displayLabel: "Arme d'épaule à mécanisme ancien",
getCategory: () => 'D',
isDummyTypology: false,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Pistolet à mécanisme ancien
export const pistolet_mecanisme_ancien = {
displayLabel: 'Pistolet à mécanisme ancien',
getCategory: () => 'D',
isDummyTypology: false,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Pistolets semi-auto modernes
export const pistolet_semi_auto_moderne = {
displayLabel: 'Pistolet semi-automatique',
getCategory: () => 'B',
isDummyTypology: true,
pistolet_semi_auto_moderne_text_option: 'Sélectionner ce que vous voyez sur votre arme : <span class="font-bold">bouton à proximité du pontet du côté gauche de la poignée</span>, OU <span class="font-bold">bouton sur le talon</span> de la crosse.',
textOptions: '',
securingSteps: [
Expand Down Expand Up @@ -51,18 +50,18 @@ export const pistolet_semi_auto_moderne = {
],
},
],
guideFactice: {
cartouche: {
dummyOptions: [
{
label: 'Cartouches',
value: 'cartouches',
img_ammo: pistoletSemiAutoModerneCartridges,
},
billes: {
{
label: 'Billes',
value: 'billes',
img_ammo: pistoletSemiAutoModerneBalls,
},
},
],
getDisclaimer: (category: string) => {
if (category === 'D') {
return 'Les <strong>armes d’alarmes</strong> sont susceptibles d’être <strong>modifiées pour tirer des munitions létales</strong>. Pour des raisons de sécurité, <strong>faites si possible expertiser l’arme.</strong>'
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/utils/firearms-utils/revolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const revolver = {
displayLabel: 'Revolver',
getCategory: () => 'B',
categoryWithoutSecuring: 'B ou D',
isDummyTypology: true,
securingSteps: [
{
text: 'En maintenant l’arme dans une <span class="font-bold">direction sécurisée</span> , sélectionnez ce que vous voyez.',
Expand Down Expand Up @@ -164,18 +163,18 @@ export const revolver = {
],
},
],
guideFactice: {
cartouches: {
dummyOptions: [
{
label: 'Balles',
value: 'cartouches',
img_ammo: revolverCartridges,
},
billes: {
{
label: 'Billes ou trou pour billes',
value: 'billes',
img_ammo: revolverBalls,
},
},
],
getDisclaimer: (category: string) => {
if (category === 'D') {
return 'Les <strong>armes d’alarmes</strong> sont susceptibles d’être <strong>modifiées pour tirer des munitions létales</strong>. Pour des raisons de sécurité, <strong>faites si possible expertiser l’arme.</strong>'
Expand All @@ -186,5 +185,4 @@ export const revolver = {
export const revolver_black_powder = {
displayLabel: 'Revolver à poudre noire',
getCategory: () => 'D',
isDummyTypology: false,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Armes d’épaule semi-automatiques ou automatiques type militaire moderne
export const semi_auto_style_militaire_autre = {
displayLabel: 'Arme semi-automatique ou automatique',
getCategory: () => 'A ou B',
isDummyTypology: true,
securingSteps: [
{
text: 'Observez la position du chargeur et sélectionnez ce que vous voyez :',
Expand Down Expand Up @@ -102,17 +101,17 @@ export const semi_auto_style_militaire_autre = {
],
},
],
guideFactice: {
cartouches: {
dummyOptions: [
{
label: 'Cartouches',
value: 'cartouches',
img_ammo: semiAutoMilitaireCartridges,
},
billes: {
{
label: 'Billes',
value: 'billes',
img_ammo: semiAutoMilitaireBalls,
},
},
],
getDisclaimer: () => "<strong>Catégorie A</strong> si à l'origine l’arme était à <strong>répétition automatique</strong> puis a été <strong>transformée</strong> en arme <strong>semi automatique</strong>, ou si l’arme possède <strong>une crosse rétractable / pliable</strong> et qu’en configuration la plus courte elle <strong>mesure moins de 60 cm</strong>.",
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ const confidenceLevel = computed(() => resultStore.confidenceLevel)
const typology = computed(() => resultStore.typology)

const currentStep = ref(1)

const isDummyTypology = TYPOLOGIES[resultStore.typology].isDummyTypology
const isLowConfidence = confidenceLevel.value === 'low'

const steps = computed(() => {
if (isDummyTypology || !isLowConfidence) {
if (TYPOLOGIES[typology]?.dummyOptions || !isLowConfidence) {
if (ALARM_GUNS_TYPOLOGIES.includes(resultStore.typology) && stepsStore.selectedAmmo === 'cartouches') {
return ['Typologie de l\'arme', 'Compléments', 'Typologie de munitions', 'Identification d\'une arme d\'alarme', 'Résultat final']
} else {
Expand Down Expand Up @@ -99,7 +97,7 @@ const showDiv = ref(false)
<div class="mt-5 fr-container">
<div class="result fr-col-11 fr-col-lg-6 mx-auto">
<StepsGuide
v-if="TYPOLOGIES[typology]?.isDummyTypology"
v-if="TYPOLOGIES[typology]?.dummyOptions"
class="!fr-container my-auto"
:steps="steps"
:current-step="currentStep"
Expand All @@ -108,7 +106,7 @@ const showDiv = ref(false)
</div>
</div>
<div
v-if="$route.path === '/guide-identification/resultat-final' || !TYPOLOGIES[typology]?.isDummyTypology"
v-if="$route.path === '/guide-identification/resultat-final' || TYPOLOGIES[typology]?.dummyOptions == undefined"
class="footer end z-1"
>
<div class="fr-col-11 fr-col-lg-6 mx-auto">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ onMounted(() => {
})

// eslint-disable-next-line camelcase
type HasGuideFactice = typeof epaule_a_verrou | typeof pistolet_semi_auto_moderne | typeof semi_auto_style_militaire_autre | typeof revolver
type HasDummyOptions = typeof epaule_a_verrou | typeof pistolet_semi_auto_moderne | typeof semi_auto_style_militaire_autre | typeof revolver
</script>

<template>
Expand Down Expand Up @@ -123,7 +123,7 @@ type HasGuideFactice = typeof epaule_a_verrou | typeof pistolet_semi_auto_modern
</div>
<div>
<template
v-for="option of (TYPOLOGIES[typology] as HasGuideFactice)?.guideFactice"
v-for="(option) in (TYPOLOGIES[typology] as HasDummyOptions)?.dummyOptions"
:key="option.value"
>
<div class="item">
Expand Down
Loading