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 #3875

Merged
merged 12 commits into from
Oct 30, 2024
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
10 changes: 9 additions & 1 deletion editor.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@
}
}
],
"no-nested-ternary": "error"
"no-nested-ternary": "error",
"@vitest/expect-expect": [
"error",
{
"assertFunctionNames": [
"expect"
]
}
]
},
"overrides": [
{
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.3",
"@opensystemslab/map": "1.0.0-alpha.4",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#54be9e0",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
Expand Down
8 changes: 4 additions & 4 deletions editor.planx.uk/pnpm-lock.yaml

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

9 changes: 3 additions & 6 deletions editor.planx.uk/src/@planx/components/AddressInput/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import {
EditorProps,
ICONS,
} from "@planx/components/ui";
import { EditorProps, ICONS } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import Input from "ui/shared/Input";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { AddressInput, parseAddressInput } from "./model";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PublicProps } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import InputLabel from "ui/public/InputLabel";
import Input from "ui/shared/Input";
import Input from "ui/shared/Input/Input";
import InputRowItem from "ui/shared/InputRowItem";

import { ERROR_MESSAGE } from "../shared/constants";
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Calculate/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import InputGroup from "ui/editor/InputGroup";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import Input from "ui/shared/Input";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import type { Calculate } from "./model";
Expand Down
24 changes: 10 additions & 14 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { clickContinue, visitedNodes } from "pages/FlowEditor/lib/__tests__/utils";
import { Store, useStore } from "pages/FlowEditor/lib/store";

const { getState, setState } = useStore;
const { upcomingCardIds, resetPreview, record } = getState();

// Helper method
const visitedNodes = () => Object.keys(getState().breadcrumbs);
const { upcomingCardIds, resetPreview, autoAnswerableOptions } = getState();

beforeEach(() => {
resetPreview();
Expand All @@ -17,13 +15,12 @@ test("When formatOutputForAutomations is true, Calculate writes an array and fut
expect(upcomingCardIds()).toEqual(["Calculate", "Question"]);

// Step forwards through the Calculate
record("Calculate", { data: { testGroup: ["2"] }, auto: true });
upcomingCardIds();

// The Question has been auto-answered
expect(visitedNodes()).toEqual(["Calculate", "Question"]);
clickContinue("Calculate", { data: { testGroup: ["2"] }, auto: true });

expect(upcomingCardIds()).toEqual(["Group2Notice"]);
// The Question can be auto-answered
expect(visitedNodes()).toEqual(["Calculate"]);
expect(upcomingCardIds()).toEqual(["Question"])
expect(autoAnswerableOptions("Question")).toEqual(["Group2Response"]);
});

test("When formatOutputForAutomations is false, Calculate writes a number and future questions are not auto-answered", () => {
Expand All @@ -32,13 +29,12 @@ test("When formatOutputForAutomations is false, Calculate writes a number and fu
expect(upcomingCardIds()).toEqual(["Calculate", "Question"]);

// Step forwards through the Calculate
record("Calculate", { data: { testGroup: 2 }, auto: true });
upcomingCardIds();
clickContinue("Calculate", { data: { testGroup: 2 }, auto: true });

// The Question has NOT been auto-answered
// The Question cannot be auto-answered
expect(visitedNodes()).toEqual(["Calculate"]);

expect(upcomingCardIds()).toEqual(["Question"]);
expect(autoAnswerableOptions("Question")).toBeUndefined();
});

const flowWithAutomation: Store.Flow = {
Expand Down
26 changes: 22 additions & 4 deletions editor.planx.uk/src/@planx/components/Checklist/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import compose from "ramda/src/compose";
import remove from "ramda/src/remove";
import React, { useEffect, useRef } from "react";
import { FormikHookReturn } from "types";
import ImgInput from "ui/editor/ImgInput";
import ImgInput from "ui/editor/ImgInput/ImgInput";
import InputGroup from "ui/editor/InputGroup";
import ListManager from "ui/editor/ListManager";
import ListManager from "ui/editor/ListManager/ListManager";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import SimpleMenu from "ui/editor/SimpleMenu";
import Input from "ui/shared/Input";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";

Expand All @@ -35,6 +35,7 @@ export interface ChecklistProps extends Checklist {
node?: {
data?: {
allRequired?: boolean;
neverAutoAnswer?: boolean;
categories?: Array<Category>;
description?: string;
fn?: string;
Expand Down Expand Up @@ -285,6 +286,7 @@ export const ChecklistComponent: React.FC<ChecklistProps> = (props) => {
const formik = useFormik<Checklist>({
initialValues: {
allRequired: props.node?.data?.allRequired || false,
neverAutoAnswer: props.node?.data?.neverAutoAnswer || false,
description: props.node?.data?.description || "",
fn: props.node?.data?.fn || "",
groupedOptions: props.groupedOptions,
Expand Down Expand Up @@ -422,6 +424,22 @@ export const ChecklistComponent: React.FC<ChecklistProps> = (props) => {
label="All required"
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.neverAutoAnswer}
onChange={() =>
formik.setFieldValue(
"neverAutoAnswer",
!formik.values.neverAutoAnswer,
)
}
/>
}
label="Always put to user (forgo automation)"
/>
</InputRow>
</InputGroup>
</ModalSectionContent>

Expand Down
44 changes: 39 additions & 5 deletions editor.planx.uk/src/@planx/components/Checklist/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import ImageButton from "@planx/components/shared/Buttons/ImageButton";
import Card from "@planx/components/shared/Preview/Card";
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader";
import { getIn, useFormik } from "formik";
import React, { useState } from "react";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useState } from "react";
import { ExpandableList, ExpandableListItem } from "ui/public/ExpandableList";
import FormWrapper from "ui/public/FormWrapper";
import FullWidthWrapper from "ui/public/FullWidthWrapper";
import ChecklistItem from "ui/shared/ChecklistItem";
import ChecklistItem from "ui/shared/ChecklistItem/ChecklistItem";
import ErrorWrapper from "ui/shared/ErrorWrapper";
import { object } from "yup";

Expand All @@ -38,6 +39,40 @@ function toggleInArray<T>(value: T, arr: Array<T>): Array<T> {
}

const ChecklistComponent: React.FC<Props> = (props) => {
const autoAnswerableOptions = useStore(
(state) => state.autoAnswerableOptions,
);

if (props.neverAutoAnswer) {
return <VisibleChecklist {...props} />;
}

let idsThatCanBeAutoAnswered: string[] | undefined;
if (props.id) idsThatCanBeAutoAnswered = autoAnswerableOptions(props.id);
if (idsThatCanBeAutoAnswered) {
return (
<AutoAnsweredChecklist {...props} answerIds={idsThatCanBeAutoAnswered} />
);
}

return <VisibleChecklist {...props} />;
};

// An auto-answered Checklist won't be seen by the user, but still leaves a breadcrumb
const AutoAnsweredChecklist: React.FC<Props & { answerIds: string[] }> = (
props,
) => {
useEffect(() => {
props.handleSubmit?.({
answers: props.answerIds,
auto: true,
});
}, []);

return null;
};

const VisibleChecklist: React.FC<Props> = (props) => {
const {
description = "",
groupedOptions,
Expand Down Expand Up @@ -168,9 +203,8 @@ const ChecklistComponent: React.FC<Props> = (props) => {
pb={2}
aria-labelledby={`group-${index}-heading`}
id={`group-${index}-content`}
data-testid={`group-${index}${
isExpanded ? "-expanded" : ""
}`}
data-testid={`group-${index}${isExpanded ? "-expanded" : ""
}`}
>
{group.children.map((option) => (
<ChecklistItem
Expand Down
1 change: 1 addition & 0 deletions editor.planx.uk/src/@planx/components/Checklist/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface Checklist extends BaseNodeData {
img?: string;
allRequired?: boolean;
categories?: Array<Category>;
neverAutoAnswer?: boolean;
}

interface ChecklistExpandableProps {
Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/Confirmation/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useFormik } from "formik";
import React, { ChangeEvent } from "react";
import ListManager, {
EditorProps as ListManagerEditorProps,
} from "ui/editor/ListManager";
} from "ui/editor/ListManager/ListManager";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import Input from "ui/shared/Input";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { Confirmation, parseNextSteps, Step } from "./model";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useEffect, useState } from "react";
import Banner from "ui/public/Banner";
import FileDownload from "ui/public/FileDownload";
import NumberedList from "ui/public/NumberedList";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml/ReactMarkdownOrHtml";

import type { Confirmation } from "./model";

Expand Down
9 changes: 3 additions & 6 deletions editor.planx.uk/src/@planx/components/ContactInput/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import {
EditorProps,
ICONS,
} from "@planx/components/ui";
import { EditorProps, ICONS } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import Input from "ui/shared/Input";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ContactInput, parseContactInput } from "./model";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PublicProps } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import InputLabel from "ui/public/InputLabel";
import Input from "ui/shared/Input";
import Input from "ui/shared/Input/Input";
import InputRowItem from "ui/shared/InputRowItem";

import { ERROR_MESSAGE } from "../shared/constants";
Expand Down
9 changes: 3 additions & 6 deletions editor.planx.uk/src/@planx/components/Content/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import type { Content } from "@planx/components/Content/model";
import { parseContent } from "@planx/components/Content/model";
import {
EditorProps,
ICONS,
} from "@planx/components/ui";
import { EditorProps, ICONS } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import ColorPicker from "ui/editor/ColorPicker";
import ColorPicker from "ui/editor/ColorPicker/ColorPicker";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import InputRow from "ui/shared/InputRow";

export type Props = EditorProps<TYPES.Content, Content>;
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/Content/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { PublicProps } from "@planx/components/ui";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analytics/provider";
import React from "react";
import { getContrastTextColor } from "styleUtils";
import { emptyContent } from "ui/editor/RichTextInput";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml";
import { emptyContent } from "ui/editor/RichTextInput/RichTextInput";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml/ReactMarkdownOrHtml";

import { HelpButton, Image } from "../shared/Preview/CardHeader/styled";
import MoreInfo from "../shared/Preview/MoreInfo";
Expand Down
13 changes: 5 additions & 8 deletions editor.planx.uk/src/@planx/components/DateInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import {
DateInput,
editorValidationSchema,
paddedDate,
parseDateInput,
} from "@planx/components/DateInput/model";
import { parseDateInput } from "@planx/components/DateInput/model";
import {
EditorProps,
ICONS,
} from "@planx/components/ui";
import { EditorProps, ICONS } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput";
import DateInputUi from "ui/shared/DateInput";
import Input from "ui/shared/Input";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import DateInputUi from "ui/shared/DateInput/DateInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

export type Props = EditorProps<TYPES.DateInput, DateInput>;
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/DateInput/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHead
import { PublicProps } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import DateInputComponent from "ui/shared/DateInput";
import DateInputComponent from "ui/shared/DateInput/DateInput";
import InputRow from "ui/shared/InputRow";
import { object } from "yup";

Expand Down
Loading
Loading