From ffc7ba08e8dbb9d383bcdb76e4c18a98dcd7a690 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 15 Aug 2024 16:09:33 +0100 Subject: [PATCH 01/24] add store values to ServiceSettings --- .../components/Settings/ServiceSettings.tsx | 26 ++++++++++++++----- .../src/pages/FlowEditor/lib/store/team.ts | 5 ++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index 0e4ef6f895..b4dfdd599a 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -5,6 +5,7 @@ import Container from "@mui/material/Container"; import FormControlLabel, { formControlLabelClasses, } from "@mui/material/FormControlLabel"; +import Link from "@mui/material/Link"; import Snackbar from "@mui/material/Snackbar"; import Switch, { SwitchProps } from "@mui/material/Switch"; import Typography from "@mui/material/Typography"; @@ -81,13 +82,23 @@ const TextInput: React.FC<{ }; const ServiceSettings: React.FC = () => { - const [flowSettings, updateFlowSettings, flowStatus, updateFlowStatus] = - useStore((state) => [ - state.flowSettings, - state.updateFlowSettings, - state.flowStatus, - state.updateFlowStatus, - ]); + const [ + flowSettings, + updateFlowSettings, + flowStatus, + updateFlowStatus, + flowSlug, + getTeam, + isFlowPublished, + ] = useStore((state) => [ + state.flowSettings, + state.updateFlowSettings, + state.flowStatus, + state.updateFlowStatus, + state.flowSlug, + state.getTeam, + state.isFlowPublished, + ]); const [isAlertOpen, setIsAlertOpen] = useState(false); @@ -280,6 +291,7 @@ const ServiceSettings: React.FC = () => {

Offline services can still be edited and published as normal.

+ + + ); +}; + const TitledLinkComponent: React.FC<{ link: string; isActive: boolean; @@ -34,6 +65,7 @@ const TitledLinkComponent: React.FC<{ Your public link + {isActive ? ( From 316fce3fbefab3d31c533379ca4b33259fffa18b Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 16 Aug 2024 11:27:20 +0100 Subject: [PATCH 08/24] refactor flowstatus use --- .../components/Settings/ServiceSettings.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index 61d9d7a78f..eed11e68cf 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -13,6 +13,7 @@ import Switch, { SwitchProps } from "@mui/material/Switch"; import Tooltip from "@mui/material/Tooltip"; import Typography from "@mui/material/Typography"; import { FlowStatus } from "@opensystemslab/planx-core/types"; +import { isActive } from "@tiptap/core"; import { useFormik } from "formik"; import React, { useState } from "react"; import { rootFlowPath } from "routes/utils"; @@ -29,11 +30,12 @@ import InputRowItem from "ui/shared/InputRowItem"; import type { FlowSettings } from "../../../../types"; import { useStore } from "../../lib/store"; -const CopyButton = (props: { link: string }) => { +const CopyButton = (props: { link: string; isActive: boolean }) => { const [copyMessage, setCopyMessage] = useState<"copy" | "copied">("copy"); return ( ); @@ -65,7 +66,7 @@ const TitledLinkComponent: React.FC<{ Your public link - + {isActive ? ( @@ -172,7 +173,6 @@ const ServiceSettings: React.FC = () => { const [ flowSettings, updateFlowSettings, - flowStatus, updateFlowStatus, flowSlug, teamDomain, @@ -180,7 +180,6 @@ const ServiceSettings: React.FC = () => { ] = useStore((state) => [ state.flowSettings, state.updateFlowSettings, - state.flowStatus, state.updateFlowStatus, state.flowSlug, state.teamDomain, @@ -392,7 +391,7 @@ const ServiceSettings: React.FC = () => { From ce5410ef961165ddebed3e2725a0f8a32bcbd3e8 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 16 Aug 2024 11:28:07 +0100 Subject: [PATCH 09/24] add flow status from store --- .../pages/FlowEditor/components/Settings/ServiceSettings.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index eed11e68cf..03583f9310 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -173,6 +173,7 @@ const ServiceSettings: React.FC = () => { const [ flowSettings, updateFlowSettings, + flowStatus, updateFlowStatus, flowSlug, teamDomain, @@ -180,6 +181,7 @@ const ServiceSettings: React.FC = () => { ] = useStore((state) => [ state.flowSettings, state.updateFlowSettings, + state.flowStatus, state.updateFlowStatus, state.flowSlug, state.teamDomain, From 0ba44e5aa440f33a286aac29edeef3b683ed69d9 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 16 Aug 2024 11:30:12 +0100 Subject: [PATCH 10/24] remove console log and comments --- .../components/Settings/ServiceSettings.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index 03583f9310..dcc67605ee 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -90,25 +90,14 @@ const PublicLink: React.FC<{ const isFlowPublic = isFlowPublished && status === "online"; const hasSubdomain = Boolean(subdomain); - console.log({ isFlowPublic, hasSubdomain }); - - // Passing both subdomain and publishedLink into this component... - // means we have the flexibility to display one or both... - // and means we need to do less upfront work in the ServiceSettings component - // the logic is contained within this one component with context around it - switch (true) { case isFlowPublic && hasSubdomain: - console.log("Flow Public and Subdomain true"); return ; case isFlowPublic && !hasSubdomain: - console.log("Flow Public and Subdomain false"); return ; case !isFlowPublic && hasSubdomain: - console.log("Flow private and Subdomain true"); return ; case !isFlowPublic && !hasSubdomain: - console.log("Flow private and Subdomain false"); return ; } }; From 4008f0aecd5b781033c96fed8b518b34e1acf12f Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 16 Aug 2024 11:32:16 +0100 Subject: [PATCH 11/24] harmonising flowStatus type use --- .../pages/FlowEditor/components/Settings/ServiceSettings.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index dcc67605ee..f18f7a16d1 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -6,14 +6,12 @@ import Container from "@mui/material/Container"; import FormControlLabel, { formControlLabelClasses, } from "@mui/material/FormControlLabel"; -import IconButton from "@mui/material/IconButton"; import Link from "@mui/material/Link"; import Snackbar from "@mui/material/Snackbar"; import Switch, { SwitchProps } from "@mui/material/Switch"; import Tooltip from "@mui/material/Tooltip"; import Typography from "@mui/material/Typography"; import { FlowStatus } from "@opensystemslab/planx-core/types"; -import { isActive } from "@tiptap/core"; import { useFormik } from "formik"; import React, { useState } from "react"; import { rootFlowPath } from "routes/utils"; @@ -83,7 +81,7 @@ const TitledLinkComponent: React.FC<{ const PublicLink: React.FC<{ isFlowPublished: boolean; - status: string; + status: FlowStatus; subdomain: string; publishedLink: string; }> = ({ isFlowPublished, status, subdomain, publishedLink }) => { From bdc268882498086a35e0a9b8093b005d0849a23d Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 16 Aug 2024 12:16:32 +0100 Subject: [PATCH 12/24] alter help text --- .../components/Settings/ServiceSettings.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index f18f7a16d1..b257a08afa 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -56,7 +56,7 @@ const CopyButton = (props: { link: string; isActive: boolean }) => { ); }; -const TitledLinkComponent: React.FC<{ +const TitledLink: React.FC<{ link: string; isActive: boolean; }> = ({ link, isActive }) => { @@ -90,13 +90,13 @@ const PublicLink: React.FC<{ switch (true) { case isFlowPublic && hasSubdomain: - return ; + return ; case isFlowPublic && !hasSubdomain: - return ; + return ; case !isFlowPublic && hasSubdomain: - return ; + return ; case !isFlowPublic && !hasSubdomain: - return ; + return ; } }; @@ -229,6 +229,20 @@ const ServiceSettings: React.FC = () => { }, }); + const publicLinkHelpText = () => { + const isFlowOnline = Boolean(statusForm.values.status === "online"); + switch (true) { + case isFlowPublished && isFlowOnline: + return ""; + case !isFlowPublished && isFlowOnline: + return "Publish your flow to activate the public link"; + case isFlowPublished && !isFlowOnline: + return "Switch your flow to 'online' to activate the public link"; + case !isFlowPublished && !isFlowOnline: + return "Publish your flow and switch it to 'online' to activate the public link"; + } + }; + const removeLinkEndSlash = (link: string) => link[link.length - 1] === "/" ? link.slice(0, -1) : link; @@ -376,6 +390,7 @@ const ServiceSettings: React.FC = () => { enable analytics gathering.

Offline services can still be edited and published as normal.

+

{publicLinkHelpText()}

Date: Fri, 16 Aug 2024 14:53:54 +0100 Subject: [PATCH 13/24] move help text, remove redundant fn, props, and Boolean() --- .../components/Settings/ServiceSettings.tsx | 89 ++++++++++++------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index b257a08afa..2b6fa5c538 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -34,7 +34,6 @@ const CopyButton = (props: { link: string; isActive: boolean }) => {