diff --git a/editor.planx.uk/src/@planx/components/ExternalPortal/Editor.tsx b/editor.planx.uk/src/@planx/components/ExternalPortal/Editor.tsx index 629fb1488b..1d0f184840 100644 --- a/editor.planx.uk/src/@planx/components/ExternalPortal/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/ExternalPortal/Editor.tsx @@ -1,22 +1,36 @@ +import Autocomplete from "@mui/material/Autocomplete"; +import ListSubheader from "@mui/material/ListSubheader"; import MenuItem from "@mui/material/MenuItem"; +import { styled } from "@mui/material/styles"; import { ComponentType as TYPES, NodeTag, } from "@opensystemslab/planx-core/types"; import { useFormik } from "formik"; -import React from "react"; +import React, { useState } from "react"; +import { FONT_WEIGHT_SEMI_BOLD } from "theme"; import { ComponentTagSelect } from "ui/editor/ComponentTagSelect"; import ModalSection from "ui/editor/ModalSection"; import ModalSectionContent from "ui/editor/ModalSectionContent"; -import SelectInput from "ui/editor/SelectInput/SelectInput"; +import { SelectMultiple, StyledTextField } from "ui/shared/SelectMultiple"; import { ICONS } from "../shared/icons"; interface Flow { id: string; - text: string; + slug: string; + name: string; + team: string; } +const AutocompleteSubHeader = styled(ListSubheader)(({ theme }) => ({ + fontWeight: FONT_WEIGHT_SEMI_BOLD, + fontSize: theme.typography.subtitle1.fontSize, + backgroundColor: theme.palette.background.dark, + color: theme.palette.getContrastText(theme.palette.background.dark), + margin: 0, +})); + const ExternalPortalForm: React.FC<{ id?: string; flowId?: string; @@ -24,6 +38,10 @@ const ExternalPortalForm: React.FC<{ flows?: Array; tags?: NodeTag[]; }> = ({ id, handleSubmit, flowId = "", flows = [], tags = [] }) => { + const [teamArray, setTeamArray] = useState(); + + const uniqueTeamArray = [...new Set(flows.map((item) => item.team))]; + const formik = useFormik({ initialValues: { flowId, @@ -51,26 +69,61 @@ const ExternalPortalForm: React.FC<{ flow that it references. + + setTeamArray([...event])} + options={uniqueTeamArray} + placeholder="" + /> + - - {!id && + groupBy={(option) => option.team} + getOptionLabel={(option) => option.name} + renderOption={(props, option) => ( + ({ paddingY: theme.spacing(1.25) })} + > + {option.name} + + )} + renderInput={(params) => ( + + )} + renderGroup={(params) => ( + <> + {params.group} + {params.children} + + )} + slot="popper" + slotProps={{ + popper: { + placement: "bottom-start", + modifiers: [{ name: "flip", enabled: false }], + }, + }} + /> { flows(order_by: { slug: asc }) { id slug + name team { slug + name } } } @@ -48,11 +50,21 @@ const getExternalPortals = async () => { flow.team && !window.location.pathname.includes(`${flow.team.slug}/${flow.slug}`), ) - .map(({ id, team, slug }: Flow) => ({ + .map(({ id, team, slug, name }: Flow) => ({ id, - text: [team.slug, slug].join("/"), + name, + slug, + team: team.name, })) - .sort(sortFlows); + .sort((a, b) => { + if (a.team > b.team) { + return 1; + } else if (b.team > a.team) { + return -1; + } else { + return 0; + } + }); }; const newNode = route(async (req) => { diff --git a/editor.planx.uk/src/ui/shared/SelectMultiple.tsx b/editor.planx.uk/src/ui/shared/SelectMultiple.tsx index 8de9e6c9c4..a53c8134b1 100644 --- a/editor.planx.uk/src/ui/shared/SelectMultiple.tsx +++ b/editor.planx.uk/src/ui/shared/SelectMultiple.tsx @@ -55,7 +55,7 @@ const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({ }, })) as typeof Autocomplete; -const StyledTextField = styled(TextField)(({ theme }) => ({ +export const StyledTextField = styled(TextField)(({ theme }) => ({ "&:focus-within": { ...borderedFocusStyle, [`& .${outlinedInputClasses.notchedOutline}`]: { @@ -114,7 +114,7 @@ export const CustomCheckbox = styled("span")(({ theme }) => ({ export function SelectMultiple(props: Props) { // MUI doesn't pass the Autocomplete value along to the TextField automatically const isSelectEmpty = !props.value?.length; - const placeholder = isSelectEmpty ? props.placeholder : undefined + const placeholder = isSelectEmpty ? props.placeholder : undefined; return (