From 423fe5538d60c5db722db589cdd9d3f4fa2ed40d Mon Sep 17 00:00:00 2001 From: Conor <905676+conorriches@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:36:49 +0000 Subject: [PATCH 1/6] new prop for editable instructions (#1161) * unblocks us * merging into feature branch --- CHANGELOG.md | 1 + README.md | 1 + .../InstructionsPanel/InstructionsPanel.jsx | 4 ++ .../InstructionsPanel.test.js | 41 +++++++++++++++++++ .../ProgressBar/ProgressBar.jsx | 5 +++ .../ProgressBar/ProgressBar.test.js | 30 +++++++++++--- .../WebComponentProject.jsx | 27 +++++++++++- src/containers/WebComponentLoader.jsx | 2 + src/redux/EditorSlice.js | 4 ++ src/web-component.js | 2 + 10 files changed, 110 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e087a85cb..90a15dd8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added +- Editable instructions - Support for the `outputPanels` attribute in the `PyodideRunner` (#1157) ## [0.28.14] - 2025-01-06 diff --git a/README.md b/README.md index 54281f396..652313d25 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ The `editor-wc` tag accepts the following attributes, which must be provided as - `assets_identifier`: Load assets (not code) from this project identifier - `auth_key`: Authenticate the user to allow them to make API requests such as saving their work - `code`: A preset blob of code to show in the editor pane (overrides content of `main.py`/`index.html`) +- `editable_instructions`: Boolean whether to show edit panel for instructions - `embedded`: Enable embedded mode which hides some functionality (defaults to `false`) - `host_styles`: Styles passed into the web component from the host page - `identifier`: Load the project with this identifier from the database diff --git a/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx b/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx index 03b711a99..4018ee125 100644 --- a/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx +++ b/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx @@ -12,6 +12,9 @@ import { quizReadyEvent } from "../../../../events/WebComponentCustomEvents"; import { setCurrentStepPosition } from "../../../../redux/InstructionsSlice"; const InstructionsPanel = () => { + const instructionsEditable = useSelector( + (state) => state.editor?.instructionsEditable, + ); const steps = useSelector((state) => state.instructions.project?.steps); const quiz = useSelector((state) => state.instructions?.quiz); const dispatch = useDispatch(); @@ -82,6 +85,7 @@ const InstructionsPanel = () => { heading={t("instructionsPanel.projectSteps")} Footer={ProgressBar} > +
{instructionsEditable &&

Edit panel will go here

}
); diff --git a/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.test.js b/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.test.js index 890cc3e2c..e3f6cdbe7 100644 --- a/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.test.js +++ b/src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.test.js @@ -12,6 +12,9 @@ describe("It renders project steps when there is no quiz", () => { beforeEach(() => { const mockStore = configureStore([]); const initialState = { + editor: { + instructionsEditable: false, + }, instructions: { project: { steps: [ @@ -67,6 +70,44 @@ describe("It renders project steps when there is no quiz", () => { }); }); +describe("When instructionsEditable is true", () => { + beforeEach(() => { + const mockStore = configureStore([]); + const initialState = { + editor: { + instructionsEditable: true, + }, + instructions: { + project: { + steps: [ + { content: "

step 0

" }, + { + content: `

step 1

+ print('hello') +

Hello world

+ .hello { color: purple } + `, + }, + ], + }, + quiz: {}, + currentStepPosition: 1, + }, + }; + const store = mockStore(initialState); + render( + + + , + ); + }); + + test("Renders the edit panel", () => { + // TODO: CR: 2024-01-14: Add edit panel + expect(screen.queryByText("Edit panel will go here")).toBeInTheDocument(); + }); +}); + describe("It renders a quiz when it has one", () => { const quizHandler = jest.fn(); diff --git a/src/components/Menus/Sidebar/InstructionsPanel/ProgressBar/ProgressBar.jsx b/src/components/Menus/Sidebar/InstructionsPanel/ProgressBar/ProgressBar.jsx index 01487a7da..b04347aa3 100644 --- a/src/components/Menus/Sidebar/InstructionsPanel/ProgressBar/ProgressBar.jsx +++ b/src/components/Menus/Sidebar/InstructionsPanel/ProgressBar/ProgressBar.jsx @@ -30,6 +30,11 @@ const ProgressBar = () => { const goToPreviousStep = () => { dispatch(setCurrentStepPosition(Math.max(currentStepPosition - 1, 0))); }; + + if (numberOfSteps === 1) { + return <>; + } + return (