-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] feat: Adds StartTimeCell to flow run data table
- Loading branch information
1 parent
87aa884
commit 3d49127
Showing
3 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ui-v2/src/components/flow-runs/data-table/start-time-cell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
type FlowRun, | ||
type FlowRunWithDeploymentAndFlow, | ||
} from "@/api/flow-runs"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Icon } from "@/components/ui/icons"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from "@/components/ui/tooltip"; | ||
import { formatDate } from "@/utils/date"; | ||
import humanizeDuration from "humanize-duration"; | ||
|
||
type StartTimeCellProps = { | ||
flowRun: FlowRun | FlowRunWithDeploymentAndFlow; | ||
}; | ||
|
||
const getDelta = (estimated_start_time_delta: null | number) => { | ||
if (!estimated_start_time_delta || estimated_start_time_delta <= 60) { | ||
return ""; | ||
} | ||
return `(${humanizeDuration(estimated_start_time_delta, { maxDecimalPoints: 0 })} late)`; | ||
}; | ||
|
||
export const StartTimeCell = ({ flowRun }: StartTimeCellProps) => { | ||
const { start_time, expected_start_time, estimated_start_time_delta } = | ||
flowRun; | ||
let text: string | undefined; | ||
let tooltipText: string | undefined; | ||
if (start_time) { | ||
text = `${formatDate(start_time, "dateTimeNumeric")} ${getDelta(estimated_start_time_delta)}`; | ||
tooltipText = new Date(start_time).toString(); | ||
} else if (expected_start_time) { | ||
text = `Scheduled for ${formatDate(expected_start_time, "dateTimeNumeric")} ${getDelta(estimated_start_time_delta)}`; | ||
tooltipText = new Date(expected_start_time).toString(); | ||
} | ||
|
||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger asChild disabled={!text}> | ||
<Button | ||
variant="ghost" | ||
className="text-sm font-mono flex gap-2 items-center" | ||
> | ||
<Icon id="Calendar" className="h-4 w-4" /> | ||
{text ?? "No start time"} | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent>{tooltipText}</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
}; |