Skip to content

Commit

Permalink
feat: feedback editor component (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Nov 1, 2024
1 parent 8c5f127 commit 363cc94
Show file tree
Hide file tree
Showing 38 changed files with 1,790 additions and 1,369 deletions.
20 changes: 11 additions & 9 deletions editor.planx.uk/docs/adding-a-new-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Let's add a `SetValue` component

## Core directory & files
## Core directory typing

1. `planx-core/src/types/component.ts`

Expand All @@ -12,9 +12,11 @@ Add type to enum in `planx-core` repository
SetValue = 380,
```

2. `mkdir src/@planx/components/SetValue`
## `planx-new` component files

3. `model.ts`
1. `mkdir src/@planx/components/SetValue`

2. `model.ts`

```typescript
import { BaseNodeData, parseBaseNodeData } from "../shared";
Expand All @@ -31,7 +33,7 @@ export const parseContent = (
});
```

4. `Editor.tsx`
3. `Editor.tsx`

```typescript
type Props = EditorProps<TYPES.SetValue, SetValue>;
Expand Down Expand Up @@ -60,7 +62,7 @@ function SetValueComponent(props: Props) {
5. `Public.tsx`

```typescript
import { PublicProps } from "@planx/components/ui";
import { PublicProps } from "@planx/components/shared/types";

type Props = PublicProps<SetValue>;

Expand All @@ -86,7 +88,7 @@ function SetValueComponent(props: Props) {

## Editor configurations

1. `src/@planx/components/ui.tsx`
1. `src/@planx/components/shared/icons.tsx`

```typescript
import PlaylistAdd from "@mui/icons-material/PlaylistAdd";
Expand Down Expand Up @@ -135,13 +137,13 @@ case TYPES.SetValue:

2. `src/@planx/components/shared/Preview/SummaryList`

If/how should this component appear on the Review page?
If/how should this component appear in a Review component:

```typescript
[TYPES.SetValue]: undefined,
```

3. `src/@planx/components/Send/bops/index`
3. In `planx-core` - `src/export/bops/index`

If/how should this component be formatted in Send data formats such as BOPS?

Expand All @@ -154,4 +156,4 @@ function isTypeForBopsPayload(type?: TYPES) {
// ...
}
}
```
```
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#54be9e0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#b4ca5a9",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
85 changes: 58 additions & 27 deletions editor.planx.uk/pnpm-lock.yaml

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

7 changes: 5 additions & 2 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { clickContinue, visitedNodes } from "pages/FlowEditor/lib/__tests__/utils";
import {
clickContinue,
visitedNodes,
} from "pages/FlowEditor/lib/__tests__/utils";
import { Store, useStore } from "pages/FlowEditor/lib/store";

const { getState, setState } = useStore;
Expand All @@ -19,7 +22,7 @@ test("When formatOutputForAutomations is true, Calculate writes an array and fut

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

Expand Down
9 changes: 5 additions & 4 deletions editor.planx.uk/src/@planx/components/Checklist/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ 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) {
Expand Down Expand Up @@ -203,8 +203,9 @@ const VisibleChecklist: 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { screen } from "@testing-library/react";
import React from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { setup } from "testUtils";

import { FeedbackEditor } from "./Editor";

describe("When the Feedback editor modal is rendered", () => {
it("does not throw an error", () => {
setup(
<DndProvider backend={HTML5Backend}>
<FeedbackEditor id="test-feedback-editor" />
</DndProvider>,
);
expect(screen.getByText("Feedback")).toBeInTheDocument();
});
});
Loading

0 comments on commit 363cc94

Please sign in to comment.