This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from odpi/react
Merge #react with #main
- Loading branch information
Showing
62 changed files
with
1,065 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_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,52 @@ | ||
import { apiUrl } from '../'; | ||
import { authHeader, handleResponse } from '../../auth'; | ||
export const glossaries = { | ||
getAll, | ||
getGlossaryCategories, | ||
getGlossaryTerms | ||
}; | ||
/** | ||
* | ||
* HTTP API request for retrieving all the asset types. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* | ||
* | ||
* @return {Promise} Returns a promise with the request. | ||
* | ||
*/ | ||
function getAll() { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
return fetch(`${apiUrl()}/api/glossaries`, requestOptions).then(handleResponse); | ||
} | ||
/** | ||
* | ||
* HTTP API request for retrieving all the glossary categories. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* | ||
* | ||
* @return {Promise} Returns a promise with the request. | ||
* | ||
*/ | ||
function getGlossaryCategories() { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
return fetch(`${apiUrl()}/api/glossaries/categories`, requestOptions).then(handleResponse); | ||
} | ||
/** | ||
* | ||
* HTTP API request for retrieving all the glossary terms. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* | ||
* | ||
* @return {Promise} Returns a promise with the request. | ||
* | ||
*/ | ||
function getGlossaryTerms() { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
return fetch(`${apiUrl()}/api/glossaries/terms`, requestOptions).then(handleResponse); | ||
} |
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,22 @@ | ||
import { authHeader, handleResponse } from '../../auth'; | ||
import { apiUrl } from '../'; | ||
function getLineageTypes() { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
return fetch(`${apiUrl()}/api/lineage/types`, requestOptions).then(handleResponse); | ||
} | ||
function getNameSuggestions(name, type) { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
let url = `${apiUrl()}/api/lineage/nodes`; | ||
if (type) { | ||
url = `${url}?type=${type.trim()}`; | ||
if (name) { | ||
url = `${url}&name=${name.trim()}`; | ||
} | ||
url = `${url}&limit=10`; | ||
} | ||
return fetch(url, requestOptions).then(handleResponse); | ||
} | ||
export const lineage = { | ||
getLineageTypes, | ||
getNameSuggestions | ||
}; |
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,20 @@ | ||
import { apiUrl } from '../'; | ||
import { authHeader, handleResponse } from '../../auth'; | ||
export const types = { | ||
getAll | ||
}; | ||
/** | ||
* | ||
* HTTP API request for retrieving all the asset types. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* | ||
* | ||
* @return {Promise} Returns a promise with the request. | ||
* | ||
*/ | ||
function getAll() { | ||
const requestOptions = { method: 'GET', headers: authHeader() }; | ||
return fetch(`${apiUrl()}/api/assets/types`, requestOptions).then(handleResponse); | ||
} |
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,7 @@ | ||
import { handleResponse } from '../auth'; | ||
const egeriaFetch = (endpoint, method, headers, options) => { | ||
const requestOptions = Object.assign({ method: method, headers: headers }, options); | ||
const apiUrl = process.env.REACT_APP_API_URL || ''; | ||
return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse); | ||
}; | ||
export { egeriaFetch }; |
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,13 @@ | ||
import { glossaries } from './data/glossaries'; | ||
import { lineage } from './data/lineage'; | ||
import { types } from './data/types'; | ||
import { egeriaFetch } from './egeria-fetch'; | ||
const apiUrl = () => { | ||
return `${process.env.REACT_APP_API_URL}`; | ||
}; | ||
function goHome() { | ||
console.log('WENT HOME'); | ||
window.location.href = '/'; | ||
} | ||
; | ||
export { apiUrl, egeriaFetch, glossaries, goHome, lineage, types }; |
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,23 @@ | ||
import { currentJwt } from "./current-jwt"; | ||
export function authHeader() { | ||
const _currentJwt = currentJwt(); | ||
if (_currentJwt) { | ||
return { "x-auth-token": _currentJwt }; | ||
} | ||
else { | ||
return {}; | ||
} | ||
} | ||
export function authHeaderWithContentType() { | ||
const _currentJwt = currentJwt(); | ||
if (_currentJwt) { | ||
return { | ||
"x-auth-token": _currentJwt, | ||
"Content-Type": "application/json", | ||
"accept": "application/json" | ||
}; | ||
} | ||
else { | ||
return {}; | ||
} | ||
} |
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,3 @@ | ||
export function currentJwt() { | ||
return localStorage.getItem('currentJwt'); | ||
} |
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,10 @@ | ||
import { logout } from './logout'; | ||
export function handleResponse(response) { | ||
if (!response.ok) { | ||
if ([401, 403].indexOf(response.status) !== -1) { | ||
logout(); | ||
} | ||
return Promise.reject(); | ||
} | ||
return response; | ||
} |
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,8 @@ | ||
import { authHeader, authHeaderWithContentType } from './auth-header'; | ||
import { currentJwt } from './current-jwt'; | ||
import { login } from './login'; | ||
import { logout } from './logout'; | ||
import { parseJwt } from './parse-jwt'; | ||
import { setToken } from './set-token'; | ||
import { handleResponse } from './handle-response'; | ||
export { authHeader, authHeaderWithContentType, currentJwt, handleResponse, login, logout, parseJwt, setToken }; |
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,16 @@ | ||
import { setToken } from './set-token'; | ||
export function login(username, password, apiUrl) { | ||
const requestOptions = { | ||
method: 'POST', | ||
body: new URLSearchParams(`username=${username}&password=${password}`) | ||
}; | ||
return fetch(`${apiUrl}`, requestOptions) | ||
.then((response) => { | ||
if (response.ok) { | ||
const token = response.headers.get('x-auth-token'); | ||
setToken(token); | ||
console.log("LOGGED IN"); | ||
} | ||
return response; | ||
}); | ||
} |
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,7 @@ | ||
export const logout = (logoutCallback) => { | ||
localStorage.removeItem('currentJwt'); | ||
console.log('LOGGED OUT'); | ||
if (logoutCallback) { | ||
logoutCallback(); | ||
} | ||
}; |
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,10 @@ | ||
export function parseJwt(token) { | ||
if (token !== "") { | ||
var base64Url = token.split('.')[1]; | ||
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); | ||
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}).join('')); | ||
return JSON.parse(jsonPayload); | ||
} | ||
} |
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,5 @@ | ||
export function setToken(token) { | ||
const _token = token || ''; | ||
localStorage.setItem('currentJwt', _token); | ||
console.log('TOKEN SAVED'); | ||
} |
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,4 @@ | ||
function capitalize(s) { | ||
return s && s[0].toUpperCase() + s.slice(1); | ||
} | ||
export { capitalize }; |
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,4 @@ | ||
const getComponent = (id) => { | ||
return document.querySelector(id); | ||
}; | ||
export { getComponent }; |
Oops, something went wrong.