Skip to content

Commit 18e1e3d

Browse files
authored
Check loadRemixDisabled (#1145)
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
1 parent 193325f commit 18e1e3d

6 files changed

+52
-11
lines changed

CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
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).
66

7-
## Unreleased
7+
## [0.28.9] - 2024-11-27
8+
9+
### Fixed
10+
11+
- Auto loading remixes when loadRemixDisabled is explicitly set (#1145)
812

913
## [0.28.8] - 2024-11-21
1014

@@ -983,7 +987,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
983987

984988
- Events in Web Component indicating whether Mission Zero criteria have been met (#113)
985989

986-
[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.8...HEAD
990+
[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.9...HEAD
991+
[0.28.9]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.9
987992
[0.28.8]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.8
988993
[0.28.7]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.7
989994
[0.28.6]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.6

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@raspberrypifoundation/editor-ui",
3-
"version": "0.28.8",
3+
"version": "0.28.9",
44
"private": true,
55
"dependencies": {
66
"@apollo/client": "^3.7.8",

src/containers/WebComponentLoader.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const WebComponentLoader = (props) => {
137137
justLoaded,
138138
hasShownSavePrompt: hasShownSavePrompt || !showSavePrompt,
139139
saveTriggered,
140+
loadRemix: loadRemix && !loadRemixDisabled,
140141
});
141142

142143
useEffect(() => {

src/containers/WebComponentLoader.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ describe("When no user is in state", () => {
200200
project: {
201201
components: [],
202202
},
203+
loadRemix: false,
203204
hasShownSavePrompt: true,
204205
justLoaded: false,
205206
user: null,
@@ -337,6 +338,7 @@ describe("When no user is in state", () => {
337338
expect(useProjectPersistence).toHaveBeenCalledWith({
338339
user,
339340
project: { components: [] },
341+
loadRemix: true,
340342
hasShownSavePrompt: true,
341343
justLoaded: false,
342344
saveTriggered: false,
@@ -496,6 +498,7 @@ describe("When user is in state", () => {
496498
reactAppApiEndpoint: "http://localhost:3009",
497499
user,
498500
project: { components: [] },
501+
loadRemix: true,
499502
hasShownSavePrompt: true,
500503
justLoaded: false,
501504
saveTriggered: false,

src/hooks/useProjectPersistence.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const useProjectPersistence = ({
1717
hasShownSavePrompt,
1818
saveTriggered,
1919
reactAppApiEndpoint,
20+
loadRemix = true,
2021
}) => {
2122
const dispatch = useDispatch();
2223

@@ -56,20 +57,22 @@ export const useProjectPersistence = ({
5657
}),
5758
);
5859
// Ensure the remixed project is loaded, otherwise we'll get in a mess
59-
dispatch(
60-
syncProject("loadRemix")({
61-
reactAppApiEndpoint,
62-
identifier: project.identifier,
63-
accessToken: user.access_token,
64-
}),
65-
);
60+
if (loadRemix) {
61+
dispatch(
62+
syncProject("loadRemix")({
63+
reactAppApiEndpoint,
64+
identifier: project.identifier,
65+
accessToken: user.access_token,
66+
}),
67+
);
68+
}
6669
}
6770
localStorage.removeItem("awaitingSave");
6871
}
6972
}
7073
};
7174
saveProject();
72-
}, [saveTriggered, project, user, dispatch, reactAppApiEndpoint]);
75+
}, [saveTriggered, project, user, dispatch, reactAppApiEndpoint, loadRemix]);
7376

7477
useEffect(() => {
7578
let debouncer = setTimeout(() => {

src/hooks/useProjectPersistence.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,35 @@ describe("When logged in", () => {
248248
});
249249
});
250250

251+
describe("When project has identifier and save triggered without loadRemix", () => {
252+
beforeEach(() => {
253+
syncProject.mockImplementationOnce(jest.fn((_) => remixProject));
254+
syncProject.mockImplementationOnce(jest.fn((_) => loadProject));
255+
256+
renderHook(() =>
257+
useProjectPersistence({
258+
user: user2,
259+
project: project,
260+
saveTriggered: true,
261+
loadRemix: false,
262+
}),
263+
);
264+
jest.runAllTimers();
265+
});
266+
267+
test("Clicking save dispatches remixProject with correct parameters", async () => {
268+
await expect(remixProject).toHaveBeenCalledWith({
269+
project: project,
270+
accessToken: user2.access_token,
271+
});
272+
});
273+
274+
test("loadRemix is not dispatched after project is remixed", async () => {
275+
await remixProject();
276+
await expect(loadProject).not.toHaveBeenCalled();
277+
});
278+
});
279+
251280
describe("When project has no identifier and awaiting save", () => {
252281
beforeEach(() => {
253282
localStorage.setItem("awaitingSave", "true");

0 commit comments

Comments
 (0)