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

chore: split residential unit List component schemas into six options #3250

Merged
merged 5 commits into from
Jun 6, 2024
Merged
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
1 change: 0 additions & 1 deletion editor.planx.uk/src/@planx/components/Checklist/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Card from "@planx/components/shared/Preview/Card";
import CardHeader from "@planx/components/shared/Preview/CardHeader";
import { getIn, useFormik } from "formik";
import React, { useState } from "react";
import InputLegend from "ui/editor/InputLegend";
import { ExpandableList, ExpandableListItem } from "ui/public/ExpandableList";
import FormWrapper from "ui/public/FormWrapper";
import FullWidthWrapper from "ui/public/FullWidthWrapper";
Expand Down
24 changes: 21 additions & 3 deletions editor.planx.uk/src/@planx/components/List/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@ import InputRowLabel from "ui/shared/InputRowLabel";

import { EditorProps, ICONS, InternalNotes, MoreInformation } from "../ui";
import { List, parseContent } from "./model";
import { ResidentialUnits } from "./schemas/ResidentialUnits";
import { ResidentialUnitsExisting } from "./schemas/ResidentialUnits/Existing";
import { ResidentialUnitsGLANew } from "./schemas/ResidentialUnits/GLA/New";
import { ResidentialUnitsGLARebuilt } from "./schemas/ResidentialUnits/GLA/Rebuilt";
import { ResidentialUnitsGLARemoved } from "./schemas/ResidentialUnits/GLA/Removed";
import { ResidentialUnitsGLARetained } from "./schemas/ResidentialUnits/GLA/Retained";
import { ResidentialUnitsProposed } from "./schemas/ResidentialUnits/Proposed";
import { Zoo } from "./schemas/Zoo";

type Props = EditorProps<TYPES.List, List>;

export const SCHEMAS = [
{ name: "Residential Units (alpha)", schema: ResidentialUnits },
{ name: "Residential units - Existing", schema: ResidentialUnitsExisting },
{ name: "Residential units - Proposed", schema: ResidentialUnitsProposed },
{ name: "Residential units (GLA) - New", schema: ResidentialUnitsGLANew },
{
name: "Residential units (GLA) - Rebuilt",
schema: ResidentialUnitsGLARebuilt,
},
{
name: "Residentail units (GLA) - Removed",
schema: ResidentialUnitsGLARemoved,
},
{
name: "Residential units (GLA) - Retained",
schema: ResidentialUnitsGLARetained,
},
{ name: "Zoo (test)", schema: Zoo },
// TODO: Residential units (GLA)
];

function ListComponent(props: Props) {
Expand Down
10 changes: 9 additions & 1 deletion editor.planx.uk/src/@planx/components/List/Public/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,16 @@ export const ListProvider: React.FC<ListProviderProps> = (props) => {
const flattenedPassportData = flatten(defaultPassportData);

// basic example of general summary stats we can add onSubmit
let sumIdenticalUnits = 0;
defaultPassportData[`${props.fn}`].map(
(item) => (sumIdenticalUnits += parseInt(item?.identicalUnits)),
);
const summaries = {
[`${props.fn}.count`]: defaultPassportData[`${props.fn}`].length,
[`${props.fn}.total.listItems`]:
defaultPassportData[`${props.fn}`].length,
...(sumIdenticalUnits > 0 && {
[`${props.fn}.total.units`]: sumIdenticalUnits,
}),
};

handleSubmit?.({
Expand Down
7 changes: 2 additions & 5 deletions editor.planx.uk/src/@planx/components/List/Public/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ export const NumberFieldInput: React.FC<Props<NumberField>> = ({
);
};

export const RadioFieldInput: React.FC<Props<QuestionField>> = ({
id,
data,
required,
}) => {
export const RadioFieldInput: React.FC<Props<QuestionField>> = (props) => {
const { formik, activeIndex } = useListContext();
const { id, data, required } = props;

return (
<FormControl sx={{ width: "100%" }} component="fieldset">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const mockPayload = {
"mockFn.two.email": "[email protected]",
"mockFn.two.name": "Richard Parker",
"mockFn.two.size": "Medium",
"mockFn.count": 2,
"mockFn.total.listItems": 2,
},
};

Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/List/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const Root = () => {
<ErrorWrapper
error={
errors.addItem
? `Please save all responses before adding a new ${schema.type.toLowerCase()}`
? `Please save all responses before adding another ${schema.type.toLowerCase()}`
: ""
}
>
Expand All @@ -181,7 +181,7 @@ const Root = () => {
sx={{ width: "100%" }}
data-testid="list-add-button"
>
+ Add a new {schema.type.toLowerCase()} description
+ Add another {schema.type.toLowerCase()} description
Copy link
Member Author

@jessicamcinchak jessicamcinchak Jun 6, 2024

Choose a reason for hiding this comment

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

One of the GLA schemas has type: "New built residential unit", so "another" prevents "new new"

</Button>
</ErrorWrapper>
</>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Schema } from "../../model";

export const ResidentialUnitsExisting: Schema = {
type: "Existing residential unit",
fields: [
{
type: "question",
data: {
title: "What best describes the tenure of this unit?",
fn: "tenure",
options: [
{ id: "MH", data: { text: "Market housing", val: "MH" } },
{
id: "SAIR",
data: { text: "Social, affordable or interim rent", val: "SAIR" },
},
{
id: "AHO",
data: { text: "Affordable home ownership", val: "AHO" },
},
{ id: "SH", data: { text: "Starter homes", val: "SH" } },
{
id: "selfCustomBuild",
data: {
text: "Self-build and custom build",
val: "selfCustomBuild",
},
},
{ id: "other", data: { text: "Other", val: "other" } },
],
},
},
{
type: "question",
data: {
title: "What best describes the type of this unit?",
fn: "type",
options: [
{ id: "house", data: { text: "House", val: "house" } },
{
id: "flat",
data: { text: "Flat, apartment or maisonette", val: "flat" },
},
{
id: "sheltered",
data: { text: "Sheltered housing", val: "sheltered" },
},
{ id: "studio", data: { text: "Studio or bedsit", val: "studio" } },
{ id: "cluster", data: { text: "Cluster flat", val: "cluster" } },
{ id: "other", data: { text: "Other", val: "other" } },
],
},
},
{
type: "number",
data: {
title: "How many bedrooms does this unit have?",
fn: "bedrooms",
allowNegatives: false,
},
},
{
type: "number",
data: {
title: "How many identical units does the description above apply to?",
fn: "identicalUnits",
allowNegatives: false,
},
},
],
min: 1,
} as const;
Loading
Loading