From 51c7c574372fc1118c694be17e5da68ab2c42184 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Sun, 17 Nov 2024 11:49:49 +0100 Subject: [PATCH 1/9] editor table is selectable --- .../components/PlanningConstraints/Editor.tsx | 45 ++++++++++++++++--- .../components/PlanningConstraints/model.ts | 2 + 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/PlanningConstraints/Editor.tsx b/editor.planx.uk/src/@planx/components/PlanningConstraints/Editor.tsx index 0e084932ed..6f1215cdfe 100644 --- a/editor.planx.uk/src/@planx/components/PlanningConstraints/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/PlanningConstraints/Editor.tsx @@ -10,7 +10,7 @@ import Typography from "@mui/material/Typography"; import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; import { EditorProps } from "@planx/components/shared/types"; import { useFormik } from "formik"; -import React from "react"; +import React, { ChangeEvent } from "react"; import { FONT_WEIGHT_BOLD } from "theme"; import InputGroup from "ui/editor/InputGroup"; import { ModalFooter } from "ui/editor/ModalFooter"; @@ -36,8 +36,38 @@ function PlanningConstraintsComponent(props: Props) { data: newValues, }); }, + validate: () => { + // TODO must select at least one formik.values.dataValues + }, }); + const changeSelectAll = + (vals: string[] | undefined) => + (_event: ChangeEvent, _checked: boolean) => { + let newCheckedVals: string[]; + if (vals?.length !== availableDatasets.length) { + newCheckedVals = availableDatasets.map((d) => d.val); + } else { + newCheckedVals = []; + } + + formik.setFieldValue("dataValues", newCheckedVals); + }; + + const changeDataset = + (val: string) => + (_event: ChangeEvent, _checked: boolean) => { + let newCheckedVals; + if (formik.values.dataValues?.includes(val)) { + newCheckedVals = formik.values.dataValues.filter((dv) => dv !== val); + } else { + newCheckedVals = formik.values.dataValues + ? [...formik.values.dataValues, val] + : [val]; + } + formik.setFieldValue("dataValues", newCheckedVals); + }; + return (