Skip to content

Commit

Permalink
Check loadRemixDisabled (#1145)
Browse files Browse the repository at this point in the history
Initial attempt at a fix for auto loading remixes when we explicitly
don't want to to avoid editor projects remixing, loading the remix then
causing a url changed based off the load rather than remix response
  • Loading branch information
sra405 authored Nov 27, 2024
1 parent 193325f commit 18e1e3d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raspberrypifoundation/editor-ui",
"version": "0.28.8",
"version": "0.28.9",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.8",
Expand Down
1 change: 1 addition & 0 deletions src/containers/WebComponentLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const WebComponentLoader = (props) => {
justLoaded,
hasShownSavePrompt: hasShownSavePrompt || !showSavePrompt,
saveTriggered,
loadRemix: loadRemix && !loadRemixDisabled,
});

useEffect(() => {
Expand Down
3 changes: 3 additions & 0 deletions src/containers/WebComponentLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ describe("When no user is in state", () => {
project: {
components: [],
},
loadRemix: false,
hasShownSavePrompt: true,
justLoaded: false,
user: null,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions src/hooks/useProjectPersistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const useProjectPersistence = ({
hasShownSavePrompt,
saveTriggered,
reactAppApiEndpoint,
loadRemix = true,
}) => {
const dispatch = useDispatch();

Expand Down Expand Up @@ -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(() => {
Expand Down
29 changes: 29 additions & 0 deletions src/hooks/useProjectPersistence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 18e1e3d

Please sign in to comment.