pierrejeambrun commented on code in PR #55927:
URL: https://github.com/apache/airflow/pull/55927#discussion_r2391750291
##########
airflow-core/src/airflow/ui/src/components/TaskInstanceTooltip.tsx:
##########
@@ -28,55 +28,109 @@ import Time from "src/components/Time";
import { Tooltip, type TooltipProps } from "src/components/ui";
import { getDuration } from "src/utils";
+type TIUnion = LightGridTaskInstanceSummary | TaskInstanceHistoryResponse |
TaskInstanceResponse;
+
type Props = {
- readonly taskInstance?: LightGridTaskInstanceSummary |
TaskInstanceHistoryResponse | TaskInstanceResponse;
+ readonly taskInstance?: TIUnion;
} & Omit<TooltipProps, "content">;
+/** Full TI shapes carry start/end; grid light shape carries min/max. */
+const hasStartEnd = (
+ ti: TIUnion,
+): ti is Extract<TIUnion, TaskInstanceHistoryResponse | TaskInstanceResponse>
=> "start_date" in ti;
+
+const hasMinMax = (
+ ti: TIUnion,
+): ti is { max_end_date: string | null; min_start_date: string | null } &
LightGridTaskInstanceSummary =>
+ "min_start_date" in ti && "max_end_date" in ti;
+
+const normalize = (value: string | null | undefined): string | undefined =>
value ?? undefined;
+
const TaskInstanceTooltip = ({ children, positioning, taskInstance, ...rest }:
Props) => {
const { t: translate } = useTranslation("common");
- return taskInstance === undefined ? (
- children
- ) : (
+ if (taskInstance === undefined) {
+ return children;
+ }
+
+ const taskId =
+ "task_id" in taskInstance && typeof taskInstance.task_id === "string" ?
taskInstance.task_id : undefined;
+ const state = "state" in taskInstance ? taskInstance.state : undefined;
+ const triggerRule =
+ "trigger_rule" in taskInstance && typeof taskInstance.trigger_rule ===
"string"
+ ? taskInstance.trigger_rule
+ : undefined;
+
+ // Computing timing + duration with correct fallbacks
+ let startedIso: string | undefined;
+ let endedIso: string | undefined;
+
+ if (hasStartEnd(taskInstance)) {
+ startedIso = normalize(taskInstance.start_date);
+ endedIso = normalize(taskInstance.end_date);
+ } else if (hasMinMax(taskInstance)) {
+ startedIso = normalize(taskInstance.min_start_date);
+ endedIso = normalize(taskInstance.max_end_date);
+ } else {
+ startedIso = undefined;
+ endedIso = undefined;
+ }
+
+ const hasStarted = typeof startedIso === "string" && startedIso.length > 0;
Review Comment:
Instead of doing all that, we should probably make the interfaces
compatibles. That would avoid such checks on the front-end.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]