Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPPETA-19] Inject the base URL into the react application #37

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ obj/

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
7 changes: 7 additions & 0 deletions src/reactapp/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.


EPPETA_API_BASE_PATH=https://localhost:7065
9 changes: 9 additions & 0 deletions src/reactapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Environment Variables

The React app uses some environment variables to set configuration values.

| Name | Required | Explanation |
| -------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| REACT_APP_EPPETA_API_BASE_PATH | yes | The EPP API base path to be used by the app to get and post data. |


## Available Scripts

In the project directory, you can run:
Expand Down
4 changes: 1 addition & 3 deletions src/reactapp/src/components/FetchHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { transform as _transform } from "lodash-es";
import { getToken } from "../components/TokenHelpers";


// TODO: replace hard-coded with some sort of runtime setting
// Will be fixed in EPPETA-19.
const BaseUrl = "https://localhost:7065";
const BaseUrl = process.env.REACT_APP_EPPETA_API_BASE_PATH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleiva-gap does this really work? I thought FetchHelpers was a client-side component, not a server-side component. But I may have misunderstood.

If it is serverside, then does this mean that one must run the application using the npm start function? That's probably acceptable inside a Docker container, but might be hard to do in a real installation, since it requires NodeJs.

Ideally in a real installation, the end-user would have a choice of webservers to run, without needing NodeJs. For example, just copy the html, compiled js files, css, and images into IIS or Apache.


const modify = async (verb, route, values) => {
if (!route.startsWith("/")) {
Expand Down
11 changes: 7 additions & 4 deletions src/reactapp/src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import {
import logo from '../assets/logo.jpg'
import { Image } from "@chakra-ui/react"
import { getLoggedInUserName, getLoggedInUserFirstName, clearToken } from "../components/TokenHelpers";
import { useNavigate } from "react-router-dom";


export default function WithSubnavigation() {
const { isOpen, onToggle } = useDisclosure();
const { isOpen, onToggle } = useDisclosure();
const navigate = useNavigate();

return (
<Box>
Expand Down Expand Up @@ -78,15 +81,15 @@ export default function WithSubnavigation() {
justify={'flex-end'}
direction={'row'}
spacing={6}>
<Button onClick={() => { window.location.href = "/login" }}
<Button onClick={() => { navigate("/login") }}
as={'a'}
fontSize={'sm'}
fontWeight={400}
variant={'link'}
href={'#'}>
Sign In
</Button>
<Button onClick={() => { window.location.href = "/signup" }}
<Button onClick={() => { navigate("/signup") }}
as={'a'}
display={{ base: 'none', md: 'inline-flex' }}
fontSize={'sm'}
Expand All @@ -113,7 +116,7 @@ export default function WithSubnavigation() {
</Flex>
<Button onClick={() => {
clearToken('');
window.location.href = "/login"
navigate("/login")
}}
as={'a'}
fontSize={'sm'}
Expand Down
2 changes: 1 addition & 1 deletion src/reactapp/src/pages/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function EvaluationTable() {
</HStack>
<SortableTable data={EvaluationRatings} headers={headers} paginate={true} itemsPerPage={50} filter={filterExpression} noRowsMessage="No evaluations to display" />
<Box textAlign="center" mt="5" mb="10">
<Button colorScheme="blue" onClick={() => (window.location.href = "/new")}>
<Button colorScheme="blue" onClick={() => (navigate("/new"))}>
New Evaluation
</Button>
</Box>
Expand Down
5 changes: 3 additions & 2 deletions src/reactapp/src/pages/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ import {
import { useState } from "react";
import { ViewIcon, ViewOffIcon } from "@chakra-ui/icons";
import { Formik, Form } from "formik";

import { useNavigate } from "react-router-dom";
import InputField from "../components/InputField";
import { post } from "../components/FetchHelpers";
import { defaultErrorMessage, AlertMessage } from "../components/AlertMessage";

export default function SignupForm() {
const navigate = useNavigate();
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const [error, setError] = useState(null);

const loadSignInPage = () => {
// TODO: what if the site is running behind a proxy? Then / might be the wrong base
// Address this in EPPETA-19
window.location.href = "/login";
navigate("/login");
};

const onSubmitSignup = async (values) => {
Expand Down