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

basic plus extra fields #883

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
15 changes: 2 additions & 13 deletions app/src/components/Modals/activity-modal/activity-modal-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
SubcategoryData,
} from "../../../app/[lng]/[inventory]/data/[step]/types";
import { resolve } from "@/util/helpers";
import { Methodology, SuggestedActivity } from "@/util/form-schema";
import { ExtraField, Methodology, SuggestedActivity } from "@/util/form-schema";
import { ActivityValue } from "@/models/ActivityValue";
import FormattedNumberInput from "@/components/formatted-number-input";
import PercentageBreakdownInput from "@/components/percentage-breakdown-input";
Expand Down Expand Up @@ -90,17 +90,6 @@ export type Inputs = {
subcategoryData: Record<string, SubcategoryData>;
};

export type ExtraField = {
id: string;
type?: string; // Specifies the type, e.g., 'text', 'number'
options?: string[]; // Array of options for selection
exclusive?: string; // An option that excludes others
multiselect?: boolean; // Whether multiple selections are allowed
units?: string[]; // Specifies units, applicable when type is 'number'
required?: boolean; // Whether the field is required
subtypes?: string[];
};

const ActivityModalBody = ({
t,
register,
Expand Down Expand Up @@ -233,7 +222,7 @@ const ActivityModalBody = ({
{f.options && (
<FormControl key={idx} className="w-full">
<BuildingTypeSelectInput
options={f.options}
options={f.options as string[]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to map or change the data type of this property here if the data is in a different format now?

required={f.required}
control={control}
multiselect={f.multiselect}
Expand Down
2 changes: 1 addition & 1 deletion app/src/util/form-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function findMethodology(
export interface ExtraField {
id: string;
type?: string;
options?: string[];
options?: string[] | { type: string; names: string[] }[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we only have one of these and rework the existing data to also use this schema. Otherwise we need to have an if/ else block for both cases in every place this is used...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially have a helper function that normalizes it, but at that point let's just use my automatic rewriting script for the JSON and fix all of the data types to be consistent.

exclusive?: string;
multiselect?: boolean;
"default-units"?: string;
Expand Down
Loading
Loading