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

session Manager #147

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VITE_SEARCH_ENDPOINT = https://www.ebi.ac.uk/ols4/api/search?
VITE_MONARCH_SEARCH = https://api-v3.monarchinitiative.org/v3/api/search?
# VITE_VOCAB_ENDPOINT = http://127.0.0.1:5000/api # local
VITE_VOCAB_ENDPOINT = https://locutus-dev-110109177269.us-central1.run.app/api # dev
# VITE_VOCAB_ENDPOINT = https://locutus-uat-1066621297011.us-central1.run.app/api # uat
VITE_CLIENT_ID = 159970607373-mvkv4lfl4ovpul5bssatuf1re4ucvg8n.apps.googleusercontent.com
VITE_MAPDRAGON_VERSION = "Development"
7 changes: 7 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { message } from 'antd';
import { useState, createContext, useRef, useEffect } from 'react';
import { AppRouter } from './AppRouter';
import { GoogleOAuthProvider } from '@react-oauth/google';
import { getSessionStatus } from './components/Manager/SessionsManager';

export const myContext = createContext();

Expand Down Expand Up @@ -36,11 +37,15 @@ function App() {
const [study, setStudy] = useState(initialStudy);
const [selectedKey, setSelectedKey] = useState(null);
const [user, setUser] = useState(null);
const [userPic, setUserPic] = useState(null);
const [ontologyForPagination, setOntologyForPagination] = useState([]);

message.config({
top: '25vh',
});
useEffect(() => {
// getSessionStatus(vocabUrl);
});
return (
<GoogleOAuthProvider clientId={clientId}>
<myContext.Provider
Expand Down Expand Up @@ -75,6 +80,8 @@ function App() {
setExportState,
user,
setUser,
userPic,
setUserPic,
importState,
setImportState,
ontologyForPagination,
Expand Down
3 changes: 2 additions & 1 deletion src/AppRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import { SearchContextRoot } from './Contexts/SearchContext.jsx';
import { About } from './components/About/About.jsx';

export const AppRouter = () => {
const { user, vocabUrl } = useContext(myContext);
const isLoggedIn = () => {
const storedUser = localStorage.getItem('user');

if (storedUser) {
return true;
} else {
Expand Down
20 changes: 15 additions & 5 deletions src/components/Auth/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import { jwtDecode } from 'jwt-decode';
import { useContext, useEffect } from 'react';
import { Logout } from './Logout';
import { myContext } from '../../App';
import { startSession } from '../Manager/SessionsManager';

export const Login = () => {
const { user, setUser } = useContext(myContext);
const { user, setUser,setUserPic, userPic, vocabUrl } = useContext(myContext);

useEffect(() => {
const storedUser = localStorage.getItem('user');
const storedUserPic = localStorage.getItem('userPic');
if (storedUser) {
setUser(JSON.parse(storedUser));
setUserPic(JSON.parse(storedUserPic));
}
}, []);
// If there is a user, it displays the Logout function with user information. Otherwise, it displays the login button
return user ? (
<Logout user={user} setUser={setUser} />
<Logout user={user} setUser={setUser} userPic={userPic} setUserPic={setUserPic} />
) : (
// Logs user in, decodes the JWT token, saves the decoded JWT in local storage and sets user to it
<div>
Expand All @@ -25,16 +28,23 @@ export const Login = () => {
const credentialResponseDecoded = jwtDecode(
credentialResponse.credential
);
setUser(credentialResponseDecoded);
console.log(credentialResponseDecoded,"credentialResponseDecoded");
localStorage.setItem(
'user',
JSON.stringify(credentialResponseDecoded)
JSON.stringify(credentialResponseDecoded.email)
);
localStorage.setItem(
'picture',
JSON.stringify(credentialResponseDecoded.picture)
);
startSession(vocabUrl, credentialResponseDecoded.email);
setUser(credentialResponseDecoded.email);
setUserPic(credentialResponseDecoded.picture);
}}
onError={() => {
console.log('Login Failed');
}}
/>
</div>
);
};
};
4 changes: 2 additions & 2 deletions src/components/Auth/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Login } from "./Login"
import { useContext } from 'react';
import { myContext } from '../../App';
import { getSessionStatus } from "../Manager/SessionsManager";
export const LoginPage = () => {
const {user} = useContext(myContext);
const {user,vocabUrl} = useContext(myContext);
return <div style={{background:"rgba(0,0,0,.2"}}>
{user &&
<h2 style={{textAlign:"center",paddingTop:'5rem'}}>You are logged in and can navigate to the rest of the site</h2>}
<div style={{ height:"5rem",display:"flex",flexDirection:"column",justifyContent:"space-around",alignItems:"center"}}>
<Login />
</div>

</div>
}
16 changes: 12 additions & 4 deletions src/components/Auth/Logout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import { googleLogout } from '@react-oauth/google';
import './Auth.scss';
import { LogoutOutlined } from '@ant-design/icons';
import { Tooltip } from 'antd';
import { endSession } from '../Manager/SessionsManager';
import { useContext } from 'react';
import { myContext } from '../../App';

export const Logout = ({ user, setUser,userPic,setUserPic }) => {
const { vocabUrl } = useContext(myContext)

export const Logout = ({ user, setUser }) => {
const logOut = () => {

googleLogout();
endSession(vocabUrl);
setUser(null);
setUserPic(null);
localStorage.removeItem('user');
};

return (
<>
<div className="logged_in_user">
<div className="user_email">
<img className="user_image" src={user.picture} />
{user?.email}
<img className="user_image" src={userPic} />
{user}
</div>
<Tooltip mouseEnterDelay={0.5} placement="bottom" title="Log out">
<LogoutOutlined
Expand All @@ -26,4 +34,4 @@ export const Logout = ({ user, setUser }) => {
</div>
</>
);
};
};
12 changes: 10 additions & 2 deletions src/components/Manager/FetchManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ontologyReducer } from './Utilitiy';
export const getAll = (vocabUrl, name, navigate) => {
return fetch(`${vocabUrl}/${name}`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -24,6 +25,7 @@ export const getAll = (vocabUrl, name, navigate) => {
export const getById = async (vocabUrl, name, id, navigate) => {
return fetch(`${vocabUrl}/${name}/${id}`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -46,13 +48,12 @@ export const getById = async (vocabUrl, name, id, navigate) => {

// Deletes one element by its id
export const handleDelete = (evt, vocabUrl, name, component, user) => {
const options = { method: 'DELETE' };
const options = { method: 'DELETE', credentials: 'include', };

if (name === 'Table' || name === 'Terminology') {
options.headers = {
'Content-Type': 'application/json',
};
options.body = JSON.stringify({ editor: user.email });
}
return fetch(`${vocabUrl}/${name}/${component.id}`, options)
.then(response => {
Expand Down Expand Up @@ -82,6 +83,7 @@ export const handleDelete = (evt, vocabUrl, name, component, user) => {
export const handleUpdate = (vocabUrl, name, component, values) => {
return fetch(`${vocabUrl}/${name}/${component.id}`, {
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -101,6 +103,7 @@ export const handleUpdate = (vocabUrl, name, component, values) => {
export const handlePost = (vocabUrl, name, body) => {
return fetch(`${vocabUrl}/${name}`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -119,6 +122,7 @@ export const handlePost = (vocabUrl, name, body) => {
export const handlePatch = (vocabUrl, name, component, body) => {
return fetch(`${vocabUrl}/${name}/${component.id}/rename`, {
method: 'PATCH',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -137,6 +141,7 @@ export const handlePatch = (vocabUrl, name, component, body) => {
export const getProvenanceByCode = async (vocabUrl, name, id, code) => {
return fetch(`${vocabUrl}/Provenance/${name}/${id}/code/${code}`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -154,6 +159,7 @@ export const getProvenanceByCode = async (vocabUrl, name, id, code) => {
export const getOntologies = vocabUrl => {
return fetch(`${vocabUrl}/OntologyAPI`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -189,6 +195,7 @@ export const olsFilterOntologiesSearch = (
`${searchUrl}q=${query}&ontology=${ontologiesToSearch}&rows=${entriesPerPage}&start=${pageStart}`,
{
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -248,6 +255,7 @@ export const getFiltersByCode = (
}`,
{
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const AssignMappings = ({
}));
const mappingsDTO = {
mappings: selectedMappings,
editor: user.email,
};

fetch(
Expand Down
4 changes: 0 additions & 4 deletions src/components/Manager/MappingsFunctions/ClearMappings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export const ClearMappings = ({ propId, component }) => {
const handleDelete = evt => {
return fetch(`${vocabUrl}/${component}/${propId}/mapping`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ editor: user.email }),
})
.then(res => {
if (res.ok) {
Expand Down
1 change: 1 addition & 0 deletions src/components/Manager/MappingsFunctions/FilterAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const FilterAPI = ({
return (
setTableLoading(true),
fetch(`${vocabUrl}/OntologyAPI/${active}`, {
credentials: 'include',
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
7 changes: 4 additions & 3 deletions src/components/Manager/MappingsFunctions/FilterReset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const FilterReset = ({ table, terminology }) => {
`${vocabUrl}/${
table
? `Table/${table.id}/filter/self`
: `Terminology/${terminology.id}/filter}`
: `Terminology/${terminology.id}/filter`
}`,
{
credentials: 'include',
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ editor: user.email }),
}
)
.then(res => {
Expand All @@ -48,9 +48,10 @@ export const FilterReset = ({ table, terminology }) => {
`${vocabUrl}/${
table
? `Table/${table.id}/filter/self`
: `Terminology/${terminology.id}/filter}`
: `Terminology/${terminology.id}/filter`
}`,
{
credentials: 'include',
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion src/components/Manager/MappingsFunctions/FilterSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export const FilterSelect = ({ component, table, terminology }) => {

const apiPreferenceDTO = {
api_preference: apiPreference?.api_preference,
editor: user.email,
};

const method =
Expand All @@ -138,6 +137,7 @@ export const FilterSelect = ({ component, table, terminology }) => {
? `Table/${table.id}/filter/self`
: `Terminology/${terminology.id}/filter`)}`,
{
credentials: 'include',
method: method,
headers: {
'Content-Type': 'application/json',
Expand All @@ -158,6 +158,7 @@ export const FilterSelect = ({ component, table, terminology }) => {
? `Table/${table.id}/filter/self`
: `Terminology/${terminology.id}/filter`)}`,
{
credentials: 'include',
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ export const GetMappingsModal = ({

const mappingsDTO = {
mappings: selectedMappings,
editor: user.email,
};

setLoading(true);
console.log(user);
fetch(
`${vocabUrl}/${componentString}/${component.id}/mapping/${mappingProp}?user_input=true&user=${user?.email}`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const OntologyFilterCodeSubmit = (
apiPreference.api_preference.ols = apiPreferencesCode;

fetch(`${vocabUrl}/Table/${table.id}/filter/${mappingProp}`, {
credentials: 'include',
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
Loading