diff --git a/CHANGELOG.md b/CHANGELOG.md index 55c2b0854..84fe7f5d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [0.28.9] - 2024-11-27 + +### Fixed + +- Auto loading remixes when loadRemixDisabled is explicitly set (#1145) ## [0.28.8] - 2024-11-21 @@ -983,7 +987,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Events in Web Component indicating whether Mission Zero criteria have been met (#113) -[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.8...HEAD +[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.9...HEAD +[0.28.9]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.9 [0.28.8]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.8 [0.28.7]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.7 [0.28.6]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.6 diff --git a/package.json b/package.json index f081fd4bc..caef9385a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@raspberrypifoundation/editor-ui", - "version": "0.28.8", + "version": "0.28.9", "private": true, "dependencies": { "@apollo/client": "^3.7.8", diff --git a/src/containers/WebComponentLoader.jsx b/src/containers/WebComponentLoader.jsx index c99422648..9d8daedc1 100644 --- a/src/containers/WebComponentLoader.jsx +++ b/src/containers/WebComponentLoader.jsx @@ -137,6 +137,7 @@ const WebComponentLoader = (props) => { justLoaded, hasShownSavePrompt: hasShownSavePrompt || !showSavePrompt, saveTriggered, + loadRemix: loadRemix && !loadRemixDisabled, }); useEffect(() => { diff --git a/src/containers/WebComponentLoader.test.js b/src/containers/WebComponentLoader.test.js index 6b91643e7..c118a625d 100644 --- a/src/containers/WebComponentLoader.test.js +++ b/src/containers/WebComponentLoader.test.js @@ -200,6 +200,7 @@ describe("When no user is in state", () => { project: { components: [], }, + loadRemix: false, hasShownSavePrompt: true, justLoaded: false, user: null, @@ -337,6 +338,7 @@ describe("When no user is in state", () => { expect(useProjectPersistence).toHaveBeenCalledWith({ user, project: { components: [] }, + loadRemix: true, hasShownSavePrompt: true, justLoaded: false, saveTriggered: false, @@ -496,6 +498,7 @@ describe("When user is in state", () => { reactAppApiEndpoint: "http://localhost:3009", user, project: { components: [] }, + loadRemix: true, hasShownSavePrompt: true, justLoaded: false, saveTriggered: false, diff --git a/src/hooks/useProjectPersistence.js b/src/hooks/useProjectPersistence.js index 5c8bc03f6..5e7b5462b 100644 --- a/src/hooks/useProjectPersistence.js +++ b/src/hooks/useProjectPersistence.js @@ -17,6 +17,7 @@ export const useProjectPersistence = ({ hasShownSavePrompt, saveTriggered, reactAppApiEndpoint, + loadRemix = true, }) => { const dispatch = useDispatch(); @@ -56,20 +57,22 @@ export const useProjectPersistence = ({ }), ); // Ensure the remixed project is loaded, otherwise we'll get in a mess - dispatch( - syncProject("loadRemix")({ - reactAppApiEndpoint, - identifier: project.identifier, - accessToken: user.access_token, - }), - ); + if (loadRemix) { + dispatch( + syncProject("loadRemix")({ + reactAppApiEndpoint, + identifier: project.identifier, + accessToken: user.access_token, + }), + ); + } } localStorage.removeItem("awaitingSave"); } } }; saveProject(); - }, [saveTriggered, project, user, dispatch, reactAppApiEndpoint]); + }, [saveTriggered, project, user, dispatch, reactAppApiEndpoint, loadRemix]); useEffect(() => { let debouncer = setTimeout(() => { diff --git a/src/hooks/useProjectPersistence.test.js b/src/hooks/useProjectPersistence.test.js index 0ccf4fc91..a80731a34 100644 --- a/src/hooks/useProjectPersistence.test.js +++ b/src/hooks/useProjectPersistence.test.js @@ -248,6 +248,35 @@ describe("When logged in", () => { }); }); + describe("When project has identifier and save triggered without loadRemix", () => { + beforeEach(() => { + syncProject.mockImplementationOnce(jest.fn((_) => remixProject)); + syncProject.mockImplementationOnce(jest.fn((_) => loadProject)); + + renderHook(() => + useProjectPersistence({ + user: user2, + project: project, + saveTriggered: true, + loadRemix: false, + }), + ); + jest.runAllTimers(); + }); + + test("Clicking save dispatches remixProject with correct parameters", async () => { + await expect(remixProject).toHaveBeenCalledWith({ + project: project, + accessToken: user2.access_token, + }); + }); + + test("loadRemix is not dispatched after project is remixed", async () => { + await remixProject(); + await expect(loadProject).not.toHaveBeenCalled(); + }); + }); + describe("When project has no identifier and awaiting save", () => { beforeEach(() => { localStorage.setItem("awaitingSave", "true");