Skip to content

Commit

Permalink
Merge pull request #468 from ai-cfia/430-inspection-details
Browse files Browse the repository at this point in the history
issue #430: Inspection details page
  • Loading branch information
k-allagbe authored Feb 17, 2025
2 parents 44687c9 + e9a92b4 commit 0e43570
Show file tree
Hide file tree
Showing 52 changed files with 1,647 additions and 790 deletions.
26 changes: 26 additions & 0 deletions docs/label-inspections/flowchart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Flowchart for launching

## /label-inspections/id

```mermaid
flowchart TD
Start([Start]) --> LabelInspectionsID["/label-inspections/id"]
LabelInspectionsID --> ImageInStore{Image in Store?}
LabelInspectionsID --> GetInspections["GET /api/inspections/id"]
ImageInStore -->|Yes| DisplayImages["Display Images"]
ImageInStore -->|No| End([End])
DisplayImages --> End
GetInspections --> ResponseStatus{Response Status?}
ResponseStatus -->|200| DisplayData["Display Data"]
ResponseStatus -->|404| NotFoundPage["Display 404 Page"]
ResponseStatus -->|Other| AlertError["Alert Error"]
DisplayData --> End
NotFoundPage --> End
AlertError --> End
```
2 changes: 1 addition & 1 deletion public/img/expandIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions public/img/expandIconUp.svg

This file was deleted.

4 changes: 0 additions & 4 deletions public/img/retractIcon.svg

This file was deleted.

4 changes: 0 additions & 4 deletions public/img/retractIconDown.svg

This file was deleted.

