-
Notifications
You must be signed in to change notification settings - Fork 2
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
Task/WG-10: Add projects and user queries. #137
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1e5f4da
Add login/logout and protected routes
nathanfranklin c35471c
Refactor
nathanfranklin 3cb4a0d
Fix tests
nathanfranklin cb5df58
Fix linting
nathanfranklin dda7fec
Fix linting
nathanfranklin 30b4c5e
Merge branch 'master' into task/WG-15-login-logout
nathanfranklin 36b0c13
Add projects and user queries.
duckonomy 2fdf472
Merge branch 'task/WG-15-login-logout' into task/WG-10-rtk-query
duckonomy ef50e4c
Fix bug.
duckonomy fcaf7c2
Fix test.
duckonomy ce151dd
Merge branch 'task/WG-10-rtk-query' of ssh://github.com/tacc-cloud/ha…
duckonomy a284ff0
Merge branch 'master' into task/WG-10-rtk-query
duckonomy 2ac1062
Add prettier.
duckonomy d1f03fe
Update authUtils.ts
duckonomy 70a1467
Merge branch 'master' into task/WG-10-rtk-query
nathanfranklin 6a06ac6
Update react/src/redux/api/geoapi.ts
nathanfranklin 653faf1
Merge branch 'master' into task/WG-10-rtk-query
nathanfranklin e316efe
Add link to related jira issue
nathanfranklin 0011101
Fix prettier issue
nathanfranklin 6a60193
Merge branch 'master' into task/WG-10-rtk-query
nathanfranklin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import MainMenu from './MainMenu'; | ||
import { Provider } from 'react-redux'; | ||
import store from '../../redux/store'; | ||
|
||
test('renders menu', () => { | ||
const { getByText } = render(<MainMenu />); | ||
const { getByText } = render( | ||
<Provider store={store}> | ||
<MainMenu /> | ||
</Provider> | ||
); | ||
expect(getByText(/Main Menu/)).toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { geoapi } from './api/geoapi'; | ||
|
||
const slice = createSlice({ | ||
name: 'projects', | ||
initialState: { projects: [] }, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addMatcher( | ||
geoapi.endpoints.getGeoapiProjects.matchFulfilled, | ||
(state, { payload }) => { | ||
state.projects = payload; | ||
} | ||
); | ||
}, | ||
}); | ||
|
||
export default slice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { combineReducers } from 'redux'; | ||
import { geoapi } from '../api/geoapi'; | ||
import authReducer from '../authSlice'; | ||
import projectsReducer from '../projectsSlice'; | ||
|
||
export const reducer = combineReducers({ | ||
auth: authReducer, | ||
projects: projectsReducer, | ||
[geoapi.reducerPath]: geoapi.reducer, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { reducer } from './reducers/reducers'; | ||
import { geoapi } from './api/geoapi'; | ||
|
||
const store = configureStore({ | ||
reducer: reducer, | ||
middleware: (getDefaultMiddleware) => | ||
getDefaultMiddleware({ serializableCheck: false }).concat( | ||
geoapi.middleware | ||
), | ||
}); | ||
|
||
export type RootState = ReturnType<typeof store.getState>; | ||
export type AppDispatch = typeof store.dispatch; | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface AuthenticatedUser { | ||
username: string | null; | ||
email: string | null; | ||
} | ||
|
||
export interface AuthToken { | ||
token: string | null; | ||
expires: number | null; | ||
} | ||
|
||
export interface AuthState { | ||
user: AuthenticatedUser | null; | ||
token: AuthToken | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
import { AuthState } from '../redux/authSlice'; | ||
import { AuthToken } from '../types'; | ||
|
||
export const AUTH_KEY = 'auth'; | ||
|
||
export function isTokenValid(auth: AuthState): boolean { | ||
if (!auth.expires) { | ||
export function isTokenValid(token: AuthToken | null): boolean { | ||
if (token) { | ||
if (!token.expires) { | ||
return false; | ||
} | ||
|
||
const now = Date.now(); | ||
return now < token.expires; | ||
} else { | ||
return false; | ||
} | ||
|
||
const now = Date.now(); | ||
return now < auth.expires; | ||
} | ||
|
||
export function getAuthFromLocalStorage(): AuthState { | ||
export function getTokenFromLocalStorage(): AuthToken { | ||
try { | ||
const tokenStr = localStorage.getItem(AUTH_KEY); | ||
if (tokenStr) { | ||
const auth = JSON.parse(tokenStr); | ||
return { token: auth.token, expires: auth.expires }; | ||
return auth; | ||
} | ||
} catch (e: any) { | ||
console.error('Error loading state from localStorage:', e); | ||
} | ||
return { token: null, expires: null }; | ||
} | ||
|
||
export function setAuthToLocalStorage(auth: AuthState) { | ||
localStorage.setItem(AUTH_KEY, JSON.stringify(auth)); | ||
export function setTokenToLocalStorage(token: AuthToken) { | ||
localStorage.setItem(AUTH_KEY, JSON.stringify(token)); | ||
} | ||
|
||
export function removeAuthFromLocalStorage() { | ||
export function removeTokenFromLocalStorage() { | ||
localStorage.removeItem(AUTH_KEY); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be added to CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a ticket: https://tacc-main.atlassian.net/browse/WG-197