Skip to content

Commit 817e28c

Browse files
conorrichessra405create-issue-branch[bot]loiswells97
authored
set REACT_APP _API_ENDPOINT and _AUTHENTICATION_URL as props (#1124)
## Issue Closes https://github.com/RaspberryPiFoundation/learner-experience-integration-tests/issues/5 ## Description * Changed how both utils function: * `src/utils/apiCallHandler.js` * `src/utils/userManager.js` * I've considered how best to adapt these helpers - I could have gone with classes or functions, and while I considered changing these to be classes, this would require more verbose invocation throughout the codebase which ended up making code harder to read, whereas the function-based approach means most calls can be left as-is. * `public/index.html` added which provides a handy link to the web-component.html rather than just a directory listing * Removed a load of code that isn't used any more --------- Co-authored-by: Scott Adams <[email protected]> Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com> Co-authored-by: Lois Wells <[email protected]> Co-authored-by: Lois Wells <[email protected]>
1 parent 932880d commit 817e28c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+400
-2451
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
REACT_APP_AUTHENTICATION_CLIENT_ID='editor-dev'
2-
REACT_APP_AUTHENTICATION_URL='http://localhost:9001'
32
REACT_APP_SENTRY_DSN=''
43
REACT_APP_SENTRY_ENV='local'
54
PUBLIC_URL='http://localhost:3011'
65
ASSETS_URL='http://localhost:3011'
7-
REACT_APP_API_ENDPOINT='http://localhost:3009'
86
REACT_APP_GOOGLE_TAG_MANAGER_ID=''
7+
REACT_APP_API_ENDPOINT='http://localhost:3009'
98
REACT_APP_PLAUSIBLE_DATA_DOMAIN=''
109
REACT_APP_PLAUSIBLE_SOURCE=''

.github/workflows/ci-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: yarn run test --coverage --maxWorkers=4 --workerThreads=true --reporters=default --reporters=jest-junit --reporters=jest-github-actions-reporter
6262
env:
6363
JEST_JUNIT_OUTPUT_DIR: ./coverage/
64-
64+
REACT_APP_API_ENDPOINT: http://localhost:3009
6565
- name: Record coverage
6666
run: ./.github/workflows/record_coverage
6767
env:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## Unreleased
88

9+
## [0.28.8] - 2024-11-04
10+
11+
### Changed
12+
- REACT_APP_API_ENDPOINT env var is now only a default for the editor-wc prop, which can be overridden (#1124)
13+
14+
### Removed
15+
- REACT_APP_AUTHENTICATION_URL env var no longer used and is instead a editor-wc prop (#1124)
16+
917

1018
## [0.28.5] - 2024-11-01
1119

public/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>You may be looking for...</h1>
2+
<ul>
3+
<li>Web Component test page <a href="http://localhost:3011/web-component.html">http://localhost:3011/web-component.html</a></li>
4+
</ul>

src/app/store.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { configureStore } from "@reduxjs/toolkit";
22
import EditorReducer from "../redux/EditorSlice";
33
import InstructionsReducer from "../redux/InstructionsSlice";
44
import { reducer, loadUser } from "redux-oidc";
5-
import userManager from "../utils/userManager";
5+
import UserManager from "../utils/userManager";
66

7+
// TODO - not used but keeping this in preparation for using
8+
// src/components/Editor/ImageUploadButton/ImageUploadButton.jsx
9+
const userManager = UserManager({ reactAppAuthenticationUrl: "TODO" });
710
const store = configureStore({
811
reducer: {
912
editor: EditorReducer,

src/components/DownloadButton/DownloadButton.jsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { toSnakeCase } from "js-convert-case";
44
import JSZip from "jszip";
55
import JSZipUtils from "jszip-utils";
66
import { useTranslation } from "react-i18next";
7-
import { useDispatch, useSelector } from "react-redux";
7+
import { useSelector } from "react-redux";
88
import PropTypes from "prop-types";
99

1010
import DesignSystemButton from "../DesignSystemButton/DesignSystemButton";
11-
import { closeLoginToSaveModal } from "../../redux/EditorSlice";
1211

1312
const DownloadButton = (props) => {
1413
const {
@@ -20,10 +19,6 @@ const DownloadButton = (props) => {
2019
} = props;
2120
const { t } = useTranslation();
2221
const project = useSelector((state) => state.editor.project);
23-
const loginToSaveModalShowing = useSelector(
24-
(state) => state.editor.loginToSaveModalShowing,
25-
);
26-
const dispatch = useDispatch();
2722

2823
const urlToPromise = (url) => {
2924
return new Promise(function (resolve, reject) {
@@ -42,9 +37,6 @@ const DownloadButton = (props) => {
4237
window.plausible("Download");
4338
}
4439

45-
if (loginToSaveModalShowing) {
46-
dispatch(closeLoginToSaveModal());
47-
}
4840
const zip = new JSZip();
4941

5042
project.components.forEach((file) => {

src/components/DownloadButton/DownloadButton.test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import DownloadButton from "./DownloadButton";
66
import FileSaver from "file-saver";
77
import JSZip from "jszip";
88
import JSZipUtils from "jszip-utils";
9-
import { closeLoginToSaveModal } from "../../redux/EditorSlice";
109

1110
jest.mock("file-saver");
1211
jest.mock("jszip");
@@ -124,27 +123,3 @@ describe("Downloading project with no name set", () => {
124123
);
125124
});
126125
});
127-
128-
test("If login to save modal open, closes it when download clicked", () => {
129-
JSZip.mockClear();
130-
const middlewares = [];
131-
const mockStore = configureStore(middlewares);
132-
const initialState = {
133-
editor: {
134-
project: {
135-
components: [],
136-
image_list: [],
137-
},
138-
loginToSaveModalShowing: true,
139-
},
140-
};
141-
const store = mockStore(initialState);
142-
render(
143-
<Provider store={store}>
144-
<DownloadButton buttonText="Download" Icon={() => {}} />
145-
</Provider>,
146-
);
147-
const downloadButton = screen.queryByText("Download").parentElement;
148-
fireEvent.click(downloadButton);
149-
expect(store.getActions()).toEqual([closeLoginToSaveModal()]);
150-
});

src/components/Editor/ImageUploadButton/ImageUploadButton.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { updateImages, setNameError } from "../../../redux/EditorSlice";
99
import Button from "../../Button/Button";
1010
import NameErrorMessage from "../ErrorMessage/NameErrorMessage";
1111
import store from "../../../app/store";
12-
import { uploadImages } from "../../../utils/apiCallHandler";
12+
import ApiCallHandler from "../../../utils/apiCallHandler";
1313

1414
const allowedExtensions = {
1515
python: ["jpg", "jpeg", "png", "gif"],
@@ -30,7 +30,7 @@ const allowedExtensionsString = (projectType) => {
3030
}
3131
};
3232

33-
const ImageUploadButton = () => {
33+
const ImageUploadButton = ({ reactAppApiEndpoint }) => {
3434
const [modalIsOpen, setIsOpen] = useState(false);
3535
const [files, setFiles] = useState([]);
3636
const dispatch = useDispatch();
@@ -51,6 +51,10 @@ const ImageUploadButton = () => {
5151
setIsOpen(true);
5252
};
5353
const saveImages = async () => {
54+
const { uploadImages } = ApiCallHandler({
55+
reactAppApiEndpoint,
56+
});
57+
5458
files.every((file) => {
5559
const fileName = file.name;
5660
const extension = fileName.split(".").slice(1).join(".").toLowerCase();

src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
1212
import { useMediaQuery } from "react-responsive";
1313
import { MOBILE_MEDIA_QUERY } from "../../../../../utils/mediaQueryBreakpoints";
1414
import ErrorMessage from "../../../ErrorMessage/ErrorMessage";
15-
import { createError } from "../../../../../utils/apiCallHandler";
15+
import ApiCallHandler from "../../../../../utils/apiCallHandler";
1616
import VisualOutputPane from "./VisualOutputPane";
1717
import OutputViewToggle from "../OutputViewToggle";
1818
import { SettingsContext } from "../../../../../utils/settings";
@@ -47,6 +47,7 @@ const PyodideRunner = (props) => {
4747
const userId = user?.profile?.user;
4848
const isSplitView = useSelector((s) => s.editor.isSplitView);
4949
const isEmbedded = useSelector((s) => s.editor.isEmbedded);
50+
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
5051
const codeRunTriggered = useSelector((s) => s.editor.codeRunTriggered);
5152
const codeRunStopped = useSelector((s) => s.editor.codeRunStopped);
5253
const output = useRef();
@@ -180,6 +181,9 @@ const PyodideRunner = (props) => {
180181
errorMessage += `:\n${mistake}`;
181182
}
182183

184+
const { createError } = ApiCallHandler({
185+
reactAppApiEndpoint,
186+
});
183187
createError(projectIdentifier, userId, { errorType: type, errorMessage });
184188
}
185189

src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
triggerDraw,
1616
} from "../../../../../redux/EditorSlice";
1717
import ErrorMessage from "../../../ErrorMessage/ErrorMessage";
18-
import { createError } from "../../../../../utils/apiCallHandler";
18+
import ApiCallHandler from "../../../../../utils/apiCallHandler";
1919
import store from "../../../../../redux/stores/WebComponentStore";
2020
import VisualOutputPane from "../VisualOutputPane";
2121
import OutputViewToggle from "../OutputViewToggle";
@@ -71,6 +71,7 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
7171
);
7272
const codeRunStopped = useSelector((state) => state.editor.codeRunStopped);
7373
const drawTriggered = useSelector((state) => state.editor.drawTriggered);
74+
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
7475
const output = useRef();
7576
const dispatch = useDispatch();
7677
const { t } = useTranslation();
@@ -314,6 +315,8 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
314315
userId = user.profile?.user;
315316
}
316317

318+
const { createError } = ApiCallHandler({ reactAppApiEndpoint });
319+
317320
errorMessage = `${errorType}: ${errorDescription} on line ${lineNumber} of ${fileName}${
318321
explanation ? `. ${explanation}` : ""
319322
}`;

src/components/Login/LoginButton.jsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)