Skip to content

Commit

Permalink
Fix try selector refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
bbovenzi committed Aug 14, 2024
1 parent 6570c6d commit 5dcc2ad
Showing 1 changed file with 37 additions and 55 deletions.
92 changes: 37 additions & 55 deletions airflow/www/static/js/dag/details/taskInstance/TrySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,76 +61,58 @@ const TrySelector = ({
const logAttemptDropdownLimit = 10;
const showDropdown = finalTryNumber > logAttemptDropdownLimit;

const tries = (tiHistory?.taskInstances || []).filter(
(t) => t?.startDate !== taskInstance?.startDate
);
tries?.push(taskInstance);

return (
<Box my={3}>
<Text as="strong">Task Tries</Text>
{!showDropdown && (
<Flex my={1} flexWrap="wrap">
{/* Even without try history showing up we should still show all try numbers */}
{Array.from({ length: finalTryNumber }, (_, i) => i + 1).map(
(tryNumber, i) => {
let attempt;
if (tries.length) {
attempt = tries[i];
}
return (
<Tooltip
key={tryNumber}
label={
!!attempt && (
<Box>
<Text>Status: {attempt.state}</Text>
<Text>
Duration:{" "}
{formatDuration(
getDuration(attempt.startDate, attempt.endDate)
)}
</Text>
</Box>
)
}
hasArrow
portalProps={{ containerRef }}
placement="top"
isDisabled={!attempt}
>
<Button
key={tryNumber}
variant={
selectedTryNumber === tryNumber ? "solid" : "ghost"
}
colorScheme="blue"
onClick={() => onSelectTryNumber?.(tryNumber)}
data-testid={`log-attempt-select-button-${tryNumber}`}
>
{tryNumber}
{!!attempt && <SimpleStatus ml={2} state={attempt.state} />}
</Button>
</Tooltip>
);
}
)}
</Flex>
)}
{showDropdown && (
{showDropdown ? (
<Select
onChange={(e) => {
onSelectTryNumber?.(Number(e.target.value));
}}
value={selectedTryNumber}
maxWidth="200px"
>
{tries.map(({ tryNumber, state }) => (
{tiHistory?.taskInstances?.map(({ tryNumber, state }) => (
<option key={tryNumber} value={tryNumber}>
{tryNumber}: {state}
</option>
))}
</Select>
) : (
<Flex my={1} flexWrap="wrap">
{tiHistory?.taskInstances?.map((ti) => (
<Tooltip
key={ti.tryNumber}
label={
<Box>
<Text>Status: {ti.state}</Text>
<Text>
Duration:{" "}
{formatDuration(getDuration(ti.startDate, ti.endDate))}
</Text>
</Box>
}
hasArrow
portalProps={{ containerRef }}
placement="top"
isDisabled={!ti}
>
<Button
key={ti.tryNumber}
variant={selectedTryNumber === ti.tryNumber ? "solid" : "ghost"}
colorScheme="blue"
onClick={() => {
if (onSelectTryNumber && ti.tryNumber)
onSelectTryNumber(ti.tryNumber);
}}
data-testid={`log-attempt-select-button-${ti.tryNumber}`}
>
{ti.tryNumber}
<SimpleStatus ml={2} state={ti.state} />
</Button>
</Tooltip>
))}
</Flex>
)}
</Box>
);
Expand Down

0 comments on commit 5dcc2ad

Please sign in to comment.