Skip to content

Commit 9adb256

Browse files
rich7420bbovenzi
andauthored
fix: Add auto-refresh functionality to Required Actions page (#56404)
* Add auto-refresh functionality to Required Actions page * switch refresh interval * remove dependance of effectiveResponseReceived * remove typescript error and comment * fix static check error * fix ts-compile-lint-ui error --------- Co-authored-by: Brent Bovenzi <brent@astronomer.io>
1 parent 3b97c94 commit 9adb256

1 file changed

Lines changed: 41 additions & 21 deletions

File tree

airflow-core/src/airflow/ui/src/pages/HITLTaskInstances/HITLTaskInstances.tsx

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { StateBadge } from "src/components/StateBadge";
3232
import Time from "src/components/Time";
3333
import { TruncatedText } from "src/components/TruncatedText";
3434
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
35+
import { useAutoRefresh } from "src/utils";
3536
import { getHITLState } from "src/utils/hitl";
3637
import { getTaskInstanceLink } from "src/utils/links";
3738

@@ -176,6 +177,8 @@ export const HITLTaskInstances = () => {
176177
const [sort] = sorting;
177178
const responseReceived = searchParams.get(RESPONSE_RECEIVED_PARAM);
178179

180+
const baseRefetchInterval = useAutoRefresh({});
181+
179182
const bodySearch = searchParams.get(BODY_SEARCH) ?? undefined;
180183
const createdAtGte = searchParams.get(CREATED_AT_GTE) ?? undefined;
181184
const createdAtLte = searchParams.get(CREATED_AT_LTE) ?? undefined;
@@ -189,27 +192,44 @@ export const HITLTaskInstances = () => {
189192
// Use the filter value if available, otherwise fall back to the old responseReceived param
190193
const effectiveResponseReceived = filterResponseReceived ?? responseReceived;
191194

192-
const { data, error, isLoading } = useTaskInstanceServiceGetHitlDetails({
193-
bodySearch,
194-
createdAtGte,
195-
createdAtLte,
196-
dagId: dagId ?? "~",
197-
dagIdPattern,
198-
dagRunId: runId ?? "~",
199-
limit: pagination.pageSize,
200-
mapIndex: parseInt(mapIndex, 10),
201-
offset: pagination.pageIndex * pagination.pageSize,
202-
orderBy: sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : [],
203-
respondedByUserName: respondedByUserName === undefined ? undefined : [respondedByUserName],
204-
responseReceived:
205-
Boolean(effectiveResponseReceived) && effectiveResponseReceived !== "all"
206-
? effectiveResponseReceived === "true"
207-
: undefined,
208-
state: effectiveResponseReceived === "false" ? ["deferred"] : undefined,
209-
subjectSearch,
210-
taskId,
211-
taskIdPattern,
212-
});
195+
const { data, error, isLoading } = useTaskInstanceServiceGetHitlDetails(
196+
{
197+
bodySearch,
198+
createdAtGte,
199+
createdAtLte,
200+
dagId: dagId ?? "~",
201+
dagIdPattern,
202+
dagRunId: runId ?? "~",
203+
limit: pagination.pageSize,
204+
mapIndex: parseInt(mapIndex, 10),
205+
offset: pagination.pageIndex * pagination.pageSize,
206+
orderBy: sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : [],
207+
respondedByUserName: respondedByUserName === undefined ? undefined : [respondedByUserName],
208+
responseReceived:
209+
Boolean(effectiveResponseReceived) && effectiveResponseReceived !== "all"
210+
? effectiveResponseReceived === "true"
211+
: undefined,
212+
state: effectiveResponseReceived === "false" ? ["deferred"] : undefined,
213+
subjectSearch,
214+
taskId,
215+
taskIdPattern,
216+
},
217+
undefined,
218+
{
219+
// Only continue auto-refetching when filtering for unreceived responses
220+
// and at least one TaskInstance is still deferred without a response.
221+
refetchInterval: (query) => {
222+
const hasDeferredWithoutResponse = Boolean(
223+
query.state.data?.hitl_details.some(
224+
(detail: HITLDetail) =>
225+
detail.responded_at === undefined && detail.task_instance.state === "deferred",
226+
),
227+
);
228+
229+
return hasDeferredWithoutResponse ? baseRefetchInterval : false;
230+
},
231+
},
232+
);
213233

214234
const handleResponseChange = useCallback(() => {
215235
setTableURLState({

0 commit comments

Comments
 (0)