Skip to content

Commit

Permalink
Merge pull request #1116 from hubmapconsortium/submitResponseProcessing
Browse files Browse the repository at this point in the history
Hook Slack notifications into Dataset, Publication, and Upload Submit…
  • Loading branch information
yuanzhou authored May 10, 2023
2 parents 093426a + aeacfa6 commit 42b468f
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 82 deletions.
4 changes: 3 additions & 1 deletion src/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ REACT_APP_SPECIMEN_API_URL = 'https://ingest-api.dev.hubmapconsortium.org'
REACT_APP_METADATA_API_URL = 'https://ingest-api.dev.hubmapconsortium.org'
REACT_APP_ENTITY_API_URL = 'https://entity-api.dev.hubmapconsortium.org'
REACT_APP_SEARCH_API_URL = 'https://search-api.dev.hubmapconsortium.org/v3'
REACT_APP_PORTAL_URL = 'https://portal.dev.hubmapconsortium.org/browse/dataset
REACT_APP_PORTAL_URL = 'https://portal.dev.hubmapconsortium.org/'
REACT_APP_UBKG_API_URL = 'https://ontology-api.dev.hubmapconsortium.org'

# UI URL (default value used for local development)
# Point to remote URL for testing and production deployment
REACT_APP_URL = 'http://localhost:8585'
# REACT_APP_URL = 'https://ingest.test.hubmapconsortium.org'
# REACT_APP_URL = 'https://ingest.dev.hubmapconsortium.org'

# Link to the registration/profile system
REACT_APP_PROFILE_URL = 'https://profile.hubmapconsortium.org'
Expand Down
69 changes: 50 additions & 19 deletions src/src/components/ingest/dataset_edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { ingest_api_allowable_edit_states,
ingest_api_dataset_submit,
ingest_api_dataset_publish,
ingest_api_users_groups,
ingest_api_allowable_edit_states_statusless} from '../../service/ingest_api';
ingest_api_allowable_edit_states_statusless,
ingest_api_notify_slack} from '../../service/ingest_api';
import { entity_api_update_entity, entity_api_get_globus_url, entity_api_get_entity } from '../../service/entity_api';
//import { withRouter } from 'react-router-dom';
import { ubkg_api_get_assay_type_set } from "../../service/ubkg_api";
Expand Down Expand Up @@ -358,6 +359,27 @@ class DatasetEdit extends Component {
}
}

