Skip to content

Commit

Permalink
feat: add score and project type fields to project overview form
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Aug 15, 2022
1 parent 302d792 commit b4bf598
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/components/Form/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export const createProjectUiSchema = (
"operatorId",
"operatorTradeName",
"proposalReference",
"score",
"projectName",
"summary",
"projectType",
"totalFundingRequest",
"projectStatus",
"projectStatusId",
Expand All @@ -49,6 +51,10 @@ export const createProjectUiSchema = (
summary: {
"ui:widget": "TextAreaWidget",
},
projectType: {
"ui:placeholder": "Select a Project Type",
"ui:widget": "SearchWidget",
},
operatorId: {
"ui:placeholder": "Select an Operator",
"ui:widget": "SearchWidget",
Expand Down Expand Up @@ -80,6 +86,10 @@ export const createProjectUiSchema = (
additionalSectorInformation: {
"ui:widget": "TextAreaWidget",
},
score: {
"ui:widget": "DecimalWidget",
decimals: 3,
},
comments: {
"ui:widget": "TextAreaWidget",
},
Expand Down Expand Up @@ -126,6 +136,13 @@ const ProjectForm: React.FC<Props> = (props) => {
}
}
}
allProjectTypes {
edges {
node {
name
}
}
}
...SelectRfpWidget_query
...SelectProjectStatusWidget_query
}
Expand Down Expand Up @@ -225,6 +242,17 @@ const ProjectForm: React.FC<Props> = (props) => {
};
}),
},
projectType: {
...projectSchema.properties.projectType,
anyOf: query.allProjectTypes.edges.map(({ node }) => {
return {
type: "string",
title: node.name,
enum: [node.name],
value: node.name,
};
}),
},
},
};
return initialSchema as JSONSchema7;
Expand Down
73 changes: 73 additions & 0 deletions app/components/Form/SelectProjectTypeWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { WidgetProps } from "@rjsf/core";
import { useMemo } from "react";
import { graphql, useFragment } from "react-relay";
import Dropdown from "@button-inc/bcgov-theme/Dropdown";

const SelectProjectType: React.FunctionComponent<WidgetProps> = (props) => {
const { id, onChange, placeholder, required, uiSchema, value, formContext } =
props;

const { allProjectTypes } = useFragment(
graphql`
fragment SelectProjectTypeWidget_query on Query {
allProjectTypes {
edges {
node {
name
}
}
}
}
`,
formContext.query
);

console.log("formContext.form", formContext.form);
const { projectType } = formContext.form || {};

const projectTypeList = useMemo(() => {
return allProjectTypes.edges
.filter((edge) => {
return edge.node.name == projectType;
})
.map((edge) => edge.node.projectStatusByProjectStatusId);
}, [allProjectTypes, projectType]);

return (
<div>
<Dropdown
id={id}
onChange={(e) => onChange(e.target.value || undefined)}
placeholder={placeholder}
size={(uiSchema && uiSchema["bcgov:size"]) || "large"}
required={required}
value={value}
>
<option key={`option-placeholder-${id}`} value={undefined}>
{placeholder}
</option>
{projectTypeList.map((type) => {
return (
<option key={type.rowId} value={type.rowId}>
{type.name}
</option>
);
})}
</Dropdown>
<style jsx>
{`
div :global(input) {
width: 100%;
}
div :global(.pg-select-wrapper) {
padding: 9px 20px 9px 2px;
margin-bottom: 5px;
margin-top: 2px;
}
`}
</style>
</div>
);
};

export default SelectProjectType;
5 changes: 5 additions & 0 deletions app/data/jsonSchemaForm/projectSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const projectSchema = {
default: undefined,
},
summary: { type: "string", title: "Project Description" },
projectType: { type: "string", title: "Project Type" },
score: {
type: "number",
title: "Score",
},
operatorId: {
type: "number",
title: "Legal Operator Name and BC Registry ID",
Expand Down
2 changes: 2 additions & 0 deletions app/lib/theme/FormWithTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MoneyWidget from "lib/theme/widgets/MoneyWidget";
import PhoneNumberWidget from "lib/theme/widgets/PhoneNumberWidget";
import DueDateWidget from "lib/theme/widgets/DueDateWidget";
import DateWidget from "./widgets/DateWidget";
import DecimalWidget from "./widgets/DecimalWidget";
import { AdjustableCalculatedValueWidget } from "./widgets/AdjustableCalculatedValueWidget";
import ReadOnlyCalculatedValueWidget from "./widgets/ReadOnlyCalculatedValueWidget";
import PercentageWidget from "./widgets/PercentageWidget";
Expand All @@ -36,6 +37,7 @@ const formTheme: ThemeProps = {
AdjustableCalculatedValueWidget,
ReadOnlyCalculatedValueWidget,
PercentageWidget: PercentageWidget,
DecimalWidget,
},
ObjectFieldTemplate: ObjectFieldTemplate,
FieldTemplate: FieldTemplate,
Expand Down
1 change: 1 addition & 0 deletions app/lib/theme/ReadOnlyTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const readOnlyTheme: ThemeProps = {
AdjustableCalculatedValueWidget: ReadOnlyAdjustableCalculatedValueWidget,
ReadOnlyCalculatedValueWidget,
PercentageWidget: ReadOnlyPercentageWidget,
DecimalWidget: ReadOnlyWidget,
},
ObjectFieldTemplate: ReadOnlyObjectFieldTemplate,
FieldTemplate: ReadOnlyFieldTemplate,
Expand Down
48 changes: 48 additions & 0 deletions app/lib/theme/widgets/DecimalWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { WidgetProps } from "@rjsf/core";
import NumberFormat from "react-number-format";

export const DecimalWidget: React.FC<WidgetProps> = ({
schema,
id,
disabled,
uiSchema,
value,
label,
onChange,
}) => {
return (
<div>
<NumberFormat
fixedDecimalScale={uiSchema.decimals}
id={id}
disabled={disabled}
className="decmial"
decimalScale={uiSchema.decimals}
defaultValue={(schema as any).defaultValue}
value={value}
onChange={(e) => onChange(e.target.value || undefined)}
style={{
border: "2px solid #606060",
borderRadius: "0.25em",
padding: "0.5em",
}}
aria-label={label}
/>
<style jsx>
{`
div :global(input) {
width: 100%;
}
div :global(.decimal:focus) {
outline-style: solid;
outline-width: 4px;
outline-color: #3b99fc;
outline-offset: 1px;
}
`}
</style>
</div>
);
};

export default DecimalWidget;

0 comments on commit b4bf598

Please sign in to comment.