Skip to content

Commit

Permalink
chore: add verification dependacncies
Browse files Browse the repository at this point in the history
  • Loading branch information
shon-button committed Jan 23, 2025
1 parent ed75993 commit 94022f2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export default function VerificationForm({
selectedValues.includes("None") ||
e.formData.visit_names?.includes("None")
) {
// 🛑 If "None" is selected:
// If "None" is selected:
// - Lock selection to only "None"
updatedData.visit_names = ["None"];
// - Clear visit_types as no visits are applicable
updatedData.visit_types = [];
// - Clear visit_others as no visits are applicable
updatedData.visit_others = [{}];
} else {
// 🟢 If "None" is not selected:
// If "None" is not selected:

// - Remove "None" from the list of selected values (if accidentally included)
updatedData.visit_names = selectedValues.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,30 @@ export default async function VerificationPage({
}));

// 🔄 Add the visit_others property
initialData.visit_others = (initialData.report_verification_visits || [])
.filter((visit: { is_other_visit: boolean }) => visit.is_other_visit)
.map(
(visit: {
visit_name: string;
visit_coordinates: string;
visit_type: string;
}) => ({
visit_name: visit.visit_name,
visit_coordinates: visit.visit_coordinates,
visit_type: visit.visit_type,
}),
);
initialData.visit_others = (
initialData.report_verification_visits || []
).some((visit: { is_other_visit: boolean }) => visit.is_other_visit)
? (initialData.report_verification_visits || [])
.filter((visit: { is_other_visit: boolean }) => visit.is_other_visit)
.map(
(visit: {
visit_name: string;
visit_coordinates: string;
visit_type: string;
}) => ({
visit_name: visit.visit_name,
visit_coordinates: visit.visit_coordinates,
visit_type: visit.visit_type,
}),
)
: [{}];

// 🚀 Fetch the list of facilities associated with the specified version ID
const facilityList = await getReportFacilityList(version_id);

// Determine operationType based on reportOperation
// 🚀 Fetch the operation associated with the specified version ID
const reportOperation = await getReportingOperation(version_id);
// Determine operationType based on reportOperation
const operationType =
reportOperation &&
reportOperation.report_operation.operation_type ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ export const createVerificationSchema = (
// Determine the schema based on the schemaType
const localSchema: RJSFSchema =
schemaType === "SFO" ? { ...sfoSchema } : { ...lfoSchema };
const defaultVisistValues = ["None", "Other"];

// Dynamically populate the "visit_names" field's enum with the facilities
switch (schemaType) {
case "SFO":
(localSchema.properties?.visit_names as any).enum = [
...defaultVisistValues,
...facilities,
"Other",
"None",
];
break;
case "LFO":
(localSchema.properties?.visit_names as any).items.enum = [
...defaultVisistValues,
...facilities,
"Other",
"None",
];
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,39 @@ export const lfoSchema: RJSFSchema = {
dependencies: {
visit_names: {
oneOf: [
// Rule when "None" is selected
{
properties: {
visit_names: {
type: "array",
items: {
type: "string",
enum: ["None"], // Only allow "None"
},
maxItems: 1, // Exactly one item
minItems: 1,
},
},
required: ["visit_names"], // Ensure "visit_names" is present
},
// Rule when "Other" is selected
{
properties: {
visit_names: {
type: "array",
contains: { const: "Other" },
},
visit_others: {
title: "Other Visit(s)",
type: "array",
default: [{}],
minItems: 1,
default: [
{
visit_name: "",
visit_coordinates: "",
visit_type: "",
},
],
items: {
type: "object",
required: ["visit_name", "visit_coordinates", "visit_type"],
Expand Down Expand Up @@ -358,10 +382,19 @@ export const lfoUiSchema: UiSchema = {
visit_others: {
"ui:FieldTemplate": FieldTemplate,
"ui:options": {
addable: true,
removable: true,
label: true,
arrayAddLabel: "Add Other Visit",
addable: true, // Ensure users can add more visits manually
},
items: {
visit_name: {
"ui:placeholder": "Enter visit name",
},
visit_coordinates: {
"ui:placeholder": "Enter coordinates",
},
visit_type: {
"ui:widget": "RadioWidget",
},
},
},
};

0 comments on commit 94022f2

Please sign in to comment.