/** * @deprecated It was used only without FF_3873 in old interface. */ import { inject, observer } from "mobx-react"; import { IconBan, IconInfoOutline } from "@humansignal/icons"; import { Button, Tooltip } from "@humansignal/ui"; import { cn } from "../../utils/bem"; import { isDefined } from "../../utils/utilities"; import "./Controls.prefix.css"; import { useCallback, useMemo, useState } from "react"; const TOOLTIP_DELAY = 0.8; const ButtonTooltip = inject("store")( observer(({ store, title, children }) => { return ( {children} ); }), ); const controlsInjector = inject(({ store }) => { return { store, history: store?.annotationStore?.selected?.history, }; }); export const Controls = controlsInjector( observer(({ store, history, annotation }) => { const isReview = store.hasInterface("review"); const historySelected = isDefined(store.annotationStore.selectedHistory); const { userGenerate, sentUserGenerate, versions, results, editable } = annotation; const buttons = []; const [isInProgress, setIsInProgress] = useState(false); // const isReady = store.annotationStore.selected.objects.every(object => object.isReady === undefined || object.isReady); const disabled = !editable || store.isSubmitting || historySelected || isInProgress; // || !isReady; const submitDisabled = store.hasInterface("annotations:deny-empty") && results.length === 0; const buttonHandler = useCallback( async (e, callback, tooltipMessage) => { const { addedCommentThisSession, currentComment, commentFormSubmit, inputRef } = store.commentStore; if (isInProgress) return; setIsInProgress(true); if (!inputRef.current || addedCommentThisSession) { callback(); } else if ((currentComment ?? "").trim()) { e.preventDefault(); await commentFormSubmit(); callback(); } else { const commentsInput = inputRef.current; store.commentStore.setTooltipMessage(tooltipMessage); commentsInput.scrollIntoView({ behavior: "smooth", }); commentsInput.focus({ preventScroll: true }); } setIsInProgress(false); }, [ store.rejectAnnotation, store.skipTask, store.commentStore.currentComment, store.commentStore.inputRef, store.commentStore.commentFormSubmit, store.commentStore.addedCommentThisSession, isInProgress, ], ); const RejectButton = useMemo(() => { return ( ); }, [disabled, store]); if (isReview) { buttons.push(RejectButton); buttons.push( , ); } else if (annotation.skipped) { buttons.push(
Was skipped
, ); buttons.push( , ); } else { // Manager roles that can force-skip unskippable tasks (OW=Owner, AD=Admin, MA=Manager) const MANAGER_ROLES = ["OW", "AD", "MA"]; if (store.hasInterface("skip")) { const task = store.task; const isEnterprise = window.APP_SETTINGS?.billing?.enterprise; const skipDisabled = isEnterprise ? task?.allow_skip === false : false; const userRole = window.APP_SETTINGS?.user?.role; const hasForceSkipPermission = MANAGER_ROLES.includes(userRole); const canSkip = !skipDisabled || hasForceSkipPermission; const isDisabled = disabled || !canSkip; const tooltip = canSkip ? "Cancel (skip) task: [ Ctrl+Space ]" : "This task cannot be skipped"; const showInfoIcon = skipDisabled && hasForceSkipPermission; if (showInfoIcon) { buttons.push( , ); } buttons.push( , ); } if ((userGenerate && !sentUserGenerate) || (store.explore && !userGenerate && store.hasInterface("submit"))) { const title = submitDisabled ? "Empty annotations denied in this project" : "Save results: [ Ctrl+Enter ]"; // span is to display tooltip for disabled button buttons.push(
, ); } if ((userGenerate && sentUserGenerate) || (!userGenerate && store.hasInterface("update"))) { const isUpdate = sentUserGenerate || versions.result; const button = ( ); buttons.push(button); } } return (
{buttons}
); }), );