Skip to content

Commit

Permalink
[OPIK-742]: open an error tooltip for a disabled run button; (#1032)
Browse files Browse the repository at this point in the history
* [OPIK-742]: open an error tooltip for a disabled run button;

* [OPIK-742]: fix lint issues;

---------

Co-authored-by: Sasha <aliaksandr@comet.com>
  • Loading branch information
aadereiko and Sasha authored Jan 13, 2025
1 parent fc0c795 commit 17895a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import useDatasetsList from "@/api/datasets/useDatasetsList";
import { Dataset, DatasetItem } from "@/types/datasets";
import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -43,8 +37,6 @@ const PlaygroundOutputActions = ({
datasetItems,
loadingDatasetItems,
}: PlaygroundOutputActionsProps) => {
const actionButtonRef = useRef<HTMLButtonElement>(null);

const [isLoadedMore, setIsLoadedMore] = useState(false);

const promptMap = usePromptMap();
Expand Down Expand Up @@ -100,7 +92,6 @@ const PlaygroundOutputActions = ({
className="mt-2.5"
variant="outline"
onClick={stopAll}
ref={actionButtonRef}
>
<Pause className="mr-1 size-4" />
Stop all
Expand All @@ -110,18 +101,28 @@ const PlaygroundOutputActions = ({
}

const areAllPromptsValid = Object.values(promptMap).every((p) => !!p.model);
const isDatasetEmpty = !!datasetId && datasetItems.length === 0;
const isDatasetEmpty =
!loadingDatasetItems && !!datasetId && datasetItems.length === 0;

const isDatasetRemoved =
datasetId && !datasets.find((d) => d.id === datasetId);
!isLoadingDatasets &&
datasetId &&
!datasets.find((d) => d.id === datasetId);

const isDisabled =
const isDisabledButton =
!areAllPromptsValid ||
loadingDatasetItems ||
isLoadingDatasets ||
isDatasetRemoved ||
isDatasetEmpty;

const style: React.CSSProperties = isDisabled
const shouldTooltipAppear = !!(
isDatasetEmpty ||
!areAllPromptsValid ||
isDatasetRemoved
);

const style: React.CSSProperties = isDisabledButton
? { pointerEvents: "auto" }
: {};

Expand All @@ -141,22 +142,27 @@ const PlaygroundOutputActions = ({
const runMessage =
promptCount === 1 ? "Run your prompt" : "Run your prompts";

const tooltipMessage = isDisabled
const tooltipMessage = isDisabledButton
? datasetRemovedMessage || emptyDatasetMessage || selectLLMModelMessage
: runMessage;

const tooltipKey = shouldTooltipAppear
? "action-tooltip-open-tooltip"
: "action-tooltip";

return (
<TooltipWrapper
content={tooltipMessage}
hotkeys={isDisabled ? undefined : RUN_HOT_KEYS}
key={tooltipKey}
defaultOpen={shouldTooltipAppear}
hotkeys={isDisabledButton ? undefined : RUN_HOT_KEYS}
>
<Button
size="sm"
className="mt-2.5"
onClick={runAll}
disabled={isDisabled}
disabled={isDisabledButton}
style={style}
ref={actionButtonRef}
>
<Play className="mr-1 size-4" />
Run all
Expand All @@ -166,7 +172,7 @@ const PlaygroundOutputActions = ({
};

useEffect(() => {
// stop streaming whenever the location changes
// stop streaming whenever a user leaves a page
return () => stopAll();
}, [stopAll]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from "react";
import { TooltipProps } from "@radix-ui/react-tooltip";

import {
Tooltip,
TooltipArrow,
Expand All @@ -14,6 +16,7 @@ export type TooltipWrapperProps = {
side?: "top" | "right" | "bottom" | "left";
hotkeys?: React.ReactNode[];
delayDuration?: number;
defaultOpen?: TooltipProps["defaultOpen"];
};

const TooltipWrapper: React.FunctionComponent<TooltipWrapperProps> = ({
Expand All @@ -22,10 +25,11 @@ const TooltipWrapper: React.FunctionComponent<TooltipWrapperProps> = ({
side,
hotkeys = null,
delayDuration = 500,
defaultOpen,
}) => {
return (
<TooltipProvider delayDuration={delayDuration}>
<Tooltip>
<Tooltip defaultOpen={defaultOpen}>
<TooltipTrigger asChild>{children}</TooltipTrigger>
<TooltipPortal>
<TooltipContent
Expand Down

0 comments on commit 17895a5

Please sign in to comment.