Skip to content

Commit

Permalink
chore: data for operation review
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jan 17, 2025
1 parent 9f3b308 commit 3e4dc06
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { WidgetProps } from "@rjsf/utils/lib/types";
import {
FieldSchema,
mapOptions,
} from "@bciers/components/form/widgets/MultiSelectWidget";

const FinalReviewMultiSelectWidget: React.FC<WidgetProps> = ({
id,
value,
schema,
uiSchema,
}) => {
const fieldSchema = schema.items as FieldSchema;
const options = mapOptions(fieldSchema);
const selectedOptions = options.filter((option) => value.includes(option.id));
const displayInline = uiSchema?.["ui:inline"];
const separator = displayInline ? ", " : ",\n";

const displayOptions = selectedOptions
.map((option) => `- ${option.label}`)
.join(separator);

return (
<div
id={id}
// Use whitespace-pre-line to display items with \n line breaks
className="read-only-widget whitespace-pre-line"
>
{displayOptions}
</div>
);
};

export default FinalReviewMultiSelectWidget;
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import readOnlyTheme from "@bciers/components/form/theme/readOnlyTheme";
import FinalReviewFieldTemplate from "./FinalReviewFieldTemplate";
import FinalReviewStringField from "./FinalReviewStringField";
import FinalReviewArrayFieldTemplate from "./FinalReviewArrayFieldTemplate";
import FinalReviewMultiSelectWidget from "./FinalReviewMultiSelectWidget";

const finalReviewTheme = {
...readOnlyTheme,
widgets: {
...readOnlyTheme.widgets,
MultiSelectWidget: FinalReviewMultiSelectWidget,
},
templates: {
...readOnlyTheme.templates,
FieldTemplate: FinalReviewFieldTemplate,
ArrayFieldTemplate: FinalReviewArrayFieldTemplate,
},
fields: {
...readOnlyTheme.fields,
StringField: FinalReviewStringField,
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
import {
operationReviewSchema,
operationReviewUiSchema,
updateSchema,
} from "@reporting/src/data/jsonSchema/operations";
import { ReviewDataFactoryItem } from "./factory";
import { getReportingOperation } from "@reporting/src/app/utils/getReportingOperation";
import { getReportingYear } from "@reporting/src/app/utils/getReportingYear";
import { formatDate } from "@reporting/src/app/utils/formatDate";
import { getRegistrationPurpose } from "@reporting/src/app/utils/getRegistrationPurpose";
import { getAllActivities } from "@reporting/src/app/utils/getAllReportingActivities";
import { getRegulatedProducts } from "@bciers/actions/api";

const operationReviewFactoryItem: ReviewDataFactoryItem = async (versionId) => {
const formData = await getReportingOperation(versionId);

const reportingYear = await getReportingYear();
const reportingWindowEnd = formatDate(
reportingYear.reporting_window_end,
"MMM DD YYYY",
);

const registrationPurpose = (await getRegistrationPurpose(versionId))
.registration_purpose;

const allActivities = await getAllActivities();
const allRegulatedProducts = await getRegulatedProducts();

const schema: any = updateSchema(
operationReviewSchema,
formData,
registrationPurpose,
reportingWindowEnd,
allActivities,
allRegulatedProducts,
);

return [
{
schema: operationReviewSchema,
data: await getReportingOperation(versionId),
schema: schema,
data: formData,
uiSchema: operationReviewUiSchema,
},
];
Expand Down

0 comments on commit 3e4dc06

Please sign in to comment.