Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { inject, observer } from "mobx-react";
 
import { IconCheck, IconCross } from "@humansignal/icons";
import { Button, Toggle } from "@humansignal/ui";
import { Space } from "../../common/Space/Space";
import { cn } from "../../utils/bem";
 
import "./AutoAcceptToggle.scss";
 
// we need to inject all of them to trigger rerender on changes to suggestions
const injector = inject(({ store }) => {
  const annotation = store.annotationStore?.selected;
  const suggestions = annotation?.suggestions;
 
  return {
    store,
    annotation,
    suggestions,
  };
});
 
export const AutoAcceptToggle = injector(
  observer(({ store, annotation, suggestions }) => {
    if (!store.autoAnnotation) return null;
 
    const withSuggestions = annotation.hasSuggestionsSupport && !store.forceAutoAcceptSuggestions;
    const loading = store.awaitingSuggestions;
 
    return (
      <div className={cn("auto-accept").toClassName()}>
        {withSuggestions && (
          <div className={cn("auto-accept").elem("wrapper").mod({ loading }).toClassName()}>
            <Space spread>
              {suggestions.size > 0 ? (
                <Space size="small">
                  <div className={cn("auto-accept").elem("info").toClassName()}>
                    {suggestions.size} suggestion{suggestions.size > 0 && "s"}
                  </div>
                  <Button
                    className={cn("auto-accept").elem("action").mod({ type: "reject" }).toClassName()}
                    onClick={() => annotation.rejectAllSuggestions()}
                  >
                    <IconCross />
                  </Button>
                  <Button
                    className={cn("auto-accept").elem("action").mod({ type: "accept" }).toClassName()}
                    onClick={() => annotation.acceptAllSuggestions()}
                  >
                    <IconCheck />
                  </Button>
                </Space>
              ) : (
                <Toggle
                  checked={store.autoAcceptSuggestions}
                  onChange={(e) => store.setAutoAcceptSuggestions(e.target.checked)}
                  label="Auto-Accept Suggestions"
                />
              )}
            </Space>
          </div>
        )}
        {loading && <div className={cn("auto-accept").elem("spinner").toClassName()} />}
      </div>
    );
  }),
);