guan404ming commented on code in PR #61058:
URL: https://github.com/apache/airflow/pull/61058#discussion_r2747217381
##########
airflow-core/src/airflow/ui/src/layouts/Details/Gantt/utils.ts:
##########
@@ -50,42 +59,135 @@ type ChartOptionsParams = {
handleBarHover: (event: ChartEvent, elements: Array<ActiveElement>) => void;
hoveredId?: string | null;
hoveredItemColor?: string;
+ labels: Array<string>;
selectedId?: string;
selectedItemColor?: string;
selectedRun?: GridRunsResponse;
selectedTimezone: string;
translate: TFunction;
};
+type TransformGanttDataParams = {
+ allTries: Array<GanttTaskInstance>;
+ currentTime: string;
+ flatNodes: Array<GridTask>;
+ gridSummaries: Array<LightGridTaskInstanceSummary>;
+ selectedTimezone: string;
+};
+
+export const transformGanttData = ({
+ allTries,
+ currentTime,
+ flatNodes,
+ gridSummaries,
+ selectedTimezone,
+}: TransformGanttDataParams): Array<GanttDataItem> => {
+ // Group tries by task_id
+ const triesByTask = new Map<string, Array<GanttTaskInstance>>();
+
+ for (const ti of allTries) {
+ const existing = triesByTask.get(ti.task_id) ?? [];
+
+ existing.push(ti);
+ triesByTask.set(ti.task_id, existing);
+ }
+
+ return flatNodes
+ .flatMap((node): Array<GanttDataItem> | undefined => {
+ const gridSummary = gridSummaries.find((ti) => ti.task_id === node.id);
+
+ // Handle groups and mapped tasks using grid summary (aggregated min/max
times)
+ if ((node.isGroup ?? node.is_mapped) && gridSummary) {
+ return [
+ {
+ isGroup: node.isGroup,
+ isMapped: node.is_mapped,
+ state: gridSummary.state,
+ taskId: gridSummary.task_id,
+ x: [
+ formatDate(gridSummary.min_start_date, selectedTimezone,
DEFAULT_DATETIME_FORMAT_WITH_TZ),
+ formatDate(gridSummary.max_end_date, selectedTimezone,
DEFAULT_DATETIME_FORMAT_WITH_TZ),
+ ],
+ y: gridSummary.task_id,
+ },
+ ];
+ }
+
+ // Handle individual tasks with all their tries
+ if (!node.isGroup) {
+ const tries = triesByTask.get(node.id);
+
+ if (tries && tries.length > 0) {
+ return tries.map((tryInstance) => {
+ const hasTaskRunning = isStatePending(tryInstance.state);
+ const endTime = hasTaskRunning ? currentTime :
tryInstance.end_date;
+
+ return {
+ isGroup: false,
+ isMapped: tryInstance.is_mapped,
+ state: tryInstance.state,
+ taskId: tryInstance.task_id,
+ tryNumber: tryInstance.try_number,
+ x: [
+ formatDate(tryInstance.start_date, selectedTimezone,
DEFAULT_DATETIME_FORMAT_WITH_TZ),
+ formatDate(endTime, selectedTimezone,
DEFAULT_DATETIME_FORMAT_WITH_TZ),
+ ],
+ y: tryInstance.task_id,
+ };
+ });
+ }
+ }
+
+ return undefined;
+ })
+ .filter((item): item is GanttDataItem => item !== undefined);
+};
+
export const createHandleBarClick =
({ dagId, data, location, navigate, runId }: HandleBarClickOptions) =>
(_: ChartEvent, elements: Array<ActiveElement>) => {
- if (elements.length > 0 && elements[0] && Boolean(runId)) {
- const clickedData = data[elements[0].index];
-
- if (clickedData) {
- const { isGroup, isMapped, taskId } = clickedData;
-
- const taskUrl = buildTaskInstanceUrl({
- currentPathname: location.pathname,
- dagId,
- isGroup: Boolean(isGroup),
- isMapped: Boolean(isMapped),
- runId,
- taskId,
- });
+ if (elements.length === 0 || !elements[0] || !runId) {
+ return;
+ }
- void Promise.resolve(
- navigate(
- {
- pathname: taskUrl,
- search: location.search,
- },
- { replace: true },
- ),
- );
- }
+ const clickedData = data[elements[0].index];
+
+ if (!clickedData) {
+ return;
}
+
+ const { isGroup, isMapped, taskId, tryNumber } = clickedData;
+
+ const taskUrl = buildTaskInstanceUrl({
+ currentPathname: location.pathname,
+ dagId,
+ isGroup: Boolean(isGroup),
+ isMapped: Boolean(isMapped),
+ runId,
+ taskId,
+ });
+
+ const searchParams = new URLSearchParams(location.search);
+ const isOlderTry =
+ tryNumber !== undefined &&
+ tryNumber <
+ Math.max(...data.filter((item) => item.taskId === taskId).map((item)
=> item.tryNumber ?? 1));
+
+ if (isOlderTry) {
+ searchParams.set("try_number", tryNumber.toString());
Review Comment:
Sure, thanks for catching this. Just updated!
--
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]