Update SampleTracker
to support dynamic activePgroup
Enhanced the `SampleTracker` component to accept and utilize an `activePgroup` prop, allowing dynamic filtering of data based on the current project group. Adjusted related polling and data fetching logic to respond to changes in `activePgroup`. Removed excessive code from the test notebook for cleanup.
This commit is contained in:
@ -46,23 +46,44 @@ async def get_samples_with_events(puck_id: int, db: Session = Depends(get_db)):
|
||||
|
||||
|
||||
@router.get("/pucks-samples", response_model=List[PuckSchema])
|
||||
async def get_all_pucks_with_samples_and_events(db: Session = Depends(get_db)):
|
||||
logging.info("Fetching all pucks with samples and events")
|
||||
async def get_all_pucks_with_samples_and_events(
|
||||
active_pgroup: str, db: Session = Depends(get_db)
|
||||
):
|
||||
logging.info(
|
||||
"Fetching all pucks with " "samples and events for active_pgroup: %s",
|
||||
active_pgroup,
|
||||
)
|
||||
|
||||
pucks = (
|
||||
db.query(PuckModel)
|
||||
.join(PuckModel.samples) # Join samples related to the puck
|
||||
.join(PuckModel.dewar) # Join the dewar from the puck
|
||||
.join(SampleModel.events) # Join sample events
|
||||
.filter(DewarModel.pgroups == active_pgroup) # Filter by the dewar's group
|
||||
.options(
|
||||
joinedload(PuckModel.samples).joinedload(
|
||||
SampleModel.events
|
||||
), # Correct nested relationship
|
||||
joinedload(PuckModel.events), # If Puck has its own events relationship
|
||||
joinedload(PuckModel.samples).joinedload(SampleModel.events),
|
||||
joinedload(PuckModel.dewar),
|
||||
)
|
||||
.distinct() # Avoid duplicate puck rows if there are multiple events/samples
|
||||
.all()
|
||||
)
|
||||
|
||||
if not pucks:
|
||||
raise HTTPException(status_code=404, detail="No pucks found in the database")
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="No pucks found with" " sample events for the active pgroup",
|
||||
)
|
||||
|
||||
# Extract samples from each puck if needed
|
||||
filtered_samples = []
|
||||
for puck in pucks:
|
||||
if puck.dewar and getattr(puck.dewar, "pgroups", None) == active_pgroup:
|
||||
for sample in puck.samples:
|
||||
filtered_samples.append(sample)
|
||||
|
||||
# Depending on what your endpoint expects,
|
||||
# you may choose to return pucks or samples.
|
||||
# For now, we're returning the list of pucks.
|
||||
return pucks
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user