Skip to content

Commit

Permalink
Refactor event label and sub-label score display in Events.jsx to inc…
Browse files Browse the repository at this point in the history
…lude the event label and sub-label percentage
  • Loading branch information
skrashevich committed Jul 11, 2023
1 parent 7c0d25f commit b7553c4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions web/src/routes/Events.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { h, Fragment } from 'preact';
import { usePersistence } from '../context';
import { route } from 'preact-router';
import ActivityIndicator from '../components/ActivityIndicator';
import Heading from '../components/Heading';
Expand Down Expand Up @@ -111,6 +112,8 @@ export default function Events({ path, ...props }) {
const { data: allLabels } = useSWR(['labels']);
const { data: allSubLabels } = useSWR(['sub_labels', { split_joined: 1 }]);

const [displayLabels, setDisplayLabels] = usePersistence('display-labels', false);

const filterValues = useMemo(
() => ({
cameras: Object.keys(config?.cameras || {}),
Expand Down Expand Up @@ -216,6 +219,13 @@ export default function Events({ path, ...props }) {
setState({ ...state, showDownloadMenu: true });
};

const onLabelsClick = (e) => {
setDisplayLabels(!displayLabels);
if (e) {
e.stopPropagation();
}
};

const showSubmitToPlus = (event_id, label, box, e) => {
if (e) {
e.stopPropagation();
Expand Down Expand Up @@ -627,13 +637,13 @@ export default function Events({ path, ...props }) {
{event.zones.join(', ').replaceAll('_', ' ')}
</div>
<div className="capitalize text-sm flex align-center">
<Score className="w-5 h-5 mr-2 inline" />
{(event?.data?.top_score || event.top_score || 0) == 0
? null
: `Label: ${((event?.data?.top_score || event.top_score) * 100).toFixed(0)}%`}
{(event?.data?.sub_label_score || 0) == 0
? null
: `, Sub Label: ${(event?.data?.sub_label_score * 100).toFixed(0)}%`}
<Score className="w-5 h-5 mr-2 inline" onClick={(e) => onLabelsClick(e, event.id)} />

Check failure on line 640 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 26 spaces but found 22
{(event?.data?.top_score || event.top_score || 0) == 0

Check failure on line 641 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 26 spaces but found 22
? null

Check failure on line 642 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 28 spaces but found 24
: `${displayLabels ? event.label : 'Label'}: ${((event?.data?.top_score || event.top_score) * 100).toFixed(0)}%`}

Check failure on line 643 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 28 spaces but found 24
{(event?.data?.sub_label_score || 0) == 0

Check failure on line 644 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 26 spaces but found 22
? null

Check failure on line 645 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 28 spaces but found 24
: `, ${displayLabels ? event.sub_label : 'Sub-label'}: ${(event?.data?.sub_label_score * 100).toFixed(0)}%`}

Check failure on line 646 in web/src/routes/Events.jsx

View workflow job for this annotation

GitHub Actions / Web - Lint

Expected indentation of 28 spaces but found 24
</div>
</div>
<div class="hidden sm:flex flex-col justify-end mr-2">
Expand Down

0 comments on commit b7553c4

Please sign in to comment.