21 changes: 13 additions & 8 deletions public/locales/en/confirmationPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sectionTitle": "Fertilizer Base Information",
"tableHeaders": {
"name": "Name",
"registrationNumber": "Registration Number",
"registrationNumbers": "Registration Numbers",
"lotNumber": "Lot Number",
"npk": "NPK",
"weight": "Weight",
Expand Down Expand Up @@ -70,22 +70,27 @@
"expandButton": "Hide image and show only label information.",
"retractButton": "Show image and label information."
},
"yes": "Yes",
"no": "No",
"error": {
"saveSuccess": "Label data saved successfully.",
"saveFailed": "Label data saving failed",
"idMissing": "ID missing in initial label data saving response",
"initialSaveFailed": "Initial label data saving failed",
"internalErrorLabelNotFound": "Internal error: Label data not found.",
"internalErrorLabelNotConfirmed": "Internal error: Label data not confirmed.",
"noFileUploaded": "No file uploaded",
"labelNotFound": "Label data not found.",
"labelAlreadyConfirmed": "Label data already confirmed.",
"labelDataNotFullySaved": "Label data not fully saved."
},
"alt":{
"alt": {
"editButton": "Edit button",
"confirmButton": "Confirm button",
"expendIcon": "Expend icon",
"retractIcon": "Retract icon"
},
"alert": {
"labelNotConfirmed": "Internal error: Label data not confirmed.",
"labelNotFound": "Label data not found.",
"initialSaveFailed": "Initial label data saving failed",
"saveFailed": "Label data saving failed",
"saveSuccess": "Label data saved successfully.",
"alreadyCompleted": "This inspection has already been completed.",
"notAllVerified": "Not all fields have been verified."
}
}
26 changes: 26 additions & 0 deletions public/locales/en/inspectionPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"inspectionDetails": "Inspection Details",
"inspectionId": "ID",
"inspector": "Inspector",
"status": "Status",
"completed": "Completed",
"incomplete": "Incomplete",
"createdAt": "Created at",
"lastUpdatedAt": "Last Updated at",
"edit": "Edit",
"discard": "Discard",
"alert": {
"getInspectionFailed": "Failed to fetch inspection details",
"deleteSuccess": "Inspection deleted successfully",
"discardFailed": "Failed to discard inspection",
"internalErrorLabelNotFound": "Internal error: Label not found"
},
"alt": {
"edit": "Edit inspection",
"discard": "Discard inspection"
},
"confirmDiscardTitle": "Confirm Discard",
"confirmDiscardMessage": "Are you sure you want to discard this inspection? This action cannot be undone.",
"cancel": "Cancel",
"confirm": "Confirm"
}
15 changes: 8 additions & 7 deletions public/locales/en/labelDataValidator.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@
"numbersOnly": "Numbers only",
"minValue": "Minimum value is 0",
"duplicateUnit": "Duplicate unit",
"invalidId": "Invalid id",
"fetchAborted": "Fetch aborted",
"failedFetchInspection": "Failed to fetch inspection.",
"noFileUploaded": "No file uploaded",
"requestCancelled": "Request cancelled",
"initialSaveFailed": "Initial label data saving failed",
"labelExtractionFailed": "Label data extraction failed"
"requestCancelled": "Request cancelled"
},
"stepper": { "next": "Next", "back": "Back", "submit": "Submit" },
"fertilizer_product": "Fertilizer",
"ingredient_component": "Ingredient"
"alert": {
"initialSaveFailed": "Initial label data saving failed",
"invalidId": "Invalid id",
"failedFetchInspection": "Failed to fetch inspection.",
"alreadyCompleted": "This inspection has already been completed.",
"labelExtractionFailed": "Label data extraction failed"
}
}
25 changes: 14 additions & 11 deletions public/locales/fr/confirmationPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sectionTitle": "Informations de base sur l'engrais",
"tableHeaders": {
"name": "Nom",
"registrationNumber": "Numéro d'enregistrement",
"registrationNumbers": "Numéros d'enregistrement",
"lotNumber": "Numéro de lot",
"npk": "NPK",
"weight": "Poids",
Expand Down Expand Up @@ -73,21 +73,24 @@
"yes": "Oui",
"no": "Non",
"error": {
"saveSuccess": "Données de l'étiquette enregistrées avec succès.",
"saveFailed": "Échec de l'enregistrement des données de l'étiquette",
"idMissing": "ID manquant dans la réponse initiale de l'enregistrement des données de l'étiquette",
"initialSaveFailed": "Échec de l'enregistrement initial des données de l'étiquette",
"internalErrorLabelNotFound": "Erreur interne : Données de l'étiquette non trouvées.",
"internalErrorLabelNotConfirmed": "Erreur interne : Données de l'étiquette non confirmées.",
"noFileUploaded": "Aucun fichier téléchargé",
"labelNotFound": "Données de l'étiquette non trouvées.",
"labelAlreadyConfirmed": "Données de l'étiquette déjà confirmées.",
"labelDataNotFullySaved": "Données de l'étiquette non entièrement enregistrées."
"idMissing": "ID manquant dans la réponse initiale de l'enregistrement des données de l'étiquette",
"noFileUploaded": "Aucun fichier téléchargé",
"labelAlreadyConfirmed": "Données de l'étiquette déjà confirmées.",
"labelDataNotFullySaved": "Données de l'étiquette non entièrement enregistrées."
},
"alt": {
"editButton": "Bouton Modifier",
"confirmButton": "Bouton Confirmer",
"expendIcon": "Icône d'expansion",
"retractIcon": "Icône de rétractation"
},
"alert": {
"labelNotConfirmed": "Données de l'étiquette non confirmées.",
"labelNotFound": "Données de l'étiquette non trouvées.",
"initialSaveFailed": "Échec de l'enregistrement initial des données de l'étiquette",
"saveFailed": "Échec de l'enregistrement des données de l'étiquette",
"saveSuccess": "Données de l'étiquette enregistrées avec succès.",
"alreadyCompleted": "Cette inspection est déjà terminée.",
"notAllVerified": "Tous les champs n'ont pas été vérifiés."
}
}
26 changes: 26 additions & 0 deletions public/locales/fr/inspectionPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"inspectionDetails": "Détails de l'inspection",
"inspectionId": "ID",
"inspector": "Inspecteur",
"status": "Statut",
"completed": "Terminée",
"incomplete": "Incomplète",
"createdAt": "Créée le",
"lastUpdatedAt": "Dernière mise à jour le",
"edit": "Modifier",
"discard": "Supprimer",
"alert": {
"getInspectionFailed": "Échec de la récupération des détails de l'inspection",
"deleteSuccess": "Inspection supprimée avec succès",
"discardFailed": "Échec de la suppression de l'inspection",
"internalErrorLabelNotFound": "Erreur interne : Étiquette non trouvée"
},
"alt": {
"edit": "Modifier l'inspection",
"discard": "Supprimer l'inspection"
},
"confirmDiscardTitle": "Confirmer la suppression",
"confirmDiscardMessage": "Êtes-vous sûr de vouloir supprimer cette inspection ? Cette action est irréversible.",
"cancel": "Annuler",
"confirm": "Confirmer"
}
13 changes: 8 additions & 5 deletions public/locales/fr/labelDataValidator.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,20 @@
"numbersOnly": "Uniquement des nombres",
"minValue": "La valeur minimale est 0",
"duplicateUnit": "Unité dupliquée",
"invalidId": "ID invalide",
"fetchAborted": "Fetch annulé",
"failedFetchInspection": "Échec de la récupération de l'inspection.",
"noFileUploaded": "Aucun fichier téléchargé",
"requestCancelled": "Requête annulée",
"initialSaveFailed": "Échec de l'enregistrement initial des données de l'étiquette",
"labelExtractionFailed": "Échec de l'extraction des données de l'étiquette"
"requestCancelled": "Requête annulée"
},
"stepper": {
"next": "Suivant",
"back": "Retour",
"submit": "Soumettre"
},
"alert": {
"labelExtractionFailed": "Échec de l'extraction des données de l'étiquette",
"initialSaveFailed": "Échec de l'enregistrement initial des données de l'étiquette",
"invalidId": "ID invalide",
"failedFetchInspection": "Échec de la récupération de l'inspection.",
"alreadyCompleted": "Cette inspection est déjà terminée."
}
}
45 changes: 33 additions & 12 deletions src/app/api-next/inspections/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ export async function GET(
.getInspectionInspectionsIdGet(id, {
headers: { Authorization: authHeader },
})
.then((inspectionResponse) => {
console.debug(
"[get inspections/id] response data:",
inspectionResponse.data,
);
const labelData = mapInspectionToLabelData(inspectionResponse.data);
.then((r) => {
console.debug("[get inspections/id] response data:", r.data);
const labelData = mapInspectionToLabelData(r.data);
console.debug("[get inspections/id] response:", labelData);
return Response.json(labelData);
})
Expand Down Expand Up @@ -68,16 +65,40 @@ export async function PUT(
.putInspectionInspectionsIdPut(id, inspectionUpdate, {
headers: { Authorization: authHeader },
})
.then((inspectionResponse) => {
console.debug(
"[put inspections/id] response data:",
inspectionResponse.data,
);
const labelData = mapInspectionToLabelData(inspectionResponse.data);
.then((r) => {
console.debug("[put inspections/id] response data:", r.data);
const labelData = mapInspectionToLabelData(r.data);
console.debug("[put inspections/id] returned labelData:", labelData);
return Response.json(labelData);
})
.catch((error) => {
return handleApiError(error);
});
}

export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string }> },
) {
const authHeader = request.headers.get("Authorization");
if (!authHeader) {
return MISSING_AUTH_RESPONSE;
}

const id = (await params).id;
if (!validate(id)) {
return INVALID_ID_RESPONSE;
}

return inspectionsApi
.deleteInspectionInspectionsIdDelete(id, {
headers: { Authorization: authHeader },
})
.then((r) => {
console.debug("[delete inspections/id] id:", id, "response:", r.data);
return new Response(null, { status: 204 });
})
.catch((error) => {
return handleApiError(error);
});
}
15 changes: 9 additions & 6 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import theme from "@/app/theme";
import FertilizerList from "@/components/InspectionList/InspectionList";
import FertilizerList from "@/components/inspection-list/InspectionList";
import useAlertStore from "@/stores/alertStore";
import { Search } from "@mui/icons-material";
import {
Expand Down Expand Up @@ -52,14 +52,14 @@ const Dashboard = () => {
<Grid
container
spacing={2}
className={"p-5 h-[calc(100vh-65px)]"}
className={"h-[calc(100vh-65px)] p-5"}
sx={{ backgroundColor: theme.palette.background.paper }}
>
<Grid size={{ xs: 12, sm: 4, md: 3 }}>
<Grid
data-testid={"user-info"}
container
className={"p-2 border-gray-200 border-2 rounded-md h-fit"}
className={"h-fit rounded-md border-2 border-gray-200 p-2"}
>
<Grid size={12}>
<Typography component={"h2"} className={"!font-black text-black"}>
Expand All @@ -76,7 +76,7 @@ const Dashboard = () => {
<Grid
container
className={
"p-2 border-gray-200 border-2 rounded-md h-fit mt-2 w-11/12"
"mt-2 h-fit w-11/12 rounded-md border-2 border-gray-200 p-2"
}
>
<Grid size={12}>
Expand All @@ -92,7 +92,7 @@ const Dashboard = () => {
<Grid
size={{ xs: 12, sm: 8, md: 9 }}
className={
"border-gray-200 border-2 rounded-md p-2 xs:pb-1 sm:pb-0 xs:h-[calc(100%-10.75rem)] sm:h-full min-h-60"
"xs:pb-1 xs:h-[calc(100%-10.75rem)] min-h-60 rounded-md border-2 border-gray-200 p-2 sm:h-full sm:pb-0"
}
>
<Grid container spacing={2} className={"h-full"}>
Expand Down Expand Up @@ -120,7 +120,10 @@ const Dashboard = () => {
className: "p-2 after:!transition-none ",
startAdornment: (
<InputAdornment position={"start"} className={"!m-0"}>
<Search color="primary" aria-label={t("alt.searchIcon")}/>
<Search
color="primary"
aria-label={t("alt.searchIcon")}
/>
</InputAdornment>
),
},
Expand Down
Loading

0 comments on commit 0e43570

Please sign in to comment.