Skip to content

Commit

Permalink
Return creator from create sample route and prepend it to table in UI (
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs authored Jan 29, 2023
1 parent eaba26f commit 1fbacf9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 1 addition & 6 deletions pydatalab/pydatalab/models/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Person(Entry):
type: str = Field("people", const=True)
"""The entry type as a string."""

identities: List[Identity]
identities: List[Identity] = Field(default_factory=list)
"""A list of identities attached to this person, e.g., email addresses, OAuth accounts."""

display_name: Optional[str]
Expand All @@ -87,11 +87,6 @@ def add_missing_type(cls, v):
def set_default_type(cls, _):
return "people"

class Config:
allow_population_by_field_name = True
extra = "forbid"
json_encoders = {bson.ObjectId: str}

@staticmethod
def new_user_from_identity(
identity: Identity, use_display_name: bool = True, use_contact_email: bool = True
Expand Down
7 changes: 7 additions & 0 deletions pydatalab/pydatalab/routes/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ def _create_sample(sample_dict: dict, copy_from_item_id: str = None) -> tuple[di

if CONFIG.TESTING:
new_sample["creator_ids"] = []
new_sample["creators"] = [
{"display_name": "Public testing user", "contact_email": "datalab@odbx.science"}
]
else:
new_sample["creator_ids"] = [current_user.person.immutable_id]
new_sample["creators"] = [{"display_name": current_user.person.display_name}]

# check to make sure that item_id isn't taken already
if flask_mongo.db.items.find_one({"item_id": sample_dict["item_id"]}):
Expand Down Expand Up @@ -311,6 +315,9 @@ def _create_sample(sample_dict: dict, copy_from_item_id: str = None) -> tuple[di
"date": new_sample.date,
"name": new_sample.name,
"creator_ids": new_sample.creator_ids,
"creators": [c.json() for c in new_sample.creators]
if new_sample.creators
else None,
},
},
201, # 201: Created
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/server_fetch_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function createNewSample(item_id, date, name, startingData = {}, copyFrom
console.log("received the following data from fetch new-sample:");
console.log(response_json.sample_list_entry);
console.log(`item_id: ${item_id}`);
store.commit("appendToSampleList", response_json.sample_list_entry);
store.commit("prependToSampleList", response_json.sample_list_entry);
// store.commit('createSampleData', {
// "item_id": item_id,
// "sample_data": response_json.sample_data
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default createStore({
// sampleSummary is a json object summarizing the new sample
state.sample_list.push(sampleSummary);
},
prependToSampleList(state, sampleSummary) {
// sampleSummary is a json object summarizing the new sample
state.sample_list.unshift(sampleSummary);
},
deleteFromSampleList(state, sample_summary) {
const index = state.sample_list.indexOf(sample_summary);
if (index > -1) {
Expand Down

0 comments on commit 1fbacf9

Please sign in to comment.