Skip to content

Commit 59d2c21

Browse files
authored
Present filtered detections in playback view (#1172)
* feat: show filtered detections in playback view * feat: consider default filter setting for displayed occurrence count
1 parent dafb83a commit 59d2c21

5 files changed

Lines changed: 40 additions & 28 deletions

File tree

ui/src/pages/session-details/playback/capture-details/capture-details.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import { ProcessNow } from './capture-job/process-now'
2121
export const CaptureDetails = ({
2222
capture,
2323
captureId,
24+
defaultFilters,
2425
}: {
2526
capture?: Capture
2627
captureId: string
28+
defaultFilters: boolean
2729
}) => {
2830
const { user } = useUser()
2931
const { projectId } = useParams()
@@ -112,13 +114,20 @@ export const CaptureDetails = ({
112114
to: APP_ROUTES.OCCURRENCES({
113115
projectId: projectId as string,
114116
}),
115-
filters: {
116-
detections__source_image: capture.id,
117-
},
117+
filters: defaultFilters
118+
? {
119+
detections__source_image: capture.id,
120+
}
121+
: {
122+
detections__source_image: capture.id,
123+
apply_defaults: 'false',
124+
},
118125
})}
119126
>
120127
<span className={classNames(styles.value, styles.bubble)}>
121-
{capture.numOccurrences}
128+
{defaultFilters
129+
? capture.numOccurrences
130+
: capture.numDetections}
122131
</span>
123132
</Link>
124133
</div>

ui/src/pages/session-details/playback/frame/frame.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
outline-color: $color-destructive-500;
4747
}
4848

49+
&.filtered {
50+
outline: 2px solid $color-neutral-300;
51+
}
52+
4953
&.active {
5054
outline: 2px solid $color-primary-2-500;
5155
}

ui/src/pages/session-details/playback/frame/frame.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ import { BoxStyle } from './types'
1919
const FALLBACK_RATIO = 16 / 9
2020

2121
interface FrameProps {
22-
src?: string
23-
width: number | null
24-
height: number | null
22+
defaultFilters: boolean
2523
detections: CaptureDetection[]
24+
height: number | null
2625
showDetections?: boolean
26+
src?: string
27+
width: number | null
2728
}
2829

2930
export const Frame = ({
30-
src,
31-
width,
32-
height,
31+
defaultFilters,
3332
detections,
33+
height,
3434
showDetections,
35+
src,
36+
width,
3537
}: FrameProps) => {
3638
const [naturalSize, setNaturalSize] = useState<{
3739
width: number
@@ -127,6 +129,7 @@ export const Frame = ({
127129
{renderOverlay && <FrameOverlay boxStyles={boxStyles} />}
128130
<FrameDetections
129131
boxStyles={boxStyles}
132+
defaultFilters={defaultFilters}
130133
detections={detections}
131134
showDetections={showDetections}
132135
/>
@@ -173,10 +176,12 @@ const FrameOverlay = ({
173176

174177
const FrameDetections = ({
175178
boxStyles,
179+
defaultFilters,
176180
detections,
177181
showDetections,
178182
}: {
179183
boxStyles: { [key: number]: BoxStyle }
184+
defaultFilters: boolean
180185
detections: CaptureDetection[]
181186
showDetections?: boolean
182187
}) => {
@@ -218,9 +223,12 @@ const FrameDetections = ({
218223
style={style}
219224
className={classNames(styles.detection, {
220225
[styles.active]: isActive,
226+
[styles.filtered]: defaultFilters
227+
? !detection.occurrenceMeetsCriteria
228+
: false,
229+
[styles.alert]: detection.score < SCORE_THRESHOLDS.ALERT,
221230
[styles.warning]:
222231
detection.score < SCORE_THRESHOLDS.WARNING,
223-
[styles.alert]: detection.score < SCORE_THRESHOLDS.ALERT,
224232
[styles.clickable]: !!detection.occurrenceId,
225233
})}
226234
onClick={() => {

ui/src/pages/session-details/playback/playback.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
CheckboxTheme,
1010
} from 'design-system/components/checkbox/checkbox'
1111
import { IconButtonTheme } from 'design-system/components/icon-button/icon-button'
12-
import { useEffect, useMemo, useState } from 'react'
12+
import { useEffect, useState } from 'react'
1313
import { ActivityPlot } from './activity-plot/lazy-activity-plot'
1414
import { CaptureDetails } from './capture-details/capture-details'
1515
import { CaptureNavigation } from './capture-navigation/capture-navigation'
@@ -51,19 +51,7 @@ export const Playback = ({
5151
}
5252
}, [activeCapture])
5353

54-
const detections = useMemo(() => {
55-
if (!activeCapture?.detections) {
56-
return []
57-
}
58-
59-
if (!defaultFilters) {
60-
return activeCapture.detections
61-
}
62-
63-
return activeCapture.detections.filter(
64-
(detection) => detection.occurrenceMeetsCriteria
65-
)
66-
}, [activeCapture?.detections, defaultFilters])
54+
const detections = activeCapture?.detections ?? []
6755

6856
if (!session.firstCapture) {
6957
return null
@@ -79,6 +67,7 @@ export const Playback = ({
7967
<CaptureDetails
8068
capture={activeCapture}
8169
captureId={activeCaptureId}
70+
defaultFilters={defaultFilters}
8271
/>
8372
</div>
8473
)}
@@ -118,11 +107,12 @@ export const Playback = ({
118107
</div>
119108
</div>
120109
<Frame
121-
src={activeCapture?.src}
122-
width={activeCapture?.width ?? session.firstCapture.width}
123-
height={activeCapture?.height ?? session.firstCapture.height}
110+
defaultFilters={defaultFilters}
124111
detections={detections}
112+
height={activeCapture?.height ?? session.firstCapture.height}
125113
showDetections={showDetections}
114+
src={activeCapture?.src}
115+
width={activeCapture?.width ?? session.firstCapture.width}
126116
/>
127117
<div className={styles.bottomBar}>
128118
<div className={styles.captureNavigationWrapper}>

ui/src/utils/getAppRoute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type FilterType =
2+
| 'apply_defaults'
23
| 'capture'
34
| 'collection'
45
| 'collections'

0 commit comments

Comments
 (0)