Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mapIndex to display extra links per mapped task. #32154

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletions airflow/www/static/js/api/useExtraLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,44 @@ export default function useExtraLinks({
dagId,
taskId,
executionDate,
mapIndex,
extraLinks,
}: {
dagId: string;
taskId: string;
executionDate: string;
mapIndex?: number | undefined;
extraLinks: string[];
}) {
return useQuery(["extraLinks", dagId, taskId, executionDate], async () => {
const data = await Promise.all(
extraLinks.map(async (link) => {
const url = `${extraLinksUrl}?task_id=${encodeURIComponent(
taskId
)}&dag_id=${encodeURIComponent(
dagId
)}&execution_date=${encodeURIComponent(
executionDate
)}&link_name=${encodeURIComponent(link)}`;
try {
const datum = await axios.get<AxiosResponse, LinkData>(url);
return {
name: link,
url: datum.url,
};
} catch (e) {
console.error(e);
return {
name: link,
url: "",
};
}
})
);
return data;
});
return useQuery(
["extraLinks", dagId, taskId, executionDate, mapIndex],
async () => {
const data = await Promise.all(
extraLinks.map(async (link) => {
mapIndex ??= -1;
const url = `${extraLinksUrl}?task_id=${encodeURIComponent(
taskId
)}&dag_id=${encodeURIComponent(
dagId
)}&execution_date=${encodeURIComponent(
executionDate
)}&link_name=${encodeURIComponent(link)}&map_index=${mapIndex}`;
try {
const datum = await axios.get<AxiosResponse, LinkData>(url);
return {
name: link,
url: datum.url,
};
} catch (e) {
console.error(e);
return {
name: link,
url: "",
};
}
})
);
return data;
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ interface Props {
dagId: string;
taskId: string;
executionDate: string;
mapIndex?: number | undefined;
extraLinks: string[];
}

const ExtraLinks = ({ dagId, taskId, executionDate, extraLinks }: Props) => {
const ExtraLinks = ({
dagId,
taskId,
executionDate,
mapIndex,
extraLinks,
}: Props) => {
const { data: links } = useExtraLinks({
dagId,
taskId,
executionDate,
mapIndex,
extraLinks,
});

Expand Down
9 changes: 9 additions & 0 deletions airflow/www/static/js/dag/details/taskInstance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ const TaskInstance = ({ taskId, runId, mapIndex }: Props) => {
key={dagId + runId + taskId + instance.mapIndex}
/>
)}
{isMapped && group.extraLinks && isMapIndexDefined && (
<ExtraLinks
taskId={taskId}
dagId={dagId}
mapIndex={mapIndex}
executionDate={executionDate}
extraLinks={group?.extraLinks}
/>
)}
{!isMapped && group.extraLinks && (
<ExtraLinks
taskId={taskId}
Expand Down