Skip to content

Commit

Permalink
Merge pull request #1011 from hubmapconsortium/sample-categories
Browse files Browse the repository at this point in the history
Fix New Dataset Registration & DataProvider on Submit/Modal
  • Loading branch information
yuanzhou committed Dec 21, 2022
2 parents d860878 + 186dfbd commit f59ea2e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 194 deletions.
37 changes: 24 additions & 13 deletions src/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import DialogTitle from '@mui/material/DialogTitle';

import AnnouncementTwoToneIcon from '@mui/icons-material/AnnouncementTwoTone';
import { ingest_api_users_groups } from './service/ingest_api';
import {search_api_get_assay_list} from "./service/search_api";
import {search_api_get_assay_list, search_api_get_assay_set} from "./service/search_api";
import {DataProviders} from "./utils/userInfo";

// import {ErrBox} from "../utils/ui_elements";
Expand Down Expand Up @@ -55,6 +55,8 @@ export function App (props){
var [timerStatus, setTimerStatus] = useState(true);
var [isLoading, setIsLoading] = useState(true);
var [dataTypeList, setDataTypeList] = useState({});
var [dataTypeListAll, setDataTypeListAll] = useState({});
var [dataTypeListPrimary, setDataTypeListPrimary] = useState({});
var [userGroups, setUserGroups] = useState({});
var [userDataGroups, setUserDataGroups] = useState({});
let navigate = useNavigate();
Expand Down Expand Up @@ -95,23 +97,32 @@ export function App (props){
setGroupsToken(JSON.parse(localStorage.getItem("info")).groups_token);
setAuthStatus(true);
setTimerStatus(false);
// console.debug("groupsToken",groupsToken);

// The Dataset Form for New entites loads through the Form
search_api_get_assay_list()
// console.debug("groupsToken",groupsToken);
search_api_get_assay_set("primary") // @TODO: Apply to dataset wrapper too?
.then((response) => {
// console.debug("fetchPrimaryDataTypes Response", response);
let data = response.data;
setDataTypeList(data);
setIsLoading(false)
// console.debug("isLoading", isLoading);
let dtypes = response.data.result;
setDataTypeList(dtypes);
setDataTypeListPrimary(dtypes);
// setIsLoading(false)
search_api_get_assay_set()
.then((response) => {
let dataAll = response.data.result;
setDataTypeListAll(dataAll);
setIsLoading(false)
})
.catch(error => {
console.debug("fetch DT list Response Error", error);
setIsLoading(false)
});
})
.catch(error => {
// console.debug("fetch DT list Response Error", error);
console.debug("fetch DT list Response Error", error);
setIsLoading(false)
// return error;
// passError(error.status, error.response );
});

// The Dataset Form for New entites loads through the Form

// return dt_dict;


Expand Down Expand Up @@ -291,7 +302,7 @@ export function App (props){
<Route path="/new">
<Route index element={<SearchComponent />} />
<Route path='donor' element={ <Forms formType='donor' onReturn={onClose} handleCancel={handleCancel} />}/>
<Route path='dataset' element={<Forms formType='dataset' dataTypeList={dataTypeList} new='true' onReturn={onClose} handleCancel={handleCancel} /> }/>
<Route path='dataset' element={<Forms formType='dataset' dataTypeList={dataTypeList} dtl_all={dataTypeListAll} dtl_primary={dataTypeListPrimary}new='true' onReturn={onClose} handleCancel={handleCancel} /> }/>
<Route path='sample' element={<Forms formType='sample' onReturn={onClose} handleCancel={handleCancel} /> }/>

{/*
Expand Down
4 changes: 2 additions & 2 deletions src/src/assets/Documents/example-sample-registrations.tsv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source_id lab_id sample_type organ_type sample_protocol description rui_location
HBM749.QJZK.937 19-002 Thymus CC-1 Block D organ_piece https://dx.doi.org/10.17504/protocols.io.8nzhvf6 Test Desc
source_id lab_id sample_category organ_type sample_protocol description rui_location
HBM749.QJZK.937 19-002 Thymus CC-1 Block D block https://dx.doi.org/10.17504/protocols.io.8nzhvf6 Test Desc
22 changes: 18 additions & 4 deletions src/src/components/ingest/dataset_edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ class DatasetEdit extends Component {
document.addEventListener("click", this.handleClickOutside);
this.setAssayLists();
var savedGeneticsStatus = undefined;
const auth = "";
try {
var auth = JSON.parse(localStorage.getItem("info")).groups_token;
} catch {
console.debug("LOCALSTROAGE Parse Fai")
var auth = "";
}

if (localStorage.getItem("info")){
const auth = JSON.parse(localStorage.getItem("info")).groups_token;

const config = {
headers: {
Authorization:
Expand All @@ -144,6 +150,7 @@ class DatasetEdit extends Component {
},
};
}else{
console.debug("No Auth Token");
localStorage.setItem("isAuthenticated", false);
}

Expand Down Expand Up @@ -176,12 +183,16 @@ class DatasetEdit extends Component {

ingest_api_users_groups(auth)
.then((res) => {
console.debug("groups", res.results);
const groups = res.results.filter(
g => g.data_provider === true
);
console.debug("groups", groups);
this.setState({
groups: groups,
groups_dataprovider: groups,
},() => {
console.debug("groups_dataprovider", this.state.groups_dataprovider);
});
})
.catch((err) => {
Expand Down Expand Up @@ -1631,8 +1642,8 @@ class DatasetEdit extends Component {

renderAssayColumn(min, max) {
// Hijacking Select options based on Primary DT status
console.debug(this.props.dtl_status);
if(this.props.dtl_status) { // true = primary dt, set options to primary
// console.debug(this.props.dtl_status);
if(this.props.dtl_status || this.props.newForm) { // true = primary dt, set options to primary
return (
this.props.dtl_primary.slice(min, max).map((val, idx) =>
{return this.renderAssay(val, idx)})
Expand Down Expand Up @@ -1687,6 +1698,9 @@ class DatasetEdit extends Component {
var len = 0;
// var dtlistLen = this.props.dataTypeList.length;
var dtlistLen = this.state.dataTypeDropdown.length;
if(this.props.newForm){
dtlistLen = this.props.dtl_primary.length;
}
if(this.props.editingDataset && this.props.editingDataset.data_types) {
//console.debug("this.props.editingDataset", this.props.editingDataset);
len = this.props.editingDataset.data_types.length;
Expand Down
31 changes: 27 additions & 4 deletions src/src/components/uuid/forms.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,35 @@ class Forms extends Component {
UNSAFE_componentWillMount() {
console.debug("UNSAFE_componentWillMount");
// console.debug("dtlist",this.props.dataTypeList);
var DTList = this.props.dataTypeList;
console.debug("prepDatatypes", this.prepDatatypes(), DTList);
// search_api_get_assay_set()
// .then((response) => {
// let allDTs = response.data.result;
// var DTList = this.props.dataTypeList;
// console.debug("prepDatatypes", this.prepDatatypes(), DTList);
// this.setState({
// dataTypeList: allDTs
// }, () => {
// console.debug("FORMS UNSAFE_componentWillMount", this.state);
// });
// })
// .catch(error => {
// console.debug("fetch DT list Response Error", error);
// // passError(error.status, error.response );
// return error;

// })


var DTList = this.props.dtl_primary;
console.debug("unsafeCOMPONENTWILLMOUNT", DTList);

this.setState({
formType: this.props.formType,
open: true,
dataTypeList: DTList
}, () => {
this.setState({ isLoading: false });
console.debug("FORMS componentWillMount", this.state);
this.setState({ isLoading: false });
console.debug("FORMS componentWillMount", this.state);
});
}

Expand Down Expand Up @@ -230,13 +249,17 @@ class Forms extends Component {
);
} else if (this.props.formType === "dataset" ) {
console.debug("NEW DATASET");

return (
<DatasetEdit
dataTypeList={this.props.dataTypeList}
onCreated={this.onCreated}
onReturn={this.props.handleCancel}
changeLink={this.onChangeGlobusLink.bind(this)}
newForm={true}
dtl_primary={this.props.dtl_primary}
dtl_all={this.props.dtl_all}
dtl_status={false}
editingDataset="{}"
/>

Expand Down
Loading

0 comments on commit f59ea2e

Please sign in to comment.