@lfai/egeria-js-commons
Version:
Common module for storing static data such as key value objects, SVGs, icon mappings, API urls.
40 lines (39 loc) • 1.9 kB
JavaScript
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 '../../../http';
import { getQueryParamsPath } from '../../../forms/index';
/**
*
* @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.
*
*/
// TODO: remove apiUrl as an optional
const fetchRawData = (formData) => __awaiter(void 0, void 0, void 0, function* () {
const { q, types } = formData;
if (q.value.length >= QUERY_MIN_LENGTH && types.value.length >= TYPES_MIN_SELECTED) {
const _queryParamsPath = getQueryParamsPath(formData);
const path = `${API_ASSETS_SEARCH_PATH}${_queryParamsPath.length ? `?${_queryParamsPath}` : ``}`;
const rawData = yield fetchData(path, 'GET');
return rawData;
}
else {
console.error('Err: API conditions were not met.');
return [];
}
});
export { fetchRawData };