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

Production deploy #4126

Merged
merged 4 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.4",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#dc2386b",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#e126742",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import DataFieldIcon from "@mui/icons-material/Code";
import DataFieldOffIcon from "@mui/icons-material/CodeOff";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import ToggleIconButton from "ui/editor/ToggleIconButton";

export const ToggleDataFieldsButton: React.FC = () => {
const [showDataFields, toggleShowDataFields] = useStore((state) => [
Expand All @@ -12,24 +10,12 @@ export const ToggleDataFieldsButton: React.FC = () => {
]);

return (
<Tooltip title="Toggle data fields" placement="right">
<IconButton
aria-label="Toggle data fields"
onClick={toggleShowDataFields}
size="large"
sx={(theme) => ({
background: theme.palette.background.paper,
padding: theme.spacing(1),
color: showDataFields
? theme.palette.text.primary
: theme.palette.text.disabled,
"&:hover": {
background: theme.palette.common.white,
},
})}
>
{showDataFields ? <DataFieldIcon /> : <DataFieldOffIcon />}
</IconButton>
</Tooltip>
<ToggleIconButton
isToggled={showDataFields}
onToggle={toggleShowDataFields}
icon={<DataFieldIcon />}
tooltip="Toggle data fields"
ariaLabel="Toggle data fields"
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import HelpTextOffIcon from "@mui/icons-material/DoNotDisturbOff";
import HelpTextIcon from "@mui/icons-material/Help";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import ToggleIconButton from "ui/editor/ToggleIconButton";

export const ToggleHelpTextButton: React.FC = () => {
const [showHelpText, toggleShowHelpText] = useStore((state) => [
Expand All @@ -12,24 +10,12 @@ export const ToggleHelpTextButton: React.FC = () => {
]);

return (
<Tooltip title="Toggle help text" placement="right">
<IconButton
aria-label="Toggle help text"
onClick={toggleShowHelpText}
size="large"
sx={(theme) => ({
background: theme.palette.background.paper,
padding: theme.spacing(1),
color: showHelpText
? theme.palette.text.primary
: theme.palette.text.disabled,
"&:hover": {
background: theme.palette.common.white,
},
})}
>
{showHelpText ? <HelpTextIcon /> : <HelpTextOffIcon />}
</IconButton>
</Tooltip>
<ToggleIconButton
isToggled={showHelpText}
onToggle={toggleShowHelpText}
icon={<HelpTextIcon />}
tooltip="Toggle help text"
ariaLabel="Toggle help text"
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ImageOffIcon from "@mui/icons-material/HideImage";
import ImageIcon from "@mui/icons-material/Image";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import ToggleIconButton from "ui/editor/ToggleIconButton";

export const ToggleImagesButton: React.FC = () => {
const [showImages, toggleShowImages] = useStore((state) => [
Expand All @@ -12,24 +10,12 @@ export const ToggleImagesButton: React.FC = () => {
]);

return (
<Tooltip title="Toggle images" placement="right">
<IconButton
aria-label="Toggle images"
onClick={toggleShowImages}
size="large"
sx={(theme) => ({
background: theme.palette.background.paper,
padding: theme.spacing(1),
color: showImages
? theme.palette.text.primary
: theme.palette.text.disabled,
"&:hover": {
background: theme.palette.common.white,
},
})}
>
{showImages ? <ImageIcon /> : <ImageOffIcon />}
</IconButton>
</Tooltip>
<ToggleIconButton
isToggled={showImages}
onToggle={toggleShowImages}
icon={<ImageIcon />}
tooltip="Toggle images"
ariaLabel="Toggle images"
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import LabelIcon from "@mui/icons-material/Label";
import LabelOffIcon from "@mui/icons-material/LabelOff";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import ToggleIconButton from "ui/editor/ToggleIconButton";

export const ToggleTagsButton: React.FC = () => {
const [showTags, toggleShowTags] = useStore((state) => [
Expand All @@ -12,24 +10,12 @@ export const ToggleTagsButton: React.FC = () => {
]);

return (
<Tooltip title="Toggle tags" placement="right">
<IconButton
aria-label="Toggle tags"
onClick={toggleShowTags}
size="large"
sx={(theme) => ({
background: theme.palette.background.paper,
padding: theme.spacing(1),
color: showTags
? theme.palette.text.primary
: theme.palette.text.disabled,
"&:hover": {
background: theme.palette.common.white,
},
})}
>
{showTags ? <LabelIcon /> : <LabelOffIcon />}
</IconButton>
</Tooltip>
<ToggleIconButton
isToggled={showTags}
onToggle={toggleShowTags}
icon={<LabelIcon />}
tooltip="Toggle tags"
ariaLabel="Toggle tags"
/>
);
};
69 changes: 40 additions & 29 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,27 @@ export const previewStore: StateCreator<
if (passportValue.length > 0) {
const existingValue = acc.data?.[key] ?? [];

const combined = key === planningConstraintsFn
? passportValue.concat(existingValue) // Planning constraints uniquely store all-levels of granularity, rather than most granular only
: passportValue
.concat(existingValue)
.reduce(
(acc: string[], curr: string, _i: number, arr: string[]) => {
if (!arr.some((x) => x !== curr && x?.startsWith(curr))) {
acc.push(curr);
}
return acc;
},
[],
);
const combined =
key === planningConstraintsFn
? passportValue.concat(existingValue) // Planning constraints uniquely store all-levels of granularity, rather than most granular only
: passportValue
.concat(existingValue)
.reduce(
(
acc: string[],
curr: string,
_i: number,
arr: string[],
) => {
if (
!arr.some((x) => x !== curr && x?.startsWith(curr))
) {
acc.push(curr);
}
return acc;
},
[],
);

passportData[key] = uniq(combined);
}
Expand Down Expand Up @@ -414,8 +422,7 @@ export const previewStore: StateCreator<
}));
const hidden = !selections.some(
(selection) =>
selection.data?.flags &&
selection.data.flags.includes(flag?.value)
selection.data?.flags && selection.data.flags.includes(flag?.value),
);

return {
Expand Down Expand Up @@ -521,7 +528,7 @@ export const previewStore: StateCreator<
// Only proceed if the user has seen at least one node with this fn before
const visitedFns = Object.entries(breadcrumbs).filter(
([nodeId, _breadcrumb]) =>
flow[nodeId].data?.fn === data.fn ||
flow[nodeId]?.data?.fn === data.fn ||
// Account for nodes like FindProperty that don't have `data.fn` prop but still set passport vars like `property.region` etc
Object.keys(passport?.data || {}).includes(data.fn),
);
Expand All @@ -530,7 +537,7 @@ export const previewStore: StateCreator<
// For each visited node, get the data values of its' options (aka edges or Answer nodes)
const visitedOptionVals: string[] = [];
visitedFns.forEach(([nodeId, _breadcrumb]) => {
flow[nodeId].edges?.map((edgeId) => {
flow[nodeId]?.edges?.map((edgeId) => {
if (flow[edgeId].type === TYPES.Answer && flow[edgeId].data?.val) {
visitedOptionVals.push(flow[edgeId].data.val);
}
Expand Down Expand Up @@ -563,11 +570,12 @@ export const previewStore: StateCreator<

// Get existing passport value(s) for this node's fn, accounting for Planning Constraints special `_nots`
const passportValues = passport.data?.[data.fn];
const nots: string[] | undefined = passport.data?.["_nots"]?.[planningConstraintsFn];
const nots: string[] | undefined =
passport.data?.["_nots"]?.[planningConstraintsFn];

const foundPassportValues =
Array.isArray(passportValues) && passportValues.length > 0;

// If we have existing passport value(s) for this fn in an eligible automation format (eg not numbers or plain strings),
// then proceed through the matching option(s) or the blank option independent if other vals have been seen before
if (foundPassportValues && data.fn !== planningConstraintsFn) {
Expand Down Expand Up @@ -598,20 +606,22 @@ export const previewStore: StateCreator<
});
});
} else {
if (blankOption?.id) { optionsThatCanBeAutoAnswered.push(blankOption.id) };
if (blankOption?.id) {
optionsThatCanBeAutoAnswered.push(blankOption.id);
}
}
}

if (data.fn === planningConstraintsFn && (foundPassportValues || nots)) {
// Planning constraints queried from an external source are stored via two separate passport vars:
// Planning constraints queried from an external source are stored via two separate passport vars:
// - One for intersections aka `planningConstraintsFn`
// - Another for not-intersections aka `_nots`
const matchingIntersectingConstraints = passportValues?.filter(
(passportValue: any) =>
sortedOptions.some((option) => passportValue === option.data?.val)
sortedOptions.some((option) => passportValue === option.data?.val),
);
const matchingNots = nots?.filter(
(not) => sortedOptions.some((option => not === option.data?.val))
const matchingNots = nots?.filter((not) =>
sortedOptions.some((option) => not === option.data?.val),
);

if (matchingIntersectingConstraints?.length > 0) {
Expand All @@ -629,12 +639,13 @@ export const previewStore: StateCreator<
sortedOptions.forEach((option) => {
nots?.forEach((not) => {
if (not === option.data?.val) {
if (blankOption?.id) optionsThatCanBeAutoAnswered.push(blankOption.id);
if (blankOption?.id)
optionsThatCanBeAutoAnswered.push(blankOption.id);
}
});
});
} else {
// If this node is asking about a constraint that we have NOT queried from an external source,
// If this node is asking about a constraint that we have NOT queried from an external source,
// Then put it to the user exactly once and automate future instances of it
if (blankOption?.id && hasVisitedEveryOption)
optionsThatCanBeAutoAnswered.push(blankOption.id);
Expand Down Expand Up @@ -831,9 +842,9 @@ export const sortBreadcrumbs = (
return editingNodes?.length
? nextBreadcrumbs
: sortIdsDepthFirst(flow)(new Set(Object.keys(nextBreadcrumbs))).reduce(
(acc, id) => ({ ...acc, [id]: nextBreadcrumbs[id] }),
{} as Store.Breadcrumbs,
);
(acc, id) => ({ ...acc, [id]: nextBreadcrumbs[id] }),
{} as Store.Breadcrumbs,
);
};

function handleNodesWithPassport({
Expand Down
Loading
Loading