From dcb8f8cf977c92d5774eac26d6eaf1406485bb8a Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Mon, 9 Jun 2025 18:06:33 -0400 Subject: [PATCH 01/16] Updates Axios to 1.9.0 and axios-hooks to 5.1.1, Update Ingest and Search API Service --- src/package.json | 4 +- src/src/service/ingest_api.js | 676 ++++++++++++++-------------------- src/src/service/search_api.js | 91 ++--- 3 files changed, 305 insertions(+), 466 deletions(-) diff --git a/src/package.json b/src/package.json index b1e85982..11101be0 100644 --- a/src/package.json +++ b/src/package.json @@ -19,8 +19,8 @@ "@mui/x-data-grid": "^6.18.0", "@mui/x-date-pickers": "^7.0.00", "@stefftek/tick.js": "^1.1.1", - "axios": "^0.24.0", - "axios-hooks": "^3.0.0", + "axios": "^1.9.0", + "axios-hooks": "^5.1.1", "bootstrap": "^5.2.0-beta1", "dayjs": "^1.11.13", "dompurify": "^3.2.4", diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index b8916fe3..3b3f9362 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -4,34 +4,30 @@ import axios from "axios"; import FormData from "form-data"; var globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; - +let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} /* * User Groups only those data provider groups are return * */ -export function ingest_api_users_groups(auth) { +export function ingest_api_users_groups() { console.debug('%c◉ Global: ', 'color:#00ff7b', globalToken); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - return axios .get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { - const group_list = res.data.groups + const group_list = res.data.groups .filter(g => g.data_provider) .map(g => { return g; }); - // console.debug('API USER GROUPs', group_list); - return {status:res.status, results:group_list} + return {status: res.status, results: group_list} }) .catch(error => { - console.debug("ERR ingest_api_users_groups", error, error.response); if (error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read") { console.debug("User exists just not in the read group"); // it's not really an /error/ to have anaccount w/o read - return {status:200, results:error.response.response} + return {status: 200, results: error.response.response} } if(error.response){ - return {status:error.response.status, results:error.response.data} + return {status: error.response.status, results: error.response.data} }else{ console.error('%c⊙ Off Format err', 'color:#ff007b', error); // console.error(error); @@ -41,22 +37,15 @@ export function ingest_api_users_groups(auth) { }); } - /* * Is User Admin * */ -export function ingest_api_user_admin(auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - return axios - .get( +export function ingest_api_user_admin() { + return axios.get( `${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) - .then(res => { - - console.debug('%c◉ res ', 'color:#00ff7b', res); + .then(res => { let groups = res.data.groups; - console.debug('%c◉ ADMIN Check:', 'color:#FF227b', groups); for (let group in groups) { let groupName = groups[group].name console.debug('%c◉ groupName ', 'color:#ffe921', groupName); @@ -65,72 +54,59 @@ export function ingest_api_user_admin(auth) { } } return false - - - }) - .catch(error => { + }) + .catch(error => { console.debug("ERR ingest_api_users_groups", error, error.response); return {error} }); } - - /* * Upload a file * */ export function ingest_api_file_upload(data, options) { - return axios - .get( - `${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) + return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) .then(res => { // console.debug("ingest_api_file_upload", res); - return {status:res.status, results:res} + return {status: res.status, results: res} }) .catch(error => { return {error} }); } - /* * User Groups ALL groups are return (For that user only) * */ -export function ingest_api_all_user_groups(auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_all_user_groups() { + const options = {headers: {Authorization: "Bearer " + globalToken, + "Content-Type": "application/json"}}; - return axios - .get( - `${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) - .then(res => { - const group_list = res.data.groups; - return {status:res.status, results:group_list} - }) - .catch(error => { - return {error} - }); + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + .then(res => { + const group_list = res.data.groups; + return {status: res.status, results: group_list} + }) + .catch(error => { + return {error} + }); } /* * ALL groups are returned * */ -export function ingest_api_all_groups(auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - return axios - .get( - `${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) - .then(res => { - const group_list = res.data.groups; - return {status:res.status, results:group_list} - }) - .catch(error => { - return {error} - }); +export function ingest_api_all_groups() { + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) + .then(res => { + const group_list = res.data.groups; + return {status: res.status, results: group_list} + }) + .catch(error => { + return {error} + }); } /* @@ -138,23 +114,20 @@ export function ingest_api_all_groups(auth) { * * return: { status, results} */ -export function ingest_api_allowable_edit_states(uuid, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_allowable_edit_states(uuid) { let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`; - return axios - .get(url,options) - .then(res => { - return {status:res.status, results:res.data} - }) - .catch(error => { - console.debug("ingest_api_allowable_edit_states", error, error.response); - if(error.response){ - return {status:error.response.status, results:error.response.data} - }else{ - return {error} - } - }); + return axios.get(url,options) + .then(res => { + return {status: res.status, results: res.data} + }) + .catch(error => { + console.debug("ingest_api_allowable_edit_states", error, error.response); + if(error.response){ + return {status: error.response.status, results: error.response.data} + }else{ + return {error} + } + }); }; /* @@ -162,352 +135,270 @@ export function ingest_api_allowable_edit_states(uuid, auth) { * * return: { status, results} */ -export function ingest_api_allowable_edit_states_statusless(uuid, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_allowable_edit_states_statusless(uuid) { let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`; - return axios - .get(url,options) - .then(res => { - return {status:res.status, results:res.data} - }) - .catch(error => { - return {error} - }); + return axios.get(url,options) + .then(res => { + return {status: res.status, results: res.data} + }) + .catch(error => { + return {error} + }); }; /* * create a dataset * */ -export function ingest_api_create_dataset(data, auth) { - // console.debug("ingest_api_create_dataset", data); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - +export function ingest_api_create_dataset(data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`; - return axios - .post(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.post(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; /* * create a publication * */ -export function ingest_api_create_publication(data, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - +export function ingest_api_create_publication(data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/publications`; - return axios - .post(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - if(error.response){ - return {status:error.response.status, results:error.response.data} - }else{ - return {error} - } - }); + return axios.post(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + if(error.response){ + return {status: error.response.status, results: error.response.data} + }else{ + return {error} + } + }); }; /* * submit a dataset * */ -export function ingest_api_dataset_submit(uuid, data, auth) { - // console.debug("ingest_api_dataset_submit", data); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_dataset_submit(uuid, data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; - - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * Publish a dataset * */ -export function ingest_api_dataset_publish(uuid, data, auth) { - // console.debug("ingest_api_dataset_submit", data); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_dataset_publish(uuid, data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`; - - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * Derived dataset * */ -export function ingest_api_derived_dataset(uuid, data, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; // @TODO: Derived? - - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); +export function ingest_api_derived_dataset(uuid, data) { + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; // @TODO: Derived? + return axios.put(url, data, options) + .then(res => { + let results = res.data; + + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * ingest_api_bulk_entities - create A file COntaining bulk entries on .TSF file upload * */ -export function ingest_api_bulk_entities_upload(type, data, auth) { - console.debug("Starting Data: ",data); - console.debug("Going to : ",type); +export function ingest_api_bulk_entities_upload(type, data) { var dataForm = new FormData(); dataForm.append('file', data); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"multipart/form-data"}, - onUploadProgress:(ev: ProgressEvent) => { - const progress = ev.loaded / ev.total * 100; - console.debug("prog", Math.round(progress)); - }}; - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`; - - return axios - .post(url, dataForm, options) - .then(res => { - console.debug("ingest_api_bulk_entities",res); - //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation - // We might back back a 201 with an array of errors encountered. Let's check for that! - let results = res.data; - console.debug("results",results); - if(results[0]){ - console.debug("results DATA ",results[0]); - } - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`; + return axios.post(url, dataForm, options) + .then(res => { + console.debug("ingest_api_bulk_entities",res); + //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation + // We might back back a 201 with an array of errors encountered. Let's check for that! + let results = res.data; + console.debug("results",results); + if(results[0]){ + console.debug("results DATA ",results[0]); + } + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * ingest_api_bulk_entities - Registers / Inserts bulk entries based on ID of .TSV file upload * */ -export function ingest_api_bulk_entities_register(type, data, auth) { - console.debug("Starting Data: ",data); - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}, - onUploadProgress:(ev: ProgressEvent) => { - const progress = ev.loaded / ev.total * 100; - console.debug("prog", Math.round(progress)); - }}; - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`; - console.debug("URL: ",url, "\n DATA",data,"\n OPTS", options); - return axios - .post(url, data, options) - .then(res => { - console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); - // console.debug("ingest_ap i_bulk_entities",res); - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - // console.debug('%c‼️ INGESTAPI BULK ERR', 'color:#ff005d', error); - // throw new Error(error); - // var err = new Error(error); - // throw err; - return (error) - }); +export function ingest_api_bulk_entities_register(type, data) { + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`; + return axios.post(url, data, options) + .then(res => { + console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); + // console.debug("ingest_ap i_bulk_entities",res); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + // console.debug('%c‼️ INGESTAPI BULK ERR', 'color:#ff005d', error); + // throw new Error(error); + // var err = new Error(error); + // throw err; + return (error) + }); }; /* gets a list of associated IDS if the entity has multiple records. these are multi-labs records */ -export function ingest_api_get_associated_ids(uuid, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - return axios - .get( - `${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) - .then(res => { - if (res.data.ingest_group_ids.length > 1) { - res.data.ingest_group_ids.sort((a, b) => { - if ( - parseInt( - a.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 - ) - ) > - parseInt( - b.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 - ) - ) - ) { - return 1; - } - if ( - parseInt( - b.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 - ) - ) > - parseInt( - a.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 - ) - ) - ) { - return -1; - } - return 0; - }); +export function ingest_api_get_associated_ids(uuid) { + return axios.get(`${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) + .then(res => { + if (res.data.ingest_group_ids.length > 1) { + res.data.ingest_group_ids.sort((a, b) => { + if ( + parseInt( + a.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) > + parseInt( + b.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) + ) { + return 1; } - return {status:res.status, results:res.data.ingest_group_ids} - }) - .catch(error => { - return {error} + if ( + parseInt( + b.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) > + parseInt( + a.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) + ) { + return -1; + } + return 0; }); + } + return {status: res.status, results: res.data.ingest_group_ids} + }) + .catch(error => { + return {error} + }); } -export function ingest_api_get_globus_url(uuid, auth) { - const config = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"multipart/form-data",},}; - - return axios - .get( - `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`, - config - ) - .then((res) => { - return {status:200, results:res.data} - }) - .catch(error => { - return {error} - }); +export function ingest_api_get_globus_url(uuid) { + return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`,options) + .then((res) => { + return {status: 200, results: res.data} + }) + .catch(error => { + return {error} + }); } - - /* * Create New Upload * */ -export function ingest_api_create_upload(data, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - +export function ingest_api_create_upload(data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`; - return axios - .post(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.post(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * Submit Uploads * */ -export function ingest_api_submit_upload(uuid, data, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - +export function ingest_api_submit_upload(uuid, data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`; - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * Validate Upload * */ -export function ingest_api_validate_upload(uuid, data, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; - +export function ingest_api_validate_upload(uuid, data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`; - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; - /* * Reorganize or uploads * */ -export function ingest_api_reorganize_upload(uuid, auth) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; +export function ingest_api_reorganize_upload(uuid) { const data = {} - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`; - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - return {error} - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + return {error} + }); }; /* @@ -515,8 +406,9 @@ export function ingest_api_reorganize_upload(uuid, auth) { * */ export function ingest_api_notify_slack(data) { - const options = {headers:{Authorization: "Bearer " + globalToken, - "Content-Type":"application/json"}}; + // @TODO: ? + const options = {headers: {Authorization: "Bearer " + globalToken, + "Content-Type": "application/json"}}; data.send_to_email = true; // const data = ["data-testing-notificatons","Beep (O v O)!"] let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/notify`; @@ -525,7 +417,7 @@ export function ingest_api_notify_slack(data) { .then(res => { console.debug("ingest_api_notify_slack",res); let results = res.data; - return {status:res.status, results:results} + return {status: res.status, results: results} }) .catch(error => { console.debug("ingest_api_notify_slack",error); @@ -537,9 +429,7 @@ export function ingest_api_notify_slack(data) { * Bulk Metadata * */ -export function ingest_api_upload_bulk_metadata(type, dataFile, auth) { - console.debug('%c⭗', 'color:#ff005d', "ingest_api_upload_bulk_metadata", dataFile, type, auth); - const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; +export function ingest_api_upload_bulk_metadata(type, dataFile) { var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'file' }),dataFile.name); formData.append('entity_type', "Sample") @@ -548,113 +438,97 @@ export function ingest_api_upload_bulk_metadata(type, dataFile, auth) { console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`; // console.debug('%c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); - return axios - .put(url,formData,options) + return axios.put(url,formData,options) .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); let results = res.data; return {status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); - // Is it a server error or just a Validation error? - console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); - // throw new Error(error); - return {error} - }); + }) + .catch(error => { + console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); + // Is it a server error or just a Validation error? + console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); + // throw new Error(error); + return {error} + }); }; - - /* * Notify * */ -export function ingest_api_publish_collection(auth, data) { - const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; +export function ingest_api_publish_collection( data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`; - console.debug('%c◉ publish ', 'color:#00ff7b', url,options); - return axios - .put(url, data, options) - .then(res => { - let results = res.data; - return {status:res.status, results:results} - }) - .catch(error => { - if(error.response){ - return {status:error.response.status, results:error.response.data} - }else{ - return {error} - } - }); + return axios.put(url, data, options) + .then(res => { + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + if(error.response){ + return {status: error.response.status, results: error.response.data} + }else{ + return {error} + } + }); }; /* * Pipeline Testing Privledges * */ -export function ingest_api_pipeline_test_privs(auth) { - const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; +export function ingest_api_pipeline_test_privs() { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`; - return axios - .get(url, options) + return axios.get(url, options) .then(res => { - console.debug("ingest_api_pipeline_test_privs",res); + console.debug("ingest_api_pipeline_test_privs",res); let results = res.data; return {status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); - // throw new Error(error); - return {error} - }); + }) + .catch(error => { + console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); + // throw new Error(error); + return {error} + }); }; - /* * Pipeline Testing Submit * */ -export function ingest_api_pipeline_test_submit(auth, data) { - const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; +export function ingest_api_pipeline_test_submit( data) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`; - console.debug('%c◉ url ', 'color:#00ff7b', url); - return axios + return axios .post(url, {}, options) .then(res => { - console.debug("ingest_api_pipeline_test_submit",res); let results = res.data; - return {status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); - // throw new Error(error); - return {error} - }); + return {status: res.status, results: results}}) + .catch(error => { + console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); + return {error} + }); }; /* * Contibutor TSV Validation * */ -export function ingest_api_validate_contributors(auth,dataFile) { - const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; +export function ingest_api_validate_contributors(dataFile) { let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`; var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values' }),dataFile.name); formData.append('entity_type', "contributors") - return axios - .post(url, formData, options) + return axios.post(url, formData, options) .then(res => { console.debug("ingest_api_validate_contributors",res); let results = res.data; return {status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); - // throw new Error(error); - return {error} - }); + }) + .catch(error => { + console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); + // throw new Error(error); + return {error} + }); }; diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 6944166a..384a86c6 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -1,11 +1,11 @@ // Search APIs import axios from "axios"; -// import { GROUPS } from "./groups"; import {ES_SEARCHABLE_FIELDS,ES_SEARCHABLE_WILDCARDS} from "../constants"; - import {ingest_api_all_user_groups} from "./ingest_api"; export const esb = require("elastic-builder"); +let globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; +let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} /* * Auth Validation method @@ -13,15 +13,8 @@ export const esb = require("elastic-builder"); * return: { status} */ // Something of a hack to validate the auth token -export function api_validate_token(auth) { - const options = { - headers: { - Authorization: "Bearer " + auth, - "Content-Type": "application/json", - }, - }; +export function api_validate_token() { let payload = search_api_filter_es_query_builder("test", 1, 1); - return axios .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -33,20 +26,12 @@ export function api_validate_token(auth) { } /* - * Search API method + * Search API metvarhod * * return: { status, results} */ -export function api_search(params, auth) { - const options = { - headers: { - Authorization: "Bearer " + auth, - "Content-Type": "application/json", - }, - }; - +export function api_search(params) { let payload = search_api_filter_es_query_builder(params, 0, 100); - return axios .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -70,18 +55,8 @@ export function api_search(params, auth) { } export function api_search2(params, auth, from, size, fields, source) { - // console.debug('%c⊙', 'color:#00ff7b', fields ); - // console.debug('%c⊙', 'color:#00ff7b', "api2", params, auth, from, size, fields,source); - const options = { - headers: { - Authorization: "Bearer " + auth, - "Content-Type": "application/json", - }, - }; let payload = search_api_filter_es_query_builder(params, from, size, fields); - // console.debug('payload', payload) - return axios - .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) + return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { // console.debug("API api_search2 res", res); let hits = res.data.hits.hits; @@ -107,12 +82,11 @@ export function api_search2(params, auth, from, size, fields, source) { * */ export function search_api_filter_es_query_builder( - fields, - from, - size, - colFields -) { - // console.debug("%c⊙queryBits:", "color:#00ff7b", fields, from, size, colFields); + fields, + from, + size, + colFields + ){ let requestBody = esb.requestBodySearch(); let boolQuery = ""; if (fields["keywords"] && fields["keywords"].indexOf("*") > -1) { @@ -217,35 +191,27 @@ export function search_api_filter_es_query_builder( return requestBody.toJSON(); } -// export function fixKeywordText(text) { -// let x = text.replace(/-/gi, "\\-"); -// return x; -// } - // this WAS a function that reads from a static file groups.jsx export function search_api_search_group_list() { - ingest_api_all_user_groups( - JSON.parse(localStorage.getItem("info")).groups_token - ) - .then((res) => { - // no need to filter out the data_providers, the ingest api does that for us - let groups = res.results; - return groups; - }) - .catch((err) => { - console.debug( - "%c⭗", - "color:#ff005d", - "search_api_search_group_list error", - err - ); - return err; - }); + ingest_api_all_user_groups(JSON.parse(localStorage.getItem("info")).groups_token) + .then((res) => { + // no need to filter out the data_providers, the ingest api does that for us + let groups = res.results; + return groups; + }) + .catch((err) => { + console.debug( + "%c⭗", + "color:#ff005d", + "search_api_search_group_list error", + err + ); + return err; + }); } export function search_api_get_assay_type(assay) { - return axios - .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype`) + return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype`) .then((res) => { let data = res.data; var found_dt = undefined; @@ -303,8 +269,7 @@ export function search_api_get_assay_set(scope) { } export function search_api_get_assay_primaries() { - return axios - .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) + return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) .then((res) => { let data = res.data; let dtListMapped = data.result.map((value, index) => { From d57ca8c34bf553a76c11b537abe07065b9e47237 Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Mon, 9 Jun 2025 18:08:58 -0400 Subject: [PATCH 02/16] Formatting fix --- .directory | 11 +++++++++++ src/.directory | 10 ++++++++++ src/src/service/search_api.js | 6 ++---- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .directory create mode 100644 src/.directory diff --git a/.directory b/.directory new file mode 100644 index 00000000..09e9456a --- /dev/null +++ b/.directory @@ -0,0 +1,11 @@ +[Dolphin] +HeaderColumnWidths=502,72,111,90,579,119,72 +SortOrder=1 +SortRole=modificationtime +Timestamp=2025,6,9,17,31,25.146 +Version=4 +ViewMode=1 +VisibleRoles=Details_text,Details_size,Details_modificationtime,Details_type,Details_path,Details_creationtime,Details_owner,CustomizedDetails + +[Settings] +HiddenFilesShown=true diff --git a/src/.directory b/src/.directory new file mode 100644 index 00000000..538f9d87 --- /dev/null +++ b/src/.directory @@ -0,0 +1,10 @@ +[Dolphin] +HeaderColumnWidths=550,72,111,90,579,119,72 +SortRole=size +Timestamp=2025,6,9,17,31,33.922 +Version=4 +ViewMode=1 +VisibleRoles=Details_text,Details_size,Details_modificationtime,Details_type,Details_path,Details_creationtime,Details_owner,CustomizedDetails + +[Settings] +HiddenFilesShown=true diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 384a86c6..f299cd20 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -15,8 +15,7 @@ let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "a // Something of a hack to validate the auth token export function api_validate_token() { let payload = search_api_filter_es_query_builder("test", 1, 1); - return axios - .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) + return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { return { status: res.status }; }) @@ -32,8 +31,7 @@ export function api_validate_token() { */ export function api_search(params) { let payload = search_api_filter_es_query_builder(params, 0, 100); - return axios - .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) + return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { let hits = res.data.hits.hits; From ecd720ddc180c72fced459b4e0debbde3606b425 Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Mon, 9 Jun 2025 18:11:51 -0400 Subject: [PATCH 03/16] Fix unused vals --- src/src/service/search_api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index f299cd20..20642144 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -52,7 +52,7 @@ export function api_search(params) { }); } -export function api_search2(params, auth, from, size, fields, source) { +export function api_search2(params, auth, from, size, fields) { let payload = search_api_filter_es_query_builder(params, from, size, fields); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -246,7 +246,7 @@ export function search_api_get_assay_set(scope) { .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) .then((res) => { let data = res.data; - let mapCheck = data.result.map((value, index) => { + let mapCheck = data.result.map((value) => { return value; }); console.debug("API get_processed_assays data", data, mapCheck); @@ -270,7 +270,7 @@ export function search_api_get_assay_primaries() { return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) .then((res) => { let data = res.data; - let dtListMapped = data.result.map((value, index) => { + let dtListMapped = data.result.map((value) => { return value; }); return { status: res.status, data: dtListMapped }; From dc31c1aa3c658590e1644eca994212df8da4a0ac Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:05:28 -0400 Subject: [PATCH 04/16] Bit more Service Cleanup & addressing 'baseUrl' type usage --- src/src/service/entity_api.js | 46 ++++++--------------- src/src/service/ingest_api.js | 78 +++++++++++------------------------ src/src/service/search_api.js | 45 ++++++++++---------- src/src/service/ubkg_api.js | 77 +++++++++++++++------------------- 4 files changed, 91 insertions(+), 155 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index 167dab2e..8da7c52b 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -3,8 +3,8 @@ import axios from "axios"; const globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; const options = { headers: { - 'X-Hubmap-Application': 'ingest-ui', - Authorization: "Bearer " + globalToken, + "X-Hubmap-Application": "ingest-ui", + "Authorization": "Bearer " + globalToken, "Content-Type": "application/json" } }; @@ -15,9 +15,8 @@ const options = { */ export function entity_api_get_entity(uuid){ // console.debug("entity_api_get_entity"); - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`; return axios - .get(url,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`,options) .then(res => { let results = res.data; return{status: res.status, results: results} @@ -37,9 +36,8 @@ export function entity_api_get_entity(uuid){ * */ export function entity_api_update_entity(uuid, data){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`; return axios - .put(url, data, options) + .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`, data, options) .then(res => { // console.debug("entity_api_update_entity", res); let results = res.data; @@ -60,10 +58,9 @@ export function entity_api_update_entity(uuid, data){ * */ export function entity_api_create_entity(entitytype, data){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${entitytype}`; return axios - .post(url, data, options) + .post(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${entitytype}`, data, options) .then(res => { let results = res.data; return{status: res.status, results: results} @@ -83,9 +80,8 @@ export function entity_api_create_entity(entitytype, data){ * */ export function entity_api_create_multiple_entities(count, data){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples/${count}`; return axios - .post(url, data, options) + .post(`${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples/${count}`, data, options) .then(res => { let results = res.data; let fin = []; @@ -105,10 +101,8 @@ export function entity_api_create_multiple_entities(count, data){ * */ export function entity_api_update_multiple_entities(data){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples`; - return axios - .put(url, data, options) + .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples`, data, options) .then(res => { let results = res.data; return{status: res.status, results: results} @@ -125,9 +119,8 @@ export function entity_api_update_multiple_entities(data){ */ // @TODO: Rename to reflect Organ endpoint export function entity_api_get_entity_ancestor(uuid){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`; return axios - .get(url,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`,options) .then(res => { // console.debug(res); let results = res.data; @@ -139,9 +132,8 @@ export function entity_api_get_entity_ancestor(uuid){ }; export function entity_api_get_entity_ancestor_organ(uuid){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`; return axios - .get(url,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`,options) .then(res => { // console.debug(res); let results = res.data; @@ -158,9 +150,8 @@ export function entity_api_get_entity_ancestor_organ(uuid){ * return: { status, results} */ export function entity_api_get_entity_ancestor_list(uuid){ - let url = `${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`; return axios - .get(url,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`,options) .then(res => { // console.debug(res); let results = res.data; @@ -177,10 +168,8 @@ export function entity_api_get_entity_ancestor_list(uuid){ * return: { status, results} */ export function entity_api_get_globus_url(uuid){ - // console.debug("entity_api_get_globus_url"); - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url`; return axios - .get(url, options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url`, options) .then((res) => { // console.debug("entity_api_get_globus_url", res); return{status: res.status, results: res.data} @@ -193,9 +182,8 @@ export function entity_api_get_globus_url(uuid){ // @TODO DEPRECATING replaced with newer ingest API call export function entity_api_attach_bulk_metadata(uuid,item){ console.debug('%c⭗', 'color:#ff005d', "entity_api_upload_bulk_metadata", item); - let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid return axios - .put(url,item,options) + .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid,item,options) .then(res => { console.debug("ingest_api_attach_bulk_metadata",res); let results = res.data; @@ -217,25 +205,16 @@ export function entity_api_get_these_entities(uuids) { let message = ""; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note - // let dupes = uuidSet.difference(uuids) if (dupes.length > 0) { message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); } - console.group("entity_api_get_these_entities"); - console.debug("uuids: ", uuids); - console.debug("uuidSet", uuidSet); - console.debug("dupes", dupes); - console.groupEnd(); - if (uuids.length === 0) { message = "No UUIDs provided"; return Promise.resolve({ status: 400, results: { message: message } }); } // Fetch all entities in parallel return Promise.all(uuidSet.map(entity_api_get_entity)) - .then((results) => { - // console.debug("entity_api_get_globus_url", res);\ let badList = []; let goodList = []; let errMessage = null; @@ -256,7 +235,6 @@ export function entity_api_get_these_entities(uuids) { error: errMessage? errMessage : null }) }) - .catch(error => ({ status: 500, message: message, diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 3b3f9362..6356edbc 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -3,8 +3,8 @@ import axios from "axios"; import FormData from "form-data"; -var globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; -let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} +const globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; +const options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} /* * User Groups only those data provider groups are return * @@ -42,8 +42,7 @@ export function ingest_api_users_groups() { * */ export function ingest_api_user_admin() { - return axios.get( - `${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { let groups = res.data.groups; for (let group in groups) { @@ -81,9 +80,6 @@ export function ingest_api_file_upload(data, options) { * */ export function ingest_api_all_user_groups() { - const options = {headers: {Authorization: "Bearer " + globalToken, - "Content-Type": "application/json"}}; - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { const group_list = res.data.groups; @@ -115,8 +111,7 @@ export function ingest_api_all_groups() { * return: { status, results} */ export function ingest_api_allowable_edit_states(uuid) { - let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`; - return axios.get(url,options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`,options) .then(res => { return {status: res.status, results: res.data} }) @@ -136,8 +131,7 @@ export function ingest_api_allowable_edit_states(uuid) { * return: { status, results} */ export function ingest_api_allowable_edit_states_statusless(uuid) { - let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`; - return axios.get(url,options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`,options) .then(res => { return {status: res.status, results: res.data} }) @@ -151,8 +145,7 @@ export function ingest_api_allowable_edit_states_statusless(uuid) { * */ export function ingest_api_create_dataset(data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`; - return axios.post(url, data, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -167,8 +160,7 @@ export function ingest_api_create_dataset(data) { * */ export function ingest_api_create_publication(data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/publications`; - return axios.post(url, data, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/publications`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -187,8 +179,7 @@ export function ingest_api_create_publication(data) { * */ export function ingest_api_dataset_submit(uuid, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -203,8 +194,7 @@ export function ingest_api_dataset_submit(uuid, data) { * */ export function ingest_api_dataset_publish(uuid, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`, data, options) .then(res => { let results = res.data; @@ -220,8 +210,7 @@ export function ingest_api_dataset_publish(uuid, data) { * */ export function ingest_api_derived_dataset(uuid, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; // @TODO: Derived? - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { let results = res.data; @@ -239,8 +228,7 @@ export function ingest_api_derived_dataset(uuid, data) { export function ingest_api_bulk_entities_upload(type, data) { var dataForm = new FormData(); dataForm.append('file', data); - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`; - return axios.post(url, dataForm, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`, dataForm, options) .then(res => { console.debug("ingest_api_bulk_entities",res); //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation @@ -262,8 +250,7 @@ export function ingest_api_bulk_entities_upload(type, data) { * */ export function ingest_api_bulk_entities_register(type, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`; - return axios.post(url, data, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`, data, options) .then(res => { console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); // console.debug("ingest_ap i_bulk_entities",res); @@ -340,8 +327,7 @@ export function ingest_api_get_globus_url(uuid) { * */ export function ingest_api_create_upload(data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`; - return axios.post(url, data, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -356,8 +342,7 @@ export function ingest_api_create_upload(data) { * */ export function ingest_api_submit_upload(uuid, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -372,8 +357,7 @@ export function ingest_api_submit_upload(uuid, data) { * */ export function ingest_api_validate_upload(uuid, data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`, data, options) .then(res => { let results = res.data; @@ -390,8 +374,7 @@ export function ingest_api_validate_upload(uuid, data) { */ export function ingest_api_reorganize_upload(uuid) { const data = {} - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -405,15 +388,9 @@ export function ingest_api_reorganize_upload(uuid) { * Notify * */ -export function ingest_api_notify_slack(data) { - // @TODO: ? - const options = {headers: {Authorization: "Bearer " + globalToken, - "Content-Type": "application/json"}}; - data.send_to_email = true; - // const data = ["data-testing-notificatons","Beep (O v O)!"] - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/notify`; +export function ingest_api_notify_slack(data) { return axios - .post(url,data,options) + .post(${process.env.REACT_APP_DATAINGEST_API_URL}/notify,data,options) .then(res => { console.debug("ingest_api_notify_slack",res); let results = res.data; @@ -423,8 +400,7 @@ export function ingest_api_notify_slack(data) { console.debug("ingest_api_notify_slack",error); return {error} }); -}; - +} /* * Bulk Metadata * @@ -436,8 +412,7 @@ export function ingest_api_upload_bulk_metadata(type, dataFile) { formData.append('sub_type', type) formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`; - // console.debug('%c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); + // console.debug(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); return axios.put(url,formData,options) .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); @@ -458,8 +433,7 @@ export function ingest_api_upload_bulk_metadata(type, dataFile) { * */ export function ingest_api_publish_collection( data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`; - return axios.put(url, data, options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`, data, options) .then(res => { let results = res.data; return {status: res.status, results: results} @@ -478,8 +452,7 @@ export function ingest_api_publish_collection( data) { * */ export function ingest_api_pipeline_test_privs() { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`; - return axios.get(url, options) + return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) .then(res => { console.debug("ingest_api_pipeline_test_privs",res); let results = res.data; @@ -497,9 +470,8 @@ export function ingest_api_pipeline_test_privs() { * */ export function ingest_api_pipeline_test_submit( data) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`; return axios - .post(url, {}, options) + .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`, {}, options) .then(res => { let results = res.data; return {status: res.status, results: results}}) @@ -514,12 +486,11 @@ export function ingest_api_pipeline_test_submit( data) { * */ export function ingest_api_validate_contributors(dataFile) { - let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`; var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values' }),dataFile.name); formData.append('entity_type', "contributors") - return axios.post(url, formData, options) + return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) .then(res => { console.debug("ingest_api_validate_contributors",res); let results = res.data; @@ -531,4 +502,3 @@ export function ingest_api_validate_contributors(dataFile) { return {error} }); }; - diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 20642144..1f6899dc 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -240,30 +240,27 @@ export function search_api_get_assay_set(scope) { default: break; } - return ( - axios - // primaryness NEEDS to be in the url, not a form body addon - .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) - .then((res) => { - let data = res.data; - let mapCheck = data.result.map((value) => { - return value; - }); - console.debug("API get_processed_assays data", data, mapCheck); - return { data }; - }) - .catch((error) => { - console.debug("search_api_get_assay_set", error, error.response); - if (error.response) { - return { - status: error.response.status, - results: error.response.data, - }; - } else { - return { error }; - } - }) - ); + return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) + .then((res) => { + let data = res.data; + let mapCheck = data.result.map((value) => { + return value; + }); + console.debug("API get_processed_assays data", data, mapCheck); + return { data }; + }) + .catch((error) => { + console.debug("search_api_get_assay_set", error, error.response); + if (error.response) { + return { + status: error.response.status, + results: error.response.data, + }; + } else { + return { error }; + } + }); + } export function search_api_get_assay_primaries() { diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index 3ad2a41c..ed98dd74 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -50,23 +50,21 @@ import { stripHTML,toTitleCase } from '../utils/string_helper' * * return: {'AO': 'Aorta' ... } */ -export function ubkg_api_get_organ_type_set(format) { - let url = `${process.env.REACT_APP_UBKG_API_URL}/organs/by-code?application_context=HUBMAP`; - return axios - .get(url) - .then(res => { - let data = res.data; - if(format && format === 'array'){ - let organArray = Object.entries(data).map(([key, value]) => ({ key, value })); - return organArray; - }else{ - return data; - } - }) - .catch(error => { - console.debug("ubkg_api_get_organ_type_set", error, error.response); - captureError(error); - }); +export function ubkg_api_get_organ_type_set(format) { + return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/organs/by-code?application_context=HUBMAP`) + .then(res => { + let data = res.data; + if(format && format === 'array'){ + let organArray = Object.entries(data).map(([key, value]) => ({ key, value })); + return organArray; + }else{ + return data; + } + }) + .catch(error => { + console.debug("ubkg_api_get_organ_type_set", error, error.response); + captureError(error); + }); }; /* @@ -74,36 +72,31 @@ export function ubkg_api_get_organ_type_set(format) { * */ export function ubkg_api_get_dataset_type_set() { - // let url = `${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`; - let url = `${process.env.REACT_APP_UBKG_API_URL}/dataset-types?application_context=HUBMAP`; - return axios - .get(url) - .then(res => { - let data = res.data; - return data; - }) - .catch(error => { - console.debug("ubkg_api_get_dataset_type_set", error, error.response); - captureError(error); - }); + return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/dataset-types?application_context=HUBMAP`) + .then(res => { + let data = res.data; + return data; + }) + .catch(error => { + console.debug("ubkg_api_get_dataset_type_set", error, error.response); + captureError(error); + }); }; /* * UBKG GET Specilized Dataset Types for Uploads method * */ -export function ubkg_api_get_upload_dataset_types() { - let url = `${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`; - return axios - .get(url) - .then(res => { - let data = res.data; - return data; - }) - .catch(error => { - console.debug("ubkg_api_get_dataset_type_set", error, error.response); - captureError(error); - }); +export function ubkg_api_get_upload_dataset_types() { + return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`) + .then(res => { + let data = res.data; + return data; + }) + .catch(error => { + console.debug("ubkg_api_get_dataset_type_set", error, error.response); + captureError(error); + }); }; /* @@ -151,9 +144,7 @@ export function ubkg_api_generate_display_subtype(entity) { } function captureError (error){ - console.debug("Error Format CHeck", error); - if(error.response ){ if(error.response.data ){ if(error.response.data.includes("")){ From fbc444f827a71bbec1026f83d498470f6482707a Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:08:18 -0400 Subject: [PATCH 05/16] fixes --- src/src/service/ingest_api.js | 4 ++-- src/src/service/ubkg_api.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 6356edbc..1514d01f 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -390,7 +390,7 @@ export function ingest_api_reorganize_upload(uuid) { */ export function ingest_api_notify_slack(data) { return axios - .post(${process.env.REACT_APP_DATAINGEST_API_URL}/notify,data,options) + .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`,data,options) .then(res => { console.debug("ingest_api_notify_slack",res); let results = res.data; @@ -413,7 +413,7 @@ export function ingest_api_upload_bulk_metadata(type, dataFile) { formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); // console.debug(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); - return axios.put(url,formData,options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`,formData,options) .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); let results = res.data; diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index ed98dd74..2f3d6d63 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -132,9 +132,7 @@ export function ubkg_api_generate_display_subtype(entity) { display_subtype=entity['dataset_type'].toString() // return (entity['dataset_type'].toString()) }else if (entity_type === 'Upload'){ - // Uploads just need language fix return ("Data Upload") - display_subtype="Data Upload" }else{ // All others (Donors, & I'm asuming Collections and Publications) just use Entity Type display_subtype= toTitleCase(entity_type.toString()) From 089d9e9cf9b5b10279131d9c2274dfda08ec4b82 Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:14:35 -0400 Subject: [PATCH 06/16] eslint object-curly-spacing --- src/src/service/entity_api.js | 2 +- src/src/service/ingest_api.js | 5 ++--- src/src/service/search_api.js | 22 +++++++++++----------- src/src/service/ubkg_api.js | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index 8da7c52b..415bdd8d 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -210,7 +210,7 @@ export function entity_api_get_these_entities(uuids) { } if (uuids.length === 0) { message = "No UUIDs provided"; - return Promise.resolve({ status: 400, results: { message: message } }); + return Promise.resolve({status: 400, results: {message: message}}); } // Fetch all entities in parallel return Promise.all(uuidSet.map(entity_api_get_entity)) diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 1514d01f..d2cbb75b 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -407,12 +407,11 @@ export function ingest_api_notify_slack(data) { */ export function ingest_api_upload_bulk_metadata(type, dataFile) { var formData = new FormData(); - formData.append('metadata', new Blob([dataFile],{type: 'file' }),dataFile.name); + formData.append('metadata', new Blob([dataFile],{type: 'file'}),dataFile.name); formData.append('entity_type', "Sample") formData.append('sub_type', type) formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); - // console.debug(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`,formData,options) .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); @@ -487,7 +486,7 @@ export function ingest_api_pipeline_test_submit( data) { */ export function ingest_api_validate_contributors(dataFile) { var formData = new FormData(); - formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values' }),dataFile.name); + formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values'}),dataFile.name); formData.append('entity_type', "contributors") return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 1f6899dc..526fe8eb 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -17,10 +17,10 @@ export function api_validate_token() { let payload = search_api_filter_es_query_builder("test", 1, 1); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { - return { status: res.status }; + return {status: res.status}; }) .catch((error) => { - return { error }; + return {error}; }); } @@ -45,10 +45,10 @@ export function api_search(params) { } }); - return { status: res.status, results: entities }; + return {status: res.status, results: entities}; }) .catch((error) => { - return { error }; + return {error}; }); } @@ -71,7 +71,7 @@ export function api_search2(params, auth, from, size, fields) { }; }) .catch((error) => { - return { error }; + return {error}; }); } @@ -220,10 +220,10 @@ export function search_api_get_assay_type(assay) { }); console.debug(found_dt); - return { status: res.status, results: found_dt }; + return {status: res.status, results: found_dt}; }) .catch((error) => { - return { error }; + return {error}; }); } @@ -247,7 +247,7 @@ export function search_api_get_assay_set(scope) { return value; }); console.debug("API get_processed_assays data", data, mapCheck); - return { data }; + return {data}; }) .catch((error) => { console.debug("search_api_get_assay_set", error, error.response); @@ -257,7 +257,7 @@ export function search_api_get_assay_set(scope) { results: error.response.data, }; } else { - return { error }; + return {error}; } }); @@ -270,9 +270,9 @@ export function search_api_get_assay_primaries() { let dtListMapped = data.result.map((value) => { return value; }); - return { status: res.status, data: dtListMapped }; + return {status: res.status, data: dtListMapped}; }) .catch((error) => { - return { error }; + return {error}; }); } diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index 2f3d6d63..9702c458 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -1,5 +1,5 @@ import axios from "axios"; -import { stripHTML,toTitleCase } from '../utils/string_helper' +import {stripHTML,toTitleCase} from '../utils/string_helper' /* * UBKG GET assaytype method @@ -55,7 +55,7 @@ export function ubkg_api_get_organ_type_set(format) { .then(res => { let data = res.data; if(format && format === 'array'){ - let organArray = Object.entries(data).map(([key, value]) => ({ key, value })); + let organArray = Object.entries(data).map(([key, value]) => ({key, value})); return organArray; }else{ return data; From dd9d7fd59de1af1087612c8576e6e56ce78c4771 Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:15:37 -0400 Subject: [PATCH 07/16] eslint space-before-blocks --- src/src/service/entity_api.js | 8 ++--- src/src/service/ingest_api.js | 62 +++++++++++++++++------------------ src/src/service/search_api.js | 48 +++++++++++++-------------- src/src/service/ubkg_api.js | 10 +++--- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index 415bdd8d..d003740c 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -201,14 +201,14 @@ export function entity_api_attach_bulk_metadata(uuid,item){ * * return: { status, results} */ -export function entity_api_get_these_entities(uuids) { +export function entity_api_get_these_entities(uuids){ let message = ""; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note - if (dupes.length > 0) { + if (dupes.length > 0){ message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); } - if (uuids.length === 0) { + if (uuids.length === 0){ message = "No UUIDs provided"; return Promise.resolve({status: 400, results: {message: message}}); } @@ -220,7 +220,7 @@ export function entity_api_get_these_entities(uuids) { let errMessage = null; results.map((item) => { console.debug('%c◉ item ', 'color:#00ff7b', item); - if (item.status !== 200) { + if (item.status !== 200){ badList.push(item.data.error || item.data.message || item.data || "Unknown Error"); errMessage = "Error fetching entities: "+ badList.join(", "); }else{ diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index d2cbb75b..65b63cb9 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -9,7 +9,7 @@ const options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": * User Groups only those data provider groups are return * */ -export function ingest_api_users_groups() { +export function ingest_api_users_groups(){ console.debug('%c◉ Global: ', 'color:#00ff7b', globalToken); return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { @@ -21,7 +21,7 @@ export function ingest_api_users_groups() { return {status: res.status, results: group_list} }) .catch(error => { - if (error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read") { + if (error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read"){ console.debug("User exists just not in the read group"); // it's not really an /error/ to have anaccount w/o read return {status: 200, results: error.response.response} @@ -41,11 +41,11 @@ export function ingest_api_users_groups() { * Is User Admin * */ -export function ingest_api_user_admin() { +export function ingest_api_user_admin(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { let groups = res.data.groups; - for (let group in groups) { + for (let group in groups){ let groupName = groups[group].name console.debug('%c◉ groupName ', 'color:#ffe921', groupName); if(groupName.includes("hubmap-data-admin")){ @@ -64,7 +64,7 @@ export function ingest_api_user_admin() { * Upload a file * */ -export function ingest_api_file_upload(data, options) { +export function ingest_api_file_upload(data, options){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) .then(res => { // console.debug("ingest_api_file_upload", res); @@ -79,7 +79,7 @@ export function ingest_api_file_upload(data, options) { * User Groups ALL groups are return (For that user only) * */ -export function ingest_api_all_user_groups() { +export function ingest_api_all_user_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { const group_list = res.data.groups; @@ -94,7 +94,7 @@ export function ingest_api_all_user_groups() { * ALL groups are returned * */ -export function ingest_api_all_groups() { +export function ingest_api_all_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) .then(res => { const group_list = res.data.groups; @@ -110,7 +110,7 @@ export function ingest_api_all_groups() { * * return: { status, results} */ -export function ingest_api_allowable_edit_states(uuid) { +export function ingest_api_allowable_edit_states(uuid){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`,options) .then(res => { return {status: res.status, results: res.data} @@ -130,7 +130,7 @@ export function ingest_api_allowable_edit_states(uuid) { * * return: { status, results} */ -export function ingest_api_allowable_edit_states_statusless(uuid) { +export function ingest_api_allowable_edit_states_statusless(uuid){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`,options) .then(res => { return {status: res.status, results: res.data} @@ -144,7 +144,7 @@ export function ingest_api_allowable_edit_states_statusless(uuid) { * create a dataset * */ -export function ingest_api_create_dataset(data) { +export function ingest_api_create_dataset(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`, data, options) .then(res => { let results = res.data; @@ -159,7 +159,7 @@ export function ingest_api_create_dataset(data) { * create a publication * */ -export function ingest_api_create_publication(data) { +export function ingest_api_create_publication(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/publications`, data, options) .then(res => { let results = res.data; @@ -178,7 +178,7 @@ export function ingest_api_create_publication(data) { * submit a dataset * */ -export function ingest_api_dataset_submit(uuid, data) { +export function ingest_api_dataset_submit(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { let results = res.data; @@ -193,7 +193,7 @@ export function ingest_api_dataset_submit(uuid, data) { * Publish a dataset * */ -export function ingest_api_dataset_publish(uuid, data) { +export function ingest_api_dataset_publish(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`, data, options) .then(res => { let results = res.data; @@ -209,7 +209,7 @@ export function ingest_api_dataset_publish(uuid, data) { * Derived dataset * */ -export function ingest_api_derived_dataset(uuid, data) { +export function ingest_api_derived_dataset(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { let results = res.data; @@ -225,7 +225,7 @@ export function ingest_api_derived_dataset(uuid, data) { * ingest_api_bulk_entities - create A file COntaining bulk entries on .TSF file upload * */ -export function ingest_api_bulk_entities_upload(type, data) { +export function ingest_api_bulk_entities_upload(type, data){ var dataForm = new FormData(); dataForm.append('file', data); return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`, dataForm, options) @@ -249,7 +249,7 @@ export function ingest_api_bulk_entities_upload(type, data) { * ingest_api_bulk_entities - Registers / Inserts bulk entries based on ID of .TSV file upload * */ -export function ingest_api_bulk_entities_register(type, data) { +export function ingest_api_bulk_entities_register(type, data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`, data, options) .then(res => { console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); @@ -269,10 +269,10 @@ export function ingest_api_bulk_entities_register(type, data) { /* gets a list of associated IDS if the entity has multiple records. these are multi-labs records */ -export function ingest_api_get_associated_ids(uuid) { +export function ingest_api_get_associated_ids(uuid){ return axios.get(`${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) .then(res => { - if (res.data.ingest_group_ids.length > 1) { + if (res.data.ingest_group_ids.length > 1){ res.data.ingest_group_ids.sort((a, b) => { if ( parseInt( @@ -285,7 +285,7 @@ export function ingest_api_get_associated_ids(uuid) { a.submission_id.lastIndexOf("-") + 1 ) ) - ) { + ){ return 1; } if ( @@ -299,7 +299,7 @@ export function ingest_api_get_associated_ids(uuid) { a.submission_id.lastIndexOf("-") + 1 ) ) - ) { + ){ return -1; } return 0; @@ -312,7 +312,7 @@ export function ingest_api_get_associated_ids(uuid) { }); } -export function ingest_api_get_globus_url(uuid) { +export function ingest_api_get_globus_url(uuid){ return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`,options) .then((res) => { return {status: 200, results: res.data} @@ -326,7 +326,7 @@ export function ingest_api_get_globus_url(uuid) { * Create New Upload * */ -export function ingest_api_create_upload(data) { +export function ingest_api_create_upload(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`, data, options) .then(res => { let results = res.data; @@ -341,7 +341,7 @@ export function ingest_api_create_upload(data) { * Submit Uploads * */ -export function ingest_api_submit_upload(uuid, data) { +export function ingest_api_submit_upload(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`, data, options) .then(res => { let results = res.data; @@ -356,7 +356,7 @@ export function ingest_api_submit_upload(uuid, data) { * Validate Upload * */ -export function ingest_api_validate_upload(uuid, data) { +export function ingest_api_validate_upload(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`, data, options) .then(res => { let results = res.data; @@ -372,7 +372,7 @@ export function ingest_api_validate_upload(uuid, data) { * Reorganize or uploads * */ -export function ingest_api_reorganize_upload(uuid) { +export function ingest_api_reorganize_upload(uuid){ const data = {} return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`, data, options) .then(res => { @@ -388,7 +388,7 @@ export function ingest_api_reorganize_upload(uuid) { * Notify * */ -export function ingest_api_notify_slack(data) { +export function ingest_api_notify_slack(data){ return axios .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`,data,options) .then(res => { @@ -405,7 +405,7 @@ export function ingest_api_notify_slack(data) { * Bulk Metadata * */ -export function ingest_api_upload_bulk_metadata(type, dataFile) { +export function ingest_api_upload_bulk_metadata(type, dataFile){ var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'file'}),dataFile.name); formData.append('entity_type', "Sample") @@ -431,7 +431,7 @@ export function ingest_api_upload_bulk_metadata(type, dataFile) { * Notify * */ -export function ingest_api_publish_collection( data) { +export function ingest_api_publish_collection( data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`, data, options) .then(res => { let results = res.data; @@ -450,7 +450,7 @@ export function ingest_api_publish_collection( data) { * Pipeline Testing Privledges * */ -export function ingest_api_pipeline_test_privs() { +export function ingest_api_pipeline_test_privs(){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) .then(res => { console.debug("ingest_api_pipeline_test_privs",res); @@ -468,7 +468,7 @@ export function ingest_api_pipeline_test_privs() { * Pipeline Testing Submit * */ -export function ingest_api_pipeline_test_submit( data) { +export function ingest_api_pipeline_test_submit( data){ return axios .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`, {}, options) .then(res => { @@ -484,7 +484,7 @@ export function ingest_api_pipeline_test_submit( data) { * Contibutor TSV Validation * */ -export function ingest_api_validate_contributors(dataFile) { +export function ingest_api_validate_contributors(dataFile){ var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values'}),dataFile.name); formData.append('entity_type', "contributors") diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 526fe8eb..e107073c 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -13,7 +13,7 @@ let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "a * return: { status} */ // Something of a hack to validate the auth token -export function api_validate_token() { +export function api_validate_token(){ let payload = search_api_filter_es_query_builder("test", 1, 1); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -29,7 +29,7 @@ export function api_validate_token() { * * return: { status, results} */ -export function api_search(params) { +export function api_search(params){ let payload = search_api_filter_es_query_builder(params, 0, 100); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -38,7 +38,7 @@ export function api_search(params) { let entities = {}; hits.forEach((s) => { let uuid = s["_source"]["uuid"]; - if (entities[uuid]) { + if (entities[uuid]){ entities[s["_source"]["uuid"]].push(s["_source"]); } else { entities[s["_source"]["uuid"]] = [s["_source"]]; @@ -52,7 +52,7 @@ export function api_search(params) { }); } -export function api_search2(params, auth, from, size, fields) { +export function api_search2(params, auth, from, size, fields){ let payload = search_api_filter_es_query_builder(params, from, size, fields); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { @@ -87,7 +87,7 @@ export function search_api_filter_es_query_builder( ){ let requestBody = esb.requestBodySearch(); let boolQuery = ""; - if (fields["keywords"] && fields["keywords"].indexOf("*") > -1) { + if (fields["keywords"] && fields["keywords"].indexOf("*") > -1){ // if keywords contain a wildcard boolQuery = esb .queryStringQuery(fields["keywords"]) @@ -95,7 +95,7 @@ export function search_api_filter_es_query_builder( } else { boolQuery = esb.boolQuery(); // if no field criteria is sent just default to a - if (Object.keys(fields).length === 0 && fields.constructor === Object) { + if (Object.keys(fields).length === 0 && fields.constructor === Object){ // console.debug("full search") boolQuery.must( esb.matchQuery( @@ -105,14 +105,14 @@ export function search_api_filter_es_query_builder( ); } else { // was a group name selected - if (fields["group_name"]) { + if (fields["group_name"]){ boolQuery.must( esb.matchQuery("group_name.keyword", fields["group_name"]) ); - } else if (fields["group_uuid"]) { + } else if (fields["group_uuid"]){ // this'll be from the dropdown, // if its a collection, we wanna search the datasets of it, not it itself - if (fields["entity_type"] === "Collection") { + if (fields["entity_type"] === "Collection"){ boolQuery.must( esb.matchQuery("datasets.group_uuid.keyword", fields["group_uuid"]) ); @@ -123,21 +123,21 @@ export function search_api_filter_es_query_builder( } } // was specimen types selected - if (fields["sample_category"]) { + if (fields["sample_category"]){ // console.debug("sample_category", fields["sample_category"]); - if (fields["sample_category"] !== "donor") { + if (fields["sample_category"] !== "donor"){ boolQuery.must( esb.matchQuery("sample_category.keyword", fields["sample_category"]) ); } else { boolQuery.must(esb.matchQuery("entity_type.keyword", "Donor")); } - } else if (fields["organ"]) { + } else if (fields["organ"]){ boolQuery.must(esb.matchQuery("organ.keyword", fields["organ"])); } else { // was entity types select - if (fields["entity_type"]) { - if (fields["entity_type"] === "DonorSample") { + if (fields["entity_type"]){ + if (fields["entity_type"] === "DonorSample"){ // hack to deal with no type selected from the UI, this clues from the donor/sample filer boolQuery.must(esb.matchQuery("entity_type", "Donor OR Sample")); } else { @@ -155,8 +155,8 @@ export function search_api_filter_es_query_builder( } } - if (fields["keywords"]) { - if (fields["keywords"] && fields["keywords"].indexOf("HBM") === 0) { + if (fields["keywords"]){ + if (fields["keywords"] && fields["keywords"].indexOf("HBM") === 0){ boolQuery.must( esb.matchQuery("hubmap_id.keyword", fields["keywords"]) ); @@ -168,7 +168,7 @@ export function search_api_filter_es_query_builder( } } } - if (fields["keywords"] && fields["keywords"].indexOf("HBM") > -1) { + if (fields["keywords"] && fields["keywords"].indexOf("HBM") > -1){ // console.debug('%c⊙', 'color:#00ff7b', "BOOLQUERY", boolQuery ); requestBody .query(boolQuery) @@ -190,7 +190,7 @@ export function search_api_filter_es_query_builder( } // this WAS a function that reads from a static file groups.jsx -export function search_api_search_group_list() { +export function search_api_search_group_list(){ ingest_api_all_user_groups(JSON.parse(localStorage.getItem("info")).groups_token) .then((res) => { // no need to filter out the data_providers, the ingest api does that for us @@ -208,13 +208,13 @@ export function search_api_search_group_list() { }); } -export function search_api_get_assay_type(assay) { +export function search_api_get_assay_type(assay){ return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype`) .then((res) => { let data = res.data; var found_dt = undefined; data.result.forEach((s) => { - if (s["name"] === assay) { + if (s["name"] === assay){ found_dt = s; } }); @@ -227,10 +227,10 @@ export function search_api_get_assay_type(assay) { }); } -export function search_api_get_assay_set(scope) { +export function search_api_get_assay_set(scope){ // Scope informs either Primary, Alt, or All var target = ""; - switch (scope) { + switch (scope){ case "primary": target = "?primary=true"; break; @@ -251,7 +251,7 @@ export function search_api_get_assay_set(scope) { }) .catch((error) => { console.debug("search_api_get_assay_set", error, error.response); - if (error.response) { + if (error.response){ return { status: error.response.status, results: error.response.data, @@ -263,7 +263,7 @@ export function search_api_get_assay_set(scope) { } -export function search_api_get_assay_primaries() { +export function search_api_get_assay_primaries(){ return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) .then((res) => { let data = res.data; diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index 9702c458..c48e1404 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -50,7 +50,7 @@ import {stripHTML,toTitleCase} from '../utils/string_helper' * * return: {'AO': 'Aorta' ... } */ -export function ubkg_api_get_organ_type_set(format) { +export function ubkg_api_get_organ_type_set(format){ return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/organs/by-code?application_context=HUBMAP`) .then(res => { let data = res.data; @@ -71,7 +71,7 @@ export function ubkg_api_get_organ_type_set(format) { * UBKG GET dataset types method * */ -export function ubkg_api_get_dataset_type_set() { +export function ubkg_api_get_dataset_type_set(){ return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/dataset-types?application_context=HUBMAP`) .then(res => { let data = res.data; @@ -87,7 +87,7 @@ export function ubkg_api_get_dataset_type_set() { * UBKG GET Specilized Dataset Types for Uploads method * */ -export function ubkg_api_get_upload_dataset_types() { +export function ubkg_api_get_upload_dataset_types(){ return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`) .then(res => { let data = res.data; @@ -103,12 +103,12 @@ export function ubkg_api_get_upload_dataset_types() { * UBKG Generate Display Subtype method * */ -export function ubkg_api_generate_display_subtype(entity) { +export function ubkg_api_generate_display_subtype(entity){ var display_subtype = "" var entity_type = entity['entity_type'] if (entity_type === 'Sample' && 'sample_category' in entity){ if (entity['sample_category'].toLowerCase() === 'organ'){ - if ('organ' in entity) { + if ('organ' in entity){ var organCode = entity['organ']; ubkg_api_get_organ_type_set() .then((res) => { From 7e374e92d4b39c630b28b63d796538d88de3dbdd Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:26:34 -0400 Subject: [PATCH 08/16] ESLint tabbing fixes --- src/src/service/entity_api.js | 50 ++++++++-------- src/src/service/ingest_api.js | 104 +++++++++++++++++----------------- src/src/service/search_api.js | 52 ++++++++--------- 3 files changed, 103 insertions(+), 103 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index d003740c..febdbd2f 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -20,7 +20,7 @@ export function entity_api_get_entity(uuid){ .then(res => { let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { console.debug("entity_api_get_entity", error, error.response); if(error.response){ @@ -28,7 +28,7 @@ export function entity_api_get_entity(uuid){ }else{ return{error} } - } ); + }); }; /* @@ -42,7 +42,7 @@ export function entity_api_update_entity(uuid, data){ // console.debug("entity_api_update_entity", res); let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { if(error.response){ console.debug("entity_api_update_entity Error", error.response.status, error.response.data); @@ -50,7 +50,7 @@ export function entity_api_update_entity(uuid, data){ }else{ return{error: error.response} } - } ); + }); }; /* @@ -64,7 +64,7 @@ export function entity_api_create_entity(entitytype, data){ .then(res => { let results = res.data; return{status: res.status, results: results} - } ) + }) .catch((error) => { console.debug("entity_api_create_entity error", error, error.response); if(error.response && error.response.data){ @@ -72,7 +72,7 @@ export function entity_api_create_entity(entitytype, data){ }else{ return{error} } - } ); + }); }; /* @@ -88,12 +88,12 @@ export function entity_api_create_multiple_entities(count, data){ results.forEach(element => { element.checked = false; // add a checked attribute for later UI usage fin.push(element); - } ); + }); return{status: res.status, results: fin} - } ) + }) .catch(error => { return{error} - } ); + }); }; /* @@ -106,10 +106,10 @@ export function entity_api_update_multiple_entities(data){ .then(res => { let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { return{error} - } ); + }); }; /* @@ -125,10 +125,10 @@ export function entity_api_get_entity_ancestor(uuid){ // console.debug(res); let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { return{error} - } ); + }); }; export function entity_api_get_entity_ancestor_organ(uuid){ @@ -138,10 +138,10 @@ export function entity_api_get_entity_ancestor_organ(uuid){ // console.debug(res); let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { return{error} - } ); + }); }; /* @@ -156,10 +156,10 @@ export function entity_api_get_entity_ancestor_list(uuid){ // console.debug(res); let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { return{error} - } ); + }); }; /* @@ -173,10 +173,10 @@ export function entity_api_get_globus_url(uuid){ .then((res) => { // console.debug("entity_api_get_globus_url", res); return{status: res.status, results: res.data} - } ) + }) .catch((error) => { return{error} - } ); + }); }; // @TODO DEPRECATING replaced with newer ingest API call @@ -188,12 +188,12 @@ export function entity_api_attach_bulk_metadata(uuid,item){ console.debug("ingest_api_attach_bulk_metadata",res); let results = res.data; return{status: res.status, results: results} - } ) + }) .catch(error => { console.debug('%c⭗ ingest_api_attach_bulk_metadata', 'color:#ff005d',error); // throw new Error(error); return{error} - } ); + }); }; /* @@ -201,14 +201,14 @@ export function entity_api_attach_bulk_metadata(uuid,item){ * * return: { status, results} */ -export function entity_api_get_these_entities(uuids){ +export function entity_api_get_these_entities(uuids) { let message = ""; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note - if (dupes.length > 0){ + if (dupes.length > 0) { message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); } - if (uuids.length === 0){ + if (uuids.length === 0) { message = "No UUIDs provided"; return Promise.resolve({status: 400, results: {message: message}}); } @@ -220,7 +220,7 @@ export function entity_api_get_these_entities(uuids){ let errMessage = null; results.map((item) => { console.debug('%c◉ item ', 'color:#00ff7b', item); - if (item.status !== 200){ + if (item.status !== 200) { badList.push(item.data.error || item.data.message || item.data || "Unknown Error"); errMessage = "Error fetching entities: "+ badList.join(", "); }else{ diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 65b63cb9..1592f764 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -14,10 +14,10 @@ export function ingest_api_users_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { const group_list = res.data.groups - .filter(g => g.data_provider) - .map(g => { - return g; - }); + .filter(g => g.data_provider) + .map(g => { + return g; + }); return {status: res.status, results: group_list} }) .catch(error => { @@ -43,21 +43,21 @@ export function ingest_api_users_groups(){ */ export function ingest_api_user_admin(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) - .then(res => { - let groups = res.data.groups; - for (let group in groups){ - let groupName = groups[group].name - console.debug('%c◉ groupName ', 'color:#ffe921', groupName); - if(groupName.includes("hubmap-data-admin")){ - return true + .then(res => { + let groups = res.data.groups; + for (let group in groups){ + let groupName = groups[group].name + console.debug('%c◉ groupName ', 'color:#ffe921', groupName); + if(groupName.includes("hubmap-data-admin")){ + return true + } } - } - return false - }) - .catch(error => { - console.debug("ERR ingest_api_users_groups", error, error.response); - return {error} - }); + return false + }) + .catch(error => { + console.debug("ERR ingest_api_users_groups", error, error.response); + return {error} + }); } /* @@ -71,8 +71,8 @@ export function ingest_api_file_upload(data, options){ return {status: res.status, results: res} }) .catch(error => { - return {error} - }); + return {error} + }); } /* @@ -83,10 +83,10 @@ export function ingest_api_all_user_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { const group_list = res.data.groups; - return {status: res.status, results: group_list} + return {status: res.status, results: group_list} }) .catch(error => { - return {error} + return {error} }); } @@ -98,10 +98,10 @@ export function ingest_api_all_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) .then(res => { const group_list = res.data.groups; - return {status: res.status, results: group_list} + return {status: res.status, results: group_list} }) .catch(error => { - return {error} + return {error} }); } @@ -147,8 +147,8 @@ export function ingest_api_allowable_edit_states_statusless(uuid){ export function ingest_api_create_dataset(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`, data, options) .then(res => { - let results = res.data; - return {status: res.status, results: results} + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { return {error} @@ -162,8 +162,8 @@ export function ingest_api_create_dataset(data){ export function ingest_api_create_publication(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/publications`, data, options) .then(res => { - let results = res.data; - return {status: res.status, results: results} + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { if(error.response){ @@ -181,7 +181,7 @@ export function ingest_api_create_publication(data){ export function ingest_api_dataset_submit(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) .catch(error => { @@ -196,7 +196,7 @@ export function ingest_api_dataset_submit(uuid, data){ export function ingest_api_dataset_publish(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`, data, options) .then(res => { - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) @@ -212,7 +212,7 @@ export function ingest_api_dataset_publish(uuid, data){ export function ingest_api_derived_dataset(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) @@ -254,7 +254,7 @@ export function ingest_api_bulk_entities_register(type, data){ .then(res => { console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); // console.debug("ingest_ap i_bulk_entities",res); - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) .catch(error => { @@ -329,7 +329,7 @@ export function ingest_api_get_globus_url(uuid){ export function ingest_api_create_upload(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`, data, options) .then(res => { - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) .catch(error => { @@ -359,7 +359,7 @@ export function ingest_api_submit_upload(uuid, data){ export function ingest_api_validate_upload(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`, data, options) .then(res => { - let results = res.data; + let results = res.data; return {status: res.status, results: results} }) @@ -393,13 +393,13 @@ export function ingest_api_notify_slack(data){ .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`,data,options) .then(res => { console.debug("ingest_api_notify_slack",res); - let results = res.data; - return {status: res.status, results: results} - }) - .catch(error => { - console.debug("ingest_api_notify_slack",error); - return {error} - }); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + console.debug("ingest_api_notify_slack",error); + return {error} + }); } /* * Bulk Metadata @@ -415,8 +415,8 @@ export function ingest_api_upload_bulk_metadata(type, dataFile){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`,formData,options) .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); - let results = res.data; - return {status: res.status, results: results} + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); @@ -434,8 +434,8 @@ export function ingest_api_upload_bulk_metadata(type, dataFile){ export function ingest_api_publish_collection( data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`, data, options) .then(res => { - let results = res.data; - return {status: res.status, results: results} + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { if(error.response){ @@ -453,9 +453,9 @@ export function ingest_api_publish_collection( data){ export function ingest_api_pipeline_test_privs(){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) .then(res => { - console.debug("ingest_api_pipeline_test_privs",res); - let results = res.data; - return {status: res.status, results: results} + console.debug("ingest_api_pipeline_test_privs",res); + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); @@ -472,8 +472,8 @@ export function ingest_api_pipeline_test_submit( data){ return axios .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`, {}, options) .then(res => { - let results = res.data; - return {status: res.status, results: results}}) + let results = res.data; + return {status: res.status, results: results}}) .catch(error => { console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); return {error} @@ -492,8 +492,8 @@ export function ingest_api_validate_contributors(dataFile){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) .then(res => { console.debug("ingest_api_validate_contributors",res); - let results = res.data; - return {status: res.status, results: results} + let results = res.data; + return {status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index e107073c..b56a09b9 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -80,11 +80,11 @@ export function api_search2(params, auth, from, size, fields){ * */ export function search_api_filter_es_query_builder( - fields, - from, - size, - colFields - ){ + fields, + from, + size, + colFields +){ let requestBody = esb.requestBodySearch(); let boolQuery = ""; if (fields["keywords"] && fields["keywords"].indexOf("*") > -1){ @@ -192,20 +192,20 @@ export function search_api_filter_es_query_builder( // this WAS a function that reads from a static file groups.jsx export function search_api_search_group_list(){ ingest_api_all_user_groups(JSON.parse(localStorage.getItem("info")).groups_token) - .then((res) => { + .then((res) => { // no need to filter out the data_providers, the ingest api does that for us - let groups = res.results; - return groups; - }) - .catch((err) => { - console.debug( - "%c⭗", - "color:#ff005d", - "search_api_search_group_list error", - err - ); - return err; - }); + let groups = res.results; + return groups; + }) + .catch((err) => { + console.debug( + "%c⭗", + "color:#ff005d", + "search_api_search_group_list error", + err + ); + return err; + }); } export function search_api_get_assay_type(assay){ @@ -231,14 +231,14 @@ export function search_api_get_assay_set(scope){ // Scope informs either Primary, Alt, or All var target = ""; switch (scope){ - case "primary": - target = "?primary=true"; - break; - case "alt": - target = "?primary=false"; - break; - default: - break; + case "primary": + target = "?primary=true"; + break; + case "alt": + target = "?primary=false"; + break; + default: + break; } return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) .then((res) => { From def406119a58e4ad56b41ba2a29dc2dad91774bc Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:29:04 -0400 Subject: [PATCH 09/16] ESLint keyword-spacing --- src/src/service/entity_api.js | 8 +-- src/src/service/ingest_api.js | 124 +++++++++++++++++----------------- src/src/service/search_api.js | 86 +++++++++++------------ src/src/service/ubkg_api.js | 26 +++---- 4 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index febdbd2f..23aca825 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -205,10 +205,10 @@ export function entity_api_get_these_entities(uuids) { let message = ""; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note - if (dupes.length > 0) { + if(dupes.length > 0) { message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); } - if (uuids.length === 0) { + if(uuids.length === 0) { message = "No UUIDs provided"; return Promise.resolve({status: 400, results: {message: message}}); } @@ -220,14 +220,14 @@ export function entity_api_get_these_entities(uuids) { let errMessage = null; results.map((item) => { console.debug('%c◉ item ', 'color:#00ff7b', item); - if (item.status !== 200) { + if(item.status !== 200) { badList.push(item.data.error || item.data.message || item.data || "Unknown Error"); errMessage = "Error fetching entities: "+ badList.join(", "); }else{ goodList.push(item); } }); - return ({ + return({ status: 200, message: message, results: goodList, diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 1592f764..ef6951c9 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -18,21 +18,21 @@ export function ingest_api_users_groups(){ .map(g => { return g; }); - return {status: res.status, results: group_list} + return{status: res.status, results: group_list} }) .catch(error => { - if (error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read"){ + if(error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read"){ console.debug("User exists just not in the read group"); // it's not really an /error/ to have anaccount w/o read - return {status: 200, results: error.response.response} + return{status: 200, results: error.response.response} } if(error.response){ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} }else{ console.error('%c⊙ Off Format err', 'color:#ff007b', error); // console.error(error); // throw new Error(error); - return {error} + return{error} } }); } @@ -45,7 +45,7 @@ export function ingest_api_user_admin(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { let groups = res.data.groups; - for (let group in groups){ + for(let group in groups){ let groupName = groups[group].name console.debug('%c◉ groupName ', 'color:#ffe921', groupName); if(groupName.includes("hubmap-data-admin")){ @@ -56,7 +56,7 @@ export function ingest_api_user_admin(){ }) .catch(error => { console.debug("ERR ingest_api_users_groups", error, error.response); - return {error} + return{error} }); } @@ -68,10 +68,10 @@ export function ingest_api_file_upload(data, options){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) .then(res => { // console.debug("ingest_api_file_upload", res); - return {status: res.status, results: res} + return{status: res.status, results: res} }) .catch(error => { - return {error} + return{error} }); } @@ -83,10 +83,10 @@ export function ingest_api_all_user_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { const group_list = res.data.groups; - return {status: res.status, results: group_list} + return{status: res.status, results: group_list} }) .catch(error => { - return {error} + return{error} }); } @@ -98,10 +98,10 @@ export function ingest_api_all_groups(){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) .then(res => { const group_list = res.data.groups; - return {status: res.status, results: group_list} + return{status: res.status, results: group_list} }) .catch(error => { - return {error} + return{error} }); } @@ -113,14 +113,14 @@ export function ingest_api_all_groups(){ export function ingest_api_allowable_edit_states(uuid){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`,options) .then(res => { - return {status: res.status, results: res.data} + return{status: res.status, results: res.data} }) .catch(error => { console.debug("ingest_api_allowable_edit_states", error, error.response); if(error.response){ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} }else{ - return {error} + return{error} } }); }; @@ -133,10 +133,10 @@ export function ingest_api_allowable_edit_states(uuid){ export function ingest_api_allowable_edit_states_statusless(uuid){ return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`,options) .then(res => { - return {status: res.status, results: res.data} + return{status: res.status, results: res.data} }) .catch(error => { - return {error} + return{error} }); }; @@ -148,10 +148,10 @@ export function ingest_api_create_dataset(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -163,13 +163,13 @@ export function ingest_api_create_publication(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/publications`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { if(error.response){ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} }else{ - return {error} + return{error} } }); }; @@ -182,10 +182,10 @@ export function ingest_api_dataset_submit(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -198,10 +198,10 @@ export function ingest_api_dataset_publish(uuid, data){ .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -214,10 +214,10 @@ export function ingest_api_derived_dataset(uuid, data){ .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -238,10 +238,10 @@ export function ingest_api_bulk_entities_upload(type, data){ if(results[0]){ console.debug("results DATA ",results[0]); } - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -255,14 +255,14 @@ export function ingest_api_bulk_entities_register(type, data){ console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); // console.debug("ingest_ap i_bulk_entities",res); let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { // console.debug('%c‼️ INGESTAPI BULK ERR', 'color:#ff005d', error); // throw new Error(error); // var err = new Error(error); // throw err; - return (error) + return(error) }); }; @@ -272,9 +272,9 @@ export function ingest_api_bulk_entities_register(type, data){ export function ingest_api_get_associated_ids(uuid){ return axios.get(`${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) .then(res => { - if (res.data.ingest_group_ids.length > 1){ + if(res.data.ingest_group_ids.length > 1){ res.data.ingest_group_ids.sort((a, b) => { - if ( + if( parseInt( a.submission_id.substring( a.submission_id.lastIndexOf("-") + 1 @@ -288,7 +288,7 @@ export function ingest_api_get_associated_ids(uuid){ ){ return 1; } - if ( + if( parseInt( b.submission_id.substring( a.submission_id.lastIndexOf("-") + 1 @@ -300,25 +300,25 @@ export function ingest_api_get_associated_ids(uuid){ ) ) ){ - return -1; + return-1; } return 0; }); } - return {status: res.status, results: res.data.ingest_group_ids} + return{status: res.status, results: res.data.ingest_group_ids} }) .catch(error => { - return {error} + return{error} }); } export function ingest_api_get_globus_url(uuid){ return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`,options) .then((res) => { - return {status: 200, results: res.data} + return{status: 200, results: res.data} }) .catch(error => { - return {error} + return{error} }); } @@ -330,10 +330,10 @@ export function ingest_api_create_upload(data){ return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -345,10 +345,10 @@ export function ingest_api_submit_upload(uuid, data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -361,10 +361,10 @@ export function ingest_api_validate_upload(uuid, data){ .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -377,10 +377,10 @@ export function ingest_api_reorganize_upload(uuid){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { - return {error} + return{error} }); }; @@ -394,11 +394,11 @@ export function ingest_api_notify_slack(data){ .then(res => { console.debug("ingest_api_notify_slack",res); let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { console.debug("ingest_api_notify_slack",error); - return {error} + return{error} }); } /* @@ -416,14 +416,14 @@ export function ingest_api_upload_bulk_metadata(type, dataFile){ .then(res => { console.debug("ingest_api_upload_bulk_metadata",res); let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); // Is it a server error or just a Validation error? console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); // throw new Error(error); - return {error} + return{error} }); }; @@ -435,13 +435,13 @@ export function ingest_api_publish_collection( data){ return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`, data, options) .then(res => { let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { if(error.response){ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} }else{ - return {error} + return{error} } }); }; @@ -455,12 +455,12 @@ export function ingest_api_pipeline_test_privs(){ .then(res => { console.debug("ingest_api_pipeline_test_privs",res); let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); // throw new Error(error); - return {error} + return{error} }); }; @@ -473,10 +473,10 @@ export function ingest_api_pipeline_test_submit( data){ .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`, {}, options) .then(res => { let results = res.data; - return {status: res.status, results: results}}) + return{status: res.status, results: results}}) .catch(error => { console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); - return {error} + return{error} }); }; @@ -493,11 +493,11 @@ export function ingest_api_validate_contributors(dataFile){ .then(res => { console.debug("ingest_api_validate_contributors",res); let results = res.data; - return {status: res.status, results: results} + return{status: res.status, results: results} }) .catch(error => { console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); // throw new Error(error); - return {error} + return{error} }); }; diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index b56a09b9..bb92e015 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -17,10 +17,10 @@ export function api_validate_token(){ let payload = search_api_filter_es_query_builder("test", 1, 1); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { - return {status: res.status}; + return{status: res.status}; }) .catch((error) => { - return {error}; + return{error}; }); } @@ -38,17 +38,17 @@ export function api_search(params){ let entities = {}; hits.forEach((s) => { let uuid = s["_source"]["uuid"]; - if (entities[uuid]){ + if(entities[uuid]){ entities[s["_source"]["uuid"]].push(s["_source"]); - } else { + }else{ entities[s["_source"]["uuid"]] = [s["_source"]]; } }); - return {status: res.status, results: entities}; + return{status: res.status, results: entities}; }) .catch((error) => { - return {error}; + return{error}; }); } @@ -64,14 +64,14 @@ export function api_search2(params, auth, from, size, fields){ data["id"] = s["_source"]["uuid"]; entities.push(data); }); - return { + return{ status: res.status, results: entities, total: res.data.hits.total.value, }; }) .catch((error) => { - return {error}; + return{error}; }); } @@ -87,15 +87,15 @@ export function search_api_filter_es_query_builder( ){ let requestBody = esb.requestBodySearch(); let boolQuery = ""; - if (fields["keywords"] && fields["keywords"].indexOf("*") > -1){ + if(fields["keywords"] && fields["keywords"].indexOf("*") > -1){ // if keywords contain a wildcard boolQuery = esb .queryStringQuery(fields["keywords"]) .fields(ES_SEARCHABLE_WILDCARDS); - } else { + }else{ boolQuery = esb.boolQuery(); // if no field criteria is sent just default to a - if (Object.keys(fields).length === 0 && fields.constructor === Object){ + if(Object.keys(fields).length === 0 && fields.constructor === Object){ // console.debug("full search") boolQuery.must( esb.matchQuery( @@ -103,49 +103,49 @@ export function search_api_filter_es_query_builder( "Donor OR Sample OR Dataset OR Upload OR Publication OR Collection" ) ); - } else { + }else{ // was a group name selected - if (fields["group_name"]){ + if(fields["group_name"]){ boolQuery.must( esb.matchQuery("group_name.keyword", fields["group_name"]) ); - } else if (fields["group_uuid"]){ + }else if(fields["group_uuid"]){ // this'll be from the dropdown, // if its a collection, we wanna search the datasets of it, not it itself - if (fields["entity_type"] === "Collection"){ + if(fields["entity_type"] === "Collection"){ boolQuery.must( esb.matchQuery("datasets.group_uuid.keyword", fields["group_uuid"]) ); - } else { + }else{ boolQuery.must( esb.matchQuery("group_uuid.keyword", fields["group_uuid"]) ); } } // was specimen types selected - if (fields["sample_category"]){ + if(fields["sample_category"]){ // console.debug("sample_category", fields["sample_category"]); - if (fields["sample_category"] !== "donor"){ + if(fields["sample_category"] !== "donor"){ boolQuery.must( esb.matchQuery("sample_category.keyword", fields["sample_category"]) ); - } else { + }else{ boolQuery.must(esb.matchQuery("entity_type.keyword", "Donor")); } - } else if (fields["organ"]){ + }else if(fields["organ"]){ boolQuery.must(esb.matchQuery("organ.keyword", fields["organ"])); - } else { + }else{ // was entity types select - if (fields["entity_type"]){ - if (fields["entity_type"] === "DonorSample"){ + if(fields["entity_type"]){ + if(fields["entity_type"] === "DonorSample"){ // hack to deal with no type selected from the UI, this clues from the donor/sample filer boolQuery.must(esb.matchQuery("entity_type", "Donor OR Sample")); - } else { + }else{ boolQuery.must( esb.matchQuery("entity_type.keyword", fields["entity_type"]) ); } - } else { + }else{ boolQuery.must( esb.matchQuery( "entity_type", @@ -155,12 +155,12 @@ export function search_api_filter_es_query_builder( } } - if (fields["keywords"]){ - if (fields["keywords"] && fields["keywords"].indexOf("HBM") === 0){ + if(fields["keywords"]){ + if(fields["keywords"] && fields["keywords"].indexOf("HBM") === 0){ boolQuery.must( esb.matchQuery("hubmap_id.keyword", fields["keywords"]) ); - } else { + }else{ boolQuery.filter( esb.multiMatchQuery(ES_SEARCHABLE_FIELDS, fields["keywords"]) ); @@ -168,7 +168,7 @@ export function search_api_filter_es_query_builder( } } } - if (fields["keywords"] && fields["keywords"].indexOf("HBM") > -1){ + if(fields["keywords"] && fields["keywords"].indexOf("HBM") > -1){ // console.debug('%c⊙', 'color:#00ff7b', "BOOLQUERY", boolQuery ); requestBody .query(boolQuery) @@ -177,7 +177,7 @@ export function search_api_filter_es_query_builder( .sort(esb.sort("last_modified_timestamp", "asc")) .source(colFields) .trackTotalHits(true); - } else { + }else{ requestBody .query(boolQuery) .from(from) @@ -214,27 +214,27 @@ export function search_api_get_assay_type(assay){ let data = res.data; var found_dt = undefined; data.result.forEach((s) => { - if (s["name"] === assay){ + if(s["name"] === assay){ found_dt = s; } }); console.debug(found_dt); - return {status: res.status, results: found_dt}; + return{status: res.status, results: found_dt}; }) .catch((error) => { - return {error}; + return{error}; }); } export function search_api_get_assay_set(scope){ // Scope informs either Primary, Alt, or All var target = ""; - switch (scope){ - case "primary": + switch(scope){ + case"primary": target = "?primary=true"; break; - case "alt": + case"alt": target = "?primary=false"; break; default: @@ -247,17 +247,17 @@ export function search_api_get_assay_set(scope){ return value; }); console.debug("API get_processed_assays data", data, mapCheck); - return {data}; + return{data}; }) .catch((error) => { console.debug("search_api_get_assay_set", error, error.response); - if (error.response){ - return { + if(error.response){ + return{ status: error.response.status, results: error.response.data, }; - } else { - return {error}; + }else{ + return{error}; } }); @@ -270,9 +270,9 @@ export function search_api_get_assay_primaries(){ let dtListMapped = data.result.map((value) => { return value; }); - return {status: res.status, data: dtListMapped}; + return{status: res.status, data: dtListMapped}; }) .catch((error) => { - return {error}; + return{error}; }); } diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index c48e1404..b9d44e2f 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -106,9 +106,9 @@ export function ubkg_api_get_upload_dataset_types(){ export function ubkg_api_generate_display_subtype(entity){ var display_subtype = "" var entity_type = entity['entity_type'] - if (entity_type === 'Sample' && 'sample_category' in entity){ - if (entity['sample_category'].toLowerCase() === 'organ'){ - if ('organ' in entity){ + if(entity_type === 'Sample' && 'sample_category' in entity){ + if(entity['sample_category'].toLowerCase() === 'organ'){ + if('organ' in entity){ var organCode = entity['organ']; ubkg_api_get_organ_type_set() .then((res) => { @@ -117,22 +117,22 @@ export function ubkg_api_generate_display_subtype(entity){ // return (res[organCode]) }) .catch((error) => { - return (error) + return(error) }); }else{ throw new Error("Missing Organ key for Sample with uuid: {entity['uuid']}") } - } else { + }else{ display_subtype=entity['sample_category'].toString(); // return entity['sample_category'].toString(); } - }else if (entity_type === 'Dataset' && 'dataset_type' in entity){ + }else if(entity_type === 'Dataset' && 'dataset_type' in entity){ // Datasets store in ugly format, need to reff pretty style display_subtype=entity['dataset_type'].toString() // return (entity['dataset_type'].toString()) - }else if (entity_type === 'Upload'){ - return ("Data Upload") + }else if(entity_type === 'Upload'){ + return("Data Upload") }else{ // All others (Donors, & I'm asuming Collections and Publications) just use Entity Type display_subtype= toTitleCase(entity_type.toString()) @@ -147,14 +147,14 @@ function captureError (error){ if(error.response.data ){ if(error.response.data.includes("")){ var responseData = stripHTML(error.response.data) - return {status: error.response.status, results: responseData} + return{status: error.response.status, results: responseData} }else{ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} } }else{ - return {status: error.response.status, results: error.response.data} + return{status: error.response.status, results: error.response.data} } - } else { - return {error} + }else{ + return{error} } } From d04cd0f3e1ee1a4e668c993aaab6d92808f627eb Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:32:44 -0400 Subject: [PATCH 10/16] ESLint Quote Enforcement --- src/src/service/entity_api.js | 32 +++++----- src/src/service/ingest_api.js | 46 +++++++-------- src/src/service/search_api.js | 108 +++++++++++++++++----------------- src/src/service/ubkg_api.js | 18 +++--- 4 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index 23aca825..a98b31e1 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -1,11 +1,11 @@ -import axios from "axios"; +import axios from 'axios'; -const globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; +const globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; const options = { headers: { - "X-Hubmap-Application": "ingest-ui", - "Authorization": "Bearer " + globalToken, - "Content-Type": "application/json" + 'X-Hubmap-Application': 'ingest-ui', + 'Authorization': 'Bearer ' + globalToken, + 'Content-Type': 'application/json' } }; /* @@ -22,7 +22,7 @@ export function entity_api_get_entity(uuid){ return{status: res.status, results: results} }) .catch(error => { - console.debug("entity_api_get_entity", error, error.response); + console.debug('entity_api_get_entity', error, error.response); if(error.response){ return error.response }else{ @@ -45,7 +45,7 @@ export function entity_api_update_entity(uuid, data){ }) .catch(error => { if(error.response){ - console.debug("entity_api_update_entity Error", error.response.status, error.response.data); + console.debug('entity_api_update_entity Error', error.response.status, error.response.data); return{status: error.response.status, results: error.response.data} }else{ return{error: error.response} @@ -66,7 +66,7 @@ export function entity_api_create_entity(entitytype, data){ return{status: res.status, results: results} }) .catch((error) => { - console.debug("entity_api_create_entity error", error, error.response); + console.debug('entity_api_create_entity error', error, error.response); if(error.response && error.response.data){ return{error: error.response.data} }else{ @@ -181,11 +181,11 @@ export function entity_api_get_globus_url(uuid){ // @TODO DEPRECATING replaced with newer ingest API call export function entity_api_attach_bulk_metadata(uuid,item){ - console.debug('%c⭗', 'color:#ff005d', "entity_api_upload_bulk_metadata", item); + console.debug('%c⭗', 'color:#ff005d', 'entity_api_upload_bulk_metadata', item); return axios .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid,item,options) .then(res => { - console.debug("ingest_api_attach_bulk_metadata",res); + console.debug('ingest_api_attach_bulk_metadata',res); let results = res.data; return{status: res.status, results: results} }) @@ -202,14 +202,14 @@ export function entity_api_attach_bulk_metadata(uuid,item){ * return: { status, results} */ export function entity_api_get_these_entities(uuids) { - let message = ""; + let message = ''; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note if(dupes.length > 0) { - message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); + message = 'Duplicate IDs found and Removed: ' + Array.from(new Set(dupes)).join(', '); } if(uuids.length === 0) { - message = "No UUIDs provided"; + message = 'No UUIDs provided'; return Promise.resolve({status: 400, results: {message: message}}); } // Fetch all entities in parallel @@ -221,8 +221,8 @@ export function entity_api_get_these_entities(uuids) { results.map((item) => { console.debug('%c◉ item ', 'color:#00ff7b', item); if(item.status !== 200) { - badList.push(item.data.error || item.data.message || item.data || "Unknown Error"); - errMessage = "Error fetching entities: "+ badList.join(", "); + badList.push(item.data.error || item.data.message || item.data || 'Unknown Error'); + errMessage = 'Error fetching entities: '+ badList.join(', '); }else{ goodList.push(item); } @@ -238,6 +238,6 @@ export function entity_api_get_these_entities(uuids) { .catch(error => ({ status: 500, message: message, - results: error.message?error.message: "Error fetching entities" + results: error.message?error.message: 'Error fetching entities' })); } diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index ef6951c9..cd41fcbd 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -1,10 +1,10 @@ // Ingest specific APIs -import axios from "axios"; -import FormData from "form-data"; +import axios from 'axios'; +import FormData from 'form-data'; -const globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; -const options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} +const globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; +const options={headers: {Authorization: 'Bearer ' + globalToken,'Content-Type': 'application/json'}} /* * User Groups only those data provider groups are return * @@ -21,8 +21,8 @@ export function ingest_api_users_groups(){ return{status: res.status, results: group_list} }) .catch(error => { - if(error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read"){ - console.debug("User exists just not in the read group"); + if(error && error.response && error.response.response && error.response.response === 'User is not a member of group HuBMAP-read'){ + console.debug('User exists just not in the read group'); // it's not really an /error/ to have anaccount w/o read return{status: 200, results: error.response.response} } @@ -48,14 +48,14 @@ export function ingest_api_user_admin(){ for(let group in groups){ let groupName = groups[group].name console.debug('%c◉ groupName ', 'color:#ffe921', groupName); - if(groupName.includes("hubmap-data-admin")){ + if(groupName.includes('hubmap-data-admin')){ return true } } return false }) .catch(error => { - console.debug("ERR ingest_api_users_groups", error, error.response); + console.debug('ERR ingest_api_users_groups', error, error.response); return{error} }); } @@ -116,7 +116,7 @@ export function ingest_api_allowable_edit_states(uuid){ return{status: res.status, results: res.data} }) .catch(error => { - console.debug("ingest_api_allowable_edit_states", error, error.response); + console.debug('ingest_api_allowable_edit_states', error, error.response); if(error.response){ return{status: error.response.status, results: error.response.data} }else{ @@ -230,13 +230,13 @@ export function ingest_api_bulk_entities_upload(type, data){ dataForm.append('file', data); return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`, dataForm, options) .then(res => { - console.debug("ingest_api_bulk_entities",res); + console.debug('ingest_api_bulk_entities',res); //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation // We might back back a 201 with an array of errors encountered. Let's check for that! let results = res.data; - console.debug("results",results); + console.debug('results',results); if(results[0]){ - console.debug("results DATA ",results[0]); + console.debug('results DATA ',results[0]); } return{status: res.status, results: results} }) @@ -277,12 +277,12 @@ export function ingest_api_get_associated_ids(uuid){ if( parseInt( a.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 + a.submission_id.lastIndexOf('-') + 1 ) ) > parseInt( b.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 + a.submission_id.lastIndexOf('-') + 1 ) ) ){ @@ -291,12 +291,12 @@ export function ingest_api_get_associated_ids(uuid){ if( parseInt( b.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 + a.submission_id.lastIndexOf('-') + 1 ) ) > parseInt( a.submission_id.substring( - a.submission_id.lastIndexOf("-") + 1 + a.submission_id.lastIndexOf('-') + 1 ) ) ){ @@ -392,12 +392,12 @@ export function ingest_api_notify_slack(data){ return axios .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`,data,options) .then(res => { - console.debug("ingest_api_notify_slack",res); + console.debug('ingest_api_notify_slack',res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug("ingest_api_notify_slack",error); + console.debug('ingest_api_notify_slack',error); return{error} }); } @@ -408,13 +408,13 @@ export function ingest_api_notify_slack(data){ export function ingest_api_upload_bulk_metadata(type, dataFile){ var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'file'}),dataFile.name); - formData.append('entity_type', "Sample") + formData.append('entity_type', 'Sample') formData.append('sub_type', type) formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`,formData,options) .then(res => { - console.debug("ingest_api_upload_bulk_metadata",res); + console.debug('ingest_api_upload_bulk_metadata',res); let results = res.data; return{status: res.status, results: results} }) @@ -453,7 +453,7 @@ export function ingest_api_publish_collection( data){ export function ingest_api_pipeline_test_privs(){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) .then(res => { - console.debug("ingest_api_pipeline_test_privs",res); + console.debug('ingest_api_pipeline_test_privs',res); let results = res.data; return{status: res.status, results: results} }) @@ -487,11 +487,11 @@ export function ingest_api_pipeline_test_submit( data){ export function ingest_api_validate_contributors(dataFile){ var formData = new FormData(); formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values'}),dataFile.name); - formData.append('entity_type', "contributors") + formData.append('entity_type', 'contributors') return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) .then(res => { - console.debug("ingest_api_validate_contributors",res); + console.debug('ingest_api_validate_contributors',res); let results = res.data; return{status: res.status, results: results} }) diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index bb92e015..64008489 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -1,11 +1,11 @@ // Search APIs -import axios from "axios"; -import {ES_SEARCHABLE_FIELDS,ES_SEARCHABLE_WILDCARDS} from "../constants"; -import {ingest_api_all_user_groups} from "./ingest_api"; -export const esb = require("elastic-builder"); -let globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; -let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "application/json"}} +import axios from 'axios'; +import {ES_SEARCHABLE_FIELDS,ES_SEARCHABLE_WILDCARDS} from '../constants'; +import {ingest_api_all_user_groups} from './ingest_api'; +export const esb = require('elastic-builder'); +let globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; +let options={headers: {Authorization: 'Bearer ' + globalToken,'Content-Type': 'application/json'}} /* * Auth Validation method @@ -14,7 +14,7 @@ let options={headers: {Authorization: "Bearer " + globalToken,"Content-Type": "a */ // Something of a hack to validate the auth token export function api_validate_token(){ - let payload = search_api_filter_es_query_builder("test", 1, 1); + let payload = search_api_filter_es_query_builder('test', 1, 1); return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { return{status: res.status}; @@ -37,11 +37,11 @@ export function api_search(params){ let entities = {}; hits.forEach((s) => { - let uuid = s["_source"]["uuid"]; + let uuid = s['_source']['uuid']; if(entities[uuid]){ - entities[s["_source"]["uuid"]].push(s["_source"]); + entities[s['_source']['uuid']].push(s['_source']); }else{ - entities[s["_source"]["uuid"]] = [s["_source"]]; + entities[s['_source']['uuid']] = [s['_source']]; } }); @@ -60,8 +60,8 @@ export function api_search2(params, auth, from, size, fields){ let hits = res.data.hits.hits; let entities = []; hits.forEach((s) => { - let data = s["_source"]; - data["id"] = s["_source"]["uuid"]; + let data = s['_source']; + data['id'] = s['_source']['uuid']; entities.push(data); }); return{ @@ -86,11 +86,11 @@ export function search_api_filter_es_query_builder( colFields ){ let requestBody = esb.requestBodySearch(); - let boolQuery = ""; - if(fields["keywords"] && fields["keywords"].indexOf("*") > -1){ + let boolQuery = ''; + if(fields['keywords'] && fields['keywords'].indexOf('*') > -1){ // if keywords contain a wildcard boolQuery = esb - .queryStringQuery(fields["keywords"]) + .queryStringQuery(fields['keywords']) .fields(ES_SEARCHABLE_WILDCARDS); }else{ boolQuery = esb.boolQuery(); @@ -99,82 +99,82 @@ export function search_api_filter_es_query_builder( // console.debug("full search") boolQuery.must( esb.matchQuery( - "entity_type", - "Donor OR Sample OR Dataset OR Upload OR Publication OR Collection" + 'entity_type', + 'Donor OR Sample OR Dataset OR Upload OR Publication OR Collection' ) ); }else{ // was a group name selected - if(fields["group_name"]){ + if(fields['group_name']){ boolQuery.must( - esb.matchQuery("group_name.keyword", fields["group_name"]) + esb.matchQuery('group_name.keyword', fields['group_name']) ); - }else if(fields["group_uuid"]){ + }else if(fields['group_uuid']){ // this'll be from the dropdown, // if its a collection, we wanna search the datasets of it, not it itself - if(fields["entity_type"] === "Collection"){ + if(fields['entity_type'] === 'Collection'){ boolQuery.must( - esb.matchQuery("datasets.group_uuid.keyword", fields["group_uuid"]) + esb.matchQuery('datasets.group_uuid.keyword', fields['group_uuid']) ); }else{ boolQuery.must( - esb.matchQuery("group_uuid.keyword", fields["group_uuid"]) + esb.matchQuery('group_uuid.keyword', fields['group_uuid']) ); } } // was specimen types selected - if(fields["sample_category"]){ + if(fields['sample_category']){ // console.debug("sample_category", fields["sample_category"]); - if(fields["sample_category"] !== "donor"){ + if(fields['sample_category'] !== 'donor'){ boolQuery.must( - esb.matchQuery("sample_category.keyword", fields["sample_category"]) + esb.matchQuery('sample_category.keyword', fields['sample_category']) ); }else{ - boolQuery.must(esb.matchQuery("entity_type.keyword", "Donor")); + boolQuery.must(esb.matchQuery('entity_type.keyword', 'Donor')); } - }else if(fields["organ"]){ - boolQuery.must(esb.matchQuery("organ.keyword", fields["organ"])); + }else if(fields['organ']){ + boolQuery.must(esb.matchQuery('organ.keyword', fields['organ'])); }else{ // was entity types select - if(fields["entity_type"]){ - if(fields["entity_type"] === "DonorSample"){ + if(fields['entity_type']){ + if(fields['entity_type'] === 'DonorSample'){ // hack to deal with no type selected from the UI, this clues from the donor/sample filer - boolQuery.must(esb.matchQuery("entity_type", "Donor OR Sample")); + boolQuery.must(esb.matchQuery('entity_type', 'Donor OR Sample')); }else{ boolQuery.must( - esb.matchQuery("entity_type.keyword", fields["entity_type"]) + esb.matchQuery('entity_type.keyword', fields['entity_type']) ); } }else{ boolQuery.must( esb.matchQuery( - "entity_type", - "Donor OR Sample OR Dataset OR Upload OR Publication OR Collection" + 'entity_type', + 'Donor OR Sample OR Dataset OR Upload OR Publication OR Collection' ) ); // default everything ; this maybe temp } } - if(fields["keywords"]){ - if(fields["keywords"] && fields["keywords"].indexOf("HBM") === 0){ + if(fields['keywords']){ + if(fields['keywords'] && fields['keywords'].indexOf('HBM') === 0){ boolQuery.must( - esb.matchQuery("hubmap_id.keyword", fields["keywords"]) + esb.matchQuery('hubmap_id.keyword', fields['keywords']) ); }else{ boolQuery.filter( - esb.multiMatchQuery(ES_SEARCHABLE_FIELDS, fields["keywords"]) + esb.multiMatchQuery(ES_SEARCHABLE_FIELDS, fields['keywords']) ); } } } } - if(fields["keywords"] && fields["keywords"].indexOf("HBM") > -1){ + if(fields['keywords'] && fields['keywords'].indexOf('HBM') > -1){ // console.debug('%c⊙', 'color:#00ff7b', "BOOLQUERY", boolQuery ); requestBody .query(boolQuery) .from(from) .size(1) - .sort(esb.sort("last_modified_timestamp", "asc")) + .sort(esb.sort('last_modified_timestamp', 'asc')) .source(colFields) .trackTotalHits(true); }else{ @@ -182,7 +182,7 @@ export function search_api_filter_es_query_builder( .query(boolQuery) .from(from) .size(size) - .sort(esb.sort("last_modified_timestamp", "asc")) + .sort(esb.sort('last_modified_timestamp', 'asc')) .source(colFields) .trackTotalHits(true); } @@ -191,7 +191,7 @@ export function search_api_filter_es_query_builder( // this WAS a function that reads from a static file groups.jsx export function search_api_search_group_list(){ - ingest_api_all_user_groups(JSON.parse(localStorage.getItem("info")).groups_token) + ingest_api_all_user_groups(JSON.parse(localStorage.getItem('info')).groups_token) .then((res) => { // no need to filter out the data_providers, the ingest api does that for us let groups = res.results; @@ -199,9 +199,9 @@ export function search_api_search_group_list(){ }) .catch((err) => { console.debug( - "%c⭗", - "color:#ff005d", - "search_api_search_group_list error", + '%c⭗', + 'color:#ff005d', + 'search_api_search_group_list error', err ); return err; @@ -214,7 +214,7 @@ export function search_api_get_assay_type(assay){ let data = res.data; var found_dt = undefined; data.result.forEach((s) => { - if(s["name"] === assay){ + if(s['name'] === assay){ found_dt = s; } }); @@ -229,13 +229,13 @@ export function search_api_get_assay_type(assay){ export function search_api_get_assay_set(scope){ // Scope informs either Primary, Alt, or All - var target = ""; + var target = ''; switch(scope){ - case"primary": - target = "?primary=true"; + case'primary': + target = '?primary=true'; break; - case"alt": - target = "?primary=false"; + case'alt': + target = '?primary=false'; break; default: break; @@ -246,11 +246,11 @@ export function search_api_get_assay_set(scope){ let mapCheck = data.result.map((value) => { return value; }); - console.debug("API get_processed_assays data", data, mapCheck); + console.debug('API get_processed_assays data', data, mapCheck); return{data}; }) .catch((error) => { - console.debug("search_api_get_assay_set", error, error.response); + console.debug('search_api_get_assay_set', error, error.response); if(error.response){ return{ status: error.response.status, diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index b9d44e2f..e33aee5f 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -1,4 +1,4 @@ -import axios from "axios"; +import axios from 'axios'; import {stripHTML,toTitleCase} from '../utils/string_helper' /* @@ -62,7 +62,7 @@ export function ubkg_api_get_organ_type_set(format){ } }) .catch(error => { - console.debug("ubkg_api_get_organ_type_set", error, error.response); + console.debug('ubkg_api_get_organ_type_set', error, error.response); captureError(error); }); }; @@ -78,7 +78,7 @@ export function ubkg_api_get_dataset_type_set(){ return data; }) .catch(error => { - console.debug("ubkg_api_get_dataset_type_set", error, error.response); + console.debug('ubkg_api_get_dataset_type_set', error, error.response); captureError(error); }); }; @@ -94,7 +94,7 @@ export function ubkg_api_get_upload_dataset_types(){ return data; }) .catch(error => { - console.debug("ubkg_api_get_dataset_type_set", error, error.response); + console.debug('ubkg_api_get_dataset_type_set', error, error.response); captureError(error); }); }; @@ -104,7 +104,7 @@ export function ubkg_api_get_upload_dataset_types(){ * */ export function ubkg_api_generate_display_subtype(entity){ - var display_subtype = "" + var display_subtype = '' var entity_type = entity['entity_type'] if(entity_type === 'Sample' && 'sample_category' in entity){ if(entity['sample_category'].toLowerCase() === 'organ'){ @@ -121,7 +121,7 @@ export function ubkg_api_generate_display_subtype(entity){ }); }else{ - throw new Error("Missing Organ key for Sample with uuid: {entity['uuid']}") + throw new Error('Missing Organ key for Sample with uuid: {entity[\'uuid\']}') } }else{ display_subtype=entity['sample_category'].toString(); @@ -132,7 +132,7 @@ export function ubkg_api_generate_display_subtype(entity){ display_subtype=entity['dataset_type'].toString() // return (entity['dataset_type'].toString()) }else if(entity_type === 'Upload'){ - return("Data Upload") + return('Data Upload') }else{ // All others (Donors, & I'm asuming Collections and Publications) just use Entity Type display_subtype= toTitleCase(entity_type.toString()) @@ -142,10 +142,10 @@ export function ubkg_api_generate_display_subtype(entity){ } function captureError (error){ - console.debug("Error Format CHeck", error); + console.debug('Error Format CHeck', error); if(error.response ){ if(error.response.data ){ - if(error.response.data.includes("")){ + if(error.response.data.includes('')){ var responseData = stripHTML(error.response.data) return{status: error.response.status, results: responseData} }else{ From 0328d7f9980f4ab21f0c28abdd350dc9ae3ec6af Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:39:08 -0400 Subject: [PATCH 11/16] ESLint Comma Spacing --- src/src/service/entity_api.js | 16 +++++++------- src/src/service/ingest_api.js | 40 +++++++++++++++++------------------ src/src/service/search_api.js | 4 ++-- src/src/service/ubkg_api.js | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index a98b31e1..9de0c2b5 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -16,7 +16,7 @@ const options = { export function entity_api_get_entity(uuid){ // console.debug("entity_api_get_entity"); return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`, options) .then(res => { let results = res.data; return{status: res.status, results: results} @@ -120,7 +120,7 @@ export function entity_api_update_multiple_entities(data){ // @TODO: Rename to reflect Organ endpoint export function entity_api_get_entity_ancestor(uuid){ return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`, options) .then(res => { // console.debug(res); let results = res.data; @@ -133,7 +133,7 @@ export function entity_api_get_entity_ancestor(uuid){ export function entity_api_get_entity_ancestor_organ(uuid){ return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`, options) .then(res => { // console.debug(res); let results = res.data; @@ -151,7 +151,7 @@ export function entity_api_get_entity_ancestor_organ(uuid){ */ export function entity_api_get_entity_ancestor_list(uuid){ return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`,options) + .get(`${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`, options) .then(res => { // console.debug(res); let results = res.data; @@ -180,17 +180,17 @@ export function entity_api_get_globus_url(uuid){ }; // @TODO DEPRECATING replaced with newer ingest API call -export function entity_api_attach_bulk_metadata(uuid,item){ +export function entity_api_attach_bulk_metadata(uuid, item){ console.debug('%c⭗', 'color:#ff005d', 'entity_api_upload_bulk_metadata', item); return axios - .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid,item,options) + .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid, item, options) .then(res => { - console.debug('ingest_api_attach_bulk_metadata',res); + console.debug('ingest_api_attach_bulk_metadata', res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug('%c⭗ ingest_api_attach_bulk_metadata', 'color:#ff005d',error); + console.debug('%c⭗ ingest_api_attach_bulk_metadata', 'color:#ff005d', error); // throw new Error(error); return{error} }); diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index cd41fcbd..8bae77ca 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -4,7 +4,7 @@ import axios from 'axios'; import FormData from 'form-data'; const globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; -const options={headers: {Authorization: 'Bearer ' + globalToken,'Content-Type': 'application/json'}} +const options={headers: {Authorization: 'Bearer ' + globalToken, 'Content-Type': 'application/json'}} /* * User Groups only those data provider groups are return * @@ -111,7 +111,7 @@ export function ingest_api_all_groups(){ * return: { status, results} */ export function ingest_api_allowable_edit_states(uuid){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`,options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`, options) .then(res => { return{status: res.status, results: res.data} }) @@ -131,7 +131,7 @@ export function ingest_api_allowable_edit_states(uuid){ * return: { status, results} */ export function ingest_api_allowable_edit_states_statusless(uuid){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`,options) + return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`, options) .then(res => { return{status: res.status, results: res.data} }) @@ -230,13 +230,13 @@ export function ingest_api_bulk_entities_upload(type, data){ dataForm.append('file', data); return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`, dataForm, options) .then(res => { - console.debug('ingest_api_bulk_entities',res); + console.debug('ingest_api_bulk_entities', res); //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation // We might back back a 201 with an array of errors encountered. Let's check for that! let results = res.data; - console.debug('results',results); + console.debug('results', results); if(results[0]){ - console.debug('results DATA ',results[0]); + console.debug('results DATA ', results[0]); } return{status: res.status, results: results} }) @@ -313,7 +313,7 @@ export function ingest_api_get_associated_ids(uuid){ } export function ingest_api_get_globus_url(uuid){ - return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`,options) + return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`, options) .then((res) => { return{status: 200, results: res.data} }) @@ -390,14 +390,14 @@ export function ingest_api_reorganize_upload(uuid){ */ export function ingest_api_notify_slack(data){ return axios - .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`,data,options) + .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`, data, options) .then(res => { - console.debug('ingest_api_notify_slack',res); + console.debug('ingest_api_notify_slack', res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug('ingest_api_notify_slack',error); + console.debug('ingest_api_notify_slack', error); return{error} }); } @@ -407,19 +407,19 @@ export function ingest_api_notify_slack(data){ */ export function ingest_api_upload_bulk_metadata(type, dataFile){ var formData = new FormData(); - formData.append('metadata', new Blob([dataFile],{type: 'file'}),dataFile.name); + formData.append('metadata', new Blob([dataFile], {type: 'file'}), dataFile.name); formData.append('entity_type', 'Sample') formData.append('sub_type', type) formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`,formData,options) + return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`, formData, options) .then(res => { - console.debug('ingest_api_upload_bulk_metadata',res); + console.debug('ingest_api_upload_bulk_metadata', res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); + console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d', error ); // Is it a server error or just a Validation error? console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); // throw new Error(error); @@ -453,12 +453,12 @@ export function ingest_api_publish_collection( data){ export function ingest_api_pipeline_test_privs(){ return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) .then(res => { - console.debug('ingest_api_pipeline_test_privs',res); + console.debug('ingest_api_pipeline_test_privs', res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); + console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d', error ); // throw new Error(error); return{error} }); @@ -475,7 +475,7 @@ export function ingest_api_pipeline_test_submit( data){ let results = res.data; return{status: res.status, results: results}}) .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); + console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d', error ); return{error} }); }; @@ -486,17 +486,17 @@ export function ingest_api_pipeline_test_submit( data){ */ export function ingest_api_validate_contributors(dataFile){ var formData = new FormData(); - formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values'}),dataFile.name); + formData.append('metadata', new Blob([dataFile], {type: 'text/tab-separated-values'}), dataFile.name); formData.append('entity_type', 'contributors') return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) .then(res => { - console.debug('ingest_api_validate_contributors',res); + console.debug('ingest_api_validate_contributors', res); let results = res.data; return{status: res.status, results: results} }) .catch(error => { - console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); + console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d', error ); // throw new Error(error); return{error} }); diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 64008489..45dd1ea1 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -1,11 +1,11 @@ // Search APIs import axios from 'axios'; -import {ES_SEARCHABLE_FIELDS,ES_SEARCHABLE_WILDCARDS} from '../constants'; +import {ES_SEARCHABLE_FIELDS, ES_SEARCHABLE_WILDCARDS} from '../constants'; import {ingest_api_all_user_groups} from './ingest_api'; export const esb = require('elastic-builder'); let globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; -let options={headers: {Authorization: 'Bearer ' + globalToken,'Content-Type': 'application/json'}} +let options={headers: {Authorization: 'Bearer ' + globalToken, 'Content-Type': 'application/json'}} /* * Auth Validation method diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index e33aee5f..91589e45 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import {stripHTML,toTitleCase} from '../utils/string_helper' +import {stripHTML, toTitleCase} from '../utils/string_helper' /* * UBKG GET assaytype method From e1af440dfc8f7bf05f9bae665c3c5abe9d6db69f Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:40:10 -0400 Subject: [PATCH 12/16] eslint file organizing --- src/src/.eslintrc.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/src/.eslintrc.js b/src/src/.eslintrc.js index 6b13a630..79f0416f 100644 --- a/src/src/.eslintrc.js +++ b/src/src/.eslintrc.js @@ -28,16 +28,19 @@ module.exports = { "react" ], rules: { - // indent: ["warn", 2], + // "indent": ["warn", 2,{ "outerIIFEBody": 1 }], + "indent": 0, // "keyword-spacing": ["warn", { - // before: false, - // after: false, - // overrides: { - // from: {before: true, after: true}, - // import: {before: false, after: true}, - // static: {after: true} - // } - // }], + // before: false, + // after: false, + // overrides: { + // from: {before: true, after: true}, + // import: {before: false, after: true}, + // static: {after: true} + // } + // } + // ], + "keyword-spacing": [0], "no-unused-expressions": ["error", { "allowTernary": true }], "no-undef": "error", "no-unused-vars": ["warn", "all"], @@ -51,21 +54,25 @@ module.exports = { "space-before-function-paren": [0], // "space-in-parens": ["warn", "never", {"exceptions": ["{}"]}], "space-in-parens": [0], + // "quotes": ["warn", "single"], + "quotes": 0, + // "jsx-quotes": ["warn", "prefer-single"], + "jsx-quotes": 0, + // "block-spacing": ["warn",'never'], + "block-spacing": 0, + // "comma-spacing": ["warn", {before: false, after: true}], + "comma-spacing": 0, + "quote-props": 0, "no-multiple-empty-lines": ["warn", {max: 1}], "no-multi-spaces": ["warn", {ignoreEOLComments: true}], "object-curly-newline": [0], - "keyword-spacing": [0], "key-spacing": ["warn", {beforeColon: false, afterColon: true, mode: "strict"}], "array-callback-return": 0, "arrow-spacing": 0, - "block-spacing": 0, - "block-spacing": 0, "brace-style": 0, "camelcase": 0, "comma-dangle": 0, - "comma-spacing": 0, "dot-notation": 0, - "indent": 0, "lines-between-class-members": 0, "no-empty": 0, "no-mixed-spaces-and-tabs": 0, @@ -79,8 +86,6 @@ module.exports = { "object-property-newline": 0, "padded-blocks": 0, "prefer-const": 0, - "quote-props": 0, - "quotes": 0, "react/jsx-no-target-blank": 0, "react/no-unescaped-entities": 0, // disable rule "react/no-unknown-property": 0, From b0c31a1ab30e289dc7039d8dcd093beff6b4112c Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:46:49 -0400 Subject: [PATCH 13/16] More ESLint Organization & Restrictions for Dev/Test Deployment clarity --- src/src/.eslintrc.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/src/.eslintrc.js b/src/src/.eslintrc.js index 79f0416f..b5569781 100644 --- a/src/src/.eslintrc.js +++ b/src/src/.eslintrc.js @@ -28,6 +28,7 @@ module.exports = { "react" ], rules: { + "no-undef": "error", // "indent": ["warn", 2,{ "outerIIFEBody": 1 }], "indent": 0, // "keyword-spacing": ["warn", { @@ -41,9 +42,12 @@ module.exports = { // } // ], "keyword-spacing": [0], - "no-unused-expressions": ["error", { "allowTernary": true }], - "no-undef": "error", - "no-unused-vars": ["warn", "all"], + // "key-spacing": ["warn", {beforeColon: false, afterColon: true, mode: "strict"}], + "key-spacing": [0], + // "no-unused-expressions": ["error", { "allowTernary": true }], + "no-unused-expressions": [0], + // "no-unused-vars": ["warn", "all"], + "no-unused-vars": [0], // "array-bracket-spacing": ["warn", "never"], "array-bracket-spacing": [0], // "object-curly-spacing": ["warn", "never"], @@ -62,11 +66,12 @@ module.exports = { "block-spacing": 0, // "comma-spacing": ["warn", {before: false, after: true}], "comma-spacing": 0, + // "no-multiple-empty-lines": ["warn", {max: 1}], + "no-multiple-empty-lines": [0], + // "no-multi-spaces": ["warn", {ignoreEOLComments: true}], + "no-multi-spaces": [0], "quote-props": 0, - "no-multiple-empty-lines": ["warn", {max: 1}], - "no-multi-spaces": ["warn", {ignoreEOLComments: true}], "object-curly-newline": [0], - "key-spacing": ["warn", {beforeColon: false, afterColon: true, mode: "strict"}], "array-callback-return": 0, "arrow-spacing": 0, "brace-style": 0, From 284ce23cd7b7b2e527edd16b514528ae992c19ef Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:52:13 -0400 Subject: [PATCH 14/16] Remove errant dolphin .directory file --- src/.directory | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/.directory diff --git a/src/.directory b/src/.directory deleted file mode 100644 index 538f9d87..00000000 --- a/src/.directory +++ /dev/null @@ -1,10 +0,0 @@ -[Dolphin] -HeaderColumnWidths=550,72,111,90,579,119,72 -SortRole=size -Timestamp=2025,6,9,17,31,33.922 -Version=4 -ViewMode=1 -VisibleRoles=Details_text,Details_size,Details_modificationtime,Details_type,Details_path,Details_creationtime,Details_owner,CustomizedDetails - -[Settings] -HiddenFilesShown=true From 7a016d175b82b9be518a2808daffaacc157d10b4 Mon Sep 17 00:00:00 2001 From: Birdmachine Date: Tue, 10 Jun 2025 11:52:40 -0400 Subject: [PATCH 15/16] add .directory to gitignore --- src/.gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/.gitignore b/src/.gitignore index 7cedefa9..a98de271 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -42,8 +42,7 @@ src/.DS_Store src/npm-debug.log* src/yarn-debug.log* src/yarn-error.log* - - +.directory #ignore the ui build dir src/build/* From 86aac4fa7ed7b426a4282989ca688da12b33782f Mon Sep 17 00:00:00 2001 From: Bird Date: Wed, 11 Jun 2025 15:48:50 -0400 Subject: [PATCH 16/16] Revert "Axios dependabot" --- .directory | 11 - src/.gitignore | 3 +- src/package.json | 4 +- src/src/.eslintrc.js | 54 +-- src/src/service/entity_api.js | 128 +++--- src/src/service/ingest_api.js | 785 ++++++++++++++++++++-------------- src/src/service/search_api.js | 272 +++++++----- src/src/service/ubkg_api.js | 121 +++--- 8 files changed, 794 insertions(+), 584 deletions(-) delete mode 100644 .directory diff --git a/.directory b/.directory deleted file mode 100644 index 09e9456a..00000000 --- a/.directory +++ /dev/null @@ -1,11 +0,0 @@ -[Dolphin] -HeaderColumnWidths=502,72,111,90,579,119,72 -SortOrder=1 -SortRole=modificationtime -Timestamp=2025,6,9,17,31,25.146 -Version=4 -ViewMode=1 -VisibleRoles=Details_text,Details_size,Details_modificationtime,Details_type,Details_path,Details_creationtime,Details_owner,CustomizedDetails - -[Settings] -HiddenFilesShown=true diff --git a/src/.gitignore b/src/.gitignore index a98de271..7cedefa9 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -42,7 +42,8 @@ src/.DS_Store src/npm-debug.log* src/yarn-debug.log* src/yarn-error.log* -.directory + + #ignore the ui build dir src/build/* diff --git a/src/package.json b/src/package.json index 11101be0..b1e85982 100644 --- a/src/package.json +++ b/src/package.json @@ -19,8 +19,8 @@ "@mui/x-data-grid": "^6.18.0", "@mui/x-date-pickers": "^7.0.00", "@stefftek/tick.js": "^1.1.1", - "axios": "^1.9.0", - "axios-hooks": "^5.1.1", + "axios": "^0.24.0", + "axios-hooks": "^3.0.0", "bootstrap": "^5.2.0-beta1", "dayjs": "^1.11.13", "dompurify": "^3.2.4", diff --git a/src/src/.eslintrc.js b/src/src/.eslintrc.js index b5569781..6b13a630 100644 --- a/src/src/.eslintrc.js +++ b/src/src/.eslintrc.js @@ -28,26 +28,19 @@ module.exports = { "react" ], rules: { - "no-undef": "error", - // "indent": ["warn", 2,{ "outerIIFEBody": 1 }], - "indent": 0, + // indent: ["warn", 2], // "keyword-spacing": ["warn", { - // before: false, - // after: false, - // overrides: { - // from: {before: true, after: true}, - // import: {before: false, after: true}, - // static: {after: true} - // } - // } - // ], - "keyword-spacing": [0], - // "key-spacing": ["warn", {beforeColon: false, afterColon: true, mode: "strict"}], - "key-spacing": [0], - // "no-unused-expressions": ["error", { "allowTernary": true }], - "no-unused-expressions": [0], - // "no-unused-vars": ["warn", "all"], - "no-unused-vars": [0], + // before: false, + // after: false, + // overrides: { + // from: {before: true, after: true}, + // import: {before: false, after: true}, + // static: {after: true} + // } + // }], + "no-unused-expressions": ["error", { "allowTernary": true }], + "no-undef": "error", + "no-unused-vars": ["warn", "all"], // "array-bracket-spacing": ["warn", "never"], "array-bracket-spacing": [0], // "object-curly-spacing": ["warn", "never"], @@ -58,26 +51,21 @@ module.exports = { "space-before-function-paren": [0], // "space-in-parens": ["warn", "never", {"exceptions": ["{}"]}], "space-in-parens": [0], - // "quotes": ["warn", "single"], - "quotes": 0, - // "jsx-quotes": ["warn", "prefer-single"], - "jsx-quotes": 0, - // "block-spacing": ["warn",'never'], - "block-spacing": 0, - // "comma-spacing": ["warn", {before: false, after: true}], - "comma-spacing": 0, - // "no-multiple-empty-lines": ["warn", {max: 1}], - "no-multiple-empty-lines": [0], - // "no-multi-spaces": ["warn", {ignoreEOLComments: true}], - "no-multi-spaces": [0], - "quote-props": 0, + "no-multiple-empty-lines": ["warn", {max: 1}], + "no-multi-spaces": ["warn", {ignoreEOLComments: true}], "object-curly-newline": [0], + "keyword-spacing": [0], + "key-spacing": ["warn", {beforeColon: false, afterColon: true, mode: "strict"}], "array-callback-return": 0, "arrow-spacing": 0, + "block-spacing": 0, + "block-spacing": 0, "brace-style": 0, "camelcase": 0, "comma-dangle": 0, + "comma-spacing": 0, "dot-notation": 0, + "indent": 0, "lines-between-class-members": 0, "no-empty": 0, "no-mixed-spaces-and-tabs": 0, @@ -91,6 +79,8 @@ module.exports = { "object-property-newline": 0, "padded-blocks": 0, "prefer-const": 0, + "quote-props": 0, + "quotes": 0, "react/jsx-no-target-blank": 0, "react/no-unescaped-entities": 0, // disable rule "react/no-unknown-property": 0, diff --git a/src/src/service/entity_api.js b/src/src/service/entity_api.js index 9de0c2b5..167dab2e 100644 --- a/src/src/service/entity_api.js +++ b/src/src/service/entity_api.js @@ -1,11 +1,11 @@ -import axios from 'axios'; +import axios from "axios"; -const globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; +const globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; const options = { headers: { 'X-Hubmap-Application': 'ingest-ui', - 'Authorization': 'Bearer ' + globalToken, - 'Content-Type': 'application/json' + Authorization: "Bearer " + globalToken, + "Content-Type": "application/json" } }; /* @@ -15,20 +15,21 @@ const options = { */ export function entity_api_get_entity(uuid){ // console.debug("entity_api_get_entity"); + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`; return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`, options) + .get(url,options) .then(res => { let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { - console.debug('entity_api_get_entity', error, error.response); + console.debug("entity_api_get_entity", error, error.response); if(error.response){ return error.response }else{ return{error} } - }); + } ); }; /* @@ -36,21 +37,22 @@ export function entity_api_get_entity(uuid){ * */ export function entity_api_update_entity(uuid, data){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`; return axios - .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}`, data, options) + .put(url, data, options) .then(res => { // console.debug("entity_api_update_entity", res); let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { if(error.response){ - console.debug('entity_api_update_entity Error', error.response.status, error.response.data); + console.debug("entity_api_update_entity Error", error.response.status, error.response.data); return{status: error.response.status, results: error.response.data} }else{ return{error: error.response} } - }); + } ); }; /* @@ -58,21 +60,22 @@ export function entity_api_update_entity(uuid, data){ * */ export function entity_api_create_entity(entitytype, data){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${entitytype}`; return axios - .post(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${entitytype}`, data, options) + .post(url, data, options) .then(res => { let results = res.data; return{status: res.status, results: results} - }) + } ) .catch((error) => { - console.debug('entity_api_create_entity error', error, error.response); + console.debug("entity_api_create_entity error", error, error.response); if(error.response && error.response.data){ return{error: error.response.data} }else{ return{error} } - }); + } ); }; /* @@ -80,20 +83,21 @@ export function entity_api_create_entity(entitytype, data){ * */ export function entity_api_create_multiple_entities(count, data){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples/${count}`; return axios - .post(`${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples/${count}`, data, options) + .post(url, data, options) .then(res => { let results = res.data; let fin = []; results.forEach(element => { element.checked = false; // add a checked attribute for later UI usage fin.push(element); - }); + } ); return{status: res.status, results: fin} - }) + } ) .catch(error => { return{error} - }); + } ); }; /* @@ -101,15 +105,17 @@ export function entity_api_create_multiple_entities(count, data){ * */ export function entity_api_update_multiple_entities(data){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples`; + return axios - .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/multiple-samples`, data, options) + .put(url, data, options) .then(res => { let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { return{error} - }); + } ); }; /* @@ -119,29 +125,31 @@ export function entity_api_update_multiple_entities(data){ */ // @TODO: Rename to reflect Organ endpoint export function entity_api_get_entity_ancestor(uuid){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`; return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`, options) + .get(url,options) .then(res => { // console.debug(res); let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { return{error} - }); + } ); }; export function entity_api_get_entity_ancestor_organ(uuid){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`; return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/ancestor-organs`, options) + .get(url,options) .then(res => { // console.debug(res); let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { return{error} - }); + } ); }; /* @@ -150,16 +158,17 @@ export function entity_api_get_entity_ancestor_organ(uuid){ * return: { status, results} */ export function entity_api_get_entity_ancestor_list(uuid){ + let url = `${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`; return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/ancestors/${uuid}`, options) + .get(url,options) .then(res => { // console.debug(res); let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { return{error} - }); + } ); }; /* @@ -168,32 +177,35 @@ export function entity_api_get_entity_ancestor_list(uuid){ * return: { status, results} */ export function entity_api_get_globus_url(uuid){ + // console.debug("entity_api_get_globus_url"); + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url`; return axios - .get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url`, options) + .get(url, options) .then((res) => { // console.debug("entity_api_get_globus_url", res); return{status: res.status, results: res.data} - }) + } ) .catch((error) => { return{error} - }); + } ); }; // @TODO DEPRECATING replaced with newer ingest API call -export function entity_api_attach_bulk_metadata(uuid, item){ - console.debug('%c⭗', 'color:#ff005d', 'entity_api_upload_bulk_metadata', item); +export function entity_api_attach_bulk_metadata(uuid,item){ + console.debug('%c⭗', 'color:#ff005d', "entity_api_upload_bulk_metadata", item); + let url = `${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid return axios - .put(`${process.env.REACT_APP_ENTITY_API_URL}/entities/`+uuid, item, options) + .put(url,item,options) .then(res => { - console.debug('ingest_api_attach_bulk_metadata', res); + console.debug("ingest_api_attach_bulk_metadata",res); let results = res.data; return{status: res.status, results: results} - }) + } ) .catch(error => { - console.debug('%c⭗ ingest_api_attach_bulk_metadata', 'color:#ff005d', error); + console.debug('%c⭗ ingest_api_attach_bulk_metadata', 'color:#ff005d',error); // throw new Error(error); return{error} - }); + } ); }; /* @@ -202,32 +214,41 @@ export function entity_api_attach_bulk_metadata(uuid, item){ * return: { status, results} */ export function entity_api_get_these_entities(uuids) { - let message = ''; + let message = ""; let uuidSet = Array.from(new Set(uuids)); // Nix any Dupes let dupes = uuids.filter((item, idx, arr) => arr.indexOf(item) !== idx); // Also get a list of dupes to note - if(dupes.length > 0) { - message = 'Duplicate IDs found and Removed: ' + Array.from(new Set(dupes)).join(', '); + // let dupes = uuidSet.difference(uuids) + if (dupes.length > 0) { + message = "Duplicate IDs found and Removed: " + Array.from(new Set(dupes)).join(", "); } - if(uuids.length === 0) { - message = 'No UUIDs provided'; - return Promise.resolve({status: 400, results: {message: message}}); + console.group("entity_api_get_these_entities"); + console.debug("uuids: ", uuids); + console.debug("uuidSet", uuidSet); + console.debug("dupes", dupes); + console.groupEnd(); + + if (uuids.length === 0) { + message = "No UUIDs provided"; + return Promise.resolve({ status: 400, results: { message: message } }); } // Fetch all entities in parallel return Promise.all(uuidSet.map(entity_api_get_entity)) + .then((results) => { + // console.debug("entity_api_get_globus_url", res);\ let badList = []; let goodList = []; let errMessage = null; results.map((item) => { console.debug('%c◉ item ', 'color:#00ff7b', item); - if(item.status !== 200) { - badList.push(item.data.error || item.data.message || item.data || 'Unknown Error'); - errMessage = 'Error fetching entities: '+ badList.join(', '); + if (item.status !== 200) { + badList.push(item.data.error || item.data.message || item.data || "Unknown Error"); + errMessage = "Error fetching entities: "+ badList.join(", "); }else{ goodList.push(item); } }); - return({ + return ({ status: 200, message: message, results: goodList, @@ -235,9 +256,10 @@ export function entity_api_get_these_entities(uuids) { error: errMessage? errMessage : null }) }) + .catch(error => ({ status: 500, message: message, - results: error.message?error.message: 'Error fetching entities' + results: error.message?error.message: "Error fetching entities" })); } diff --git a/src/src/service/ingest_api.js b/src/src/service/ingest_api.js index 8bae77ca..b8916fe3 100644 --- a/src/src/service/ingest_api.js +++ b/src/src/service/ingest_api.js @@ -1,108 +1,136 @@ // Ingest specific APIs -import axios from 'axios'; -import FormData from 'form-data'; +import axios from "axios"; +import FormData from "form-data"; + +var globalToken = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")).groups_token : null; -const globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; -const options={headers: {Authorization: 'Bearer ' + globalToken, 'Content-Type': 'application/json'}} /* * User Groups only those data provider groups are return * */ -export function ingest_api_users_groups(){ +export function ingest_api_users_groups(auth) { console.debug('%c◉ Global: ', 'color:#00ff7b', globalToken); - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + return axios .get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) .then(res => { - const group_list = res.data.groups - .filter(g => g.data_provider) - .map(g => { - return g; - }); - return{status: res.status, results: group_list} + const group_list = res.data.groups + .filter(g => g.data_provider) + .map(g => { + return g; + }); + // console.debug('API USER GROUPs', group_list); + return {status:res.status, results:group_list} }) .catch(error => { - if(error && error.response && error.response.response && error.response.response === 'User is not a member of group HuBMAP-read'){ - console.debug('User exists just not in the read group'); + console.debug("ERR ingest_api_users_groups", error, error.response); + if (error && error.response && error.response.response && error.response.response === "User is not a member of group HuBMAP-read") { + console.debug("User exists just not in the read group"); // it's not really an /error/ to have anaccount w/o read - return{status: 200, results: error.response.response} + return {status:200, results:error.response.response} } if(error.response){ - return{status: error.response.status, results: error.response.data} + return {status:error.response.status, results:error.response.data} }else{ console.error('%c⊙ Off Format err', 'color:#ff007b', error); // console.error(error); // throw new Error(error); - return{error} + return {error} } }); } + /* * Is User Admin * */ -export function ingest_api_user_admin(){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) - .then(res => { - let groups = res.data.groups; - for(let group in groups){ - let groupName = groups[group].name - console.debug('%c◉ groupName ', 'color:#ffe921', groupName); - if(groupName.includes('hubmap-data-admin')){ - return true - } +export function ingest_api_user_admin(auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + return axios + .get( + `${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + .then(res => { + + console.debug('%c◉ res ', 'color:#00ff7b', res); + let groups = res.data.groups; + console.debug('%c◉ ADMIN Check:', 'color:#FF227b', groups); + for (let group in groups) { + let groupName = groups[group].name + console.debug('%c◉ groupName ', 'color:#ffe921', groupName); + if(groupName.includes("hubmap-data-admin")){ + return true } - return false - }) - .catch(error => { - console.debug('ERR ingest_api_users_groups', error, error.response); - return{error} - }); + } + return false + + + }) + .catch(error => { + console.debug("ERR ingest_api_users_groups", error, error.response); + return {error} + }); } + + /* * Upload a file * */ -export function ingest_api_file_upload(data, options){ - return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) +export function ingest_api_file_upload(data, options) { + return axios + .get( + `${process.env.REACT_APP_DATAINGEST_API_URL}/file-upload`, data, options) .then(res => { // console.debug("ingest_api_file_upload", res); - return{status: res.status, results: res} + return {status:res.status, results:res} }) .catch(error => { - return{error} - }); + return {error} + }); } + /* * User Groups ALL groups are return (For that user only) * */ -export function ingest_api_all_user_groups(){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) - .then(res => { - const group_list = res.data.groups; - return{status: res.status, results: group_list} - }) - .catch(error => { - return{error} - }); +export function ingest_api_all_user_groups(auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + return axios + .get( + `${process.env.REACT_APP_METADATA_API_URL}/metadata/usergroups`, options) + .then(res => { + const group_list = res.data.groups; + return {status:res.status, results:group_list} + }) + .catch(error => { + return {error} + }); } /* * ALL groups are returned * */ -export function ingest_api_all_groups(){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) - .then(res => { - const group_list = res.data.groups; - return{status: res.status, results: group_list} - }) - .catch(error => { - return{error} - }); +export function ingest_api_all_groups(auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + return axios + .get( + `${process.env.REACT_APP_METADATA_API_URL}/metadata/data-provider-groups`, options) + .then(res => { + const group_list = res.data.groups; + return {status:res.status, results:group_list} + }) + .catch(error => { + return {error} + }); } /* @@ -110,19 +138,23 @@ export function ingest_api_all_groups(){ * * return: { status, results} */ -export function ingest_api_allowable_edit_states(uuid){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`, options) - .then(res => { - return{status: res.status, results: res.data} - }) - .catch(error => { - console.debug('ingest_api_allowable_edit_states', error, error.response); - if(error.response){ - return{status: error.response.status, results: error.response.data} - }else{ - return{error} - } - }); +export function ingest_api_allowable_edit_states(uuid, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states`; + return axios + .get(url,options) + .then(res => { + return {status:res.status, results:res.data} + }) + .catch(error => { + console.debug("ingest_api_allowable_edit_states", error, error.response); + if(error.response){ + return {status:error.response.status, results:error.response.data} + }else{ + return {error} + } + }); }; /* @@ -130,374 +162,499 @@ export function ingest_api_allowable_edit_states(uuid){ * * return: { status, results} */ -export function ingest_api_allowable_edit_states_statusless(uuid){ - return axios.get(`${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`, options) - .then(res => { - return{status: res.status, results: res.data} - }) - .catch(error => { - return{error} - }); +export function ingest_api_allowable_edit_states_statusless(uuid, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_METADATA_API_URL}/entities/${uuid}/allowable-edit-states?ignore-publication-status=true`; + return axios + .get(url,options) + .then(res => { + return {status:res.status, results:res.data} + }) + .catch(error => { + return {error} + }); }; /* * create a dataset * */ -export function ingest_api_create_dataset(data){ - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_create_dataset(data, auth) { + // console.debug("ingest_api_create_dataset", data); + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets`; + return axios + .post(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; /* * create a publication * */ -export function ingest_api_create_publication(data){ - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/publications`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - if(error.response){ - return{status: error.response.status, results: error.response.data} - }else{ - return{error} - } - }); +export function ingest_api_create_publication(data, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/publications`; + return axios + .post(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + if(error.response){ + return {status:error.response.status, results:error.response.data} + }else{ + return {error} + } + }); }; /* * submit a dataset * */ -export function ingest_api_dataset_submit(uuid, data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_dataset_submit(uuid, data, auth) { + // console.debug("ingest_api_dataset_submit", data); + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; + + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * Publish a dataset * */ -export function ingest_api_dataset_publish(uuid, data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`, data, options) - .then(res => { - let results = res.data; - - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_dataset_publish(uuid, data, auth) { + // console.debug("ingest_api_dataset_submit", data); + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/publish`; + + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * Derived dataset * */ -export function ingest_api_derived_dataset(uuid, data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`, data, options) - .then(res => { - let results = res.data; - - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_derived_dataset(uuid, data, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${uuid}/submit`; // @TODO: Derived? + + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * ingest_api_bulk_entities - create A file COntaining bulk entries on .TSF file upload * */ -export function ingest_api_bulk_entities_upload(type, data){ +export function ingest_api_bulk_entities_upload(type, data, auth) { + console.debug("Starting Data: ",data); + console.debug("Going to : ",type); var dataForm = new FormData(); dataForm.append('file', data); - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`, dataForm, options) - .then(res => { - console.debug('ingest_api_bulk_entities', res); - //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation - // We might back back a 201 with an array of errors encountered. Let's check for that! - let results = res.data; - console.debug('results', results); - if(results[0]){ - console.debug('results DATA ', results[0]); - } - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"multipart/form-data"}, + onUploadProgress:(ev: ProgressEvent) => { + const progress = ev.loaded / ev.total * 100; + console.debug("prog", Math.round(progress)); + }}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk-upload`; + + return axios + .post(url, dataForm, options) + .then(res => { + console.debug("ingest_api_bulk_entities",res); + //There's a chance our data may pass the Entity validation, but not the Subsequent pre-insert Valudation + // We might back back a 201 with an array of errors encountered. Let's check for that! + let results = res.data; + console.debug("results",results); + if(results[0]){ + console.debug("results DATA ",results[0]); + } + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * ingest_api_bulk_entities - Registers / Inserts bulk entries based on ID of .TSV file upload * */ -export function ingest_api_bulk_entities_register(type, data){ - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`, data, options) - .then(res => { - console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); - // console.debug("ingest_ap i_bulk_entities",res); - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - // console.debug('%c‼️ INGESTAPI BULK ERR', 'color:#ff005d', error); - // throw new Error(error); - // var err = new Error(error); - // throw err; - return(error) - }); +export function ingest_api_bulk_entities_register(type, data, auth) { + console.debug("Starting Data: ",data); + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}, + onUploadProgress:(ev: ProgressEvent) => { + const progress = ev.loaded / ev.total * 100; + console.debug("prog", Math.round(progress)); + }}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/${type.toLowerCase()}/bulk`; + console.debug("URL: ",url, "\n DATA",data,"\n OPTS", options); + return axios + .post(url, data, options) + .then(res => { + console.debug('%c⭗ INGESTAPI BULK RES: ', 'color:#FF00FF', res); + // console.debug("ingest_ap i_bulk_entities",res); + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + // console.debug('%c‼️ INGESTAPI BULK ERR', 'color:#ff005d', error); + // throw new Error(error); + // var err = new Error(error); + // throw err; + return (error) + }); }; /* gets a list of associated IDS if the entity has multiple records. these are multi-labs records */ -export function ingest_api_get_associated_ids(uuid){ - return axios.get(`${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) - .then(res => { - if(res.data.ingest_group_ids.length > 1){ - res.data.ingest_group_ids.sort((a, b) => { - if( - parseInt( - a.submission_id.substring( - a.submission_id.lastIndexOf('-') + 1 - ) - ) > - parseInt( - b.submission_id.substring( - a.submission_id.lastIndexOf('-') + 1 - ) - ) - ){ - return 1; - } - if( - parseInt( - b.submission_id.substring( - a.submission_id.lastIndexOf('-') + 1 - ) - ) > - parseInt( - a.submission_id.substring( - a.submission_id.lastIndexOf('-') + 1 - ) - ) - ){ - return-1; +export function ingest_api_get_associated_ids(uuid, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + return axios + .get( + `${process.env.REACT_APP_SPECIMEN_API_URL}/specimens/${uuid}/ingest-group-ids`, options) + .then(res => { + if (res.data.ingest_group_ids.length > 1) { + res.data.ingest_group_ids.sort((a, b) => { + if ( + parseInt( + a.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) > + parseInt( + b.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) + ) { + return 1; + } + if ( + parseInt( + b.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) > + parseInt( + a.submission_id.substring( + a.submission_id.lastIndexOf("-") + 1 + ) + ) + ) { + return -1; + } + return 0; + }); } - return 0; + return {status:res.status, results:res.data.ingest_group_ids} + }) + .catch(error => { + return {error} }); - } - return{status: res.status, results: res.data.ingest_group_ids} - }) - .catch(error => { - return{error} - }); } -export function ingest_api_get_globus_url(uuid){ - return axios.get(`${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`, options) - .then((res) => { - return{status: 200, results: res.data} - }) - .catch(error => { - return{error} - }); +export function ingest_api_get_globus_url(uuid, auth) { + const config = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"multipart/form-data",},}; + + return axios + .get( + `${process.env.REACT_APP_ENTITY_API_URL}/entities/${uuid}/globus-url/`, + config + ) + .then((res) => { + return {status:200, results:res.data} + }) + .catch(error => { + return {error} + }); } + + /* * Create New Upload * */ -export function ingest_api_create_upload(data){ - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_create_upload(data, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads`; + return axios + .post(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * Submit Uploads * */ -export function ingest_api_submit_upload(uuid, data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); +export function ingest_api_submit_upload(uuid, data, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/submit`; + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * Validate Upload * */ -export function ingest_api_validate_upload(uuid, data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`, data, options) - .then(res => { - let results = res.data; +export function ingest_api_validate_upload(uuid, data, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/validate`; + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; + /* * Reorganize or uploads * */ -export function ingest_api_reorganize_upload(uuid){ +export function ingest_api_reorganize_upload(uuid, auth) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; const data = {} - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - return{error} - }); + + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/uploads/${uuid}/reorganize`; + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + return {error} + }); }; /* * Notify * */ -export function ingest_api_notify_slack(data){ +export function ingest_api_notify_slack(data) { + const options = {headers:{Authorization: "Bearer " + globalToken, + "Content-Type":"application/json"}}; + data.send_to_email = true; + // const data = ["data-testing-notificatons","Beep (O v O)!"] + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/notify`; return axios - .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/notify`, data, options) + .post(url,data,options) .then(res => { - console.debug('ingest_api_notify_slack', res); - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - console.debug('ingest_api_notify_slack', error); - return{error} - }); -} + console.debug("ingest_api_notify_slack",res); + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + console.debug("ingest_api_notify_slack",error); + return {error} + }); +}; + /* * Bulk Metadata * */ -export function ingest_api_upload_bulk_metadata(type, dataFile){ +export function ingest_api_upload_bulk_metadata(type, dataFile, auth) { + console.debug('%c⭗', 'color:#ff005d', "ingest_api_upload_bulk_metadata", dataFile, type, auth); + const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; var formData = new FormData(); - formData.append('metadata', new Blob([dataFile], {type: 'file'}), dataFile.name); - formData.append('entity_type', 'Sample') + formData.append('metadata', new Blob([dataFile],{type: 'file' }),dataFile.name); + formData.append('entity_type', "Sample") formData.append('sub_type', type) formData.append('validate_uuids', 1) console.debug('%c⊙ DATA', 'color:#00ff7b', formData ); - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`, formData, options) + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/sample-bulk-metadata`; + // console.debug('%c⊙ url,dataForm,options', 'color:#00ff7b', url,formData,options ); + return axios + .put(url,formData,options) .then(res => { - console.debug('ingest_api_upload_bulk_metadata', res); - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d', error ); - // Is it a server error or just a Validation error? - console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); - // throw new Error(error); - return{error} - }); + console.debug("ingest_api_upload_bulk_metadata",res); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + console.debug('%c⭗ ingest_api_upload_bulk_metadata', 'color:#ff005d',error ); + // Is it a server error or just a Validation error? + console.debug('%c◉ error ', 'color:#00ff7b', error, error.status); + // throw new Error(error); + return {error} + }); }; + + /* * Notify * */ -export function ingest_api_publish_collection( data){ - return axios.put(`${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`, data, options) - .then(res => { - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - if(error.response){ - return{status: error.response.status, results: error.response.data} - }else{ - return{error} - } - }); +export function ingest_api_publish_collection(auth, data) { + const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/collections/${data}/register-doi`; + console.debug('%c◉ publish ', 'color:#00ff7b', url,options); + return axios + .put(url, data, options) + .then(res => { + let results = res.data; + return {status:res.status, results:results} + }) + .catch(error => { + if(error.response){ + return {status:error.response.status, results:error.response.data} + }else{ + return {error} + } + }); }; /* * Pipeline Testing Privledges * */ -export function ingest_api_pipeline_test_privs(){ - return axios.get(`${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`, options) +export function ingest_api_pipeline_test_privs(auth) { + const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/has-pipeline-test-privs`; + return axios + .get(url, options) .then(res => { - console.debug('ingest_api_pipeline_test_privs', res); - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d', error ); - // throw new Error(error); - return{error} - }); + console.debug("ingest_api_pipeline_test_privs",res); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + console.debug('%c⭗ ingest_api_pipeline_test_privs', 'color:#ff005d',error ); + // throw new Error(error); + return {error} + }); }; + /* * Pipeline Testing Submit * */ -export function ingest_api_pipeline_test_submit( data){ - return axios - .post(`${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`, {}, options) +export function ingest_api_pipeline_test_submit(auth, data) { + const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/datasets/${data['uuid']}/submit-for-pipeline-testing`; + console.debug('%c◉ url ', 'color:#00ff7b', url); + return axios + .post(url, {}, options) .then(res => { - let results = res.data; - return{status: res.status, results: results}}) - .catch(error => { - console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d', error ); - return{error} - }); + console.debug("ingest_api_pipeline_test_submit",res); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + console.debug('%c⭗ ingest_api_pipeline_test_submit', 'color:#ff005d',error ); + // throw new Error(error); + return {error} + }); }; /* * Contibutor TSV Validation * */ -export function ingest_api_validate_contributors(dataFile){ +export function ingest_api_validate_contributors(auth,dataFile) { + const options = {headers:{Authorization: "Bearer " + globalToken,"Content-Type":"application/json"}}; + let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`; var formData = new FormData(); - formData.append('metadata', new Blob([dataFile], {type: 'text/tab-separated-values'}), dataFile.name); - formData.append('entity_type', 'contributors') + formData.append('metadata', new Blob([dataFile],{type: 'text/tab-separated-values' }),dataFile.name); + formData.append('entity_type', "contributors") - return axios.post(`${process.env.REACT_APP_DATAINGEST_API_URL}/metadata/validate?ensure-latest-cedar-version=true`, formData, options) + return axios + .post(url, formData, options) .then(res => { - console.debug('ingest_api_validate_contributors', res); - let results = res.data; - return{status: res.status, results: results} - }) - .catch(error => { - console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d', error ); - // throw new Error(error); - return{error} - }); + console.debug("ingest_api_validate_contributors",res); + let results = res.data; + return {status: res.status, results: results} + }) + .catch(error => { + console.debug('%c⭗ ingest_api_validate_contributors', 'color:#ff005d',error ); + // throw new Error(error); + return {error} + }); }; + diff --git a/src/src/service/search_api.js b/src/src/service/search_api.js index 45dd1ea1..6944166a 100644 --- a/src/src/service/search_api.js +++ b/src/src/service/search_api.js @@ -1,11 +1,11 @@ // Search APIs -import axios from 'axios'; -import {ES_SEARCHABLE_FIELDS, ES_SEARCHABLE_WILDCARDS} from '../constants'; -import {ingest_api_all_user_groups} from './ingest_api'; -export const esb = require('elastic-builder'); -let globalToken = localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')).groups_token : null; -let options={headers: {Authorization: 'Bearer ' + globalToken, 'Content-Type': 'application/json'}} +import axios from "axios"; +// import { GROUPS } from "./groups"; +import {ES_SEARCHABLE_FIELDS,ES_SEARCHABLE_WILDCARDS} from "../constants"; + +import {ingest_api_all_user_groups} from "./ingest_api"; +export const esb = require("elastic-builder"); /* * Auth Validation method @@ -13,65 +13,92 @@ let options={headers: {Authorization: 'Bearer ' + globalToken, 'Content-Type': ' * return: { status} */ // Something of a hack to validate the auth token -export function api_validate_token(){ - let payload = search_api_filter_es_query_builder('test', 1, 1); - return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) +export function api_validate_token(auth) { + const options = { + headers: { + Authorization: "Bearer " + auth, + "Content-Type": "application/json", + }, + }; + let payload = search_api_filter_es_query_builder("test", 1, 1); + + return axios + .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { - return{status: res.status}; + return { status: res.status }; }) .catch((error) => { - return{error}; + return { error }; }); } /* - * Search API metvarhod + * Search API method * * return: { status, results} */ -export function api_search(params){ +export function api_search(params, auth) { + const options = { + headers: { + Authorization: "Bearer " + auth, + "Content-Type": "application/json", + }, + }; + let payload = search_api_filter_es_query_builder(params, 0, 100); - return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) + + return axios + .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { let hits = res.data.hits.hits; let entities = {}; hits.forEach((s) => { - let uuid = s['_source']['uuid']; - if(entities[uuid]){ - entities[s['_source']['uuid']].push(s['_source']); - }else{ - entities[s['_source']['uuid']] = [s['_source']]; + let uuid = s["_source"]["uuid"]; + if (entities[uuid]) { + entities[s["_source"]["uuid"]].push(s["_source"]); + } else { + entities[s["_source"]["uuid"]] = [s["_source"]]; } }); - return{status: res.status, results: entities}; + return { status: res.status, results: entities }; }) .catch((error) => { - return{error}; + return { error }; }); } -export function api_search2(params, auth, from, size, fields){ +export function api_search2(params, auth, from, size, fields, source) { + // console.debug('%c⊙', 'color:#00ff7b', fields ); + // console.debug('%c⊙', 'color:#00ff7b', "api2", params, auth, from, size, fields,source); + const options = { + headers: { + Authorization: "Bearer " + auth, + "Content-Type": "application/json", + }, + }; let payload = search_api_filter_es_query_builder(params, from, size, fields); - return axios.post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) + // console.debug('payload', payload) + return axios + .post(`${process.env.REACT_APP_SEARCH_API_URL}/search`, payload, options) .then((res) => { // console.debug("API api_search2 res", res); let hits = res.data.hits.hits; let entities = []; hits.forEach((s) => { - let data = s['_source']; - data['id'] = s['_source']['uuid']; + let data = s["_source"]; + data["id"] = s["_source"]["uuid"]; entities.push(data); }); - return{ + return { status: res.status, results: entities, total: res.data.hits.total.value, }; }) .catch((error) => { - return{error}; + return { error }; }); } @@ -84,195 +111,208 @@ export function search_api_filter_es_query_builder( from, size, colFields -){ +) { + // console.debug("%c⊙queryBits:", "color:#00ff7b", fields, from, size, colFields); let requestBody = esb.requestBodySearch(); - let boolQuery = ''; - if(fields['keywords'] && fields['keywords'].indexOf('*') > -1){ + let boolQuery = ""; + if (fields["keywords"] && fields["keywords"].indexOf("*") > -1) { // if keywords contain a wildcard boolQuery = esb - .queryStringQuery(fields['keywords']) + .queryStringQuery(fields["keywords"]) .fields(ES_SEARCHABLE_WILDCARDS); - }else{ + } else { boolQuery = esb.boolQuery(); // if no field criteria is sent just default to a - if(Object.keys(fields).length === 0 && fields.constructor === Object){ + if (Object.keys(fields).length === 0 && fields.constructor === Object) { // console.debug("full search") boolQuery.must( esb.matchQuery( - 'entity_type', - 'Donor OR Sample OR Dataset OR Upload OR Publication OR Collection' + "entity_type", + "Donor OR Sample OR Dataset OR Upload OR Publication OR Collection" ) ); - }else{ + } else { // was a group name selected - if(fields['group_name']){ + if (fields["group_name"]) { boolQuery.must( - esb.matchQuery('group_name.keyword', fields['group_name']) + esb.matchQuery("group_name.keyword", fields["group_name"]) ); - }else if(fields['group_uuid']){ + } else if (fields["group_uuid"]) { // this'll be from the dropdown, // if its a collection, we wanna search the datasets of it, not it itself - if(fields['entity_type'] === 'Collection'){ + if (fields["entity_type"] === "Collection") { boolQuery.must( - esb.matchQuery('datasets.group_uuid.keyword', fields['group_uuid']) + esb.matchQuery("datasets.group_uuid.keyword", fields["group_uuid"]) ); - }else{ + } else { boolQuery.must( - esb.matchQuery('group_uuid.keyword', fields['group_uuid']) + esb.matchQuery("group_uuid.keyword", fields["group_uuid"]) ); } } // was specimen types selected - if(fields['sample_category']){ + if (fields["sample_category"]) { // console.debug("sample_category", fields["sample_category"]); - if(fields['sample_category'] !== 'donor'){ + if (fields["sample_category"] !== "donor") { boolQuery.must( - esb.matchQuery('sample_category.keyword', fields['sample_category']) + esb.matchQuery("sample_category.keyword", fields["sample_category"]) ); - }else{ - boolQuery.must(esb.matchQuery('entity_type.keyword', 'Donor')); + } else { + boolQuery.must(esb.matchQuery("entity_type.keyword", "Donor")); } - }else if(fields['organ']){ - boolQuery.must(esb.matchQuery('organ.keyword', fields['organ'])); - }else{ + } else if (fields["organ"]) { + boolQuery.must(esb.matchQuery("organ.keyword", fields["organ"])); + } else { // was entity types select - if(fields['entity_type']){ - if(fields['entity_type'] === 'DonorSample'){ + if (fields["entity_type"]) { + if (fields["entity_type"] === "DonorSample") { // hack to deal with no type selected from the UI, this clues from the donor/sample filer - boolQuery.must(esb.matchQuery('entity_type', 'Donor OR Sample')); - }else{ + boolQuery.must(esb.matchQuery("entity_type", "Donor OR Sample")); + } else { boolQuery.must( - esb.matchQuery('entity_type.keyword', fields['entity_type']) + esb.matchQuery("entity_type.keyword", fields["entity_type"]) ); } - }else{ + } else { boolQuery.must( esb.matchQuery( - 'entity_type', - 'Donor OR Sample OR Dataset OR Upload OR Publication OR Collection' + "entity_type", + "Donor OR Sample OR Dataset OR Upload OR Publication OR Collection" ) ); // default everything ; this maybe temp } } - if(fields['keywords']){ - if(fields['keywords'] && fields['keywords'].indexOf('HBM') === 0){ + if (fields["keywords"]) { + if (fields["keywords"] && fields["keywords"].indexOf("HBM") === 0) { boolQuery.must( - esb.matchQuery('hubmap_id.keyword', fields['keywords']) + esb.matchQuery("hubmap_id.keyword", fields["keywords"]) ); - }else{ + } else { boolQuery.filter( - esb.multiMatchQuery(ES_SEARCHABLE_FIELDS, fields['keywords']) + esb.multiMatchQuery(ES_SEARCHABLE_FIELDS, fields["keywords"]) ); } } } } - if(fields['keywords'] && fields['keywords'].indexOf('HBM') > -1){ + if (fields["keywords"] && fields["keywords"].indexOf("HBM") > -1) { // console.debug('%c⊙', 'color:#00ff7b', "BOOLQUERY", boolQuery ); requestBody .query(boolQuery) .from(from) .size(1) - .sort(esb.sort('last_modified_timestamp', 'asc')) + .sort(esb.sort("last_modified_timestamp", "asc")) .source(colFields) .trackTotalHits(true); - }else{ + } else { requestBody .query(boolQuery) .from(from) .size(size) - .sort(esb.sort('last_modified_timestamp', 'asc')) + .sort(esb.sort("last_modified_timestamp", "asc")) .source(colFields) .trackTotalHits(true); } return requestBody.toJSON(); } +// export function fixKeywordText(text) { +// let x = text.replace(/-/gi, "\\-"); +// return x; +// } + // this WAS a function that reads from a static file groups.jsx -export function search_api_search_group_list(){ - ingest_api_all_user_groups(JSON.parse(localStorage.getItem('info')).groups_token) +export function search_api_search_group_list() { + ingest_api_all_user_groups( + JSON.parse(localStorage.getItem("info")).groups_token + ) .then((res) => { - // no need to filter out the data_providers, the ingest api does that for us + // no need to filter out the data_providers, the ingest api does that for us let groups = res.results; return groups; }) .catch((err) => { console.debug( - '%c⭗', - 'color:#ff005d', - 'search_api_search_group_list error', + "%c⭗", + "color:#ff005d", + "search_api_search_group_list error", err ); return err; }); } -export function search_api_get_assay_type(assay){ - return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype`) +export function search_api_get_assay_type(assay) { + return axios + .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype`) .then((res) => { let data = res.data; var found_dt = undefined; data.result.forEach((s) => { - if(s['name'] === assay){ + if (s["name"] === assay) { found_dt = s; } }); console.debug(found_dt); - return{status: res.status, results: found_dt}; + return { status: res.status, results: found_dt }; }) .catch((error) => { - return{error}; + return { error }; }); } -export function search_api_get_assay_set(scope){ +export function search_api_get_assay_set(scope) { // Scope informs either Primary, Alt, or All - var target = ''; - switch(scope){ - case'primary': - target = '?primary=true'; - break; - case'alt': - target = '?primary=false'; - break; - default: - break; + var target = ""; + switch (scope) { + case "primary": + target = "?primary=true"; + break; + case "alt": + target = "?primary=false"; + break; + default: + break; } - return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) - .then((res) => { - let data = res.data; - let mapCheck = data.result.map((value) => { - return value; - }); - console.debug('API get_processed_assays data', data, mapCheck); - return{data}; - }) - .catch((error) => { - console.debug('search_api_get_assay_set', error, error.response); - if(error.response){ - return{ - status: error.response.status, - results: error.response.data, - }; - }else{ - return{error}; - } - }); - + return ( + axios + // primaryness NEEDS to be in the url, not a form body addon + .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype` + target) + .then((res) => { + let data = res.data; + let mapCheck = data.result.map((value, index) => { + return value; + }); + console.debug("API get_processed_assays data", data, mapCheck); + return { data }; + }) + .catch((error) => { + console.debug("search_api_get_assay_set", error, error.response); + if (error.response) { + return { + status: error.response.status, + results: error.response.data, + }; + } else { + return { error }; + } + }) + ); } -export function search_api_get_assay_primaries(){ - return axios.get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) +export function search_api_get_assay_primaries() { + return axios + .get(`${process.env.REACT_APP_SEARCH_API_URL}/assaytype?primary=true`) .then((res) => { let data = res.data; - let dtListMapped = data.result.map((value) => { + let dtListMapped = data.result.map((value, index) => { return value; }); - return{status: res.status, data: dtListMapped}; + return { status: res.status, data: dtListMapped }; }) .catch((error) => { - return{error}; + return { error }; }); } diff --git a/src/src/service/ubkg_api.js b/src/src/service/ubkg_api.js index 91589e45..3ad2a41c 100644 --- a/src/src/service/ubkg_api.js +++ b/src/src/service/ubkg_api.js @@ -1,5 +1,5 @@ -import axios from 'axios'; -import {stripHTML, toTitleCase} from '../utils/string_helper' +import axios from "axios"; +import { stripHTML,toTitleCase } from '../utils/string_helper' /* * UBKG GET assaytype method @@ -50,65 +50,72 @@ import {stripHTML, toTitleCase} from '../utils/string_helper' * * return: {'AO': 'Aorta' ... } */ -export function ubkg_api_get_organ_type_set(format){ - return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/organs/by-code?application_context=HUBMAP`) - .then(res => { - let data = res.data; - if(format && format === 'array'){ - let organArray = Object.entries(data).map(([key, value]) => ({key, value})); - return organArray; - }else{ - return data; - } - }) - .catch(error => { - console.debug('ubkg_api_get_organ_type_set', error, error.response); - captureError(error); - }); +export function ubkg_api_get_organ_type_set(format) { + let url = `${process.env.REACT_APP_UBKG_API_URL}/organs/by-code?application_context=HUBMAP`; + return axios + .get(url) + .then(res => { + let data = res.data; + if(format && format === 'array'){ + let organArray = Object.entries(data).map(([key, value]) => ({ key, value })); + return organArray; + }else{ + return data; + } + }) + .catch(error => { + console.debug("ubkg_api_get_organ_type_set", error, error.response); + captureError(error); + }); }; /* * UBKG GET dataset types method * */ -export function ubkg_api_get_dataset_type_set(){ - return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/dataset-types?application_context=HUBMAP`) - .then(res => { - let data = res.data; - return data; - }) - .catch(error => { - console.debug('ubkg_api_get_dataset_type_set', error, error.response); - captureError(error); - }); +export function ubkg_api_get_dataset_type_set() { + // let url = `${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`; + let url = `${process.env.REACT_APP_UBKG_API_URL}/dataset-types?application_context=HUBMAP`; + return axios + .get(url) + .then(res => { + let data = res.data; + return data; + }) + .catch(error => { + console.debug("ubkg_api_get_dataset_type_set", error, error.response); + captureError(error); + }); }; /* * UBKG GET Specilized Dataset Types for Uploads method * */ -export function ubkg_api_get_upload_dataset_types(){ - return axios.get(`${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`) - .then(res => { - let data = res.data; - return data; - }) - .catch(error => { - console.debug('ubkg_api_get_dataset_type_set', error, error.response); - captureError(error); - }); +export function ubkg_api_get_upload_dataset_types() { + let url = `${process.env.REACT_APP_UBKG_API_URL}/valueset?parent_sab=HUBMAP&parent_code=C003041&child_sabs=HUBMAP`; + return axios + .get(url) + .then(res => { + let data = res.data; + return data; + }) + .catch(error => { + console.debug("ubkg_api_get_dataset_type_set", error, error.response); + captureError(error); + }); }; /* * UBKG Generate Display Subtype method * */ -export function ubkg_api_generate_display_subtype(entity){ - var display_subtype = '' +export function ubkg_api_generate_display_subtype(entity) { + var display_subtype = "" var entity_type = entity['entity_type'] - if(entity_type === 'Sample' && 'sample_category' in entity){ - if(entity['sample_category'].toLowerCase() === 'organ'){ - if('organ' in entity){ + if (entity_type === 'Sample' && 'sample_category' in entity){ + if (entity['sample_category'].toLowerCase() === 'organ'){ + if ('organ' in entity) { var organCode = entity['organ']; ubkg_api_get_organ_type_set() .then((res) => { @@ -117,22 +124,24 @@ export function ubkg_api_generate_display_subtype(entity){ // return (res[organCode]) }) .catch((error) => { - return(error) + return (error) }); }else{ - throw new Error('Missing Organ key for Sample with uuid: {entity[\'uuid\']}') + throw new Error("Missing Organ key for Sample with uuid: {entity['uuid']}") } - }else{ + } else { display_subtype=entity['sample_category'].toString(); // return entity['sample_category'].toString(); } - }else if(entity_type === 'Dataset' && 'dataset_type' in entity){ + }else if (entity_type === 'Dataset' && 'dataset_type' in entity){ // Datasets store in ugly format, need to reff pretty style display_subtype=entity['dataset_type'].toString() // return (entity['dataset_type'].toString()) - }else if(entity_type === 'Upload'){ - return('Data Upload') + }else if (entity_type === 'Upload'){ + // Uploads just need language fix + return ("Data Upload") + display_subtype="Data Upload" }else{ // All others (Donors, & I'm asuming Collections and Publications) just use Entity Type display_subtype= toTitleCase(entity_type.toString()) @@ -142,19 +151,21 @@ export function ubkg_api_generate_display_subtype(entity){ } function captureError (error){ - console.debug('Error Format CHeck', error); + + console.debug("Error Format CHeck", error); + if(error.response ){ if(error.response.data ){ - if(error.response.data.includes('')){ + if(error.response.data.includes("")){ var responseData = stripHTML(error.response.data) - return{status: error.response.status, results: responseData} + return {status: error.response.status, results: responseData} }else{ - return{status: error.response.status, results: error.response.data} + return {status: error.response.status, results: error.response.data} } }else{ - return{status: error.response.status, results: error.response.data} + return {status: error.response.status, results: error.response.data} } - }else{ - return{error} + } else { + return {error} } }