Skip to content

Commit

Permalink
fixed add detector, list detectors bug
Browse files Browse the repository at this point in the history
  • Loading branch information
max-at-groundlight committed Nov 9, 2023
1 parent 0b72b86 commit 2157b0e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 9 additions & 1 deletion api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ def get_detectors():
endpoint = config["endpoint"] if "endpoint" in config else None
# TODO: use this as default gl
gl = groundlight.Groundlight(api_token=api_key, endpoint=endpoint)
results = []
try:
return [json.loads(d.json()) for d in gl.list_detectors().results]
i = 1
curr_det_list = gl.list_detectors().results
while len(curr_det_list) == 10:
results.extend(curr_det_list)
i += 1
curr_det_list = gl.list_detectors(page=i).results
results.extend(curr_det_list)
return [json.loads(d.json()) for d in results]
except:
return []

Expand Down
5 changes: 0 additions & 5 deletions app/detectors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ export default function Home() {
detectors.length > 0 && showEditNotificationsOverlay && detectorsByGroup[editNotificationsOverlayGroupIndex][0] &&
<EditNotificationsOverlay detector={detectorsByGroup[editNotificationsOverlayGroupIndex][0]} detectors={availableDetectors} index={0} onSave={async (e) => {
setShowEditNotificationsOverlay(false);
// let detectors_copy = detectors.slice();
// for (const idx in detectorIndiciesByGroup[editNotificationsOverlayGroupIndex]) {
// detectors_copy[detectorIndiciesByGroup[editNotificationsOverlayGroupIndex][idx]].config.notifications = e.config;
// }
// saveDetectors(detectors_copy);
for (const det of detectorsByGroup[editNotificationsOverlayGroupIndex]) {
det.edit({ ...det, config: { ...det.config, notifications: e.config } })
}
Expand Down
13 changes: 12 additions & 1 deletion components/EditDetectorOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { Dropdown } from "./Dropdown";
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import useEscape from "@/utils/useEscape";
Expand All @@ -16,6 +16,17 @@ export const EditDetectorOverlay = ({ detector, detectors, index, startWithNew,
const [pin, setPin] = useState<number | undefined>(detector.config.pin);
const [pinActiveState, setPinActiveState] = useState<number | undefined>(detector.config.pin_active_state);

useEffect(() => {
setNewDetector(startWithNew || false);
setName(detector.name);
setQuery(detector.query);
setId(detector.id);
setTriggerType(detector.config.trigger_type);
setCycleTime(detector.config.cycle_time);
setPin(detector.config.pin);
setPinActiveState(detector.config.pin_active_state);
}, [detector, startWithNew]);

const isDetectorValid = newDetector ?
name !== "" && query !== "" && !detectors.map(d => d.name).includes(name) : id !== "" && detectors.map(d => d.name).includes(name);

Expand Down

0 comments on commit 2157b0e

Please sign in to comment.