Skip to content

Commit

Permalink
Merge branch 'tt/vite' into tt/reduce-github-actions-build-time
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadain committed Oct 14, 2022
2 parents ef9a504 + de00632 commit 8821782
Show file tree
Hide file tree
Showing 66 changed files with 2,474 additions and 9,544 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vendor.bundle.js
bundle.js.map
dist/
yarn-error.log
src/app/public/data
src/app/data

# Bundled JS
src/app/build
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Split DrawMap commponents into Layers and DrawTools [#57](https://github.com/azavea/iow-boundary-tool/pull/57)
- Make `Roles` enum an `IntEnum` subclass [#74](https://github.com/azavea/iow-boundary-tool/pull/74)
- Drop `Role` table and refactor as choice field on User [#117](https://github.com/azavea/iow-boundary-tool/pull/117)
- Return user information from login endpoint [#136](https://github.com/azavea/iow-boundary-tool/pull/136)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
stdin_open: true
working_dir: /usr/local/src
environment:
- REACT_APP_GIT_COMMIT=${REACT_APP_GIT_COMMIT:-latest}
- VITE_GIT_COMMIT=${VITE_GIT_COMMIT:-latest}
- CHOKIDAR_USEPOLLING=true
- CHOKIDAR_INTERVAL=100
- PORT=4545
Expand Down
19 changes: 0 additions & 19 deletions src/app/craco.config.js

This file was deleted.

File renamed without changes.
File renamed without changes.
16 changes: 4 additions & 12 deletions src/app/public/index.html → src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="iow-boundary-tool"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="apple-touch-icon" href="/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="manifest" href="/manifest.json" />
<title>Boundary Sync</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
15 changes: 7 additions & 8 deletions src/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
"react-redux": "^8.0.2",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-use": "^17.3.2",
"redux": "^4.2.0",
"redux-logger": "^3.0.6"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test"
"start": "vite",
"build": "vite build",
"test": "vite test"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -59,10 +58,10 @@
]
},
"devDependencies": {
"@babel/core": "^7.17.12",
"@craco/craco": "^6.4.3",
"babel-jest": "28.1.0",
"@vitejs/plugin-react": "^2.0.1",
"eslint": "^8.25.0",
"eslint-config-react-app": "^7.0.1",
"prettier": "^2.6.2",
"prettier-loader": "^3.3.0"
"vite": "^3.0.7"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import {
} from '@heroicons/react/outline';
import { CursorClickIcon } from '@heroicons/react/solid';

import AddPolygonIcon from '../../img/AddPolygonIcon.js';
import DeletePolygonConfirmModal from './DeletePolygonConfirmModal.js';
import { useDialogController } from '../../hooks.js';
import EditPolygonModal from './EditPolygonModal.js';
import AddPolygonIcon from '../../img/AddPolygonIcon';
import DeletePolygonConfirmModal from './DeletePolygonConfirmModal';
import { useDialogController } from '../../hooks';
import EditPolygonModal from './EditPolygonModal';
import {
cancelAddPolygon,
startAddPolygon,
toggleEditMode,
togglePolygonVisibility,
} from '../../store/mapSlice.js';
} from '../../store/mapSlice';

const POLYGON_BUTTON_WIDTH = 40;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function MunicipalBoundariesLayer() {
});

useEffect(() => {
fetch(`${process.env.PUBLIC_URL}/data/muni.geo.json`)
fetch(new URL('../../../data/muni.geo.json', import.meta.url).href)
.then(response => response.json())
.then(setLayerData);
}, []);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { ArrowLeftIcon, CogIcon, LogoutIcon } from '@heroicons/react/outline';
import apiClient from '../api/client';
import { API_URLS, NAVBAR_HEIGHT } from '../constants';
import { logout, setSelectedUtility } from '../store/authSlice';
import { logout, setUtilityByPwsid } from '../store/authSlice';

const NAVBAR_VARIANTS = {
DRAW: 'draw',
Expand Down Expand Up @@ -102,31 +102,33 @@ function ExitButton({ variant }) {
function UtilityControl({ variant }) {
const dispatch = useDispatch();

// placeholders
const utilities = ['Raleigh City of', 'Azavea Test Utility'];
const selectedUtility =
useSelector(state => state.auth.selectedUtility) || utilities[0];
const utilities = useSelector(state => state.auth.user.utilities);
const utility = useSelector(state => state.auth.utility);

return variant === NAVBAR_VARIANTS.SUBMISSION && utilities.length > 1 ? (
if (!utility) {
return null;
}

return variant === NAVBAR_VARIANTS.SUBMISSION && utilities?.length > 1 ? (
<Select
variant='filled'
h='40px'
w='250px'
value={selectedUtility}
value={utility.pwsid}
onChange={e => {
dispatch(setSelectedUtility(e.target.value));
dispatch(setUtilityByPwsid(e.target.value));
}}
_focus={{ background: 'white' }}
>
{utilities.map(u => {
{utilities.map(({ id, pwsid, name }) => {
return (
<option key={u} value={u}>
{u}
<option key={id} value={pwsid}>
{name}
</option>
);
})}
</Select>
) : (
<Text textStyle='selectedUtility'>{selectedUtility}</Text>
<Text textStyle='selectedUtility'>{utility.name}</Text>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { API_URLS } from '../constants';
import { login, setLocationBeforeAuth } from '../store/authSlice';

export default function PrivateRoute({ children }) {
const signedIn = useSelector(state => state.auth.signedIn);
const user = useSelector(state => state.auth.user);
const location = useLocation();
const navigate = useNavigate();
const dispatch = useDispatch();
Expand All @@ -17,20 +17,20 @@ export default function PrivateRoute({ children }) {
// Log in this user if they have an authenticated session
// Handles losing Redux state on refresh
useEffect(() => {
if (!signedIn) {
if (!user) {
dispatch(setLocationBeforeAuth(location));
apiClient
.get(API_URLS.LOGIN)
.then(() => {
dispatch(login());
.then(({ data: user }) => {
dispatch(login(user));
})
.catch(() => {
if (!locationIsLogin) {
navigate('/login');
}
});
}
}, [signedIn, location, locationIsLogin, navigate, dispatch]);
}, [user, location, locationIsLogin, navigate, dispatch]);

return locationIsLogin ? null : children;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function TableRows() {
}
}

function TableRow({ boundary: { id, location, pwsid, last_modified, status } }) {
function TableRow({
boundary: { id, location, pwsid, last_modified, status },
}) {
const navigate = useNavigate();

return (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/app/src/pages/Login.js → src/app/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function Login() {
email,
password,
})
.then(() => {
dispatch(login());
.then(({ data: user }) => {
dispatch(login(user));
})
.catch(apiError => {
if (apiError.response?.status === API_STATUSES.REDIRECT) {
Expand All @@ -34,20 +34,20 @@ export default function Login() {
});
};

const signedIn = useSelector(state => state.auth.signedIn);
const user = useSelector(state => state.auth.user);
const locationBeforeAuth = useSelector(
state => state.auth.locationBeforeAuth
);

// Upon successful sign in, redirect if specified (e.g. by /login route)
useEffect(() => {
if (signedIn) {
if (user) {
navigate(locationBeforeAuth, { replace: true });
}
if (forgotPassword) {
navigate('/forgot');
}
}, [navigate, signedIn, forgotPassword, locationBeforeAuth]);
}, [navigate, user, forgotPassword, locationBeforeAuth]);

return (
<LoginForm>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 13 additions & 18 deletions src/app/src/store/authSlice.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import { createSlice } from '@reduxjs/toolkit';

const initialState = {
signedIn: false,
locationBeforeAuth: '/welcome',
utilities: [],
selectedUtility: null,
user: false,
utility: null,
};

export const authSlice = createSlice({
name: 'auth',
initialState,
reducers: {
login: state => {
state.signedIn = true;
login: (state, { payload: user }) => {
state.user = user;

if (user.utilities) {
state.utility = user.utilities[0];
}
},
logout: state => {
state.signedIn = false;
state.user = false;
},
setLocationBeforeAuth: (state, { payload: location }) => {
if (!location.pathname.startsWith('/login')) {
state.locationBeforeAuth = location;
}
},
setUtilities: (state, { payload: utilities }) => {
state.utilities = utilities;
},
setSelectedUtility: (state, { payload: selectedUtility }) => {
state.selectedUtility = selectedUtility;
setUtilityByPwsid: (state, { payload: pwsid }) => {
state.utility = state.user.utilities.find(u => u.pwsid === pwsid);
},
},
});

export const {
login,
logout,
setLocationBeforeAuth,
setUtilities,
setSelectedUtility,
} = authSlice.actions;
export const { login, logout, setLocationBeforeAuth, setUtilityByPwsid } =
authSlice.actions;

export default authSlice.reducer;
File renamed without changes.
10 changes: 10 additions & 0 deletions src/app/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
server: {
port: process.env.PORT,
host: true,
},
});
Loading

0 comments on commit 8821782

Please sign in to comment.