From 6e4a952e2c9109519e4ce1f21f06fe0a9ced791c Mon Sep 17 00:00:00 2001 From: ollie <107874766+zz-hh-aa@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:45:51 +0100 Subject: [PATCH 01/11] feat: add metabase token and base url placeholders to dotenv template (#3815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dafydd Llŷr Pearson --- .env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.example b/.env.example index 9ee369705a..5bb66c3715 100644 --- a/.env.example +++ b/.env.example @@ -51,6 +51,8 @@ SLACK_WEBHOOK_URL=👻 # Metabase analytics METABASE_PORT=5000 +METABASE_API_KEY=👻 +METABASE_URL_EXT=http://localhost:${METABASE_PORT} # Minio object storage server MINIO_PORT=9000 From 5d76d2054cf9219773790cc59b4c4d8287d16b5f Mon Sep 17 00:00:00 2001 From: Ian Jones <51156018+ianjon3s@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:57:31 +0100 Subject: [PATCH 02/11] fix: Editor graph styling snags (#3821) --- .../src/pages/FlowEditor/floweditor.scss | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/floweditor.scss b/editor.planx.uk/src/pages/FlowEditor/floweditor.scss index 561d37248a..429c293660 100644 --- a/editor.planx.uk/src/pages/FlowEditor/floweditor.scss +++ b/editor.planx.uk/src/pages/FlowEditor/floweditor.scss @@ -138,6 +138,11 @@ $fontMonospace: "Source Code Pro", monospace; border: $nodeBorderWidth dashed red; } + // Allow nodes to expand to width of data when toggled + &:not(.type-Section):not(.portal) > a { + width: 100%; + } + & a { position: relative; display: flex; @@ -150,6 +155,8 @@ $fontMonospace: "Source Code Pro", monospace; background: white; user-select: none; padding: 6px 12px; + overflow-wrap: break-word; + word-break: break-word; * { pointer-events: none; @@ -161,16 +168,14 @@ $fontMonospace: "Source Code Pro", monospace; overflow-wrap: break-word; } - > svg { + // Component icon + & svg { margin-left: -6px; - margin-top: 0.5px; - width: 16px; - height: 16px; - opacity: 0.6; - } - - > span:not(:first-child) { - margin-left: 6px; + margin-top: -1px; + margin-right: 6px; + width: 19px; + height: 19px; + opacity: 0.75; } } From f7bef14f47611e493fdfa4262cb49153581d0503 Mon Sep 17 00:00:00 2001 From: Rory Doak <138574807+RODO94@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:49:12 +0100 Subject: [PATCH 03/11] bug: Calculate component error handling fix (#3805) --- .../@planx/components/Calculate/Editor.tsx | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/Calculate/Editor.tsx b/editor.planx.uk/src/@planx/components/Calculate/Editor.tsx index c1c0239ab5..ef45074716 100644 --- a/editor.planx.uk/src/@planx/components/Calculate/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/Calculate/Editor.tsx @@ -3,11 +3,8 @@ import { styled } from "@mui/material/styles"; import Switch from "@mui/material/Switch"; import Typography from "@mui/material/Typography"; import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; -import { - EditorProps, - ICONS, -} from "@planx/components/ui"; -import { useFormik } from "formik"; +import { EditorProps, ICONS } from "@planx/components/ui"; +import { FormikErrors, useFormik } from "formik"; import React from "react"; import InputGroup from "ui/editor/InputGroup"; import { ModalFooter } from "ui/editor/ModalFooter"; @@ -36,12 +33,51 @@ export default function Component(props: Props) { props.handleSubmit({ type: TYPES.Calculate, data: newValues }); } }, - validate: () => { - // can parse formula - getVariables(formik.values.formula); + validate: (values) => { + const errors: FormikErrors = {}; + try { + // can parse formula + getVariables(formik.values.formula); + + // Validate formula + const result = evaluate( + values.formula, + values.samples, + values.defaults, + ); + + if (Number.isNaN(Number(result))) { + errors.formula = "Enter a formula which outputs a number"; + } + } catch (error: any) { + errors.formula = error.message; + } + return errors; }, + + validateOnChange: false, }); + const sampleResult = React.useMemo(() => { + try { + const result = evaluate( + formik.values.formula, + formik.values.samples, + formik.values.defaults, + ); + // Type guard as mathjs evaluates `m` to a "Unit" object for "meter" + if (!Number.isNaN(Number(result))) { + return result; + } else if (result === undefined) { + return "a number returned from the formula above"; + } else { + return `'${result}' which is of the type: ${typeof result}`; + } + } catch (e) { + return UNKNOWN; + } + }, [formik.values.formula, formik.values.defaults, formik.values.samples]); + /** * When the formula is updated, remove any defaults which are no longer used */ @@ -65,24 +101,6 @@ export default function Component(props: Props) { } }, [formik.values.formula]); - const sampleResult = React.useMemo(() => { - try { - const result = evaluate( - formik.values.formula, - formik.values.samples, - formik.values.defaults, - ); - // Type guard as mathjs evaluates `m` to a "Unit" object for "meter" - if (typeof result === "number") { - return result; - } else { - return UNKNOWN; - } - } catch (e) { - return UNKNOWN; - } - }, [formik.values.formula, formik.values.defaults, formik.values.samples]); - return (