pierrejeambrun commented on code in PR #60591:
URL: https://github.com/apache/airflow/pull/60591#discussion_r2789040724


##########
airflow-core/src/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx:
##########
@@ -34,20 +34,53 @@ import { isStatePending, useAutoRefresh } from "src/utils";
 
 import ClearTaskInstanceConfirmationDialog from 
"./ClearTaskInstanceConfirmationDialog";
 
-type Props = {
+type CommonProps = {
+  readonly allMapped?: boolean;
   readonly onClose: () => void;
   readonly open: boolean;
-  readonly taskInstance: TaskInstanceResponse;
 };
 
-const ClearTaskInstanceDialog = ({ onClose: onCloseDialog, open: openDialog, 
taskInstance }: Props) => {
-  const taskId = taskInstance.task_id;
-  const mapIndex = taskInstance.map_index;
+type Props = (
+  | {
+      readonly dagId: string;
+      readonly dagRunId: string;
+      readonly mapIndex?: number;
+      readonly taskId: string;
+      readonly taskInstance?: never; // Ensure taskInstance is not present
+    }
+  | {
+      readonly dagId?: never; // Ensure individual props are not present
+      readonly dagRunId?: never;
+      readonly mapIndex?: never;
+      readonly taskId?: never;
+      readonly taskInstance: TaskInstanceResponse;
+    }
+) &
+  CommonProps;
+
+const ClearTaskInstanceDialog = ({
+  allMapped = false,
+  onClose: onCloseDialog,
+  open: openDialog,
+  ...rest
+}: Props) => {
   const { t: translate } = useTranslation();
   const { onClose, onOpen, open } = useDisclosure();
 
-  const dagId = taskInstance.dag_id;
-  const dagRunId = taskInstance.dag_run_id;
+  const { dagId, dagRunId, taskId, taskInstance } = rest.taskInstance
+    ? {
+        dagId: rest.taskInstance.dag_id,
+        dagRunId: rest.taskInstance.dag_run_id,
+        taskId: rest.taskInstance.task_id,
+        taskInstance: rest.taskInstance,
+      }
+    : {
+        dagId: rest.dagId,
+        dagRunId: rest.dagRunId,
+        taskId: rest.taskId,
+        taskInstance: undefined,
+      };
+  const mapIndex = allMapped ? undefined : rest.taskInstance?.map_index ?? 
rest.mapIndex ?? -1;

Review Comment:
   This will be simplified, if all props are passed down and we don't have both 
`dagId, task_id, etc...` and a `TaskInstance` object. 
   
   Only the former.



##########
airflow-core/src/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceButton.tsx:
##########
@@ -84,12 +92,15 @@ const ClearTaskInstanceButton = ({
         </IconButton>
       </Tooltip>
 
-      {useInternalDialog && open && isGroup ? (
-        <ClearGroupTaskInstanceDialog onClose={onClose} open={open} 
taskInstance={groupTaskInstance} />
-      ) : undefined}
-
-      {useInternalDialog && open && !isGroup && taskInstance ? (
-        <ClearTaskInstanceDialog onClose={onClose} open={open} 
taskInstance={taskInstance} />
+      {useInternalDialog && open ? (
+        <ClearTaskInstanceDialog
+          allMapped={allMapped}
+          onClose={onClose}
+          open={open}
+          {...(allMapped
+            ? { dagId: dagId as string, dagRunId: dagRunId as string, taskId: 
taskId as string }
+            : { taskInstance: selectedInstance as TaskInstanceResponse })}
+        />

Review Comment:
   I don't understand this. Just pass `dagId, dagRunId, and taskId` from props, 
`taskInstance` shouldn't be a props of this component at all I believe. This 
would make the interface simpler.



##########
airflow-core/src/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceConfirmationDialog.tsx:
##########
@@ -81,11 +89,14 @@ const ClearTaskInstanceConfirmationDialog = ({
     if (!isFetching && open && data) {
       const isInTriggeringState = taskCurrentState === "queued" || 
taskCurrentState === "scheduled";
 
-      if (!preventRunningTask || !isInTriggeringState) {
+      const shouldBeReady = preventRunningTask && isInTriggeringState;
+
+      if (shouldBeReady) {
+        setIsReady(true);
+      } else {
+        // eslint-disable-next-line @typescript-eslint/no-unused-expressions

Review Comment:
   This eslint disable shouldn't be needed.



##########
airflow-core/src/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx:
##########
@@ -34,20 +34,53 @@ import { isStatePending, useAutoRefresh } from "src/utils";
 
 import ClearTaskInstanceConfirmationDialog from 
"./ClearTaskInstanceConfirmationDialog";
 
-type Props = {
+type CommonProps = {
+  readonly allMapped?: boolean;
   readonly onClose: () => void;
   readonly open: boolean;
-  readonly taskInstance: TaskInstanceResponse;
 };
 
-const ClearTaskInstanceDialog = ({ onClose: onCloseDialog, open: openDialog, 
taskInstance }: Props) => {
-  const taskId = taskInstance.task_id;
-  const mapIndex = taskInstance.map_index;
+type Props = (
+  | {
+      readonly dagId: string;
+      readonly dagRunId: string;
+      readonly mapIndex?: number;
+      readonly taskId: string;
+      readonly taskInstance?: never; // Ensure taskInstance is not present
+    }
+  | {
+      readonly dagId?: never; // Ensure individual props are not present
+      readonly dagRunId?: never;
+      readonly mapIndex?: never;
+      readonly taskId?: never;
+      readonly taskInstance: TaskInstanceResponse;
+    }
+) &
+  CommonProps;
+
+const ClearTaskInstanceDialog = ({
+  allMapped = false,
+  onClose: onCloseDialog,
+  open: openDialog,
+  ...rest

Review Comment:
   Don't collect everything from `...rest`



##########
airflow-core/src/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx:
##########
@@ -34,20 +34,53 @@ import { isStatePending, useAutoRefresh } from "src/utils";
 
 import ClearTaskInstanceConfirmationDialog from 
"./ClearTaskInstanceConfirmationDialog";
 
-type Props = {
+type CommonProps = {
+  readonly allMapped?: boolean;
   readonly onClose: () => void;
   readonly open: boolean;
-  readonly taskInstance: TaskInstanceResponse;
 };
 
-const ClearTaskInstanceDialog = ({ onClose: onCloseDialog, open: openDialog, 
taskInstance }: Props) => {
-  const taskId = taskInstance.task_id;
-  const mapIndex = taskInstance.map_index;
+type Props = (
+  | {
+      readonly dagId: string;
+      readonly dagRunId: string;
+      readonly mapIndex?: number;
+      readonly taskId: string;
+      readonly taskInstance?: never; // Ensure taskInstance is not present
+    }
+  | {
+      readonly dagId?: never; // Ensure individual props are not present
+      readonly dagRunId?: never;
+      readonly mapIndex?: never;
+      readonly taskId?: never;
+      readonly taskInstance: TaskInstanceResponse;
+    }
+) &

Review Comment:
   Interface should be
   ```suggestion
   type Props = {
         readonly dagId: string;
         readonly dagRunId: string;
         readonly mapIndex?: number;
         readonly taskId: string;
       } & CommonProps
   ```



-- 
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]

Reply via email to