uncapError(response){

var submitErrorResponse="Uncaptured Error";
if(response.err && response.err.response.data ){
submitErrorResponse = response.err.response.data
}
if(response.error && response.error.response.data ){
submitErrorResponse = response.error.response.data
}
if(typeof response === "string"){
submitErrorResponse = response;
}
this.setState({
showSubmitModal:false,
submit_error: true,
submitting: false,
submitErrorResponse:submitErrorResponse,
buttonSpinnerTarget:"" }, () => {
this.props.reportError();
});
}
setAssayLists(){
ubkg_api_get_assay_type_set()
.then((res) => {
Expand Down Expand Up @@ -975,32 +997,43 @@ class DatasetEdit extends Component {
}
entity_api_update_entity(this.props.editingDataset.uuid, JSON.stringify(dataSubmit), JSON.parse(localStorage.getItem("info")).groups_token)
.then((response) => {
// We shouldn't need to check agaisnt Trojan errors hiding in 200s anymore,
// if they appear, file as bugs on returning API
console.debug("entity_api_update_entity response", response);
// var portalURL= process.env.REACT_APP_PORTAL_URL+"/browse/dataset/"+this.props.editingDataset.uuid
var ingestURL= process.env.REACT_APP_URL+"/dataset/"+this.props.editingDataset.uuid
var slackMessage = {
"channel": "#data-testing-notifications",
"message": "Dataset has been submitted ("+ingestURL+")"
}
ingest_api_notify_slack(JSON.parse(localStorage.getItem("info")).groups_token, slackMessage)
.then((slackRes) => {
console.debug("slackRes", slackRes);
if (response.status < 300) {
this.setState({
submit_error: false,
submitting: false,
});
this.props.onUpdated(response.results);
console.debug("submitting");
this.props.onUpdated(response.results);
} else {
var submitErrorResponse="Uncaptured Error";
if(response.err && response.err.response.data ){
submitErrorResponse = response.err.response.data
}
if(response.error && response.error.response.data ){
submitErrorResponse = response.error.response.data
}
if(typeof response === "string"){
submitErrorResponse = response;
}
this.setState({
showSubmitModal:false,
submit_error: true,
submitting: false,
submitErrorResponse:submitErrorResponse,
buttonSpinnerTarget:"" }, () => {
this.props.reportError();
});
submitErrorResponse:response,
buttonSpinnerTarget:"" });
this.props.reportError(response);
}
// this.props.onUpdated(res.data);
})
.catch((error) => {
this.setState({
submit_error: true,
submitting: false,
submitErrorResponse:error.result.data,
buttonSpinnerTarget:"", });
});

})
.catch((error) => {
this.props.reportError(error);
Expand Down Expand Up @@ -1795,11 +1828,9 @@ class DatasetEdit extends Component {
}

assay_contains_pii(assay) {
console.debug("AssauCOntainsPii", assay);
let assay_val = [...assay.values()][0] // only one assay can now be selected, the Set() is older code
for (let i in this.props.dataTypeList) {
let e = this.props.dataTypeList[i]
console.debug(e, e['contains_pii'], assay_val);
if (e['name'] === assay_val) {
// console.debug("e:",e,e['contains_pii']);
return e['contains_pii']
Expand Down
27 changes: 21 additions & 6 deletions src/src/components/ingest/publications_edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
ingest_api_dataset_publish,
ingest_api_users_groups,
ingest_api_allowable_edit_states_statusless,
ingest_api_notify_slack
} from "../../service/ingest_api";
import {
entity_api_update_entity,
Expand Down Expand Up @@ -1071,11 +1072,25 @@ class PublicationEdit extends Component {
.then((response) => {
console.debug("entity_api_update_entity SUBMIT response", response);
if (response.status < 300 ) {
this.setState({
submit_error: false,
submitting: false,
});
this.props.onUpdated(response.results);
var ingestURL= process.env.REACT_APP_URL+"/publication/"+this.props.editingPublication.uuid
var slackMessage = {
"channel": "#data-testing-notifications",
"message": "Publication has been submitted ("+ingestURL+")"
}
ingest_api_notify_slack(JSON.parse(localStorage.getItem("info")).groups_token, slackMessage)
.then((slackRes) => {
console.debug("slackRes", slackRes);
if (response.status < 300) {
this.setState({
submit_error: false,
submitting: false,
});

this.props.onUpdated(response.results);
} else {
this.props.reportError(response);
}
})
} else {
console.debug("entity_api_update_entity SUBMITNONERR error", response);
this.setState({
Expand Down Expand Up @@ -1555,7 +1570,7 @@ class PublicationEdit extends Component {
{pubCheck && versCheck && latestCheck && (
<>{this.renderNewVersionButtons()}</>
)}
{(subCheck || newStateCheck)&& adminCheck && latestCheck && (
{(subCheck || newStateCheck) && adminCheck && latestCheck && (
<>{this.processButton()}</>
)}
{writeCheck && !newFormCheck && newStateCheck &&(
Expand Down
128 changes: 72 additions & 56 deletions src/src/components/uploads/editUploads.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { ingest_api_get_globus_url,
ingest_api_validate_upload,
ingest_api_submit_upload,
ingest_api_reorganize_upload,
ingest_api_all_user_groups } from '../../service/ingest_api';
ingest_api_all_user_groups,
ingest_api_notify_slack } from '../../service/ingest_api';
import {
entity_api_update_entity,
entity_api_get_globus_url
Expand Down Expand Up @@ -422,36 +423,57 @@ class EditUploads extends Component{
GroupSelectShow: false,
submitting_submission: true,
});


// package the data up
let data = {
title: this.state.title,
description: this.state.description
};


if (this.props.editingUpload) {
// if user selected Publish
ingest_api_submit_upload(this.props.editingUpload.uuid, JSON.stringify(data), JSON.parse(localStorage.getItem("info")).groups_token)
.then((response) => {
this.handleSpinnerClear();
if (response.status === 200) {
this.props.onUpdated(response.results);
var ingestURL= process.env.REACT_APP_URL+"/upload/"+this.props.editingUpload.uuid
var slackMessage = {
"channel": "#data-testing-notifications",
"message": "Upload has been submitted ("+ingestURL+")"
}
ingest_api_notify_slack(JSON.parse(localStorage.getItem("info")).groups_token, slackMessage)
.then((slackRes) => {
console.debug("slackRes", slackRes);
if (response.status < 300) {
this.setState({
submit_error: false,
submitting: false,
});
this.props.onUpdated(response.results);
} else {
this.uncapError(response);
}
})
.catch((error) => {
this.setState({
submit_error: true,
submitting: false,
submitErrorResponse:error.result.data,
buttonSpinnerTarget:"", });
});
this.handleSpinnerClear();
} else {
this.setState({ submit_error: true, submitting: false, submitting_submission:false });
this.handleSpinnerClear();
}
})
.catch((error) => {

})
.catch((error) => {
this.handleSpinnerClear();
});
}
}
}else{
this.handleSpinnerClear();
this.handleSpinnerClear();
}
});
};
Expand Down Expand Up @@ -510,51 +532,47 @@ class EditUploads extends Component{


renderButtonBar(){
return (
<div>
<div className="col-sm-12 align-right">
<Divider />
</div>

{this.renderHelperText()}
<Box
sx={{
width: "100%",
justifyContent: 'flex-end',
display: 'flex',
'& > *': {
m: 1,
},
button:{
m:1,
align:'right',
float:'right',
},

}}
>
<ButtonGroup component={Box} display="block !important"

orientation="horizontal"
// alignItems="right"
// aria-label="horizontal outlined button group"
>
<Button
variant="contained"
type='button'
disabled={this.state.submitting || this.state.submitting_submission}
onClick={() => this.props.handleCancel()}>
Cancel
</Button>
{this.renderSaveButton()}
{this.renderReorganizeButton()}
{this.renderSubmitButton()}
{this.renderValidateButton()}
</ButtonGroup>
</Box>

</div>
);
return (
<div>
<div className="col-sm-12 align-right">
<Divider />
</div>
{this.renderHelperText()}
<Box
sx={{
width: "100%",
justifyContent: 'flex-end',
display: 'flex',
'& > *': {
m: 1,
},
button:{
m:1,
align:'right',
float:'right',
},
}}
>
<ButtonGroup
component={Box}
display="block !important"
orientation="horizontal">
<Button
variant="contained"
type='button'
disabled={this.state.submitting || this.state.submitting_submission}
onClick={() => this.props.handleCancel()}>
Cancel
</Button>
{this.renderSaveButton()}
{this.renderReorganizeButton()}
{this.renderSubmitButton()}
{this.renderValidateButton()}
</ButtonGroup>
</Box>

</div>
);
}

renderValidateButton() {
Expand Down Expand Up @@ -709,11 +727,9 @@ renderReorganizeButton() {
}, () => {

});

this.handleValidateUpload(i);
}else if(action==="submit"){

this.handleValidateUploadSubmission(i);
this.handleValidateUploadSubmission(i);
} else if (action === "reorganize") {
this.handleReorganize();
}
Expand Down
27 changes: 27 additions & 0 deletions src/src/service/ingest_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,30 @@ export function ingest_api_reorganize_upload(uuid, auth) {
return {error}
});
};

/*
* Slack Notify
*
*/
export function ingest_api_notify_slack(auth, data) {
const options = {
headers: {
Authorization:
"Bearer " + auth,
"Content-Type": "application/json"
}
};
// const data = ["data-testing-notificatons","Beep (O v O)!"]
let url = `${process.env.REACT_APP_DATAINGEST_API_URL}/notify-slack`;
return axios
.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}
});
};

0 comments on commit 42b468f

Please sign in to comment.