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 #27 from sarbull/main
Extract AssetCatalog API logic
- Loading branch information
Showing
38 changed files
with
523 additions
and
20 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,3 @@ | ||
import { fetchRawData } from './search'; | ||
import { fetchTypes } from './types'; | ||
export { fetchRawData, fetchTypes }; |
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,37 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { API_ASSETS_SEARCH_PATH } from '../../routes'; | ||
import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED } from '../../../commons/constants'; | ||
import { fetchData } from '../../egeria-fetch'; | ||
import { getQueryParamsPath } from '../../../commons/helpers'; | ||
/** | ||
* | ||
* @param formData should contain all the query params from the URL | ||
* @param apiUrl is an optional parameter but it is used if API is deployed | ||
* in a different location | ||
* @returns empty array if conditions aren't met otherwise it will fetch data | ||
* from the API | ||
* | ||
* This function is used to fetch data for Asset Catalog. | ||
* | ||
*/ | ||
const fetchRawData = (formData, apiUrl) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { q, types } = formData; | ||
if (q.length >= QUERY_MIN_LENGTH && types.length >= TYPES_MIN_SELECTED) { | ||
const _queryParams = getQueryParamsPath(formData); | ||
const path = `${apiUrl || ''}${API_ASSETS_SEARCH_PATH}${_queryParams.length ? `?${_queryParams.join('&')}` : ``}`; | ||
const rawData = yield fetchData(path, 'GET'); | ||
return rawData; | ||
} | ||
else { | ||
return []; | ||
} | ||
}); | ||
export { fetchRawData }; |
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,31 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { API_ASSETS_TYPES_PATH } from '../../routes'; | ||
import { fetchData } from '../../egeria-fetch'; | ||
/** | ||
* @param apiUrl is an optional parameter but it is used if API is deployed | ||
* in a different location | ||
* | ||
* This function is used to fetch Asset Types. | ||
* | ||
*/ | ||
const fetchTypes = (apiUrl) => __awaiter(void 0, void 0, void 0, function* () { | ||
let typesData = yield fetchData(`${apiUrl || ''}${API_ASSETS_TYPES_PATH}`, 'GET'); | ||
typesData = [ | ||
...typesData.map((d) => { | ||
return { | ||
value: d.name, | ||
label: d.name | ||
}; | ||
}) | ||
]; | ||
return typesData; | ||
}); | ||
export { fetchTypes }; |
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,7 +1,34 @@ | ||
import { handleResponse } from '../auth'; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { handleResponse, authHeader } 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 }; | ||
/* | ||
* @param uri is the full URL | ||
* @param method usual fetch methods such as 'GET', 'POST', etc. | ||
* @param callback this is an optional callback function that can be used | ||
* in a different context to get the response and manage it | ||
* in a custom manner | ||
* @returns | ||
*/ | ||
const fetchData = (uri, method, callback) => __awaiter(void 0, void 0, void 0, function* () { | ||
const res = yield egeriaFetch(uri, method, Object.assign({}, authHeader()), {}); | ||
const data = yield res.json(); | ||
if (callback) { | ||
callback(data); | ||
} | ||
else { | ||
return data; | ||
} | ||
}); | ||
export { egeriaFetch, fetchData }; |
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,6 @@ | ||
/** | ||
* CONSTANTS used for API URLs | ||
*/ | ||
const API_ASSETS_SEARCH_PATH = '/api/assets/search'; | ||
const API_ASSETS_TYPES_PATH = '/api/assets/types'; | ||
export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; |
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 @@ | ||
/** | ||
* CONSTANTS used through the entire application. | ||
*/ | ||
const QUERY_MIN_LENGTH = 3; | ||
const TYPES_MIN_SELECTED = 1; | ||
const PAGE_SIZE_INCREASE_VALUE = 25; | ||
export { PAGE_SIZE_INCREASE_VALUE, QUERY_MIN_LENGTH, TYPES_MIN_SELECTED }; |
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,38 @@ | ||
import { PAGE_SIZE_INCREASE_VALUE } from './constants'; | ||
/** | ||
* | ||
* @param formData should contain all the query params from the URL | ||
* @returns an array of query params prepared to be concatenated in order to | ||
* form a valid URL path | ||
*/ | ||
const getQueryParamsPath = (formData) => { | ||
const { q, exactMatch, caseSensitive, types, pageSize } = formData; | ||
let queryParams = []; | ||
if (q) { | ||
queryParams.push(`q=${q}`); | ||
} | ||
if (types && types.length > 0) { | ||
queryParams.push(`types=${types.join(',')}`); | ||
} | ||
queryParams.push(`exactMatch=${exactMatch}`); | ||
queryParams.push(`caseSensitive=${caseSensitive}`); | ||
queryParams.push(`pageSize=${pageSize}`); | ||
return queryParams; | ||
}; | ||
/** | ||
* | ||
* @param searchParams react-router-dom object that contains and object with all | ||
* query params | ||
* @returns a new object with validated query params input for Asset Catalog | ||
*/ | ||
const getQueryParams = (searchParams) => { | ||
var _a; | ||
return { | ||
q: searchParams.get('q') || '', | ||
types: ((_a = searchParams.get('types')) === null || _a === void 0 ? void 0 : _a.split(',')) || [], | ||
exactMatch: searchParams.get('exactMatch') === "true" ? true : false, | ||
caseSensitive: searchParams.get('caseSensitive') === "true" ? true : false, | ||
pageSize: searchParams.get('pageSize') ? parseInt(searchParams.get('pageSize')) : PAGE_SIZE_INCREASE_VALUE | ||
}; | ||
}; | ||
export { getQueryParams, getQueryParamsPath }; |
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 @@ | ||
import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE } from './constants'; | ||
import { getQueryParams, getQueryParamsPath } from './helpers'; | ||
import { ASSET_CATALOG_PATH } from './paths'; | ||
export { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH }; |
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 @@ | ||
/** | ||
* CONSTANTS used for main application paths (deep linking). | ||
*/ | ||
const ASSET_CATALOG_PATH = '/assets/catalog'; | ||
export { ASSET_CATALOG_PATH }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
export {}; |
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 @@ | ||
import { fetchRawData } from './search'; | ||
import { fetchTypes } from './types'; | ||
export { fetchRawData, fetchTypes }; |
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 @@ | ||
import { formData } from '../../../types/formData'; | ||
/** | ||
* | ||
* @param formData should contain all the query params from the URL | ||
* @param apiUrl is an optional parameter but it is used if API is deployed | ||
* in a different location | ||
* @returns empty array if conditions aren't met otherwise it will fetch data | ||
* from the API | ||
* | ||
* This function is used to fetch data for Asset Catalog. | ||
* | ||
*/ | ||
declare const fetchRawData: (formData: formData, apiUrl?: string) => Promise<any>; | ||
export { fetchRawData }; |
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,9 @@ | ||
/** | ||
* @param apiUrl is an optional parameter but it is used if API is deployed | ||
* in a different location | ||
* | ||
* This function is used to fetch Asset Types. | ||
* | ||
*/ | ||
declare const fetchTypes: (apiUrl?: string) => Promise<any>; | ||
export { fetchTypes }; |
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,2 +1,3 @@ | ||
declare const egeriaFetch: (endpoint: string, method: string, headers: any, options: any) => Promise<any>; | ||
export { egeriaFetch }; | ||
declare const fetchData: (uri: string, method: string, callback?: Function) => Promise<any>; | ||
export { egeriaFetch, fetchData }; |
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,7 +1,9 @@ | ||
import { glossaries } from './data/glossaries'; | ||
import { lineage } from './data/lineage'; | ||
import { types } from './data/types'; | ||
import { egeriaFetch } from './egeria-fetch'; | ||
import { egeriaFetch, fetchData } from './egeria-fetch'; | ||
import { fetchRawData, fetchTypes } from './assets'; | ||
import { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH } from './routes'; | ||
declare const apiUrl: () => string; | ||
declare function goHome(): void; | ||
export { apiUrl, egeriaFetch, glossaries, goHome, lineage, types }; | ||
export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH, apiUrl, egeriaFetch, fetchData, fetchRawData, fetchTypes, 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,6 @@ | ||
/** | ||
* CONSTANTS used for API URLs | ||
*/ | ||
declare const API_ASSETS_SEARCH_PATH = "/api/assets/search"; | ||
declare const API_ASSETS_TYPES_PATH = "/api/assets/types"; | ||
export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; |
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 @@ | ||
/** | ||
* CONSTANTS used through the entire application. | ||
*/ | ||
declare const QUERY_MIN_LENGTH = 3; | ||
declare const TYPES_MIN_SELECTED = 1; | ||
declare const PAGE_SIZE_INCREASE_VALUE = 25; | ||
export { PAGE_SIZE_INCREASE_VALUE, QUERY_MIN_LENGTH, TYPES_MIN_SELECTED }; |
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 { formData } from '../types/formData'; | ||
/** | ||
* | ||
* @param formData should contain all the query params from the URL | ||
* @returns an array of query params prepared to be concatenated in order to | ||
* form a valid URL path | ||
*/ | ||
declare const getQueryParamsPath: (formData: formData) => any; | ||
/** | ||
* | ||
* @param searchParams react-router-dom object that contains and object with all | ||
* query params | ||
* @returns a new object with validated query params input for Asset Catalog | ||
*/ | ||
declare const getQueryParams: (searchParams: any) => { | ||
q: any; | ||
types: any; | ||
exactMatch: boolean; | ||
caseSensitive: boolean; | ||
pageSize: number; | ||
}; | ||
export { getQueryParams, getQueryParamsPath }; |
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 @@ | ||
import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE } from './constants'; | ||
import { getQueryParams, getQueryParamsPath } from './helpers'; | ||
import { ASSET_CATALOG_PATH } from './paths'; | ||
export { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH }; |
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 @@ | ||
/** | ||
* CONSTANTS used for main application paths (deep linking). | ||
*/ | ||
declare const ASSET_CATALOG_PATH = "/assets/catalog"; | ||
export { ASSET_CATALOG_PATH }; |
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,12 @@ | ||
/** | ||
* Interface used for the Asset Catalog form. | ||
* It's describing the attributes types used. | ||
*/ | ||
interface formData { | ||
caseSensitive: boolean; | ||
exactMatch: boolean; | ||
pageSize: number; | ||
q: string; | ||
types: Array<string>; | ||
} | ||
export type { formData }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
import { fetchRawData } from './search'; | ||
import { fetchTypes } from './types'; | ||
|
||
export { | ||
fetchRawData, | ||
fetchTypes | ||
} |
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,36 @@ | ||
import { API_ASSETS_SEARCH_PATH } from '../../routes'; | ||
import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED } from '../../../commons/constants'; | ||
import { formData } from '../../../types/formData'; | ||
import { fetchData } from '../../egeria-fetch'; | ||
import { getQueryParamsPath } from '../../../commons/helpers'; | ||
|
||
/** | ||
* | ||
* @param formData should contain all the query params from the URL | ||
* @param apiUrl is an optional parameter but it is used if API is deployed | ||
* in a different location | ||
* @returns empty array if conditions aren't met otherwise it will fetch data | ||
* from the API | ||
* | ||
* This function is used to fetch data for Asset Catalog. | ||
* | ||
*/ | ||
const fetchRawData = async (formData: formData, apiUrl?: string) => { | ||
const {q, types} = formData; | ||
|
||
if(q.length >= QUERY_MIN_LENGTH && types.length >= TYPES_MIN_SELECTED) { | ||
const _queryParams = getQueryParamsPath(formData); | ||
|
||
const path = `${apiUrl || ''}${API_ASSETS_SEARCH_PATH}${_queryParams.length ? `?${_queryParams.join('&')}` : ``}`; | ||
|
||
const rawData = await fetchData(path, 'GET'); | ||
|
||
return rawData; | ||
} else { | ||
return []; | ||
} | ||
}; | ||
|
||
export { | ||
fetchRawData | ||
} |
Oops, something went wrong.