Skip to content

Commit

Permalink
edit the ignore_allocat_ids parameter of the Kowalski filters auto fo…
Browse files Browse the repository at this point in the history
…llowup section from the frontend
  • Loading branch information
Theodlz committed Aug 21, 2024
1 parent 4f539ab commit 8ba86cb
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 32 deletions.
49 changes: 29 additions & 20 deletions extensions/skyportal/skyportal/handlers/api/kowalski_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,38 +348,47 @@ def patch(self, filter_id):
"priority_order",
"radius",
"implements_update",
"ignore_allocation_ids",
}
if not set(auto_followup.keys()).issubset(valid_keys):
return self.error(
f"auto_followup dict keys must be a subset of {valid_keys}"
)
# query the allocation by id
allocation_id = auto_followup.get("allocation_id", None)
if allocation_id is None:

# if no allocation is provided + auto_followup is active + we are not now setting it to False, return error
if (
allocation_id is None
and existing_data.get("auto_followup", {}).get("active", False)
and auto_followup["active"]
):
return self.error("auto_followup dict must contain 'allocation_id' key")
with self.Session() as session:
allocation = session.scalar(
Allocation.select(session.user_or_token).where(
Allocation.id == allocation_id
)
)
if allocation is None:
return self.error(f"Allocation {allocation_id} not found")
try:
facility_api = allocation.instrument.api_class
except Exception as e:
return self.error(
f"Could not get facility API of allocation {allocation_id}: {e}"
)

priority_order = facility_api.priorityOrder
if priority_order not in ["asc", "desc"]:
return self.error(
"priority order of allocation must be one of ['asc', 'desc']"
# only if the allocation_id is provided, we can check the priority_order and implements_update
if allocation_id is not None:
with self.Session() as session:
allocation = session.scalar(
Allocation.select(session.user_or_token).where(
Allocation.id == allocation_id
)
)
if allocation is None:
return self.error(f"Allocation {allocation_id} not found")
try:
facility_api = allocation.instrument.api_class
except Exception as e:
return self.error(
f"Could not get facility API of allocation {allocation_id}: {e}"
)

auto_followup["priority_order"] = priority_order
priority_order = facility_api.priorityOrder
if priority_order not in ["asc", "desc"]:
return self.error(
"priority order of allocation must be one of ['asc', 'desc']"
)

auto_followup["priority_order"] = priority_order
auto_followup["implements_update"] = facility_api.implements()["update"]

patch_data["auto_followup"] = auto_followup
Expand Down
101 changes: 89 additions & 12 deletions extensions/skyportal/static/js/components/filter/FilterPlugins.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ const FilterPlugins = ({ group }) => {
useState(null);
const [selectedIgnoreGroupIds, setSelectedIgnoreGroupIds] = useState([]);
const [selectedTargetGroupIds, setSelectedTargetGroupIds] = useState([]);
const [selectedIgnoreAllocationIds, setSelectedIgnoreAllocationIds] =
useState([]);
const [selectedSaver, setSelectedSaver] = useState(null);

useEffect(() => {
Expand All @@ -389,6 +391,11 @@ const FilterPlugins = ({ group }) => {
if (filter_v?.auto_followup?.target_group_ids?.length > 0) {
setSelectedTargetGroupIds(filter_v.auto_followup.target_group_ids);
}
if (filter_v?.auto_followup?.ignore_allocation_ids?.length > 0) {
setSelectedIgnoreAllocationIds(
filter_v.auto_followup.ignore_allocation_ids,
);
}
if (filter_v?.autosave?.ignore_group_ids?.length > 0) {
setSelectedIgnoreGroupIds(filter_v.autosave.ignore_group_ids);
}
Expand Down Expand Up @@ -624,6 +631,26 @@ const FilterPlugins = ({ group }) => {
dispatch(filterVersionActions.fetchFilterVersion(fid));
};

const onSubmitSaveAutoFollowupIgnoreAllocations = async (e) => {
const newAutoFollowup = filter_v.auto_followup;
newAutoFollowup.ignore_allocation_ids = e.target.value;
const result = await dispatch(
filterVersionActions.editAutoFollowup({
filter_id: filter.id,
auto_followup: newAutoFollowup,
}),
);
if (result.status === "success") {
dispatch(
showNotification(
`Saved new auto followup ignore_allocation_ids to ${e.target.value}`,
),
);
setSelectedIgnoreAllocationIds(e.target.value);
}
dispatch(filterVersionActions.fetchFilterVersion(fid));
};

const handleNew = () => {
setOpenNew(true);
};
Expand Down Expand Up @@ -1519,33 +1546,83 @@ const FilterPlugins = ({ group }) => {
gap: "0.25rem",
}}
>
<InputLabel id="autoFollowupGroupsSelectLabel">
<Typography id="autoFollowupGroupsSelectLabel">
Triggering constraints
</InputLabel>
</Typography>
<Tooltip title="Constraints are applied to triggers from the filter, cancelling them if they are met: classified (on SkyPortal or TNS), has spectra, has requests, ... but not only looking at the source of the alert, but anything within that radius.">
<IconButton size="small">
<HelpOutlineIcon />
</IconButton>
</Tooltip>
</div>
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "end",
gap: "1rem",
}}
>
<div style={{ marginTop: "1rem" }}>
<InputLabel id="auto_followup_constraints_radius">
Radius (arcsec) to apply constraints
</InputLabel>
<TextField
labelId="auto_followup_constraints_radius"
className={classes.formControl}
disabled={!filter_v.active}
id="auto_followup_constraints"
label="Radius (arcsec)"
id="auto_followup_constraints_radius"
defaultValue={filter_v.auto_followup?.radius}
onChange={(event) =>
setAutoFollowupRadius(event.target.value)
}
/>
</div>
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "end",
gap: "1rem",
marginTop: "1rem",
}}
>
{filter_v?.fv &&
filter_v?.auto_followup?.active === true && (
<div>
<InputLabel id="ignoreAllocationSelectLabel">
Cancel if existing pending/completed triggers
with:
</InputLabel>
<Select
inputProps={{
MenuProps: { disableScrollLock: true },
}}
labelId="ignoreAllocationSelectLabel"
value={selectedIgnoreAllocationIds}
onChange={
onSubmitSaveAutoFollowupIgnoreAllocations
}
name="autoFollowupIgnoreAllocationsSelect"
className={classes.allocationSelect}
multiple
>
{allocationListApiClassname?.map((allocation) => (
<MenuItem
value={allocation.id}
key={allocation.id}
className={classes.SelectItem}
>
{`${instLookUp[allocation.instrument_id]?.name} - ${
groupLookUp[allocation.group_id]?.name
} (PI ${allocation.pi})`}
</MenuItem>
))}
</Select>
</div>
)}
</div>
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "end",
gap: "1rem",
marginTop: "1rem",
}}
>
<Button
variant="contained"
color="primary"
Expand Down

0 comments on commit 8ba86cb

Please sign in to comment.