From d90ec19215b5b5f3de2f222bbc011a5ed18fdd20 Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Thu, 24 Apr 2025 19:06:33 +0100 Subject: [PATCH 01/18] Add support for favorite/pin dags to dashboard, using localStorage. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana --- .../DagActions/FavoriteDagButton.tsx | 56 +++++++++++++++++++ .../airflow/ui/src/pages/DagsList/DagCard.tsx | 2 + .../ui/src/pages/DagsList/DagsList.tsx | 9 +++ .../ui/src/pages/Dashboard/Dashboard.tsx | 4 ++ .../FavoriteDags/FavoriteDagCard.tsx | 51 +++++++++++++++++ .../Dashboard/FavoriteDags/FavoriteDags.tsx | 43 ++++++++++++++ .../src/pages/Dashboard/FavoriteDags/index.ts | 20 +++++++ .../airflow/ui/src/queries/useFavoriteDag.ts | 56 +++++++++++++++++++ 8 files changed, 241 insertions(+) create mode 100644 airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx create mode 100644 airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx create mode 100644 airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx create mode 100644 airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts create mode 100644 airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts diff --git a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx new file mode 100644 index 0000000000000..b97a921c5d4fa --- /dev/null +++ b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx @@ -0,0 +1,56 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Box } from "@chakra-ui/react"; +import { FiStar } from "react-icons/fi"; + +import ActionButton from "../ui/ActionButton"; +import { updateFavoriteDags, fetchFavoriteDags } from "src/queries/useFavoriteDag"; + + +type FavoriteDagButtonProps = { + readonly dagId: string; + readonly withText?: boolean; +}; + +export const FavoriteDagButton = ({ dagId, withText = true}: FavoriteDagButtonProps) => { + const { data: favorites } = fetchFavoriteDags(); + const { mutate: toggleFavorite } = updateFavoriteDags(); + + const isCurrentFavorite = favorites?.includes(dagId) ?? false; + + const onToggle = () => { + toggleFavorite({ dagId, isFavorite: !isCurrentFavorite }); + }; + + return ( + + } + onClick={onToggle} + text={isCurrentFavorite ? "Unfavorite Dag" : "Favorite Dag"} + variant="solid" + withText={withText} + /> + + ); +}; + + diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx index 35990017ec80b..221a3a872ba59 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx @@ -32,6 +32,7 @@ import { isStatePending, useAutoRefresh } from "src/utils"; import { DagTags } from "./DagTags"; import { RecentRuns } from "./RecentRuns"; import { Schedule } from "./Schedule"; +import { FavoriteDagButton } from "src/components/DagActions/FavoriteDagButton"; type Props = { readonly dag: DAGWithLatestDagRunsResponse; @@ -62,6 +63,7 @@ export const DagCard = ({ dag }: Props) => { pr={2} /> + diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx index 046fe5d14aea6..ce0dea6e85281 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx @@ -33,6 +33,7 @@ import { useLocalStorage } from "usehooks-ts"; import type { DagRunState, DAGWithLatestDagRunsResponse } from "openapi/requests/types.gen"; import DeleteDagButton from "src/components/DagActions/DeleteDagButton"; +import { FavoriteDagButton } from "src/components/DagActions/FavoriteDagButton"; import DagRunInfo from "src/components/DagRunInfo"; import { DataTable } from "src/components/DataTable"; import { ToggleTableDisplay } from "src/components/DataTable/ToggleTableDisplay"; @@ -132,6 +133,14 @@ const createColumns = ( enableSorting: false, header: "", }, + { + accessorKey: "favorite", + cell: ({ row: { original } }) => ( + + ), + enableSorting: false, + header: "", + }, { accessorKey: "delete", cell: ({ row: { original } }) => ( diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx index 18e69dc5e9492..044153ccf4687 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx @@ -28,6 +28,7 @@ import { Health } from "./Health"; import { HistoricalMetrics } from "./HistoricalMetrics"; import { PoolSummary } from "./PoolSummary"; import { Stats } from "./Stats"; +import { FavoriteDags } from "./FavoriteDags"; export const Dashboard = () => { const alerts = useConfig("dashboard_alert") as Array; @@ -64,6 +65,9 @@ export const Dashboard = () => { + + + diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx new file mode 100644 index 0000000000000..fd5f24ee832e5 --- /dev/null +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx @@ -0,0 +1,51 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Box, Button, Text, VStack } from "@chakra-ui/react"; +import { useDagsServiceRecentDagRuns } from "openapi/queries"; +import { Link as RouterLink } from "react-router-dom"; +import { RecentRuns } from "src/pages/DagsList/RecentRuns"; + +type FavoriteDagProps = { + readonly dag_id: string; +}; + +export const FavoriteDagCard = ({ dag_id }: FavoriteDagProps) => { + + const { data } = useDagsServiceRecentDagRuns({ + dagIds: [dag_id], + dagRunsLimit: 5, + }); + + const latestRuns = data?.dags[0]?.latest_dag_runs || []; + + return ( + + + + ); +}; diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx new file mode 100644 index 0000000000000..eea9a1a58ec50 --- /dev/null +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx @@ -0,0 +1,43 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Box, Flex, Heading, HStack } from "@chakra-ui/react"; +import { FiStar } from "react-icons/fi"; +import { FavoriteDagCard } from "./FavoriteDagCard"; +import { fetchFavoriteDags } from "src/queries/useFavoriteDag"; + + +export const FavoriteDags = () => { + const { data: favorites } = fetchFavoriteDags(); + + return ( + + + + + Favorite Dags + + + + {favorites.map((dag_id) => ( + + ))} + + + ); +}; diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts new file mode 100644 index 0000000000000..8daccb0f7d937 --- /dev/null +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts @@ -0,0 +1,20 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { FavoriteDags } from "./FavoriteDags"; \ No newline at end of file diff --git a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts new file mode 100644 index 0000000000000..6ed9c460e4eea --- /dev/null +++ b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts @@ -0,0 +1,56 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; + +const FAVORITES_KEY = "favoriteDags"; + +const getFavoriteDags = (): string[] => { + const favorites = localStorage.getItem(FAVORITES_KEY); + return favorites ? JSON.parse(favorites) : []; +}; + +const setFavoriteDags = (favorites: string[]) => { + localStorage.setItem(FAVORITES_KEY, JSON.stringify(favorites)); +}; + +export const fetchFavoriteDags = () => { + return useQuery({ + queryKey: [FAVORITES_KEY], + queryFn: () => Promise.resolve(getFavoriteDags()), + initialData: [], + }); +}; + +export const updateFavoriteDags = () => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ dagId, isFavorite }: { dagId: string; isFavorite: boolean }) => { + const current = getFavoriteDags(); + const updated = isFavorite + ? [...new Set([...current, dagId])] + : current.filter((id) => id !== dagId); + setFavoriteDags(updated); + return Promise.resolve(updated); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["favoriteDags"] }); + }, + }); +}; \ No newline at end of file From 81f72a7550ab955fe3b0c70c4e06cb400644b41b Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Fri, 25 Apr 2025 15:33:29 +0100 Subject: [PATCH 02/18] Add support for favorite/pin dags to dashboard, persistent between sessions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana mariana.marcal.santana@tecnico.ulisboa.pt --- .../api_fastapi/core_api/datamodels/dags.py | 6 + .../core_api/routes/public/dags.py | 42 +++++++ airflow-core/src/airflow/models/dag.py | 53 +++++++++ .../airflow/ui/openapi-gen/queries/common.ts | 1 + .../airflow/ui/openapi-gen/queries/queries.ts | 107 +++++++++++++++++- .../ui/openapi-gen/requests/services.gen.ts | 35 +++++- .../ui/openapi-gen/requests/types.gen.ts | 17 +++ .../DagActions/FavoriteDagButton.tsx | 28 +++-- .../airflow/ui/src/pages/DagsList/DagCard.tsx | 2 +- .../ui/src/pages/DagsList/DagsList.tsx | 6 +- .../Dashboard/FavoriteDags/FavoriteDags.tsx | 9 +- .../airflow/ui/src/queries/useFavoriteDag.ts | 56 ++++----- 12 files changed, 310 insertions(+), 52 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py index 499b66c8e98be..ac8dbcda49bb2 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py @@ -60,6 +60,7 @@ class DAGResponse(BaseModel): dag_id: str dag_display_name: str is_paused: bool + is_favorite: bool | None is_stale: bool last_parsed_time: datetime | None last_expired: datetime | None @@ -122,6 +123,11 @@ class DAGPatchBody(StrictBaseModel): is_paused: bool +class DAGFavoriteBody(StrictBaseModel): + """Dag Serializer for updatable bodies.""" + + is_favorite: bool + class DAGCollectionResponse(BaseModel): """DAG Collection serializer for responses.""" diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py index 0cc1893543fd7..7e1bf8c69a80c 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py @@ -55,6 +55,7 @@ DAGCollectionResponse, DAGDetailsResponse, DAGPatchBody, + DAGFavoriteBody, DAGResponse, ) from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc @@ -316,6 +317,47 @@ def patch_dags( total_entries=total_entries, ) +@dags_router.put( + "/{dag_id}", + responses=create_openapi_http_exception_doc( + [ + status.HTTP_400_BAD_REQUEST, + status.HTTP_404_NOT_FOUND, + ] + ), + dependencies=[Depends(requires_access_dag(method="PUT")), Depends(action_logging())], +) +def favorite_dag( + dag_id: str, + favorite_body: DAGFavoriteBody, + session: SessionDep, + update_mask: list[str] | None = Query(None), +) -> DAGResponse: + """Favorite the specific DAG.""" + dag = session.get(DagModel, dag_id) + + if dag is None: + raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id: {dag_id} was not found") + + fields_to_update = favorite_body.model_fields_set + if update_mask: + if update_mask != ["is_favorite"]: + raise HTTPException( + status.HTTP_400_BAD_REQUEST, "Only `is_favorite` field can be updated through the REST API" + ) + fields_to_update = fields_to_update.intersection(update_mask) + else: + try: + DAGFavoriteBody(**favorite_body.model_dump()) + except ValidationError as e: + raise RequestValidationError(errors=e.errors()) + + data = favorite_body.model_dump(include=fields_to_update, by_alias=True) + + for key, val in data.items(): + setattr(dag, key, val) + + return dag @dags_router.delete( "/{dag_id}", diff --git a/airflow-core/src/airflow/models/dag.py b/airflow-core/src/airflow/models/dag.py index 0332a2e825e24..7a2f08b5196da 100644 --- a/airflow-core/src/airflow/models/dag.py +++ b/airflow-core/src/airflow/models/dag.py @@ -743,6 +743,11 @@ def get_is_stale(self, session=NEW_SESSION) -> None: def get_is_paused(self, session=NEW_SESSION) -> None: """Return a boolean indicating whether this DAG is paused.""" return session.scalar(select(DagModel.is_paused).where(DagModel.dag_id == self.dag_id)) + + @provide_session + def get_is_favorite(self, session=NEW_SESSION) -> None: + """Return a boolean indicating whether this DAG is favorited.""" + return session.scalar(select(DagModel.is_favorite).where(DagModel.dag_id == self.dag_id)) @provide_session def get_bundle_name(self, session=NEW_SESSION) -> str | None: @@ -1874,6 +1879,8 @@ class DagModel(Base): # Set this default value of is_paused based on a configuration value! is_paused_at_creation = airflow_conf.getboolean("core", "dags_are_paused_at_creation") is_paused = Column(Boolean, default=is_paused_at_creation) + # Whether the DAG is favorited + is_favorite = Column(Boolean, default=False) # Whether that DAG was seen on the last DagBag load is_stale = Column(Boolean, default=True) # Last time the scheduler started @@ -2037,7 +2044,12 @@ def get_last_dagrun(self, session=NEW_SESSION, include_manually_triggered=False) def get_is_paused(self, *, session: Session | None = None) -> bool: """Provide interface compatibility to 'DAG'.""" return self.is_paused + + def get_is_favorite(self, *, session: Session | None = None) -> bool: + """Provide interface compatibility to 'DAG'.""" + return self.is_favorite + def get_is_active(self, *, session: Session | None = None) -> bool: """Provide interface compatibility to 'DAG'.""" return not self.is_stale @@ -2060,6 +2072,26 @@ def get_paused_dag_ids(dag_ids: list[str], session: Session = NEW_SESSION) -> se paused_dag_ids = {paused_dag_id for (paused_dag_id,) in paused_dag_ids} return paused_dag_ids + + @staticmethod + @provide_session + def get_favorite_dag_ids(dag_ids: list[str], session: Session = NEW_SESSION) -> set[str]: + """ + Given a list of dag_ids, get a set of Favorited Dag Ids. + + :param dag_ids: List of Dag ids + :param session: ORM Session + :return: Favorited Dag_ids + """ + favorited_dag_ids = session.execute( + select(DagModel.dag_id) + .where(DagModel.is_favorite == expression.true()) + .where(DagModel.dag_id.in_(dag_ids)) + ) + + favorited_dag_ids = {favorited_dag_id for (favorited_dag_id,) in favorited_dag_ids} + return favorited_dag_ids + @property def safe_dag_id(self): @@ -2085,6 +2117,27 @@ def set_is_paused(self, is_paused: bool, session=NEW_SESSION) -> None: ) session.commit() + @provide_session + def set_is_favorite(self, is_favorite: bool, session=NEW_SESSION) -> None: + """ + Favorite/Unfavorite a DAG. + + :param is_favorite: Is the DAG favorited + :param session: session + """ + filter_query = [ + DagModel.dag_id == self.dag_id, + ] + + session.execute( + update(DagModel) + .where(or_(*filter_query)) + .values(is_favorite=is_favorite) + .execution_options(synchronize_session="fetch") + ) + session.commit() + + @hybrid_property def dag_display_name(self) -> str: return self._dag_display_property_value or self.dag_id diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts index 2eb6e29ef579e..6eccd51177ec0 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts @@ -737,6 +737,7 @@ export type ConnectionServiceBulkConnectionsMutationResult = Awaited>; export type DagServicePatchDagsMutationResult = Awaited>; export type DagServicePatchDagMutationResult = Awaited>; +export type DagServiceFavoriteDagMutationResult = Awaited>; export type TaskInstanceServicePatchTaskInstanceMutationResult = Awaited>; export type TaskInstanceServicePatchTaskInstanceByMapIndexMutationResult = Awaited>; export type TaskInstanceServiceBulkTaskInstancesMutationResult = Awaited>; diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts index 627188e6746fa..37daa0051b1cc 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts @@ -1,8 +1,66 @@ // generated with @7nohe/openapi-react-query-codegen@1.6.2 import { UseMutationOptions, UseQueryOptions, useMutation, useQuery } from "@tanstack/react-query"; -import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagParsingService, DagReportService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DependenciesService, EventLogService, ExtraLinksService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, VariableService, VersionService, XcomService } from "../requests/services.gen"; -import { BackfillPostBody, BulkBody_BulkTaskInstanceBody_, BulkBody_ConnectionBody_, BulkBody_PoolBody_, BulkBody_VariableBody_, ClearTaskInstancesBody, ConnectionBody, CreateAssetEventsBody, DAGPatchBody, DAGRunClearBody, DAGRunPatchBody, DAGRunsBatchBody, DagRunState, DagWarningType, PatchTaskInstanceBody, PoolBody, PoolPatchBody, TaskInstancesBatchBody, TriggerDAGRunPostBody, VariableBody, XComCreateBody, XComUpdateBody } from "../requests/types.gen"; + +import { + AssetService, + AuthLinksService, + BackfillService, + CalendarService, + ConfigService, + ConnectionService, + DagParsingService, + DagReportService, + DagRunService, + DagService, + DagSourceService, + DagStatsService, + DagVersionService, + DagWarningService, + DashboardService, + DependenciesService, + EventLogService, + ExtraLinksService, + GridService, + ImportErrorService, + JobService, + LoginService, + MonitorService, + PluginService, + PoolService, + ProviderService, + StructureService, + TaskInstanceService, + TaskService, + VariableService, + VersionService, + XcomService, +} from "../requests/services.gen"; +import { + BackfillPostBody, + BulkBody_BulkTaskInstanceBody_, + BulkBody_ConnectionBody_, + BulkBody_PoolBody_, + BulkBody_VariableBody_, + ClearTaskInstancesBody, + ConnectionBody, + CreateAssetEventsBody, + DAGFavoriteBody, + DAGPatchBody, + DAGRunClearBody, + DAGRunPatchBody, + DAGRunsBatchBody, + DagRunState, + DagWarningType, + PatchTaskInstanceBody, + PoolBody, + PoolPatchBody, + TaskInstancesBatchBody, + TriggerDAGRunPostBody, + VariableBody, + XComCreateBody, + XComUpdateBody, +} from "../requests/types.gen"; import * as Common from "./common"; /** * Get Assets @@ -1737,6 +1795,51 @@ export const useDagServicePatchDag = ({ mutationFn: ({ dagId, requestBody, updateMask }) => DagService.patchDag({ dagId, requestBody, updateMask }) as unknown as Promise, ...options }); + +/** + * Favorite Dag + * Toggle favorite the specific DAG. + * @param data The data for the request. + * @param data.dagId + * @param data.requestBody + * @param data.updateMask + * @returns DAGResponse Successful Response + * @throws ApiError + */ +export const useDagServiceFavoriteDag = < + TData = Common.DagServiceFavoriteDagMutationResult, + TError = unknown, + TContext = unknown, +>( + options?: Omit< + UseMutationOptions< + TData, + TError, + { + dagId: string; + requestBody: DAGFavoriteBody; + updateMask?: string[]; + }, + TContext + >, + "mutationFn" + >, +) => + useMutation< + TData, + TError, + { + dagId: string; + requestBody: DAGFavoriteBody; + updateMask?: string[]; + }, + TContext + >({ + mutationFn: ({ dagId, requestBody, updateMask }) => + DagService.favoriteDag({ dagId, requestBody, updateMask }) as unknown as Promise, + ...options, + }); + /** * Patch Task Instance * Update a task instance. diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts index a12039ac322f1..619719037d815 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { GetAssetsData, GetAssetsResponse, GetAssetAliasesData, GetAssetAliasesResponse, GetAssetAliasData, GetAssetAliasResponse, GetAssetEventsData, GetAssetEventsResponse, CreateAssetEventData, CreateAssetEventResponse, MaterializeAssetData, MaterializeAssetResponse, GetAssetQueuedEventsData, GetAssetQueuedEventsResponse, DeleteAssetQueuedEventsData, DeleteAssetQueuedEventsResponse, GetAssetData, GetAssetResponse, GetDagAssetQueuedEventsData, GetDagAssetQueuedEventsResponse, DeleteDagAssetQueuedEventsData, DeleteDagAssetQueuedEventsResponse, GetDagAssetQueuedEventData, GetDagAssetQueuedEventResponse, DeleteDagAssetQueuedEventData, DeleteDagAssetQueuedEventResponse, NextRunAssetsData, NextRunAssetsResponse, ListBackfillsData, ListBackfillsResponse, CreateBackfillData, CreateBackfillResponse, GetBackfillData, GetBackfillResponse, PauseBackfillData, PauseBackfillResponse, UnpauseBackfillData, UnpauseBackfillResponse, CancelBackfillData, CancelBackfillResponse, CreateBackfillDryRunData, CreateBackfillDryRunResponse, ListBackfillsUiData, ListBackfillsUiResponse, DeleteConnectionData, DeleteConnectionResponse, GetConnectionData, GetConnectionResponse, PatchConnectionData, PatchConnectionResponse, GetConnectionsData, GetConnectionsResponse, PostConnectionData, PostConnectionResponse, BulkConnectionsData, BulkConnectionsResponse, TestConnectionData, TestConnectionResponse, CreateDefaultConnectionsResponse, HookMetaDataResponse, GetDagRunData, GetDagRunResponse, DeleteDagRunData, DeleteDagRunResponse, PatchDagRunData, PatchDagRunResponse, GetUpstreamAssetEventsData, GetUpstreamAssetEventsResponse, ClearDagRunData, ClearDagRunResponse, GetDagRunsData, GetDagRunsResponse, TriggerDagRunData, TriggerDagRunResponse, GetListDagRunsBatchData, GetListDagRunsBatchResponse, GetDagSourceData, GetDagSourceResponse, GetDagStatsData, GetDagStatsResponse, GetDagReportsData, GetDagReportsResponse, GetConfigData, GetConfigResponse, GetConfigValueData, GetConfigValueResponse, GetConfigsResponse, ListDagWarningsData, ListDagWarningsResponse, GetDagsData, GetDagsResponse, PatchDagsData, PatchDagsResponse, GetDagData, GetDagResponse, PatchDagData, PatchDagResponse, DeleteDagData, DeleteDagResponse, GetDagDetailsData, GetDagDetailsResponse, GetDagTagsData, GetDagTagsResponse, GetDagsUiData, GetDagsUiResponse, GetEventLogData, GetEventLogResponse, GetEventLogsData, GetEventLogsResponse, GetExtraLinksData, GetExtraLinksResponse, GetTaskInstanceData, GetTaskInstanceResponse, PatchTaskInstanceData, PatchTaskInstanceResponse, DeleteTaskInstanceData, DeleteTaskInstanceResponse, GetMappedTaskInstancesData, GetMappedTaskInstancesResponse, GetTaskInstanceDependenciesByMapIndexData, GetTaskInstanceDependenciesByMapIndexResponse, GetTaskInstanceDependenciesData, GetTaskInstanceDependenciesResponse, GetTaskInstanceTriesData, GetTaskInstanceTriesResponse, GetMappedTaskInstanceTriesData, GetMappedTaskInstanceTriesResponse, GetMappedTaskInstanceData, GetMappedTaskInstanceResponse, PatchTaskInstanceByMapIndexData, PatchTaskInstanceByMapIndexResponse, GetTaskInstancesData, GetTaskInstancesResponse, BulkTaskInstancesData, BulkTaskInstancesResponse, GetTaskInstancesBatchData, GetTaskInstancesBatchResponse, GetTaskInstanceTryDetailsData, GetTaskInstanceTryDetailsResponse, GetMappedTaskInstanceTryDetailsData, GetMappedTaskInstanceTryDetailsResponse, PostClearTaskInstancesData, PostClearTaskInstancesResponse, PatchTaskInstanceDryRunByMapIndexData, PatchTaskInstanceDryRunByMapIndexResponse, PatchTaskInstanceDryRunData, PatchTaskInstanceDryRunResponse, GetLogData, GetLogResponse, GetExternalLogUrlData, GetExternalLogUrlResponse, GetImportErrorData, GetImportErrorResponse, GetImportErrorsData, GetImportErrorsResponse, GetJobsData, GetJobsResponse, GetPluginsData, GetPluginsResponse, ImportErrorsResponse, DeletePoolData, DeletePoolResponse, GetPoolData, GetPoolResponse, PatchPoolData, PatchPoolResponse, GetPoolsData, GetPoolsResponse, PostPoolData, PostPoolResponse, BulkPoolsData, BulkPoolsResponse, GetProvidersData, GetProvidersResponse, GetXcomEntryData, GetXcomEntryResponse, UpdateXcomEntryData, UpdateXcomEntryResponse, GetXcomEntriesData, GetXcomEntriesResponse, CreateXcomEntryData, CreateXcomEntryResponse, GetTasksData, GetTasksResponse, GetTaskData, GetTaskResponse, DeleteVariableData, DeleteVariableResponse, GetVariableData, GetVariableResponse, PatchVariableData, PatchVariableResponse, GetVariablesData, GetVariablesResponse, PostVariableData, PostVariableResponse, BulkVariablesData, BulkVariablesResponse, ReparseDagFileData, ReparseDagFileResponse, GetDagVersionData, GetDagVersionResponse, GetDagVersionsData, GetDagVersionsResponse, GetHealthResponse, GetVersionResponse, LoginData, LoginResponse, LogoutData, LogoutResponse, GetAuthMenusResponse, GetDependenciesData, GetDependenciesResponse, HistoricalMetricsData, HistoricalMetricsResponse, DagStatsResponse2, StructureDataData, StructureDataResponse2, GridDataData, GridDataResponse, GetDagStructureData, GetDagStructureResponse, GetGridRunsData, GetGridRunsResponse, GetGridTiSummariesData, GetGridTiSummariesResponse, GetLatestRunData, GetLatestRunResponse, GetCalendarData, GetCalendarResponse } from './types.gen'; +import type { GetAssetsData, GetAssetsResponse, GetAssetAliasesData, GetAssetAliasesResponse, GetAssetAliasData, GetAssetAliasResponse, GetAssetEventsData, GetAssetEventsResponse, CreateAssetEventData, CreateAssetEventResponse, MaterializeAssetData, MaterializeAssetResponse, GetAssetQueuedEventsData, GetAssetQueuedEventsResponse, DeleteAssetQueuedEventsData, DeleteAssetQueuedEventsResponse, GetAssetData, GetAssetResponse, GetDagAssetQueuedEventsData, GetDagAssetQueuedEventsResponse, DeleteDagAssetQueuedEventsData, DeleteDagAssetQueuedEventsResponse, GetDagAssetQueuedEventData, GetDagAssetQueuedEventResponse, DeleteDagAssetQueuedEventData, DeleteDagAssetQueuedEventResponse, NextRunAssetsData, NextRunAssetsResponse, ListBackfillsData, ListBackfillsResponse, CreateBackfillData, CreateBackfillResponse, GetBackfillData, GetBackfillResponse, PauseBackfillData, PauseBackfillResponse, UnpauseBackfillData, UnpauseBackfillResponse, CancelBackfillData, CancelBackfillResponse, CreateBackfillDryRunData, CreateBackfillDryRunResponse, ListBackfillsUiData, ListBackfillsUiResponse, DeleteConnectionData, DeleteConnectionResponse, GetConnectionData, GetConnectionResponse, PatchConnectionData, PatchConnectionResponse, GetConnectionsData, GetConnectionsResponse, PostConnectionData, PostConnectionResponse, BulkConnectionsData, BulkConnectionsResponse, TestConnectionData, TestConnectionResponse, CreateDefaultConnectionsResponse, HookMetaDataResponse, GetDagRunData, GetDagRunResponse, DeleteDagRunData, DeleteDagRunResponse, PatchDagRunData, PatchDagRunResponse, GetUpstreamAssetEventsData, GetUpstreamAssetEventsResponse, ClearDagRunData, ClearDagRunResponse, GetDagRunsData, GetDagRunsResponse, TriggerDagRunData, TriggerDagRunResponse, GetListDagRunsBatchData, GetListDagRunsBatchResponse, GetDagSourceData, GetDagSourceResponse, GetDagStatsData, GetDagStatsResponse, GetDagReportsData, GetDagReportsResponse, GetConfigData, GetConfigResponse, GetConfigValueData, GetConfigValueResponse, GetConfigsResponse, ListDagWarningsData, ListDagWarningsResponse, GetDagsData, GetDagsResponse, PatchDagsData, PatchDagsResponse, GetDagData, GetDagResponse, PatchDagData, PatchDagResponse, DeleteDagData, DeleteDagResponse, GetDagDetailsData, GetDagDetailsResponse, GetDagTagsData, GetDagTagsResponse, GetDagsUiData, GetDagsUiResponse, GetEventLogData, GetEventLogResponse, GetEventLogsData, GetEventLogsResponse, GetExtraLinksData, GetExtraLinksResponse, GetTaskInstanceData, GetTaskInstanceResponse, PatchTaskInstanceData, PatchTaskInstanceResponse, DeleteTaskInstanceData, DeleteTaskInstanceResponse, GetMappedTaskInstancesData, GetMappedTaskInstancesResponse, GetTaskInstanceDependenciesByMapIndexData, GetTaskInstanceDependenciesByMapIndexResponse, GetTaskInstanceDependenciesData, GetTaskInstanceDependenciesResponse, GetTaskInstanceTriesData, GetTaskInstanceTriesResponse, GetMappedTaskInstanceTriesData, GetMappedTaskInstanceTriesResponse, GetMappedTaskInstanceData, GetMappedTaskInstanceResponse, PatchTaskInstanceByMapIndexData, PatchTaskInstanceByMapIndexResponse, GetTaskInstancesData, GetTaskInstancesResponse, BulkTaskInstancesData, BulkTaskInstancesResponse, GetTaskInstancesBatchData, GetTaskInstancesBatchResponse, GetTaskInstanceTryDetailsData, GetTaskInstanceTryDetailsResponse, GetMappedTaskInstanceTryDetailsData, GetMappedTaskInstanceTryDetailsResponse, PostClearTaskInstancesData, PostClearTaskInstancesResponse, PatchTaskInstanceDryRunByMapIndexData, PatchTaskInstanceDryRunByMapIndexResponse, PatchTaskInstanceDryRunData, PatchTaskInstanceDryRunResponse, GetLogData, GetLogResponse, GetExternalLogUrlData, GetExternalLogUrlResponse, GetImportErrorData, GetImportErrorResponse, GetImportErrorsData, GetImportErrorsResponse, GetJobsData, GetJobsResponse, GetPluginsData, GetPluginsResponse, ImportErrorsResponse, DeletePoolData, DeletePoolResponse, GetPoolData, GetPoolResponse, PatchPoolData, PatchPoolResponse, GetPoolsData, GetPoolsResponse, PostPoolData, PostPoolResponse, BulkPoolsData, BulkPoolsResponse, GetProvidersData, GetProvidersResponse, GetXcomEntryData, GetXcomEntryResponse, UpdateXcomEntryData, UpdateXcomEntryResponse, GetXcomEntriesData, GetXcomEntriesResponse, CreateXcomEntryData, CreateXcomEntryResponse, GetTasksData, GetTasksResponse, GetTaskData, GetTaskResponse, DeleteVariableData, DeleteVariableResponse, GetVariableData, GetVariableResponse, PatchVariableData, PatchVariableResponse, GetVariablesData, GetVariablesResponse, PostVariableData, PostVariableResponse, BulkVariablesData, BulkVariablesResponse, ReparseDagFileData, ReparseDagFileResponse, GetDagVersionData, GetDagVersionResponse, GetDagVersionsData, GetDagVersionsResponse, GetHealthResponse, GetVersionResponse, LoginData, LoginResponse, LogoutData, LogoutResponse, GetAuthMenusResponse, GetDependenciesData, GetDependenciesResponse, HistoricalMetricsData, HistoricalMetricsResponse, DagStatsResponse2, StructureDataData, StructureDataResponse2, GridDataData, GridDataResponse, GetDagStructureData, GetDagStructureResponse, GetGridRunsData, GetGridRunsResponse, GetGridTiSummariesData, GetGridTiSummariesResponse, GetLatestRunData, GetLatestRunResponse, GetCalendarData, GetCalendarResponse, FavoriteDagData, FavoriteDagResponse } from './types.gen'; export class AssetService { /** @@ -1435,6 +1435,39 @@ export class DagService { }); } + /** + * Favorite Dag + * Toggle favorite the specific DAG. + * @param data The data for the request. + * @param data.dagId + * @param data.requestBody + * @param data.updateMask + * @returns DAGResponse Successful Response + * @throws ApiError + */ + public static favoriteDag(data: FavoriteDagData): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v2/dags/{dag_id}', + path: { + dag_id: data.dagId, + }, + query: { + update_mask: data.updateMask, + }, + body: data.requestBody, + mediaType: 'application/json', + errors: { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 422: 'Validation Error' + } + }); + } + + /** * Delete Dag * Delete the specific DAG. diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts index e09579e651ca6..4dbc64fa58a41 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts @@ -546,6 +546,13 @@ export type DAGDetailsResponse = { readonly latest_dag_version: DagVersionResponse | null; }; +/** + * Dag Serializer for updatable bodies. + */ +export type DAGFavoriteBody = { + is_favorite: boolean; +}; + /** * Dag Serializer for updatable bodies. */ @@ -560,6 +567,7 @@ export type DAGResponse = { dag_id: string; dag_display_name: string; is_paused: boolean; + is_favorite?: boolean; is_stale: boolean; last_parsed_time: string | null; last_expired: string | null; @@ -1672,6 +1680,7 @@ export type DAGWithLatestDagRunsResponse = { dag_id: string; dag_display_name: string; is_paused: boolean; + is_favorite?: boolean; is_stale: boolean; last_parsed_time: string | null; last_expired: string | null; @@ -2325,6 +2334,14 @@ export type PatchDagData = { export type PatchDagResponse = DAGResponse; +export type FavoriteDagData = { + dagId: string; + requestBody: DAGFavoriteBody; + updateMask?: Array | null; +}; + +export type FavoriteDagResponse = DAGResponse; + export type DeleteDagData = { dagId: string; }; diff --git a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx index b97a921c5d4fa..2949183d39cc5 100644 --- a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx +++ b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx @@ -20,32 +20,36 @@ import { Box } from "@chakra-ui/react"; import { FiStar } from "react-icons/fi"; import ActionButton from "../ui/ActionButton"; -import { updateFavoriteDags, fetchFavoriteDags } from "src/queries/useFavoriteDag"; +import { useFavoriteDag } from "src/queries/useFavoriteDag"; +import { useCallback } from "react"; type FavoriteDagButtonProps = { readonly dagId: string; + readonly isFavorite?: boolean; readonly withText?: boolean; }; -export const FavoriteDagButton = ({ dagId, withText = true}: FavoriteDagButtonProps) => { - const { data: favorites } = fetchFavoriteDags(); - const { mutate: toggleFavorite } = updateFavoriteDags(); +export const FavoriteDagButton = ({ dagId, isFavorite, withText = true}: FavoriteDagButtonProps) => { + const { mutate: toggleFavorite } = useFavoriteDag({ dagId }); - const isCurrentFavorite = favorites?.includes(dagId) ?? false; - - const onToggle = () => { - toggleFavorite({ dagId, isFavorite: !isCurrentFavorite }); - }; + const onToggle = useCallback(() => { + toggleFavorite({ + dagId, + requestBody: { + is_favorite: !isFavorite, + }, + }); + }, [dagId, isFavorite, toggleFavorite]); return ( } + icon={} onClick={onToggle} - text={isCurrentFavorite ? "Unfavorite Dag" : "Favorite Dag"} + text={isFavorite ? "Unfavorite Dag" : "Favorite Dag"} variant="solid" withText={withText} /> diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx index 221a3a872ba59..adea2fcacaba0 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx @@ -63,7 +63,7 @@ export const DagCard = ({ dag }: Props) => { pr={2} /> - + diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx index ce0dea6e85281..8a59ca1dbe250 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx @@ -136,7 +136,11 @@ const createColumns = ( { accessorKey: "favorite", cell: ({ row: { original } }) => ( - + ), enableSorting: false, header: "", diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx index eea9a1a58ec50..f717504d987e6 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx @@ -19,11 +19,12 @@ import { Box, Flex, Heading, HStack } from "@chakra-ui/react"; import { FiStar } from "react-icons/fi"; import { FavoriteDagCard } from "./FavoriteDagCard"; -import { fetchFavoriteDags } from "src/queries/useFavoriteDag"; +import { useDagServiceGetDags } from "openapi/queries"; export const FavoriteDags = () => { - const { data: favorites } = fetchFavoriteDags(); + const { data: allDags } = useDagServiceGetDags(); + const favorites = allDags?.dags?.filter((dag) => dag.is_favorite) ?? []; return ( @@ -34,8 +35,8 @@ export const FavoriteDags = () => { - {favorites.map((dag_id) => ( - + {favorites.map((dag) => ( + ))} diff --git a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts index 6ed9c460e4eea..f721c971455fd 100644 --- a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts +++ b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts @@ -16,41 +16,35 @@ * specific language governing permissions and limitations * under the License. */ -import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; +import { useQueryClient } from "@tanstack/react-query"; -const FAVORITES_KEY = "favoriteDags"; +import { + UseDagRunServiceGetDagRunsKeyFn, + UseDagServiceGetDagDetailsKeyFn, + UseDagServiceGetDagKeyFn, + useDagServiceGetDagsKey, + useDagServiceFavoriteDag, + useDagsServiceRecentDagRunsKey, + UseTaskInstanceServiceGetTaskInstancesKeyFn, +} from "openapi/queries"; -const getFavoriteDags = (): string[] => { - const favorites = localStorage.getItem(FAVORITES_KEY); - return favorites ? JSON.parse(favorites) : []; -}; - -const setFavoriteDags = (favorites: string[]) => { - localStorage.setItem(FAVORITES_KEY, JSON.stringify(favorites)); -}; +export const useFavoriteDag = ({ dagId }: { dagId: string }) => { + const queryClient = useQueryClient(); -export const fetchFavoriteDags = () => { - return useQuery({ - queryKey: [FAVORITES_KEY], - queryFn: () => Promise.resolve(getFavoriteDags()), - initialData: [], - }); -}; + const onSuccess = async () => { + const queryKeys = [ + [useDagServiceGetDagsKey], + [useDagsServiceRecentDagRunsKey], + UseDagServiceGetDagKeyFn({ dagId }, [{ dagId }]), + UseDagServiceGetDagDetailsKeyFn({ dagId }, [{ dagId }]), + UseDagRunServiceGetDagRunsKeyFn({ dagId }, [{ dagId }]), + UseTaskInstanceServiceGetTaskInstancesKeyFn({ dagId, dagRunId: "~" }, [{ dagId, dagRunId: "~" }]), + ]; -export const updateFavoriteDags = () => { - const queryClient = useQueryClient(); + await Promise.all(queryKeys.map((key) => queryClient.invalidateQueries({ queryKey: key }))); + }; - return useMutation({ - mutationFn: ({ dagId, isFavorite }: { dagId: string; isFavorite: boolean }) => { - const current = getFavoriteDags(); - const updated = isFavorite - ? [...new Set([...current, dagId])] - : current.filter((id) => id !== dagId); - setFavoriteDags(updated); - return Promise.resolve(updated); - }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["favoriteDags"] }); - }, + return useDagServiceFavoriteDag({ + onSuccess, }); }; \ No newline at end of file From 56c5ee91c667278466ebc996a1bcb6ad74997a90 Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Sat, 26 Apr 2025 17:46:55 +0100 Subject: [PATCH 03/18] Implement unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana --- .../core_api/routes/public/test_dags.py | 33 +++++++++++++++++++ airflow-core/tests/unit/models/test_dag.py | 14 ++++++++ 2 files changed, 47 insertions(+) diff --git a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py index 4af37668482d1..e388abe00b304 100644 --- a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py +++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py @@ -391,6 +391,39 @@ def test_patch_dags_should_response_403(self, unauthorized_test_client): response = unauthorized_test_client.patch("/dags", json={"is_paused": True}) assert response.status_code == 403 +class TestFavoriteDag(TestDagEndpoint): + """Unit tests for Favorite DAG.""" + + @pytest.mark.parametrize( + "query_params, dag_id, body, expected_status_code, expected_is_favorite", + [ + ({}, "fake_dag_id", {"is_favorite": True}, 404, None), + ({"update_mask": ["field_1", "is_favorite"]}, DAG1_ID, {"is_favorite": True}, 400, None), + ({}, DAG1_ID, {"is_favorite": True}, 200, True), + ({}, DAG1_ID, {"is_favorite": False}, 200, False), + ({"update_mask": ["is_favorite"]}, DAG1_ID, {"is_favorite": True}, 200, True), + ({"update_mask": ["is_favorite"]}, DAG1_ID, {"is_favorite": False}, 200, False), + ], + ) + def test_favorite_dag( + self, test_client, query_params, dag_id, body, expected_status_code, expected_is_favorite, session + ): + response = test_client.put(f"/dags/{dag_id}", json=body, params=query_params) + + assert response.status_code == expected_status_code + if expected_status_code == 200: + body = response.json() + assert body["is_favorite"] == expected_is_favorite + check_last_log(session, dag_id=dag_id, event="favorite_dag", logical_date=None) + + def test_favorite_dag_should_response_401(self, unauthenticated_test_client): + response = unauthenticated_test_client.put(f"/dags/{DAG1_ID}", json={"is_favorite": True}) + assert response.status_code == 401 + + def test_favorite_dag_should_response_403(self, unauthorized_test_client): + response = unauthorized_test_client.put(f"/dags/{DAG1_ID}", json={"is_favorite": True}) + assert response.status_code == 403 + class TestDagDetails(TestDagEndpoint): """Unit tests for DAG Details.""" diff --git a/airflow-core/tests/unit/models/test_dag.py b/airflow-core/tests/unit/models/test_dag.py index a173d7ec50f17..486a5a31ffcce 100644 --- a/airflow-core/tests/unit/models/test_dag.py +++ b/airflow-core/tests/unit/models/test_dag.py @@ -1256,6 +1256,20 @@ def test_get_paused_dag_ids(self): with create_session() as session: session.query(DagModel).filter(DagModel.dag_id == dag_id).delete(synchronize_session=False) + def test_get_favorite_dag_ids(self): + dag_id = "test_get_favorite_dag_ids" + dag = DAG(dag_id, schedule=None) + dag.sync_to_db() + dagModel = DagModel.get_dagmodel(dag_id) + assert dagModel is not None + + dagModel.set_is_favorite(True) + favorite_dag_ids = DagModel.get_favorite_dag_ids([dag_id]) + assert favorite_dag_ids == {dag_id} + + with create_session() as session: + session.query(DagModel).filter(DagModel.dag_id == dag_id).delete(synchronize_session=False) + @pytest.mark.parametrize( "schedule_arg, expected_timetable, interval_description", [ From 4ccddbe67d752e4fecda03886c388e754ed79286 Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Sat, 10 May 2025 21:58:12 +0100 Subject: [PATCH 04/18] Add support for favorite/pin dags to dashboard. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The favorited DAGs by an user, are stored persistently in the database. Co-authored-by: Mariana Isabel Marçal Santana --- .../api_fastapi/core_api/datamodels/dags.py | 2 +- .../openapi/v2-rest-api-generated.yaml | 91 +++++ .../core_api/routes/public/dags.py | 65 +-- airflow-core/src/airflow/models/__init__.py | 2 + airflow-core/src/airflow/models/dag.py | 53 --- .../src/airflow/models/dag_favorite.py | 29 ++ .../airflow/ui/openapi-gen/queries/common.ts | 12 +- .../ui/openapi-gen/queries/ensureQueryData.ts | 11 + .../ui/openapi-gen/queries/prefetch.ts | 11 + .../airflow/ui/openapi-gen/queries/queries.ts | 104 ++--- .../ui/openapi-gen/queries/suspense.ts | 19 + .../ui/openapi-gen/requests/schemas.gen.ts | 14 + .../ui/openapi-gen/requests/services.gen.ts | 381 +++++++++--------- .../ui/openapi-gen/requests/types.gen.ts | 50 ++- .../DagActions/FavoriteDagButton.tsx | 38 +- .../airflow/ui/src/pages/DagsList/DagCard.tsx | 4 +- .../ui/src/pages/DagsList/DagsList.tsx | 8 +- .../ui/src/pages/Dashboard/Dashboard.tsx | 2 +- .../FavoriteDags/FavoriteDagCard.tsx | 33 +- .../Dashboard/FavoriteDags/FavoriteDags.tsx | 69 +++- .../src/pages/Dashboard/FavoriteDags/index.ts | 2 +- .../airflow/ui/src/queries/useFavoriteDag.ts | 2 +- .../core_api/routes/public/test_dags.py | 77 +++- airflow-core/tests/unit/models/test_dag.py | 14 - .../airflowctl/api/datamodels/generated.py | 11 + 25 files changed, 707 insertions(+), 397 deletions(-) create mode 100644 airflow-core/src/airflow/models/dag_favorite.py diff --git a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py index ac8dbcda49bb2..1dfdff27196a2 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dags.py @@ -60,7 +60,6 @@ class DAGResponse(BaseModel): dag_id: str dag_display_name: str is_paused: bool - is_favorite: bool | None is_stale: bool last_parsed_time: datetime | None last_expired: datetime | None @@ -123,6 +122,7 @@ class DAGPatchBody(StrictBaseModel): is_paused: bool + class DAGFavoriteBody(StrictBaseModel): """Dag Serializer for updatable bodies.""" diff --git a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml index 9a47eba0c10a2..4d3fc06d1d045 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml +++ b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml @@ -2607,6 +2607,34 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' + /api/v2/dags/favorite: + get: + tags: + - DAG + summary: Get Favorite Dags + description: Get DAGs favorited by the user. + operationId: get_favorite_dags + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/DAGCollectionResponse' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + security: + - OAuth2PasswordBearer: [] /api/v2/dags: get: tags: @@ -3036,6 +3064,58 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' + put: + tags: + - DAG + summary: Favorite Dag + description: Favorite the specific DAG. + operationId: favorite_dag + security: + - OAuth2PasswordBearer: [] + parameters: + - name: dag_id + in: path + required: true + schema: + type: string + title: Dag Id + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/DAGFavoriteBody' + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/DAGResponse' + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Not Found + '422': + description: Validation Error + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' delete: tags: - DAG @@ -8382,6 +8462,17 @@ components: - latest_dag_version title: DAGDetailsResponse description: Specific serializer for DAG Details responses. + DAGFavoriteBody: + properties: + is_favorite: + type: boolean + title: Is Favorite + additionalProperties: false + type: object + required: + - is_favorite + title: DAGFavoriteBody + description: Dag Serializer for updatable bodies. DAGPatchBody: properties: is_paused: diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py index 7e1bf8c69a80c..b69ec0400f9ad 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py @@ -22,7 +22,7 @@ from fastapi import Depends, HTTPException, Query, Response, status from fastapi.exceptions import RequestValidationError from pydantic import ValidationError -from sqlalchemy import select, update +from sqlalchemy import delete, insert, select, update from airflow.api.common import delete_dag as delete_dag_module from airflow.api_fastapi.common.dagbag import DagBagDep @@ -54,24 +54,45 @@ from airflow.api_fastapi.core_api.datamodels.dags import ( DAGCollectionResponse, DAGDetailsResponse, - DAGPatchBody, DAGFavoriteBody, + DAGPatchBody, DAGResponse, ) from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc from airflow.api_fastapi.core_api.security import ( EditableDagsFilterDep, + GetUserDep, ReadableDagsFilterDep, requires_access_dag, ) from airflow.api_fastapi.logging.decorators import action_logging from airflow.exceptions import AirflowException, DagNotFound from airflow.models import DAG, DagModel +from airflow.models.dag_favorite import DagFavorite from airflow.models.dagrun import DagRun dags_router = AirflowRouter(tags=["DAG"], prefix="/dags") +@dags_router.get("/favorite", dependencies=[Depends(requires_access_dag(method="GET"))]) +def get_favorite_dags(session: SessionDep, user: GetUserDep) -> DAGCollectionResponse: + """Get DAGs favorited by the user.""" + user_id = user.get_id() + + favorite_dags_query = ( + select(DagModel) + .join(DagFavorite, DagModel.dag_id == DagFavorite.dag_id) + .where(DagFavorite.user_id == user_id) + ) + + dags = session.scalars(favorite_dags_query).all() + + return DAGCollectionResponse( + dags=dags, + total_entries=len(dags), + ) + + @dags_router.get("", dependencies=[Depends(requires_access_dag(method="GET"))]) def get_dags( limit: QueryLimit, @@ -317,47 +338,39 @@ def patch_dags( total_entries=total_entries, ) + @dags_router.put( "/{dag_id}", - responses=create_openapi_http_exception_doc( - [ - status.HTTP_400_BAD_REQUEST, - status.HTTP_404_NOT_FOUND, - ] - ), + responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]), dependencies=[Depends(requires_access_dag(method="PUT")), Depends(action_logging())], ) def favorite_dag( dag_id: str, favorite_body: DAGFavoriteBody, session: SessionDep, - update_mask: list[str] | None = Query(None), + user: GetUserDep, ) -> DAGResponse: """Favorite the specific DAG.""" dag = session.get(DagModel, dag_id) + if not dag: + raise HTTPException(status.HTTP_404_NOT_FOUND, detail=f"DAG with id '{dag_id}' not found") - if dag is None: - raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id: {dag_id} was not found") + user_id = user.get_id() - fields_to_update = favorite_body.model_fields_set - if update_mask: - if update_mask != ["is_favorite"]: - raise HTTPException( - status.HTTP_400_BAD_REQUEST, "Only `is_favorite` field can be updated through the REST API" - ) - fields_to_update = fields_to_update.intersection(update_mask) + if favorite_body.is_favorite: + session.execute(insert(DagFavorite).values(dag_id=dag_id, user_id=user_id)) else: - try: - DAGFavoriteBody(**favorite_body.model_dump()) - except ValidationError as e: - raise RequestValidationError(errors=e.errors()) + session.execute( + delete(DagFavorite).where( + DagFavorite.dag_id == dag_id, + DagFavorite.user_id == user_id, + ) + ) - data = favorite_body.model_dump(include=fields_to_update, by_alias=True) + session.commit() - for key, val in data.items(): - setattr(dag, key, val) + return DAGResponse.model_validate(dag) - return dag @dags_router.delete( "/{dag_id}", diff --git a/airflow-core/src/airflow/models/__init__.py b/airflow-core/src/airflow/models/__init__.py index b28c3f2b0639a..7078de158cbaa 100644 --- a/airflow-core/src/airflow/models/__init__.py +++ b/airflow-core/src/airflow/models/__init__.py @@ -99,6 +99,7 @@ def __getattr__(name): "DagRun": "airflow.models.dagrun", "DagTag": "airflow.models.dag", "DagWarning": "airflow.models.dagwarning", + "DagFavorite": "airflow.models.dag_favorite", "DbCallbackRequest": "airflow.models.db_callback_request", "Deadline": "airflow.models.deadline", "Log": "airflow.models.log", @@ -123,6 +124,7 @@ def __getattr__(name): from airflow.models.baseoperator import BaseOperator from airflow.models.connection import Connection from airflow.models.dag import DAG, DagModel, DagTag + from airflow.models.dag_favorite import DagFavorite from airflow.models.dagbag import DagBag from airflow.models.dagrun import DagRun from airflow.models.dagwarning import DagWarning diff --git a/airflow-core/src/airflow/models/dag.py b/airflow-core/src/airflow/models/dag.py index 7a2f08b5196da..0332a2e825e24 100644 --- a/airflow-core/src/airflow/models/dag.py +++ b/airflow-core/src/airflow/models/dag.py @@ -743,11 +743,6 @@ def get_is_stale(self, session=NEW_SESSION) -> None: def get_is_paused(self, session=NEW_SESSION) -> None: """Return a boolean indicating whether this DAG is paused.""" return session.scalar(select(DagModel.is_paused).where(DagModel.dag_id == self.dag_id)) - - @provide_session - def get_is_favorite(self, session=NEW_SESSION) -> None: - """Return a boolean indicating whether this DAG is favorited.""" - return session.scalar(select(DagModel.is_favorite).where(DagModel.dag_id == self.dag_id)) @provide_session def get_bundle_name(self, session=NEW_SESSION) -> str | None: @@ -1879,8 +1874,6 @@ class DagModel(Base): # Set this default value of is_paused based on a configuration value! is_paused_at_creation = airflow_conf.getboolean("core", "dags_are_paused_at_creation") is_paused = Column(Boolean, default=is_paused_at_creation) - # Whether the DAG is favorited - is_favorite = Column(Boolean, default=False) # Whether that DAG was seen on the last DagBag load is_stale = Column(Boolean, default=True) # Last time the scheduler started @@ -2044,12 +2037,7 @@ def get_last_dagrun(self, session=NEW_SESSION, include_manually_triggered=False) def get_is_paused(self, *, session: Session | None = None) -> bool: """Provide interface compatibility to 'DAG'.""" return self.is_paused - - def get_is_favorite(self, *, session: Session | None = None) -> bool: - """Provide interface compatibility to 'DAG'.""" - return self.is_favorite - def get_is_active(self, *, session: Session | None = None) -> bool: """Provide interface compatibility to 'DAG'.""" return not self.is_stale @@ -2072,26 +2060,6 @@ def get_paused_dag_ids(dag_ids: list[str], session: Session = NEW_SESSION) -> se paused_dag_ids = {paused_dag_id for (paused_dag_id,) in paused_dag_ids} return paused_dag_ids - - @staticmethod - @provide_session - def get_favorite_dag_ids(dag_ids: list[str], session: Session = NEW_SESSION) -> set[str]: - """ - Given a list of dag_ids, get a set of Favorited Dag Ids. - - :param dag_ids: List of Dag ids - :param session: ORM Session - :return: Favorited Dag_ids - """ - favorited_dag_ids = session.execute( - select(DagModel.dag_id) - .where(DagModel.is_favorite == expression.true()) - .where(DagModel.dag_id.in_(dag_ids)) - ) - - favorited_dag_ids = {favorited_dag_id for (favorited_dag_id,) in favorited_dag_ids} - return favorited_dag_ids - @property def safe_dag_id(self): @@ -2117,27 +2085,6 @@ def set_is_paused(self, is_paused: bool, session=NEW_SESSION) -> None: ) session.commit() - @provide_session - def set_is_favorite(self, is_favorite: bool, session=NEW_SESSION) -> None: - """ - Favorite/Unfavorite a DAG. - - :param is_favorite: Is the DAG favorited - :param session: session - """ - filter_query = [ - DagModel.dag_id == self.dag_id, - ] - - session.execute( - update(DagModel) - .where(or_(*filter_query)) - .values(is_favorite=is_favorite) - .execution_options(synchronize_session="fetch") - ) - session.commit() - - @hybrid_property def dag_display_name(self) -> str: return self._dag_display_property_value or self.dag_id diff --git a/airflow-core/src/airflow/models/dag_favorite.py b/airflow-core/src/airflow/models/dag_favorite.py new file mode 100644 index 0000000000000..d3df57431401f --- /dev/null +++ b/airflow-core/src/airflow/models/dag_favorite.py @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from sqlalchemy import Column, ForeignKey, String + +from airflow.models.base import Base + + +class DagFavorite(Base): + __tablename__ = "dag_favorite" + + user_id = Column(String, primary_key=True) + dag_id = Column(ForeignKey("dag.dag_id", ondelete="CASCADE"), primary_key=True) diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts index 6eccd51177ec0..92c0bd45572b8 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts @@ -207,6 +207,16 @@ export const UseDagWarningServiceListDagWarningsKeyFn = ({ dagId, limit, offset, orderBy?: string; warningType?: DagWarningType; } = {}, queryKey?: Array) => [useDagWarningServiceListDagWarningsKey, ...(queryKey ?? [{ dagId, limit, offset, orderBy, warningType }])]; +export type DagServiceGetFavoriteDagsDefaultResponse = Awaited>; +export type DagServiceGetFavoriteDagsQueryResult< + TData = DagServiceGetFavoriteDagsDefaultResponse, + TError = unknown, +> = UseQueryResult; +export const useDagServiceGetFavoriteDagsKey = "DagServiceGetFavoriteDags"; +export const UseDagServiceGetFavoriteDagsKeyFn = (queryKey?: Array) => [ + useDagServiceGetFavoriteDagsKey, + ...(queryKey ?? []), +]; export type DagServiceGetDagsDefaultResponse = Awaited>; export type DagServiceGetDagsQueryResult = UseQueryResult; export const useDagServiceGetDagsKey = "DagServiceGetDags"; @@ -731,13 +741,13 @@ export type VariableServicePostVariableMutationResult = Awaited>; export type BackfillServiceUnpauseBackfillMutationResult = Awaited>; export type BackfillServiceCancelBackfillMutationResult = Awaited>; +export type DagServiceFavoriteDagMutationResult = Awaited>; export type DagParsingServiceReparseDagFileMutationResult = Awaited>; export type ConnectionServicePatchConnectionMutationResult = Awaited>; export type ConnectionServiceBulkConnectionsMutationResult = Awaited>; export type DagRunServicePatchDagRunMutationResult = Awaited>; export type DagServicePatchDagsMutationResult = Awaited>; export type DagServicePatchDagMutationResult = Awaited>; -export type DagServiceFavoriteDagMutationResult = Awaited>; export type TaskInstanceServicePatchTaskInstanceMutationResult = Awaited>; export type TaskInstanceServicePatchTaskInstanceByMapIndexMutationResult = Awaited>; export type TaskInstanceServiceBulkTaskInstancesMutationResult = Awaited>; diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts index bea49000ad73c..f610a988a44d6 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts @@ -382,6 +382,17 @@ export const ensureUseDagWarningServiceListDagWarningsData = (queryClient: Query orderBy?: string; warningType?: DagWarningType; } = {}) => queryClient.ensureQueryData({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) }); +/** + * Get Favorite Dags + * Get DAGs favorited by the user. + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ +export const ensureUseDagServiceGetFavoriteDagsData = (queryClient: QueryClient) => + queryClient.ensureQueryData({ + queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(), + queryFn: () => DagService.getFavoriteDags(), + }); /** * Get Dags * Get all DAGs. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts index 67dcf913da5c3..21ddf53097eda 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts @@ -382,6 +382,17 @@ export const prefetchUseDagWarningServiceListDagWarnings = (queryClient: QueryCl orderBy?: string; warningType?: DagWarningType; } = {}) => queryClient.prefetchQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) }); +/** + * Get Favorite Dags + * Get DAGs favorited by the user. + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ +export const prefetchUseDagServiceGetFavoriteDags = (queryClient: QueryClient) => + queryClient.prefetchQuery({ + queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(), + queryFn: () => DagService.getFavoriteDags(), + }); /** * Get Dags * Get all DAGs. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts index 37daa0051b1cc..c9da7770f5511 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts @@ -440,6 +440,25 @@ export const useDagWarningServiceListDagWarnings = , "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }, queryKey), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) as TData, ...options }); +/** + * Get Favorite Dags + * Get DAGs favorited by the user. + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ +export const useDagServiceGetFavoriteDags = < + TData = Common.DagServiceGetFavoriteDagsDefaultResponse, + TError = unknown, + TQueryKey extends Array = unknown[], +>( + queryKey?: TQueryKey, + options?: Omit, "queryKey" | "queryFn">, +) => + useQuery({ + queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(queryKey), + queryFn: () => DagService.getFavoriteDags() as TData, + ...options, + }); /** * Get Dags * Get all DAGs. @@ -1669,6 +1688,46 @@ export const useBackfillServiceCancelBackfill = , "mutationFn">) => useMutation({ mutationFn: ({ backfillId }) => BackfillService.cancelBackfill({ backfillId }) as unknown as Promise, ...options }); +/** + * Favorite Dag + * Favorite the specific DAG. + * @param data The data for the request. + * @param data.dagId + * @param data.requestBody + * @returns DAGResponse Successful Response + * @throws ApiError + */ +export const useDagServiceFavoriteDag = < + TData = Common.DagServiceFavoriteDagMutationResult, + TError = unknown, + TContext = unknown, +>( + options?: Omit< + UseMutationOptions< + TData, + TError, + { + dagId: string; + requestBody: DAGFavoriteBody; + }, + TContext + >, + "mutationFn" + >, +) => + useMutation< + TData, + TError, + { + dagId: string; + requestBody: DAGFavoriteBody; + }, + TContext + >({ + mutationFn: ({ dagId, requestBody }) => + DagService.favoriteDag({ dagId, requestBody }) as unknown as Promise, + ...options, + }); /** * Reparse Dag File * Request re-parsing a DAG file. @@ -1795,51 +1854,6 @@ export const useDagServicePatchDag = ({ mutationFn: ({ dagId, requestBody, updateMask }) => DagService.patchDag({ dagId, requestBody, updateMask }) as unknown as Promise, ...options }); - -/** - * Favorite Dag - * Toggle favorite the specific DAG. - * @param data The data for the request. - * @param data.dagId - * @param data.requestBody - * @param data.updateMask - * @returns DAGResponse Successful Response - * @throws ApiError - */ -export const useDagServiceFavoriteDag = < - TData = Common.DagServiceFavoriteDagMutationResult, - TError = unknown, - TContext = unknown, ->( - options?: Omit< - UseMutationOptions< - TData, - TError, - { - dagId: string; - requestBody: DAGFavoriteBody; - updateMask?: string[]; - }, - TContext - >, - "mutationFn" - >, -) => - useMutation< - TData, - TError, - { - dagId: string; - requestBody: DAGFavoriteBody; - updateMask?: string[]; - }, - TContext - >({ - mutationFn: ({ dagId, requestBody, updateMask }) => - DagService.favoriteDag({ dagId, requestBody, updateMask }) as unknown as Promise, - ...options, - }); - /** * Patch Task Instance * Update a task instance. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts index beb1362751f87..66bb2b598b5f9 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts @@ -382,6 +382,25 @@ export const useDagWarningServiceListDagWarningsSuspense = , "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }, queryKey), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) as TData, ...options }); +/** + * Get Favorite Dags + * Get DAGs favorited by the user. + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ +export const useDagServiceGetFavoriteDagsSuspense = < + TData = Common.DagServiceGetFavoriteDagsDefaultResponse, + TError = unknown, + TQueryKey extends Array = unknown[], +>( + queryKey?: TQueryKey, + options?: Omit, "queryKey" | "queryFn">, +) => + useSuspenseQuery({ + queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(queryKey), + queryFn: () => DagService.getFavoriteDags() as TData, + ...options, + }); /** * Get Dags * Get all DAGs. diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts index 8efd3e111efb1..a14818384d58c 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts @@ -1952,6 +1952,20 @@ export const $DAGDetailsResponse = { description: 'Specific serializer for DAG Details responses.' } as const; +export const $DAGFavoriteBody = { + properties: { + is_favorite: { + type: "boolean", + title: "Is Favorite", + }, + }, + additionalProperties: false, + type: "object", + required: ["is_favorite"], + title: "DAGFavoriteBody", + description: "Dag Serializer for updatable bodies.", +} as const; + export const $DAGPatchBody = { properties: { is_paused: { diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts index 619719037d815..5685dbc1fb557 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts @@ -1281,192 +1281,203 @@ export class DagWarningService { } export class DagService { - /** - * Get Dags - * Get all DAGs. - * @param data The data for the request. - * @param data.limit - * @param data.offset - * @param data.tags - * @param data.tagsMatchMode - * @param data.owners - * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. - * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. - * @param data.excludeStale - * @param data.paused - * @param data.lastDagRunState - * @param data.dagRunStartDateGte - * @param data.dagRunStartDateLte - * @param data.dagRunEndDateGte - * @param data.dagRunEndDateLte - * @param data.dagRunState - * @param data.orderBy - * @returns DAGCollectionResponse Successful Response - * @throws ApiError - */ - public static getDags(data: GetDagsData = {}): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v2/dags', - query: { - limit: data.limit, - offset: data.offset, - tags: data.tags, - tags_match_mode: data.tagsMatchMode, - owners: data.owners, - dag_id_pattern: data.dagIdPattern, - dag_display_name_pattern: data.dagDisplayNamePattern, - exclude_stale: data.excludeStale, - paused: data.paused, - last_dag_run_state: data.lastDagRunState, - dag_run_start_date_gte: data.dagRunStartDateGte, - dag_run_start_date_lte: data.dagRunStartDateLte, - dag_run_end_date_gte: data.dagRunEndDateGte, - dag_run_end_date_lte: data.dagRunEndDateLte, - dag_run_state: data.dagRunState, - order_by: data.orderBy - }, - errors: { - 401: 'Unauthorized', - 403: 'Forbidden', - 422: 'Validation Error' - } - }); - } - - /** - * Patch Dags - * Patch multiple DAGs. - * @param data The data for the request. - * @param data.requestBody - * @param data.updateMask - * @param data.limit - * @param data.offset - * @param data.tags - * @param data.tagsMatchMode - * @param data.owners - * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. - * @param data.excludeStale - * @param data.paused - * @returns DAGCollectionResponse Successful Response - * @throws ApiError - */ - public static patchDags(data: PatchDagsData): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v2/dags', - query: { - update_mask: data.updateMask, - limit: data.limit, - offset: data.offset, - tags: data.tags, - tags_match_mode: data.tagsMatchMode, - owners: data.owners, - dag_id_pattern: data.dagIdPattern, - exclude_stale: data.excludeStale, - paused: data.paused - }, - body: data.requestBody, - mediaType: 'application/json', - errors: { - 400: 'Bad Request', - 401: 'Unauthorized', - 403: 'Forbidden', - 404: 'Not Found', - 422: 'Validation Error' - } - }); - } - - /** - * Get Dag - * Get basic information about a DAG. - * @param data The data for the request. - * @param data.dagId - * @returns DAGResponse Successful Response - * @throws ApiError - */ - public static getDag(data: GetDagData): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v2/dags/{dag_id}', - path: { - dag_id: data.dagId - }, - errors: { - 400: 'Bad Request', - 401: 'Unauthorized', - 403: 'Forbidden', - 404: 'Not Found', - 422: 'Unprocessable Entity' - } - }); - } - - /** - * Patch Dag - * Patch the specific DAG. - * @param data The data for the request. - * @param data.dagId - * @param data.requestBody - * @param data.updateMask - * @returns DAGResponse Successful Response - * @throws ApiError - */ - public static patchDag(data: PatchDagData): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v2/dags/{dag_id}', - path: { - dag_id: data.dagId - }, - query: { - update_mask: data.updateMask - }, - body: data.requestBody, - mediaType: 'application/json', - errors: { - 400: 'Bad Request', - 401: 'Unauthorized', - 403: 'Forbidden', - 404: 'Not Found', - 422: 'Validation Error' - } - }); - } - - /** - * Favorite Dag - * Toggle favorite the specific DAG. - * @param data The data for the request. - * @param data.dagId - * @param data.requestBody - * @param data.updateMask - * @returns DAGResponse Successful Response - * @throws ApiError - */ - public static favoriteDag(data: FavoriteDagData): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v2/dags/{dag_id}', - path: { - dag_id: data.dagId, - }, - query: { - update_mask: data.updateMask, - }, - body: data.requestBody, - mediaType: 'application/json', - errors: { - 400: 'Bad Request', - 401: 'Unauthorized', - 403: 'Forbidden', - 404: 'Not Found', - 422: 'Validation Error' - } - }); - } + /** + * Get Favorite Dags + * Get DAGs favorited by the user. + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ + public static getFavoriteDags(): CancelablePromise { + return __request(OpenAPI, { + method: "GET", + url: "/api/v2/dags/favorite", + errors: { + 401: "Unauthorized", + 403: "Forbidden", + }, + }); + } + + /** + * Get Dags + * Get all DAGs. + * @param data The data for the request. + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @param data.lastDagRunState + * @param data.dagRunStartDateGte + * @param data.dagRunStartDateLte + * @param data.dagRunEndDateGte + * @param data.dagRunEndDateLte + * @param data.dagRunState + * @param data.orderBy + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ + public static getDags(data: GetDagsData = {}): CancelablePromise { + return __request(OpenAPI, { + method: "GET", + url: "/api/v2/dags", + query: { + limit: data.limit, + offset: data.offset, + tags: data.tags, + tags_match_mode: data.tagsMatchMode, + owners: data.owners, + dag_id_pattern: data.dagIdPattern, + dag_display_name_pattern: data.dagDisplayNamePattern, + exclude_stale: data.excludeStale, + paused: data.paused, + last_dag_run_state: data.lastDagRunState, + dag_run_start_date_gte: data.dagRunStartDateGte, + dag_run_start_date_lte: data.dagRunStartDateLte, + dag_run_end_date_gte: data.dagRunEndDateGte, + dag_run_end_date_lte: data.dagRunEndDateLte, + dag_run_state: data.dagRunState, + order_by: data.orderBy, + }, + errors: { + 401: "Unauthorized", + 403: "Forbidden", + 422: "Validation Error", + }, + }); + } + + /** + * Patch Dags + * Patch multiple DAGs. + * @param data The data for the request. + * @param data.requestBody + * @param data.updateMask + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @returns DAGCollectionResponse Successful Response + * @throws ApiError + */ + public static patchDags(data: PatchDagsData): CancelablePromise { + return __request(OpenAPI, { + method: "PATCH", + url: "/api/v2/dags", + query: { + update_mask: data.updateMask, + limit: data.limit, + offset: data.offset, + tags: data.tags, + tags_match_mode: data.tagsMatchMode, + owners: data.owners, + dag_id_pattern: data.dagIdPattern, + exclude_stale: data.excludeStale, + paused: data.paused, + }, + body: data.requestBody, + mediaType: "application/json", + errors: { + 400: "Bad Request", + 401: "Unauthorized", + 403: "Forbidden", + 404: "Not Found", + 422: "Validation Error", + }, + }); + } + + /** + * Get Dag + * Get basic information about a DAG. + * @param data The data for the request. + * @param data.dagId + * @returns DAGResponse Successful Response + * @throws ApiError + */ + public static getDag(data: GetDagData): CancelablePromise { + return __request(OpenAPI, { + method: "GET", + url: "/api/v2/dags/{dag_id}", + path: { + dag_id: data.dagId, + }, + errors: { + 400: "Bad Request", + 401: "Unauthorized", + 403: "Forbidden", + 404: "Not Found", + 422: "Unprocessable Entity", + }, + }); + } + + /** + * Patch Dag + * Patch the specific DAG. + * @param data The data for the request. + * @param data.dagId + * @param data.requestBody + * @param data.updateMask + * @returns DAGResponse Successful Response + * @throws ApiError + */ + public static patchDag(data: PatchDagData): CancelablePromise { + return __request(OpenAPI, { + method: "PATCH", + url: "/api/v2/dags/{dag_id}", + path: { + dag_id: data.dagId, + }, + query: { + update_mask: data.updateMask, + }, + body: data.requestBody, + mediaType: "application/json", + errors: { + 400: "Bad Request", + 401: "Unauthorized", + 403: "Forbidden", + 404: "Not Found", + 422: "Validation Error", + }, + }); + } + /** + * Favorite Dag + * Favorite the specific DAG. + * @param data The data for the request. + * @param data.dagId + * @param data.requestBody + * @returns DAGResponse Successful Response + * @throws ApiError + */ + public static favoriteDag(data: FavoriteDagData): CancelablePromise { + return __request(OpenAPI, { + method: "PUT", + url: "/api/v2/dags/{dag_id}", + path: { + dag_id: data.dagId, + }, + body: data.requestBody, + mediaType: "application/json", + errors: { + 401: "Unauthorized", + 403: "Forbidden", + 404: "Not Found", + 422: "Validation Error", + }, + }); + } /** * Delete Dag diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts index 4dbc64fa58a41..b82c9e6ad90f7 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts @@ -567,7 +567,6 @@ export type DAGResponse = { dag_id: string; dag_display_name: string; is_paused: boolean; - is_favorite?: boolean; is_stale: boolean; last_parsed_time: string | null; last_expired: string | null; @@ -1680,7 +1679,6 @@ export type DAGWithLatestDagRunsResponse = { dag_id: string; dag_display_name: string; is_paused: boolean; - is_favorite?: boolean; is_stale: boolean; last_parsed_time: string | null; last_expired: string | null; @@ -2275,6 +2273,8 @@ export type ListDagWarningsData = { export type ListDagWarningsResponse = DAGWarningCollectionResponse; +export type GetFavoriteDagsResponse = DAGCollectionResponse; + export type GetDagsData = { /** * SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. @@ -2337,7 +2337,6 @@ export type PatchDagResponse = DAGResponse; export type FavoriteDagData = { dagId: string; requestBody: DAGFavoriteBody; - updateMask?: Array | null; }; export type FavoriteDagResponse = DAGResponse; @@ -4197,6 +4196,24 @@ export type $OpenApiTs = { }; }; }; + "/api/v2/dags/favorite": { + get: { + res: { + /** + * Successful Response + */ + 200: DAGCollectionResponse; + /** + * Unauthorized + */ + 401: HTTPExceptionResponse; + /** + * Forbidden + */ + 403: HTTPExceptionResponse; + }; + }; + }; '/api/v2/dags': { get: { req: GetDagsData; @@ -4308,7 +4325,32 @@ export type $OpenApiTs = { 422: HTTPValidationError; }; }; - delete: { + put: { + req: FavoriteDagData; + res: { + /** + * Successful Response + */ + 200: DAGResponse; + /** + * Unauthorized + */ + 401: HTTPExceptionResponse; + /** + * Forbidden + */ + 403: HTTPExceptionResponse; + /** + * Not Found + */ + 404: HTTPExceptionResponse; + /** + * Validation Error + */ + 422: HTTPValidationError; + }; + }; + delete: { req: DeleteDagData; res: { /** diff --git a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx index 2949183d39cc5..093ac3396b242 100644 --- a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx +++ b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx @@ -17,37 +17,51 @@ * under the License. */ import { Box } from "@chakra-ui/react"; +import { useCallback, useMemo } from "react"; import { FiStar } from "react-icons/fi"; -import ActionButton from "../ui/ActionButton"; +import { useDagServiceGetFavoriteDags } from "openapi/queries"; import { useFavoriteDag } from "src/queries/useFavoriteDag"; -import { useCallback } from "react"; +import ActionButton from "../ui/ActionButton"; type FavoriteDagButtonProps = { readonly dagId: string; - readonly isFavorite?: boolean; readonly withText?: boolean; }; -export const FavoriteDagButton = ({ dagId, isFavorite, withText = true}: FavoriteDagButtonProps) => { +export const FavoriteDagButton = ({ dagId, withText = true }: FavoriteDagButtonProps) => { + const { data: favorites, refetch } = useDagServiceGetFavoriteDags(); + + const isFavorite = useMemo( + () => favorites?.dags.some((fav) => fav.dag_id === dagId) ?? false, + [favorites, dagId], + ); + const { mutate: toggleFavorite } = useFavoriteDag({ dagId }); const onToggle = useCallback(() => { - toggleFavorite({ - dagId, - requestBody: { - is_favorite: !isFavorite, + toggleFavorite( + { + dagId, + requestBody: { + is_favorite: !isFavorite, + }, + }, + { + onSuccess: () => { + void refetch(); + }, }, - }); - }, [dagId, isFavorite, toggleFavorite]); + ); + }, [dagId, isFavorite, toggleFavorite, refetch]); return ( } + icon={} onClick={onToggle} text={isFavorite ? "Unfavorite Dag" : "Favorite Dag"} variant="solid" @@ -56,5 +70,3 @@ export const FavoriteDagButton = ({ dagId, isFavorite, withText = true}: Favorit ); }; - - diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx index adea2fcacaba0..5e24fb1a1b96b 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx @@ -22,6 +22,7 @@ import { Link as RouterLink } from "react-router-dom"; import type { DAGWithLatestDagRunsResponse } from "openapi/requests/types.gen"; import DeleteDagButton from "src/components/DagActions/DeleteDagButton"; +import { FavoriteDagButton } from "src/components/DagActions/FavoriteDagButton"; import DagRunInfo from "src/components/DagRunInfo"; import { Stat } from "src/components/Stat"; import { TogglePause } from "src/components/TogglePause"; @@ -32,7 +33,6 @@ import { isStatePending, useAutoRefresh } from "src/utils"; import { DagTags } from "./DagTags"; import { RecentRuns } from "./RecentRuns"; import { Schedule } from "./Schedule"; -import { FavoriteDagButton } from "src/components/DagActions/FavoriteDagButton"; type Props = { readonly dag: DAGWithLatestDagRunsResponse; @@ -63,7 +63,7 @@ export const DagCard = ({ dag }: Props) => { pr={2} /> - + diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx index 8a59ca1dbe250..f1488d2dfd5ef 100644 --- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx +++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx @@ -135,13 +135,7 @@ const createColumns = ( }, { accessorKey: "favorite", - cell: ({ row: { original } }) => ( - - ), + cell: ({ row: { original } }) => , enableSorting: false, header: "", }, diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx index 044153ccf4687..964b62d056b40 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx @@ -24,11 +24,11 @@ import ReactMarkdown from "src/components/ReactMarkdown"; import { Accordion, Alert } from "src/components/ui"; import { useConfig } from "src/queries/useConfig"; +import { FavoriteDags } from "./FavoriteDags"; import { Health } from "./Health"; import { HistoricalMetrics } from "./HistoricalMetrics"; import { PoolSummary } from "./PoolSummary"; import { Stats } from "./Stats"; -import { FavoriteDags } from "./FavoriteDags"; export const Dashboard = () => { const alerts = useConfig("dashboard_alert") as Array; diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx index fd5f24ee832e5..792c6889c7410 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx @@ -17,35 +17,44 @@ * under the License. */ import { Box, Button, Text, VStack } from "@chakra-ui/react"; -import { useDagsServiceRecentDagRuns } from "openapi/queries"; import { Link as RouterLink } from "react-router-dom"; + +import { useDagsServiceRecentDagRuns } from "openapi/queries"; import { RecentRuns } from "src/pages/DagsList/RecentRuns"; type FavoriteDagProps = { - readonly dag_id: string; + readonly dagId: string; }; -export const FavoriteDagCard = ({ dag_id }: FavoriteDagProps) => { - +export const FavoriteDagCard = ({ dagId }: FavoriteDagProps) => { const { data } = useDagsServiceRecentDagRuns({ - dagIds: [dag_id], + dagIds: [dagId], dagRunsLimit: 5, }); - const latestRuns = data?.dags[0]?.latest_dag_runs || []; - + const latestRuns = data?.dags[0]?.latest_dag_runs ?? []; + return ( - - - + ); }; diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx index f717504d987e6..ed54261207bc8 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx @@ -16,29 +16,60 @@ * specific language governing permissions and limitations * under the License. */ -import { Box, Flex, Heading, HStack } from "@chakra-ui/react"; +import { Box, Flex, Heading, HStack, Text } from "@chakra-ui/react"; +import { useMemo, useState } from "react"; import { FiStar } from "react-icons/fi"; + +import { useDagServiceGetFavoriteDags } from "openapi/queries"; + import { FavoriteDagCard } from "./FavoriteDagCard"; -import { useDagServiceGetDags } from "openapi/queries"; +const MAX_VISIBLE = 5; export const FavoriteDags = () => { - const { data: allDags } = useDagServiceGetDags(); - const favorites = allDags?.dags?.filter((dag) => dag.is_favorite) ?? []; - - return ( - - - - - Favorite Dags - - - - {favorites.map((dag) => ( - - ))} - + const { data: favorites } = useDagServiceGetFavoriteDags(); + + const [showAll, setShowAll] = useState(false); + + const visibleFavorites = useMemo(() => { + if (!favorites?.dags) { + return []; + } + + return showAll ? favorites.dags : favorites.dags.slice(0, MAX_VISIBLE); + }, [favorites, showAll]); + + if (!favorites) { + return undefined; + } + + return ( + + + + + Favorite Dags + + + + {visibleFavorites.map((dag) => ( + + ))} + + {favorites.total_entries > MAX_VISIBLE && ( + + setShowAll(!showAll)} + > + {showAll ? "Show Less" : "Show More"} + - ); + )} + + ); }; diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts index 8daccb0f7d937..4c8f5fd306a0f 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/index.ts @@ -17,4 +17,4 @@ * under the License. */ -export { FavoriteDags } from "./FavoriteDags"; \ No newline at end of file +export { FavoriteDags } from "./FavoriteDags"; diff --git a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts index f721c971455fd..34242c68ea658 100644 --- a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts +++ b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts @@ -47,4 +47,4 @@ export const useFavoriteDag = ({ dagId }: { dagId: string }) => { return useDagServiceFavoriteDag({ onSuccess, }); -}; \ No newline at end of file +}; diff --git a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py index e388abe00b304..168a6969914cc 100644 --- a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py +++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py @@ -21,8 +21,10 @@ import pendulum import pytest +from sqlalchemy import select from airflow.models.dag import DagModel, DagTag +from airflow.models.dag_favorite import DagFavorite from airflow.models.dagrun import DagRun from airflow.providers.standard.operators.empty import EmptyOperator from airflow.utils.session import provide_session @@ -153,6 +155,52 @@ def teardown_method(self) -> None: self._clear_db() +class TestGetFavoriteDags(TestDagEndpoint): + """Unit tests for Get Favorite DAGs.""" + + @pytest.mark.parametrize( + "setup_favorites, expected_total_entries, expected_ids", + [ + ([], 0, []), + ([DAG1_ID], 1, [DAG1_ID]), + ([DAG1_ID, DAG2_ID], 2, [DAG1_ID, DAG2_ID]), + ], + ) + def test_get_favorite_dags( + self, session, test_client, setup_favorites, expected_total_entries, expected_ids + ): + session.query(DagFavorite).delete() + session.query(DagModel).delete() + session.commit() + + dags = [ + DagModel(dag_id=dag_id, fileloc=f"/fake/path/{dag_id}.py") + for dag_id in [DAG1_ID, DAG2_ID, DAG3_ID] + ] + session.add_all(dags) + session.commit() + + for dag_id in setup_favorites: + session.add(DagFavorite(user_id="test", dag_id=dag_id)) + session.commit() + + response = test_client.get("/dags/favorite") + + assert response.status_code == 200 + body = response.json() + + assert body["total_entries"] == expected_total_entries + assert sorted([dag["dag_id"] for dag in body["dags"]]) == sorted(expected_ids) + + def test_get_favorite_dags_should_response_401(self, unauthenticated_test_client): + response = unauthenticated_test_client.get("/dags/favorite") + assert response.status_code == 401 + + def test_get_favorite_dags_should_response_403(self, unauthorized_test_client): + response = unauthorized_test_client.get("/dags/favorite") + assert response.status_code == 403 + + class TestGetDags(TestDagEndpoint): """Unit tests for Get DAGs.""" @@ -391,29 +439,34 @@ def test_patch_dags_should_response_403(self, unauthorized_test_client): response = unauthorized_test_client.patch("/dags", json={"is_paused": True}) assert response.status_code == 403 + class TestFavoriteDag(TestDagEndpoint): """Unit tests for Favorite DAG.""" @pytest.mark.parametrize( - "query_params, dag_id, body, expected_status_code, expected_is_favorite", + "dag_id, body, expected_status_code, expected_exist_in_favorites", [ - ({}, "fake_dag_id", {"is_favorite": True}, 404, None), - ({"update_mask": ["field_1", "is_favorite"]}, DAG1_ID, {"is_favorite": True}, 400, None), - ({}, DAG1_ID, {"is_favorite": True}, 200, True), - ({}, DAG1_ID, {"is_favorite": False}, 200, False), - ({"update_mask": ["is_favorite"]}, DAG1_ID, {"is_favorite": True}, 200, True), - ({"update_mask": ["is_favorite"]}, DAG1_ID, {"is_favorite": False}, 200, False), + ("fake_dag_id", {"is_favorite": True}, 404, None), + (DAG1_ID, {"is_favorite": True}, 200, True), + (DAG1_ID, {"is_favorite": False}, 200, False), ], ) def test_favorite_dag( - self, test_client, query_params, dag_id, body, expected_status_code, expected_is_favorite, session + self, test_client, dag_id, body, expected_status_code, expected_exist_in_favorites, session ): - response = test_client.put(f"/dags/{dag_id}", json=body, params=query_params) - + response = test_client.put(f"/dags/{dag_id}", json=body) assert response.status_code == expected_status_code + if expected_status_code == 200: - body = response.json() - assert body["is_favorite"] == expected_is_favorite + result = session.execute( + select(DagFavorite).where(DagFavorite.dag_id == dag_id, DagFavorite.user_id == "test") + ).first() + + if expected_exist_in_favorites: + assert result is not None + else: + assert result is None + check_last_log(session, dag_id=dag_id, event="favorite_dag", logical_date=None) def test_favorite_dag_should_response_401(self, unauthenticated_test_client): diff --git a/airflow-core/tests/unit/models/test_dag.py b/airflow-core/tests/unit/models/test_dag.py index 486a5a31ffcce..a173d7ec50f17 100644 --- a/airflow-core/tests/unit/models/test_dag.py +++ b/airflow-core/tests/unit/models/test_dag.py @@ -1256,20 +1256,6 @@ def test_get_paused_dag_ids(self): with create_session() as session: session.query(DagModel).filter(DagModel.dag_id == dag_id).delete(synchronize_session=False) - def test_get_favorite_dag_ids(self): - dag_id = "test_get_favorite_dag_ids" - dag = DAG(dag_id, schedule=None) - dag.sync_to_db() - dagModel = DagModel.get_dagmodel(dag_id) - assert dagModel is not None - - dagModel.set_is_favorite(True) - favorite_dag_ids = DagModel.get_favorite_dag_ids([dag_id]) - assert favorite_dag_ids == {dag_id} - - with create_session() as session: - session.query(DagModel).filter(DagModel.dag_id == dag_id).delete(synchronize_session=False) - @pytest.mark.parametrize( "schedule_arg, expected_timetable, interval_description", [ diff --git a/airflow-ctl/src/airflowctl/api/datamodels/generated.py b/airflow-ctl/src/airflowctl/api/datamodels/generated.py index a4f2e00bbff79..931ab3b57bc19 100644 --- a/airflow-ctl/src/airflowctl/api/datamodels/generated.py +++ b/airflow-ctl/src/airflowctl/api/datamodels/generated.py @@ -287,6 +287,17 @@ class CreateAssetEventsBody(BaseModel): extra: Annotated[dict[str, Any] | None, Field(title="Extra")] = None +class DAGFavoriteBody(BaseModel): + """ + Dag Serializer for updatable bodies. + """ + + model_config = ConfigDict( + extra="forbid", + ) + is_favorite: Annotated[bool, Field(title="Is Favorite")] + + class DAGPatchBody(BaseModel): """ Dag Serializer for updatable bodies. From 6d35c4a42e8f8df08ce56c405744c5f6019f173a Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Sat, 17 May 2025 17:30:43 +0100 Subject: [PATCH 05/18] Added no favorites message. Fix deleted DAGs being shown as favorites. Review the display structure of the favorite DAGs in the dashboard. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana --- .../Dashboard/FavoriteDags/FavoriteDags.tsx | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx index ed54261207bc8..cd468b790209d 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx @@ -16,19 +16,28 @@ * specific language governing permissions and limitations * under the License. */ -import { Box, Flex, Heading, HStack, Text } from "@chakra-ui/react"; -import { useMemo, useState } from "react"; +import { Box, Flex, Heading, SimpleGrid, Text } from "@chakra-ui/react"; +import { useEffect, useMemo, useState } from "react"; import { FiStar } from "react-icons/fi"; import { useDagServiceGetFavoriteDags } from "openapi/queries"; import { FavoriteDagCard } from "./FavoriteDagCard"; +import { useQueryClient } from "@tanstack/react-query"; +import { useLocation } from "react-router-dom"; const MAX_VISIBLE = 5; export const FavoriteDags = () => { + const queryClient = useQueryClient(); + const location = useLocation(); + const { data: favorites } = useDagServiceGetFavoriteDags(); + useEffect(() => { + queryClient.refetchQueries({ queryKey: ['DagServiceGetFavoriteDags'] }); + }, [location.key, queryClient]); + const [showAll, setShowAll] = useState(false); const visibleFavorites = useMemo(() => { @@ -40,7 +49,7 @@ export const FavoriteDags = () => { }, [favorites, showAll]); if (!favorites) { - return undefined; + return null; } return ( @@ -51,24 +60,34 @@ export const FavoriteDags = () => { Favorite Dags - - {visibleFavorites.map((dag) => ( - - ))} - - {favorites.total_entries > MAX_VISIBLE && ( - - setShowAll(!showAll)} - > - {showAll ? "Show Less" : "Show More"} - - + + {favorites.dags.length === 0 ? ( + + No favorites yet. Click the star icon next to a DAG in the list to add it to your favorites. + + ) : ( + <> + + {visibleFavorites.map((dag) => ( + + ))} + + + {favorites.total_entries > MAX_VISIBLE && ( + + setShowAll(!showAll)} + > + {showAll ? "Show Less" : "Show More"} + + + )} + )} ); From 6bdcf71d394eaeb77058757f7ef7c1316b8fd672 Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Sat, 31 May 2025 16:48:17 +0100 Subject: [PATCH 06/18] Rebase and minor fixes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana --- .../FavoriteDags/FavoriteDagCard.tsx | 53 +++++++++++-------- .../airflow/ui/src/queries/useFavoriteDag.ts | 4 +- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx index 792c6889c7410..b50f8fd65c504 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx @@ -19,7 +19,7 @@ import { Box, Button, Text, VStack } from "@chakra-ui/react"; import { Link as RouterLink } from "react-router-dom"; -import { useDagsServiceRecentDagRuns } from "openapi/queries"; +import { useDagServiceRecentDagRuns } from "openapi/queries"; import { RecentRuns } from "src/pages/DagsList/RecentRuns"; type FavoriteDagProps = { @@ -27,7 +27,7 @@ type FavoriteDagProps = { }; export const FavoriteDagCard = ({ dagId }: FavoriteDagProps) => { - const { data } = useDagsServiceRecentDagRuns({ + const { data } = useDagServiceRecentDagRuns({ dagIds: [dagId], dagRunsLimit: 5, }); @@ -35,26 +35,33 @@ export const FavoriteDagCard = ({ dagId }: FavoriteDagProps) => { const latestRuns = data?.dags[0]?.latest_dag_runs ?? []; return ( - - - + + + + + ); }; diff --git a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts index 34242c68ea658..dc2a47a34dc8b 100644 --- a/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts +++ b/airflow-core/src/airflow/ui/src/queries/useFavoriteDag.ts @@ -24,7 +24,7 @@ import { UseDagServiceGetDagKeyFn, useDagServiceGetDagsKey, useDagServiceFavoriteDag, - useDagsServiceRecentDagRunsKey, + useDagServiceRecentDagRunsKey, UseTaskInstanceServiceGetTaskInstancesKeyFn, } from "openapi/queries"; @@ -34,7 +34,7 @@ export const useFavoriteDag = ({ dagId }: { dagId: string }) => { const onSuccess = async () => { const queryKeys = [ [useDagServiceGetDagsKey], - [useDagsServiceRecentDagRunsKey], + [useDagServiceRecentDagRunsKey], UseDagServiceGetDagKeyFn({ dagId }, [{ dagId }]), UseDagServiceGetDagDetailsKeyFn({ dagId }, [{ dagId }]), UseDagRunServiceGetDagRunsKeyFn({ dagId }, [{ dagId }]), From bd89292dd884e1f471a8af15c99f99128933077b Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Thu, 5 Jun 2025 23:03:34 +0100 Subject: [PATCH 07/18] =?UTF-8?q?Use=20i18n=20module=20and=20fix=20DB=20mi?= =?UTF-8?q?gration.=20Co-authored-by:=20Mariana=20Isabel=20Mar=C3=A7al=20S?= =?UTF-8?q?antana=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- airflow-core/docs/img/airflow_erd.sha256 | 2 +- airflow-core/docs/img/airflow_erd.svg | 2965 +++++++++-------- airflow-core/docs/migrations-ref.rst | 4 +- .../0075_3_1_0_add_dag_favorite_table.py | 55 + airflow-core/src/airflow/models/__init__.py | 3 +- .../ui/public/i18n/locales/en/dags.json | 2 + .../ui/public/i18n/locales/en/dashboard.json | 6 + .../DagActions/FavoriteDagButton.tsx | 6 +- .../Dashboard/FavoriteDags/FavoriteDags.tsx | 11 +- airflow-core/src/airflow/utils/db.py | 2 +- 10 files changed, 1573 insertions(+), 1483 deletions(-) create mode 100644 airflow-core/src/airflow/migrations/versions/0075_3_1_0_add_dag_favorite_table.py diff --git a/airflow-core/docs/img/airflow_erd.sha256 b/airflow-core/docs/img/airflow_erd.sha256 index bc2221290c43f..98b1a7b36c0ab 100644 --- a/airflow-core/docs/img/airflow_erd.sha256 +++ b/airflow-core/docs/img/airflow_erd.sha256 @@ -1 +1 @@ -a8edcc8b63444f327ddea859988c23c87a1a722e2b6a430734e61518777d3e61 \ No newline at end of file +bfeffeb93cb52060bd0a87f9e5d847fc4f3a683f463b496ca23428f171cf0f9c \ No newline at end of file diff --git a/airflow-core/docs/img/airflow_erd.svg b/airflow-core/docs/img/airflow_erd.svg index a7bacd714f8c7..d0b2c24ae8cfa 100644 --- a/airflow-core/docs/img/airflow_erd.svg +++ b/airflow-core/docs/img/airflow_erd.svg @@ -4,11 +4,11 @@ - - + + %3 - + dag_priority_parsing_request @@ -305,1083 +305,1083 @@ asset_alias - -asset_alias - -id - - [INTEGER] - NOT NULL - -group - - [VARCHAR(1500)] - NOT NULL - -name - - [VARCHAR(1500)] - NOT NULL + +asset_alias + +id + + [INTEGER] + NOT NULL + +group + + [VARCHAR(1500)] + NOT NULL + +name + + [VARCHAR(1500)] + NOT NULL asset_alias_asset - -asset_alias_asset - -alias_id - - [INTEGER] - NOT NULL - -asset_id - - [INTEGER] - NOT NULL + +asset_alias_asset + +alias_id + + [INTEGER] + NOT NULL + +asset_id + + [INTEGER] + NOT NULL asset_alias--asset_alias_asset - -0..N -1 + +0..N +1 asset_alias_asset_event - -asset_alias_asset_event - -alias_id - - [INTEGER] - NOT NULL - -event_id - - [INTEGER] - NOT NULL + +asset_alias_asset_event + +alias_id + + [INTEGER] + NOT NULL + +event_id + + [INTEGER] + NOT NULL asset_alias--asset_alias_asset_event - -0..N -1 + +0..N +1 dag_schedule_asset_alias_reference - -dag_schedule_asset_alias_reference - -alias_id - - [INTEGER] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL + +dag_schedule_asset_alias_reference + +alias_id + + [INTEGER] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL asset_alias--dag_schedule_asset_alias_reference - -0..N -1 + +0..N +1 asset - -asset - -id - - [INTEGER] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -extra - - [JSON] - NOT NULL - -group - - [VARCHAR(1500)] - NOT NULL - -name - - [VARCHAR(1500)] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL - -uri - - [VARCHAR(1500)] - NOT NULL + +asset + +id + + [INTEGER] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +extra + + [JSON] + NOT NULL + +group + + [VARCHAR(1500)] + NOT NULL + +name + + [VARCHAR(1500)] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL + +uri + + [VARCHAR(1500)] + NOT NULL asset--asset_alias_asset - -0..N -1 + +0..N +1 asset_trigger - -asset_trigger - -asset_id - - [INTEGER] - NOT NULL - -trigger_id - - [INTEGER] - NOT NULL + +asset_trigger + +asset_id + + [INTEGER] + NOT NULL + +trigger_id + + [INTEGER] + NOT NULL asset--asset_trigger - -0..N -1 + +0..N +1 asset_active - -asset_active - -name - - [VARCHAR(1500)] - NOT NULL - -uri - - [VARCHAR(1500)] - NOT NULL + +asset_active + +name + + [VARCHAR(1500)] + NOT NULL + +uri + + [VARCHAR(1500)] + NOT NULL asset--asset_active - -1 -1 + +1 +1 asset--asset_active - -1 -1 + +1 +1 dag_schedule_asset_reference - -dag_schedule_asset_reference - -asset_id - - [INTEGER] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL + +dag_schedule_asset_reference + +asset_id + + [INTEGER] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL asset--dag_schedule_asset_reference - -0..N -1 + +0..N +1 task_outlet_asset_reference - -task_outlet_asset_reference - -asset_id - - [INTEGER] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -task_id - - [VARCHAR(250)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL + +task_outlet_asset_reference + +asset_id + + [INTEGER] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +task_id + + [VARCHAR(250)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL asset--task_outlet_asset_reference - -0..N -1 + +0..N +1 task_inlet_asset_reference - -task_inlet_asset_reference - -asset_id - - [INTEGER] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -task_id - - [VARCHAR(250)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL + +task_inlet_asset_reference + +asset_id + + [INTEGER] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +task_id + + [VARCHAR(250)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL asset--task_inlet_asset_reference - -0..N -1 + +0..N +1 asset_dag_run_queue - -asset_dag_run_queue - -asset_id - - [INTEGER] - NOT NULL - -target_dag_id - - [VARCHAR(250)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL + +asset_dag_run_queue + +asset_id + + [INTEGER] + NOT NULL + +target_dag_id + + [VARCHAR(250)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL asset--asset_dag_run_queue - -0..N -1 + +0..N +1 asset_event - -asset_event - -id - - [INTEGER] - NOT NULL - -asset_id - - [INTEGER] - NOT NULL - -extra - - [JSON] - NOT NULL - -source_dag_id - - [VARCHAR(250)] - -source_map_index - - [INTEGER] - -source_run_id - - [VARCHAR(250)] - -source_task_id - - [VARCHAR(250)] - -timestamp - - [TIMESTAMP] - NOT NULL + +asset_event + +id + + [INTEGER] + NOT NULL + +asset_id + + [INTEGER] + NOT NULL + +extra + + [JSON] + NOT NULL + +source_dag_id + + [VARCHAR(250)] + +source_map_index + + [INTEGER] + +source_run_id + + [VARCHAR(250)] + +source_task_id + + [VARCHAR(250)] + +timestamp + + [TIMESTAMP] + NOT NULL asset_event--asset_alias_asset_event - -0..N -1 + +0..N +1 dagrun_asset_event - -dagrun_asset_event - -dag_run_id - - [INTEGER] - NOT NULL - -event_id - - [INTEGER] - NOT NULL + +dagrun_asset_event + +dag_run_id + + [INTEGER] + NOT NULL + +event_id + + [INTEGER] + NOT NULL asset_event--dagrun_asset_event - -0..N -1 + +0..N +1 trigger - -trigger - -id - - [INTEGER] - NOT NULL - -classpath - - [VARCHAR(1000)] - NOT NULL - -created_date - - [TIMESTAMP] - NOT NULL - -kwargs - - [TEXT] - NOT NULL - -triggerer_id - - [INTEGER] + +trigger + +id + + [INTEGER] + NOT NULL + +classpath + + [VARCHAR(1000)] + NOT NULL + +created_date + + [TIMESTAMP] + NOT NULL + +kwargs + + [TEXT] + NOT NULL + +triggerer_id + + [INTEGER] trigger--asset_trigger - -0..N -1 + +0..N +1 task_instance - -task_instance - -id - - [UUID] - NOT NULL - -context_carrier - - [JSONB] - -custom_operator_name - - [VARCHAR(1000)] - -dag_id - - [VARCHAR(250)] - NOT NULL - -dag_version_id - - [UUID] - -duration - - [DOUBLE_PRECISION] - -end_date - - [TIMESTAMP] - -executor - - [VARCHAR(1000)] - -executor_config - - [BYTEA] - -external_executor_id - - [VARCHAR(250)] - -hostname - - [VARCHAR(1000)] - -last_heartbeat_at - - [TIMESTAMP] - -map_index - - [INTEGER] - NOT NULL - -max_tries - - [INTEGER] - -next_kwargs - - [JSONB] - -next_method - - [VARCHAR(1000)] - -operator - - [VARCHAR(1000)] - -pid - - [INTEGER] - -pool - - [VARCHAR(256)] - NOT NULL - -pool_slots - - [INTEGER] - NOT NULL - -priority_weight - - [INTEGER] - -queue - - [VARCHAR(256)] - -queued_by_job_id - - [INTEGER] - -queued_dttm - - [TIMESTAMP] - -rendered_map_index - - [VARCHAR(250)] - -run_id - - [VARCHAR(250)] - NOT NULL - -scheduled_dttm - - [TIMESTAMP] - -span_status - - [VARCHAR(250)] - NOT NULL - -start_date - - [TIMESTAMP] - -state - - [VARCHAR(20)] - -task_display_name - - [VARCHAR(2000)] - -task_id - - [VARCHAR(250)] - NOT NULL - -trigger_id - - [INTEGER] - -trigger_timeout - - [TIMESTAMP] - -try_number - - [INTEGER] - -unixname - - [VARCHAR(1000)] - -updated_at - - [TIMESTAMP] + +task_instance + +id + + [UUID] + NOT NULL + +context_carrier + + [JSONB] + +custom_operator_name + + [VARCHAR(1000)] + +dag_id + + [VARCHAR(250)] + NOT NULL + +dag_version_id + + [UUID] + +duration + + [DOUBLE_PRECISION] + +end_date + + [TIMESTAMP] + +executor + + [VARCHAR(1000)] + +executor_config + + [BYTEA] + +external_executor_id + + [VARCHAR(250)] + +hostname + + [VARCHAR(1000)] + +last_heartbeat_at + + [TIMESTAMP] + +map_index + + [INTEGER] + NOT NULL + +max_tries + + [INTEGER] + +next_kwargs + + [JSONB] + +next_method + + [VARCHAR(1000)] + +operator + + [VARCHAR(1000)] + +pid + + [INTEGER] + +pool + + [VARCHAR(256)] + NOT NULL + +pool_slots + + [INTEGER] + NOT NULL + +priority_weight + + [INTEGER] + +queue + + [VARCHAR(256)] + +queued_by_job_id + + [INTEGER] + +queued_dttm + + [TIMESTAMP] + +rendered_map_index + + [VARCHAR(250)] + +run_id + + [VARCHAR(250)] + NOT NULL + +scheduled_dttm + + [TIMESTAMP] + +span_status + + [VARCHAR(250)] + NOT NULL + +start_date + + [TIMESTAMP] + +state + + [VARCHAR(20)] + +task_display_name + + [VARCHAR(2000)] + +task_id + + [VARCHAR(250)] + NOT NULL + +trigger_id + + [INTEGER] + +trigger_timeout + + [TIMESTAMP] + +try_number + + [INTEGER] + +unixname + + [VARCHAR(1000)] + +updated_at + + [TIMESTAMP] trigger--task_instance - -0..N -{0,1} + +0..N +{0,1} - + task_map - -task_map - -dag_id - - [VARCHAR(250)] - NOT NULL - -map_index - - [INTEGER] - NOT NULL - -run_id - - [VARCHAR(250)] - NOT NULL - -task_id - - [VARCHAR(250)] - NOT NULL - -keys - - [JSONB] - -length - - [INTEGER] - NOT NULL - - - -task_instance--task_map - -0..N -1 + +task_map + +dag_id + + [VARCHAR(250)] + NOT NULL + +map_index + + [INTEGER] + NOT NULL + +run_id + + [VARCHAR(250)] + NOT NULL + +task_id + + [VARCHAR(250)] + NOT NULL + +keys + + [JSONB] + +length + + [INTEGER] + NOT NULL task_instance--task_map - -0..N -1 + +0..N +1 task_instance--task_map - -0..N -1 + +0..N +1 task_instance--task_map - -0..N -1 + +0..N +1 + + + +task_instance--task_map + +0..N +1 - + task_reschedule - -task_reschedule - -id - - [INTEGER] - NOT NULL - -duration - - [INTEGER] - NOT NULL - -end_date - - [TIMESTAMP] - NOT NULL - -reschedule_date - - [TIMESTAMP] - NOT NULL - -start_date - - [TIMESTAMP] - NOT NULL - -ti_id - - [UUID] - NOT NULL + +task_reschedule + +id + + [INTEGER] + NOT NULL + +duration + + [INTEGER] + NOT NULL + +end_date + + [TIMESTAMP] + NOT NULL + +reschedule_date + + [TIMESTAMP] + NOT NULL + +start_date + + [TIMESTAMP] + NOT NULL + +ti_id + + [UUID] + NOT NULL - + task_instance--task_reschedule - -0..N -1 + +0..N +1 - + xcom - -xcom - -dag_run_id - - [INTEGER] - NOT NULL - -key - - [VARCHAR(512)] - NOT NULL - -map_index - - [INTEGER] - NOT NULL - -task_id - - [VARCHAR(250)] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -run_id - - [VARCHAR(250)] - NOT NULL - -timestamp - - [TIMESTAMP] - NOT NULL - -value - - [JSONB] - - - -task_instance--xcom - -0..N -1 + +xcom + +dag_run_id + + [INTEGER] + NOT NULL + +key + + [VARCHAR(512)] + NOT NULL + +map_index + + [INTEGER] + NOT NULL + +task_id + + [VARCHAR(250)] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +run_id + + [VARCHAR(250)] + NOT NULL + +timestamp + + [TIMESTAMP] + NOT NULL + +value + + [JSONB] task_instance--xcom - -0..N -1 + +0..N +1 task_instance--xcom - -0..N -1 + +0..N +1 task_instance--xcom - -0..N -1 + +0..N +1 + + + +task_instance--xcom + +0..N +1 - + task_instance_note - -task_instance_note - -ti_id - - [UUID] - NOT NULL - -content - - [VARCHAR(1000)] - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL - -user_id - - [VARCHAR(128)] + +task_instance_note + +ti_id + + [UUID] + NOT NULL + +content + + [VARCHAR(1000)] + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL + +user_id + + [VARCHAR(128)] - + task_instance--task_instance_note - -1 -1 + +1 +1 - + task_instance_history - -task_instance_history - -task_instance_id - - [UUID] - NOT NULL - -context_carrier - - [JSONB] - -custom_operator_name - - [VARCHAR(1000)] - -dag_id - - [VARCHAR(250)] - NOT NULL - -dag_version_id - - [UUID] - -duration - - [DOUBLE_PRECISION] - -end_date - - [TIMESTAMP] - -executor - - [VARCHAR(1000)] - -executor_config - - [BYTEA] - -external_executor_id - - [VARCHAR(250)] - -hostname - - [VARCHAR(1000)] - -map_index - - [INTEGER] - NOT NULL - -max_tries - - [INTEGER] - -next_kwargs - - [JSONB] - -next_method - - [VARCHAR(1000)] - -operator - - [VARCHAR(1000)] - -pid - - [INTEGER] - -pool - - [VARCHAR(256)] - NOT NULL - -pool_slots - - [INTEGER] - NOT NULL - -priority_weight - - [INTEGER] - -queue - - [VARCHAR(256)] - -queued_by_job_id - - [INTEGER] - -queued_dttm - - [TIMESTAMP] - -rendered_map_index - - [VARCHAR(250)] - -run_id - - [VARCHAR(250)] - NOT NULL - -scheduled_dttm - - [TIMESTAMP] - -span_status - - [VARCHAR(250)] - NOT NULL - -start_date - - [TIMESTAMP] - -state - - [VARCHAR(20)] - -task_display_name - - [VARCHAR(2000)] - -task_id - - [VARCHAR(250)] - NOT NULL - -trigger_id - - [INTEGER] - -trigger_timeout - - [TIMESTAMP] - -try_number - - [INTEGER] - NOT NULL - -unixname - - [VARCHAR(1000)] - -updated_at - - [TIMESTAMP] - - - -task_instance--task_instance_history - -0..N -1 + +task_instance_history + +task_instance_id + + [UUID] + NOT NULL + +context_carrier + + [JSONB] + +custom_operator_name + + [VARCHAR(1000)] + +dag_id + + [VARCHAR(250)] + NOT NULL + +dag_version_id + + [UUID] + +duration + + [DOUBLE_PRECISION] + +end_date + + [TIMESTAMP] + +executor + + [VARCHAR(1000)] + +executor_config + + [BYTEA] + +external_executor_id + + [VARCHAR(250)] + +hostname + + [VARCHAR(1000)] + +map_index + + [INTEGER] + NOT NULL + +max_tries + + [INTEGER] + +next_kwargs + + [JSONB] + +next_method + + [VARCHAR(1000)] + +operator + + [VARCHAR(1000)] + +pid + + [INTEGER] + +pool + + [VARCHAR(256)] + NOT NULL + +pool_slots + + [INTEGER] + NOT NULL + +priority_weight + + [INTEGER] + +queue + + [VARCHAR(256)] + +queued_by_job_id + + [INTEGER] + +queued_dttm + + [TIMESTAMP] + +rendered_map_index + + [VARCHAR(250)] + +run_id + + [VARCHAR(250)] + NOT NULL + +scheduled_dttm + + [TIMESTAMP] + +span_status + + [VARCHAR(250)] + NOT NULL + +start_date + + [TIMESTAMP] + +state + + [VARCHAR(20)] + +task_display_name + + [VARCHAR(2000)] + +task_id + + [VARCHAR(250)] + NOT NULL + +trigger_id + + [INTEGER] + +trigger_timeout + + [TIMESTAMP] + +try_number + + [INTEGER] + NOT NULL + +unixname + + [VARCHAR(1000)] + +updated_at + + [TIMESTAMP] task_instance--task_instance_history - -0..N -1 + +0..N +1 task_instance--task_instance_history - -0..N -1 + +0..N +1 task_instance--task_instance_history - -0..N -1 + +0..N +1 + + + +task_instance--task_instance_history + +0..N +1 - + rendered_task_instance_fields - -rendered_task_instance_fields - -dag_id - - [VARCHAR(250)] - NOT NULL - -map_index - - [INTEGER] - NOT NULL - -run_id - - [VARCHAR(250)] - NOT NULL - -task_id - - [VARCHAR(250)] - NOT NULL - -k8s_pod_yaml - - [JSON] - -rendered_fields - - [JSON] - NOT NULL - - - -task_instance--rendered_task_instance_fields - -0..N -1 + +rendered_task_instance_fields + +dag_id + + [VARCHAR(250)] + NOT NULL + +map_index + + [INTEGER] + NOT NULL + +run_id + + [VARCHAR(250)] + NOT NULL + +task_id + + [VARCHAR(250)] + NOT NULL + +k8s_pod_yaml + + [JSON] + +rendered_fields + + [JSON] + NOT NULL task_instance--rendered_task_instance_fields - -0..N -1 + +0..N +1 task_instance--rendered_task_instance_fields - -0..N -1 + +0..N +1 task_instance--rendered_task_instance_fields - -0..N -1 + +0..N +1 + + + +task_instance--rendered_task_instance_fields + +0..N +1 @@ -1526,716 +1526,739 @@ dag--dag_schedule_asset_alias_reference - -0..N -1 + +0..N +1 dag--dag_schedule_asset_reference - -0..N -1 + +0..N +1 dag--task_outlet_asset_reference - -0..N -1 + +0..N +1 dag--task_inlet_asset_reference - -0..N -1 + +0..N +1 dag--asset_dag_run_queue - -0..N -1 + +0..N +1 dag_schedule_asset_name_reference - -dag_schedule_asset_name_reference - -dag_id - - [VARCHAR(250)] - NOT NULL - -name - - [VARCHAR(1500)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL + +dag_schedule_asset_name_reference + +dag_id + + [VARCHAR(250)] + NOT NULL + +name + + [VARCHAR(1500)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL dag--dag_schedule_asset_name_reference - -0..N -1 + +0..N +1 dag_schedule_asset_uri_reference - -dag_schedule_asset_uri_reference - -dag_id - - [VARCHAR(250)] - NOT NULL - -uri - - [VARCHAR(1500)] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL + +dag_schedule_asset_uri_reference + +dag_id + + [VARCHAR(250)] + NOT NULL + +uri + + [VARCHAR(1500)] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL dag--dag_schedule_asset_uri_reference - -0..N -1 + +0..N +1 dag_version - -dag_version - -id - - [UUID] - NOT NULL - -bundle_name - - [VARCHAR(250)] - -bundle_version - - [VARCHAR(250)] - -created_at - - [TIMESTAMP] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -last_updated - - [TIMESTAMP] - NOT NULL - -version_number - - [INTEGER] - NOT NULL + +dag_version + +id + + [UUID] + NOT NULL + +bundle_name + + [VARCHAR(250)] + +bundle_version + + [VARCHAR(250)] + +created_at + + [TIMESTAMP] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +last_updated + + [TIMESTAMP] + NOT NULL + +version_number + + [INTEGER] + NOT NULL dag--dag_version - -0..N -1 + +0..N +1 dag_tag - -dag_tag - -dag_id - - [VARCHAR(250)] - NOT NULL - -name - - [VARCHAR(100)] - NOT NULL + +dag_tag + +dag_id + + [VARCHAR(250)] + NOT NULL + +name + + [VARCHAR(100)] + NOT NULL dag--dag_tag - -0..N -1 + +0..N +1 dag_owner_attributes - -dag_owner_attributes - -dag_id - - [VARCHAR(250)] - NOT NULL - -owner - - [VARCHAR(500)] - NOT NULL - -link - - [VARCHAR(500)] - NOT NULL + +dag_owner_attributes + +dag_id + + [VARCHAR(250)] + NOT NULL + +owner + + [VARCHAR(500)] + NOT NULL + +link + + [VARCHAR(500)] + NOT NULL dag--dag_owner_attributes - -0..N -1 + +0..N +1 dag_warning - -dag_warning - -dag_id - - [VARCHAR(250)] - NOT NULL - -warning_type - - [VARCHAR(50)] - NOT NULL - -message - - [TEXT] - NOT NULL - -timestamp - - [TIMESTAMP] - NOT NULL + +dag_warning + +dag_id + + [VARCHAR(250)] + NOT NULL + +warning_type + + [VARCHAR(50)] + NOT NULL + +message + + [TEXT] + NOT NULL + +timestamp + + [TIMESTAMP] + NOT NULL dag--dag_warning - -0..N -1 + +0..N +1 - + +dag_favorite + +dag_favorite + +dag_id + + [VARCHAR(250)] + NOT NULL + +user_id + + [VARCHAR] + NOT NULL + + + +dag--dag_favorite + +0..N +1 + + + deadline - -deadline - -id - - [UUID] - NOT NULL - -callback - - [VARCHAR(500)] - NOT NULL - -callback_kwargs - - [JSON] - -dag_id - - [VARCHAR(250)] - -dagrun_id - - [INTEGER] - -deadline_time - - [TIMESTAMP] - NOT NULL + +deadline + +id + + [UUID] + NOT NULL + +callback + + [VARCHAR(500)] + NOT NULL + +callback_kwargs + + [JSON] + +dag_id + + [VARCHAR(250)] + +dagrun_id + + [INTEGER] + +deadline_time + + [TIMESTAMP] + NOT NULL - + dag--deadline - -0..N -{0,1} + +0..N +{0,1} - + dag_version--task_instance - -0..N -{0,1} + +0..N +{0,1} - + dag_run - -dag_run - -id - - [INTEGER] - NOT NULL - -backfill_id - - [INTEGER] - -bundle_version - - [VARCHAR(250)] - -clear_number - - [INTEGER] - NOT NULL - -conf - - [JSONB] - -context_carrier - - [JSONB] - -created_dag_version_id - - [UUID] - -creating_job_id - - [INTEGER] - -dag_id - - [VARCHAR(250)] - NOT NULL - -data_interval_end - - [TIMESTAMP] - -data_interval_start - - [TIMESTAMP] - -end_date - - [TIMESTAMP] - -last_scheduling_decision - - [TIMESTAMP] - -log_template_id - - [INTEGER] - -logical_date - - [TIMESTAMP] - -queued_at - - [TIMESTAMP] - -run_after - - [TIMESTAMP] - NOT NULL - -run_id - - [VARCHAR(250)] - NOT NULL - -run_type - - [VARCHAR(50)] - NOT NULL - -scheduled_by_job_id - - [INTEGER] - -span_status - - [VARCHAR(250)] - NOT NULL - -start_date - - [TIMESTAMP] - -state - - [VARCHAR(50)] - -triggered_by - - [VARCHAR(50)] - -triggering_user_name - - [VARCHAR(512)] - -updated_at - - [TIMESTAMP] + +dag_run + +id + + [INTEGER] + NOT NULL + +backfill_id + + [INTEGER] + +bundle_version + + [VARCHAR(250)] + +clear_number + + [INTEGER] + NOT NULL + +conf + + [JSONB] + +context_carrier + + [JSONB] + +created_dag_version_id + + [UUID] + +creating_job_id + + [INTEGER] + +dag_id + + [VARCHAR(250)] + NOT NULL + +data_interval_end + + [TIMESTAMP] + +data_interval_start + + [TIMESTAMP] + +end_date + + [TIMESTAMP] + +last_scheduling_decision + + [TIMESTAMP] + +log_template_id + + [INTEGER] + +logical_date + + [TIMESTAMP] + +queued_at + + [TIMESTAMP] + +run_after + + [TIMESTAMP] + NOT NULL + +run_id + + [VARCHAR(250)] + NOT NULL + +run_type + + [VARCHAR(50)] + NOT NULL + +scheduled_by_job_id + + [INTEGER] + +span_status + + [VARCHAR(250)] + NOT NULL + +start_date + + [TIMESTAMP] + +state + + [VARCHAR(50)] + +triggered_by + + [VARCHAR(50)] + +triggering_user_name + + [VARCHAR(512)] + +updated_at + + [TIMESTAMP] - + dag_version--dag_run - -0..N -{0,1} + +0..N +{0,1} - + dag_code - -dag_code - -id - - [UUID] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -dag_version_id - - [UUID] - NOT NULL - -fileloc - - [VARCHAR(2000)] - NOT NULL - -last_updated - - [TIMESTAMP] - NOT NULL - -source_code - - [TEXT] - NOT NULL - -source_code_hash - - [VARCHAR(32)] - NOT NULL + +dag_code + +id + + [UUID] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +dag_version_id + + [UUID] + NOT NULL + +fileloc + + [VARCHAR(2000)] + NOT NULL + +last_updated + + [TIMESTAMP] + NOT NULL + +source_code + + [TEXT] + NOT NULL + +source_code_hash + + [VARCHAR(32)] + NOT NULL - + dag_version--dag_code - -0..N -1 + +0..N +1 - + serialized_dag - -serialized_dag - -id - - [UUID] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -dag_hash - - [VARCHAR(32)] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -dag_version_id - - [UUID] - NOT NULL - -data - - [JSON] - -data_compressed - - [BYTEA] - -last_updated - - [TIMESTAMP] - NOT NULL + +serialized_dag + +id + + [UUID] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +dag_hash + + [VARCHAR(32)] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +dag_version_id + + [UUID] + NOT NULL + +data + + [JSON] + +data_compressed + + [BYTEA] + +last_updated + + [TIMESTAMP] + NOT NULL - + dag_version--serialized_dag - -0..N -1 + +0..N +1 - + dag_run--dagrun_asset_event - -0..N -1 + +0..N +1 - + dag_run--task_instance - -0..N -1 + +0..N +1 - + dag_run--task_instance - -0..N -1 + +0..N +1 - + dag_run--deadline - -0..N -{0,1} + +0..N +{0,1} - + backfill_dag_run - -backfill_dag_run - -id - - [INTEGER] - NOT NULL - -backfill_id - - [INTEGER] - NOT NULL - -dag_run_id - - [INTEGER] - -exception_reason - - [VARCHAR(250)] - -logical_date - - [TIMESTAMP] - NOT NULL - -sort_ordinal - - [INTEGER] - NOT NULL + +backfill_dag_run + +id + + [INTEGER] + NOT NULL + +backfill_id + + [INTEGER] + NOT NULL + +dag_run_id + + [INTEGER] + +exception_reason + + [VARCHAR(250)] + +logical_date + + [TIMESTAMP] + NOT NULL + +sort_ordinal + + [INTEGER] + NOT NULL - + dag_run--backfill_dag_run - -0..N -{0,1} + +0..N +{0,1} - + dag_run_note - -dag_run_note - -dag_run_id - - [INTEGER] - NOT NULL - -content - - [VARCHAR(1000)] - -created_at - - [TIMESTAMP] - NOT NULL - -updated_at - - [TIMESTAMP] - NOT NULL - -user_id - - [VARCHAR(128)] + +dag_run_note + +dag_run_id + + [INTEGER] + NOT NULL + +content + + [VARCHAR(1000)] + +created_at + + [TIMESTAMP] + NOT NULL + +updated_at + + [TIMESTAMP] + NOT NULL + +user_id + + [VARCHAR(128)] - + dag_run--dag_run_note - -1 -1 + +1 +1 - + log_template - -log_template - -id - - [INTEGER] - NOT NULL - -created_at - - [TIMESTAMP] - NOT NULL - -elasticsearch_id - - [TEXT] - NOT NULL - -filename - - [TEXT] - NOT NULL + +log_template + +id + + [INTEGER] + NOT NULL + +created_at + + [TIMESTAMP] + NOT NULL + +elasticsearch_id + + [TEXT] + NOT NULL + +filename + + [TEXT] + NOT NULL - + log_template--dag_run - -0..N -{0,1} + +0..N +{0,1} - + backfill - -backfill - -id - - [INTEGER] - NOT NULL - -completed_at - - [TIMESTAMP] - -created_at - - [TIMESTAMP] - NOT NULL - -dag_id - - [VARCHAR(250)] - NOT NULL - -dag_run_conf - - [JSON] - NOT NULL - -from_date - - [TIMESTAMP] - NOT NULL - -is_paused - - [BOOLEAN] - -max_active_runs - - [INTEGER] - NOT NULL - -reprocess_behavior - - [VARCHAR(250)] - NOT NULL - -to_date - - [TIMESTAMP] - NOT NULL - -triggering_user_name - - [VARCHAR(512)] - -updated_at - - [TIMESTAMP] - NOT NULL + +backfill + +id + + [INTEGER] + NOT NULL + +completed_at + + [TIMESTAMP] + +created_at + + [TIMESTAMP] + NOT NULL + +dag_id + + [VARCHAR(250)] + NOT NULL + +dag_run_conf + + [JSON] + NOT NULL + +from_date + + [TIMESTAMP] + NOT NULL + +is_paused + + [BOOLEAN] + +max_active_runs + + [INTEGER] + NOT NULL + +reprocess_behavior + + [VARCHAR(250)] + NOT NULL + +to_date + + [TIMESTAMP] + NOT NULL + +triggering_user_name + + [VARCHAR(512)] + +updated_at + + [TIMESTAMP] + NOT NULL - + backfill--dag_run - -0..N -{0,1} + +0..N +{0,1} - + backfill--backfill_dag_run - -0..N -1 + +0..N +1 - + alembic_version alembic_version diff --git a/airflow-core/docs/migrations-ref.rst b/airflow-core/docs/migrations-ref.rst index e75af75b23bc5..13635111eb278 100644 --- a/airflow-core/docs/migrations-ref.rst +++ b/airflow-core/docs/migrations-ref.rst @@ -39,7 +39,9 @@ Here's the list of all the Database Migrations that are executed via when you ru +-------------------------+------------------+-------------------+--------------------------------------------------------------+ | Revision ID | Revises ID | Airflow Version | Description | +=========================+==================+===================+==============================================================+ -| ``66a7743fe20e`` (head) | ``583e80dfcef4`` | ``3.1.0`` | Add triggering user to dag_run. | +| ``ffdb0566c7c0`` (head) | ``66a7743fe20e`` | ``3.1.0`` | add dag_favorite table | ++-------------------------+------------------+-------------------+--------------------------------------------------------------+ +| ``66a7743fe20e`` | ``583e80dfcef4`` | ``3.1.0`` | Add triggering user to dag_run. | +-------------------------+------------------+-------------------+--------------------------------------------------------------+ | ``583e80dfcef4`` | ``3ac9e5732b1f`` | ``3.1.0`` | Add task_inlet_asset_reference table. | +-------------------------+------------------+-------------------+--------------------------------------------------------------+ diff --git a/airflow-core/src/airflow/migrations/versions/0075_3_1_0_add_dag_favorite_table.py b/airflow-core/src/airflow/migrations/versions/0075_3_1_0_add_dag_favorite_table.py new file mode 100644 index 0000000000000..5a193ebb83197 --- /dev/null +++ b/airflow-core/src/airflow/migrations/versions/0075_3_1_0_add_dag_favorite_table.py @@ -0,0 +1,55 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" +add dag_favorite table + +Revision ID: ffdb0566c7c0 +Revises: 66a7743fe20e +Create Date: 2025-06-05 15:06:08.903908 + +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op + +revision = "ffdb0566c7c0" +down_revision = "66a7743fe20e" +branch_labels = None +depends_on = None +airflow_version = "3.1.0" + + +def upgrade(): + """Apply add dag_favorite table""" + op.create_table( + "dag_favorite", + sa.Column("user_id", sa.String(), nullable=False), + sa.Column("dag_id", sa.String(length=250), nullable=False), + sa.ForeignKeyConstraint( + ["dag_id"], ["dag.dag_id"], name=op.f("dag_favorite_dag_id_fkey"), ondelete="CASCADE" + ), + sa.PrimaryKeyConstraint("user_id", "dag_id", name=op.f("dag_favorite_pkey")), + ) + + +def downgrade(): + """Unapply add dag_favorite table""" + op.drop_table("dag_favorite") diff --git a/airflow-core/src/airflow/models/__init__.py b/airflow-core/src/airflow/models/__init__.py index 7078de158cbaa..3e472b70b4bca 100644 --- a/airflow-core/src/airflow/models/__init__.py +++ b/airflow-core/src/airflow/models/__init__.py @@ -60,6 +60,7 @@ def import_all_models(): import airflow.models.asset import airflow.models.backfill + import airflow.models.dag_favorite import airflow.models.dag_version import airflow.models.dagbundle import airflow.models.dagwarning @@ -99,7 +100,6 @@ def __getattr__(name): "DagRun": "airflow.models.dagrun", "DagTag": "airflow.models.dag", "DagWarning": "airflow.models.dagwarning", - "DagFavorite": "airflow.models.dag_favorite", "DbCallbackRequest": "airflow.models.db_callback_request", "Deadline": "airflow.models.deadline", "Log": "airflow.models.log", @@ -124,7 +124,6 @@ def __getattr__(name): from airflow.models.baseoperator import BaseOperator from airflow.models.connection import Connection from airflow.models.dag import DAG, DagModel, DagTag - from airflow.models.dag_favorite import DagFavorite from airflow.models.dagbag import DagBag from airflow.models.dagrun import DagRun from airflow.models.dagwarning import DagWarning diff --git a/airflow-core/src/airflow/ui/public/i18n/locales/en/dags.json b/airflow-core/src/airflow/ui/public/i18n/locales/en/dags.json index c804a985fb570..65aedaf11c234 100644 --- a/airflow-core/src/airflow/ui/public/i18n/locales/en/dags.json +++ b/airflow-core/src/airflow/ui/public/i18n/locales/en/dags.json @@ -15,7 +15,9 @@ "paused": "Paused" } }, + "favoriteDag": "Favorite Dag", "ownerLink": "Owner link for {{owner}}", + "unfavoriteDag": "Unfavorite Dag", "runAndTaskActions": { "affectedTasks": { "noItemsFound": "No tasks found.", diff --git a/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json b/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json index 3b945abbb4552..3722e0de8bc2f 100644 --- a/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json +++ b/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json @@ -1,5 +1,11 @@ { "group": "Group", + "favorite": { + "favoriteDags": "Favorite Dags", + "noFavoriteDags": "No favorites yet. Click the star icon next to a DAG in the list to add it to your favorites.", + "showLess": "Show Less", + "showMore": "Show More" + }, "health": { "dagProcessor": "Dag Processor", "health": "Health", diff --git a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx index 093ac3396b242..e685fc5544f0e 100644 --- a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx +++ b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx @@ -18,6 +18,7 @@ */ import { Box } from "@chakra-ui/react"; import { useCallback, useMemo } from "react"; +import { useTranslation } from "react-i18next"; import { FiStar } from "react-icons/fi"; import { useDagServiceGetFavoriteDags } from "openapi/queries"; @@ -31,6 +32,7 @@ type FavoriteDagButtonProps = { }; export const FavoriteDagButton = ({ dagId, withText = true }: FavoriteDagButtonProps) => { + const { t: translate } = useTranslation("dags"); const { data: favorites, refetch } = useDagServiceGetFavoriteDags(); const isFavorite = useMemo( @@ -59,11 +61,11 @@ export const FavoriteDagButton = ({ dagId, withText = true }: FavoriteDagButtonP return ( } onClick={onToggle} - text={isFavorite ? "Unfavorite Dag" : "Favorite Dag"} + text={isFavorite ? translate("list.unfavoriteDag") : translate("list.favoriteDag")} variant="solid" withText={withText} /> diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx index cd468b790209d..3920238d4f44d 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx @@ -21,7 +21,7 @@ import { useEffect, useMemo, useState } from "react"; import { FiStar } from "react-icons/fi"; import { useDagServiceGetFavoriteDags } from "openapi/queries"; - +import { useTranslation } from "react-i18next"; import { FavoriteDagCard } from "./FavoriteDagCard"; import { useQueryClient } from "@tanstack/react-query"; import { useLocation } from "react-router-dom"; @@ -32,6 +32,7 @@ export const FavoriteDags = () => { const queryClient = useQueryClient(); const location = useLocation(); + const { t: translate } = useTranslation("dashboard"); const { data: favorites } = useDagServiceGetFavoriteDags(); useEffect(() => { @@ -57,13 +58,13 @@ export const FavoriteDags = () => { - Favorite Dags + {translate("favorite.favoriteDags")} {favorites.dags.length === 0 ? ( - No favorites yet. Click the star icon next to a DAG in the list to add it to your favorites. + {translate("favorite.noFavoriteDags")} ) : ( <> @@ -78,12 +79,12 @@ export const FavoriteDags = () => { setShowAll(!showAll)} > - {showAll ? "Show Less" : "Show More"} + {showAll ? translate("favorite.showLess") : translate("favorite.showMore")} )} diff --git a/airflow-core/src/airflow/utils/db.py b/airflow-core/src/airflow/utils/db.py index 67cbb95461522..c93d84433bd11 100644 --- a/airflow-core/src/airflow/utils/db.py +++ b/airflow-core/src/airflow/utils/db.py @@ -93,7 +93,7 @@ class MappedClassProtocol(Protocol): "2.10.3": "5f2621c13b39", "3.0.0": "29ce7909c52b", "3.0.3": "fe199e1abd77", - "3.1.0": "66a7743fe20e", + "3.1.0": "ffdb0566c7c0", } From 46fba274df28f3167de4ed123f879ec9ba46b6ca Mon Sep 17 00:00:00 2001 From: Pedro Leal Date: Mon, 9 Jun 2025 00:39:52 +0100 Subject: [PATCH 08/18] Review API endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariana Isabel Marçal Santana --- .../openapi/v2-rest-api-generated.yaml | 147 +++++----- .../core_api/routes/public/dags.py | 76 ++--- .../airflow/ui/openapi-gen/queries/common.ts | 94 +++++-- .../ui/openapi-gen/queries/ensureQueryData.ts | 145 +++++++--- .../ui/openapi-gen/queries/prefetch.ts | 145 +++++++--- .../airflow/ui/openapi-gen/queries/queries.ts | 261 ++++++++++++------ .../ui/openapi-gen/queries/suspense.ts | 148 ++++++---- .../ui/openapi-gen/requests/schemas.gen.ts | 14 - .../ui/openapi-gen/requests/services.gen.ts | 54 ++-- .../ui/openapi-gen/requests/types.gen.ts | 108 ++++---- .../ui/public/i18n/locales/en/dashboard.json | 2 +- .../DagActions/FavoriteDagButton.tsx | 21 +- .../FavoriteDags/FavoriteDagCard.tsx | 10 +- .../Dashboard/FavoriteDags/FavoriteDags.tsx | 17 +- .../ui/src/queries/useUnfavoriteDag.ts | 50 ++++ .../core_api/routes/public/test_dags.py | 134 ++++----- 16 files changed, 890 insertions(+), 536 deletions(-) create mode 100644 airflow-core/src/airflow/ui/src/queries/useUnfavoriteDag.ts diff --git a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml index 4d3fc06d1d045..f0fa3f3f1cb6d 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml +++ b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml @@ -2607,34 +2607,6 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' - /api/v2/dags/favorite: - get: - tags: - - DAG - summary: Get Favorite Dags - description: Get DAGs favorited by the user. - operationId: get_favorite_dags - responses: - '200': - description: Successful Response - content: - application/json: - schema: - $ref: '#/components/schemas/DAGCollectionResponse' - '401': - description: Unauthorized - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPExceptionResponse' - '403': - description: Forbidden - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPExceptionResponse' - security: - - OAuth2PasswordBearer: [] /api/v2/dags: get: tags: @@ -2645,6 +2617,14 @@ paths: security: - OAuth2PasswordBearer: [] parameters: + - name: favorites + in: query + required: false + schema: + anyOf: + - type: boolean + - type: 'null' + title: Favorites - name: limit in: query required: false @@ -3064,12 +3044,12 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' - put: + delete: tags: - DAG - summary: Favorite Dag - description: Favorite the specific DAG. - operationId: favorite_dag + summary: Delete Dag + description: Delete the specific DAG. + operationId: delete_dag security: - OAuth2PasswordBearer: [] parameters: @@ -3079,19 +3059,12 @@ paths: schema: type: string title: Dag Id - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/DAGFavoriteBody' responses: '200': description: Successful Response content: application/json: - schema: - $ref: '#/components/schemas/DAGResponse' + schema: {} '401': content: application/json: @@ -3104,6 +3077,12 @@ paths: schema: $ref: '#/components/schemas/HTTPExceptionResponse' description: Forbidden + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Bad Request '404': content: application/json: @@ -3111,17 +3090,18 @@ paths: $ref: '#/components/schemas/HTTPExceptionResponse' description: Not Found '422': - description: Validation Error content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' - delete: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Unprocessable Entity + /api/v2/dags/{dag_id}/details: + get: tags: - DAG - summary: Delete Dag - description: Delete the specific DAG. - operationId: delete_dag + summary: Get Dag Details + description: Get details of DAG. + operationId: get_dag_details security: - OAuth2PasswordBearer: [] parameters: @@ -3136,7 +3116,8 @@ paths: description: Successful Response content: application/json: - schema: {} + schema: + $ref: '#/components/schemas/DAGDetailsResponse' '401': content: application/json: @@ -3162,18 +3143,18 @@ paths: $ref: '#/components/schemas/HTTPExceptionResponse' description: Not Found '422': + description: Validation Error content: application/json: schema: - $ref: '#/components/schemas/HTTPExceptionResponse' - description: Unprocessable Entity - /api/v2/dags/{dag_id}/details: - get: + $ref: '#/components/schemas/HTTPValidationError' + /api/v2/dags/{dag_id}/favorite: + post: tags: - DAG - summary: Get Dag Details - description: Get details of DAG. - operationId: get_dag_details + summary: Favorite Dag + description: Mark the DAG as favorite. + operationId: favorite_dag security: - OAuth2PasswordBearer: [] parameters: @@ -3189,7 +3170,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DAGDetailsResponse' + $ref: '#/components/schemas/DAGResponse' '401': content: application/json: @@ -3202,12 +3183,53 @@ paths: schema: $ref: '#/components/schemas/HTTPExceptionResponse' description: Forbidden - '400': + '404': content: application/json: schema: $ref: '#/components/schemas/HTTPExceptionResponse' - description: Bad Request + description: Not Found + '422': + description: Validation Error + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + /api/v2/dags/{dag_id}/unfavorite: + post: + tags: + - DAG + summary: Unfavorite Dag + description: Unmark the DAG as favorite. + operationId: unfavorite_dag + security: + - OAuth2PasswordBearer: [] + parameters: + - name: dag_id + in: path + required: true + schema: + type: string + title: Dag Id + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/DAGResponse' + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Forbidden '404': content: application/json: @@ -8462,17 +8484,6 @@ components: - latest_dag_version title: DAGDetailsResponse description: Specific serializer for DAG Details responses. - DAGFavoriteBody: - properties: - is_favorite: - type: boolean - title: Is Favorite - additionalProperties: false - type: object - required: - - is_favorite - title: DAGFavoriteBody - description: Dag Serializer for updatable bodies. DAGPatchBody: properties: is_paused: diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py index b69ec0400f9ad..88f72e5a5b2bb 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py @@ -54,7 +54,6 @@ from airflow.api_fastapi.core_api.datamodels.dags import ( DAGCollectionResponse, DAGDetailsResponse, - DAGFavoriteBody, DAGPatchBody, DAGResponse, ) @@ -74,25 +73,6 @@ dags_router = AirflowRouter(tags=["DAG"], prefix="/dags") -@dags_router.get("/favorite", dependencies=[Depends(requires_access_dag(method="GET"))]) -def get_favorite_dags(session: SessionDep, user: GetUserDep) -> DAGCollectionResponse: - """Get DAGs favorited by the user.""" - user_id = user.get_id() - - favorite_dags_query = ( - select(DagModel) - .join(DagFavorite, DagModel.dag_id == DagFavorite.dag_id) - .where(DagFavorite.user_id == user_id) - ) - - dags = session.scalars(favorite_dags_query).all() - - return DAGCollectionResponse( - dags=dags, - total_entries=len(dags), - ) - - @dags_router.get("", dependencies=[Depends(requires_access_dag(method="GET"))]) def get_dags( limit: QueryLimit, @@ -135,9 +115,19 @@ def get_dags( ], readable_dags_filter: ReadableDagsFilterDep, session: SessionDep, + user: GetUserDep, + favorites: Annotated[bool | None, Query()] = None, ) -> DAGCollectionResponse: """Get all DAGs.""" - query = generate_dag_with_latest_run_query( + if favorites is True: + user_id = user.get_id() + query = ( + select(DagModel) + .join(DagFavorite, DagModel.dag_id == DagFavorite.dag_id) + .where(DagFavorite.user_id == user_id) + ) + else: + query = generate_dag_with_latest_run_query( max_run_filters=[ dag_run_start_date_range, dag_run_end_date_range, @@ -339,34 +329,50 @@ def patch_dags( ) -@dags_router.put( - "/{dag_id}", +@dags_router.post( + "/{dag_id}/favorite", responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]), - dependencies=[Depends(requires_access_dag(method="PUT")), Depends(action_logging())], + dependencies=[Depends(requires_access_dag(method="POST")), Depends(action_logging())], ) def favorite_dag( dag_id: str, - favorite_body: DAGFavoriteBody, session: SessionDep, user: GetUserDep, ) -> DAGResponse: - """Favorite the specific DAG.""" + """Mark the DAG as favorite.""" dag = session.get(DagModel, dag_id) if not dag: raise HTTPException(status.HTTP_404_NOT_FOUND, detail=f"DAG with id '{dag_id}' not found") user_id = user.get_id() + session.execute(insert(DagFavorite).values(dag_id=dag_id, user_id=user_id)) + session.commit() + + return DAGResponse.model_validate(dag) - if favorite_body.is_favorite: - session.execute(insert(DagFavorite).values(dag_id=dag_id, user_id=user_id)) - else: - session.execute( - delete(DagFavorite).where( - DagFavorite.dag_id == dag_id, - DagFavorite.user_id == user_id, - ) - ) +@dags_router.post( + "/{dag_id}/unfavorite", + responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]), + dependencies=[Depends(requires_access_dag(method="POST")), Depends(action_logging())], +) +def unfavorite_dag( + dag_id: str, + session: SessionDep, + user: GetUserDep, +) -> DAGResponse: + """Unmark the DAG as favorite.""" + dag = session.get(DagModel, dag_id) + if not dag: + raise HTTPException(status.HTTP_404_NOT_FOUND, detail=f"DAG with id '{dag_id}' not found") + + user_id = user.get_id() + session.execute( + delete(DagFavorite).where( + DagFavorite.dag_id == dag_id, + DagFavorite.user_id == user_id, + ) + ) session.commit() return DAGResponse.model_validate(dag) diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts index 92c0bd45572b8..88ade8984d941 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/common.ts @@ -207,37 +207,72 @@ export const UseDagWarningServiceListDagWarningsKeyFn = ({ dagId, limit, offset, orderBy?: string; warningType?: DagWarningType; } = {}, queryKey?: Array) => [useDagWarningServiceListDagWarningsKey, ...(queryKey ?? [{ dagId, limit, offset, orderBy, warningType }])]; -export type DagServiceGetFavoriteDagsDefaultResponse = Awaited>; -export type DagServiceGetFavoriteDagsQueryResult< - TData = DagServiceGetFavoriteDagsDefaultResponse, - TError = unknown, -> = UseQueryResult; -export const useDagServiceGetFavoriteDagsKey = "DagServiceGetFavoriteDags"; -export const UseDagServiceGetFavoriteDagsKeyFn = (queryKey?: Array) => [ - useDagServiceGetFavoriteDagsKey, - ...(queryKey ?? []), -]; export type DagServiceGetDagsDefaultResponse = Awaited>; export type DagServiceGetDagsQueryResult = UseQueryResult; export const useDagServiceGetDagsKey = "DagServiceGetDags"; -export const UseDagServiceGetDagsKeyFn = ({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }: { - dagDisplayNamePattern?: string; - dagIdPattern?: string; - dagRunEndDateGte?: string; - dagRunEndDateLte?: string; - dagRunStartDateGte?: string; - dagRunStartDateLte?: string; - dagRunState?: string[]; - excludeStale?: boolean; - lastDagRunState?: DagRunState; - limit?: number; - offset?: number; - orderBy?: string; - owners?: string[]; - paused?: boolean; - tags?: string[]; - tagsMatchMode?: "any" | "all"; -} = {}, queryKey?: Array) => [useDagServiceGetDagsKey, ...(queryKey ?? [{ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }])]; +export const UseDagServiceGetDagsKeyFn = ( + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }: { + dagDisplayNamePattern?: string; + dagIdPattern?: string; + dagRunEndDateGte?: string; + dagRunEndDateLte?: string; + dagRunStartDateGte?: string; + dagRunStartDateLte?: string; + dagRunState?: string[]; + excludeStale?: boolean; + favorites?: boolean; + lastDagRunState?: DagRunState; + limit?: number; + offset?: number; + orderBy?: string; + owners?: string[]; + paused?: boolean; + tags?: string[]; + tagsMatchMode?: "any" | "all"; + } = {}, + queryKey?: Array, +) => [ + useDagServiceGetDagsKey, + ...(queryKey ?? [ + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }, + ]), +]; export type DagServiceGetDagDefaultResponse = Awaited>; export type DagServiceGetDagQueryResult = UseQueryResult; export const useDagServiceGetDagKey = "DagServiceGetDag"; @@ -733,6 +768,8 @@ export type ConnectionServiceCreateDefaultConnectionsMutationResult = Awaited>; export type DagRunServiceTriggerDagRunMutationResult = Awaited>; export type DagRunServiceGetListDagRunsBatchMutationResult = Awaited>; +export type DagServiceFavoriteDagMutationResult = Awaited>; +export type DagServiceUnfavoriteDagMutationResult = Awaited>; export type TaskInstanceServiceGetTaskInstancesBatchMutationResult = Awaited>; export type TaskInstanceServicePostClearTaskInstancesMutationResult = Awaited>; export type PoolServicePostPoolMutationResult = Awaited>; @@ -741,7 +778,6 @@ export type VariableServicePostVariableMutationResult = Awaited>; export type BackfillServiceUnpauseBackfillMutationResult = Awaited>; export type BackfillServiceCancelBackfillMutationResult = Awaited>; -export type DagServiceFavoriteDagMutationResult = Awaited>; export type DagParsingServiceReparseDagFileMutationResult = Awaited>; export type ConnectionServicePatchConnectionMutationResult = Awaited>; export type ConnectionServiceBulkConnectionsMutationResult = Awaited>; diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts index f610a988a44d6..c5c1f6d5a64f8 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts @@ -383,58 +383,111 @@ export const ensureUseDagWarningServiceListDagWarningsData = (queryClient: Query warningType?: DagWarningType; } = {}) => queryClient.ensureQueryData({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) }); /** - * Get Favorite Dags - * Get DAGs favorited by the user. + * Get Dags + * Get all DAGs. + * @param data The data for the request. + * @param data.favorites + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @param data.lastDagRunState + * @param data.dagRunStartDateGte + * @param data.dagRunStartDateLte + * @param data.dagRunEndDateGte + * @param data.dagRunEndDateLte + * @param data.dagRunState + * @param data.orderBy * @returns DAGCollectionResponse Successful Response * @throws ApiError */ -export const ensureUseDagServiceGetFavoriteDagsData = (queryClient: QueryClient) => +export const ensureUseDagServiceGetDagsData = ( + queryClient: QueryClient, + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }: { + dagDisplayNamePattern?: string; + dagIdPattern?: string; + dagRunEndDateGte?: string; + dagRunEndDateLte?: string; + dagRunStartDateGte?: string; + dagRunStartDateLte?: string; + dagRunState?: string[]; + excludeStale?: boolean; + favorites?: boolean; + lastDagRunState?: DagRunState; + limit?: number; + offset?: number; + orderBy?: string; + owners?: string[]; + paused?: boolean; + tags?: string[]; + tagsMatchMode?: "any" | "all"; + } = {}, +) => queryClient.ensureQueryData({ - queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(), - queryFn: () => DagService.getFavoriteDags(), + queryKey: Common.UseDagServiceGetDagsKeyFn({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }), + queryFn: () => + DagService.getDags({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }), }); /** -* Get Dags -* Get all DAGs. -* @param data The data for the request. -* @param data.limit -* @param data.offset -* @param data.tags -* @param data.tagsMatchMode -* @param data.owners -* @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.excludeStale -* @param data.paused -* @param data.lastDagRunState -* @param data.dagRunStartDateGte -* @param data.dagRunStartDateLte -* @param data.dagRunEndDateGte -* @param data.dagRunEndDateLte -* @param data.dagRunState -* @param data.orderBy -* @returns DAGCollectionResponse Successful Response -* @throws ApiError -*/ -export const ensureUseDagServiceGetDagsData = (queryClient: QueryClient, { dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }: { - dagDisplayNamePattern?: string; - dagIdPattern?: string; - dagRunEndDateGte?: string; - dagRunEndDateLte?: string; - dagRunStartDateGte?: string; - dagRunStartDateLte?: string; - dagRunState?: string[]; - excludeStale?: boolean; - lastDagRunState?: DagRunState; - limit?: number; - offset?: number; - orderBy?: string; - owners?: string[]; - paused?: boolean; - tags?: string[]; - tagsMatchMode?: "any" | "all"; -} = {}) => queryClient.ensureQueryData({ queryKey: Common.UseDagServiceGetDagsKeyFn({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }), queryFn: () => DagService.getDags({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }) }); -/** * Get Dag * Get basic information about a DAG. * @param data The data for the request. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts index 21ddf53097eda..2a0df3b5376a8 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts @@ -383,58 +383,111 @@ export const prefetchUseDagWarningServiceListDagWarnings = (queryClient: QueryCl warningType?: DagWarningType; } = {}) => queryClient.prefetchQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) }); /** - * Get Favorite Dags - * Get DAGs favorited by the user. + * Get Dags + * Get all DAGs. + * @param data The data for the request. + * @param data.favorites + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @param data.lastDagRunState + * @param data.dagRunStartDateGte + * @param data.dagRunStartDateLte + * @param data.dagRunEndDateGte + * @param data.dagRunEndDateLte + * @param data.dagRunState + * @param data.orderBy * @returns DAGCollectionResponse Successful Response * @throws ApiError */ -export const prefetchUseDagServiceGetFavoriteDags = (queryClient: QueryClient) => +export const prefetchUseDagServiceGetDags = ( + queryClient: QueryClient, + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }: { + dagDisplayNamePattern?: string; + dagIdPattern?: string; + dagRunEndDateGte?: string; + dagRunEndDateLte?: string; + dagRunStartDateGte?: string; + dagRunStartDateLte?: string; + dagRunState?: string[]; + excludeStale?: boolean; + favorites?: boolean; + lastDagRunState?: DagRunState; + limit?: number; + offset?: number; + orderBy?: string; + owners?: string[]; + paused?: boolean; + tags?: string[]; + tagsMatchMode?: "any" | "all"; + } = {}, +) => queryClient.prefetchQuery({ - queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(), - queryFn: () => DagService.getFavoriteDags(), + queryKey: Common.UseDagServiceGetDagsKeyFn({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }), + queryFn: () => + DagService.getDags({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }), }); /** -* Get Dags -* Get all DAGs. -* @param data The data for the request. -* @param data.limit -* @param data.offset -* @param data.tags -* @param data.tagsMatchMode -* @param data.owners -* @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.excludeStale -* @param data.paused -* @param data.lastDagRunState -* @param data.dagRunStartDateGte -* @param data.dagRunStartDateLte -* @param data.dagRunEndDateGte -* @param data.dagRunEndDateLte -* @param data.dagRunState -* @param data.orderBy -* @returns DAGCollectionResponse Successful Response -* @throws ApiError -*/ -export const prefetchUseDagServiceGetDags = (queryClient: QueryClient, { dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }: { - dagDisplayNamePattern?: string; - dagIdPattern?: string; - dagRunEndDateGte?: string; - dagRunEndDateLte?: string; - dagRunStartDateGte?: string; - dagRunStartDateLte?: string; - dagRunState?: string[]; - excludeStale?: boolean; - lastDagRunState?: DagRunState; - limit?: number; - offset?: number; - orderBy?: string; - owners?: string[]; - paused?: boolean; - tags?: string[]; - tagsMatchMode?: "any" | "all"; -} = {}) => queryClient.prefetchQuery({ queryKey: Common.UseDagServiceGetDagsKeyFn({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }), queryFn: () => DagService.getDags({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }) }); -/** * Get Dag * Get basic information about a DAG. * @param data The data for the request. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts index c9da7770f5511..2a4f067baf67c 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts @@ -45,7 +45,6 @@ import { ClearTaskInstancesBody, ConnectionBody, CreateAssetEventsBody, - DAGFavoriteBody, DAGPatchBody, DAGRunClearBody, DAGRunPatchBody, @@ -441,66 +440,120 @@ export const useDagWarningServiceListDagWarnings = , "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }, queryKey), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) as TData, ...options }); /** - * Get Favorite Dags - * Get DAGs favorited by the user. + * Get Dags + * Get all DAGs. + * @param data The data for the request. + * @param data.favorites + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @param data.lastDagRunState + * @param data.dagRunStartDateGte + * @param data.dagRunStartDateLte + * @param data.dagRunEndDateGte + * @param data.dagRunEndDateLte + * @param data.dagRunState + * @param data.orderBy * @returns DAGCollectionResponse Successful Response * @throws ApiError */ -export const useDagServiceGetFavoriteDags = < - TData = Common.DagServiceGetFavoriteDagsDefaultResponse, +export const useDagServiceGetDags = < + TData = Common.DagServiceGetDagsDefaultResponse, TError = unknown, TQueryKey extends Array = unknown[], >( + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }: { + dagDisplayNamePattern?: string; + dagIdPattern?: string; + dagRunEndDateGte?: string; + dagRunEndDateLte?: string; + dagRunStartDateGte?: string; + dagRunStartDateLte?: string; + dagRunState?: string[]; + excludeStale?: boolean; + favorites?: boolean; + lastDagRunState?: DagRunState; + limit?: number; + offset?: number; + orderBy?: string; + owners?: string[]; + paused?: boolean; + tags?: string[]; + tagsMatchMode?: "any" | "all"; + } = {}, queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">, ) => useQuery({ - queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(queryKey), - queryFn: () => DagService.getFavoriteDags() as TData, + queryKey: Common.UseDagServiceGetDagsKeyFn( + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }, + queryKey, + ), + queryFn: () => + DagService.getDags({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }) as TData, ...options, }); /** -* Get Dags -* Get all DAGs. -* @param data The data for the request. -* @param data.limit -* @param data.offset -* @param data.tags -* @param data.tagsMatchMode -* @param data.owners -* @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.excludeStale -* @param data.paused -* @param data.lastDagRunState -* @param data.dagRunStartDateGte -* @param data.dagRunStartDateLte -* @param data.dagRunEndDateGte -* @param data.dagRunEndDateLte -* @param data.dagRunState -* @param data.orderBy -* @returns DAGCollectionResponse Successful Response -* @throws ApiError -*/ -export const useDagServiceGetDags = = unknown[]>({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }: { - dagDisplayNamePattern?: string; - dagIdPattern?: string; - dagRunEndDateGte?: string; - dagRunEndDateLte?: string; - dagRunStartDateGte?: string; - dagRunStartDateLte?: string; - dagRunState?: string[]; - excludeStale?: boolean; - lastDagRunState?: DagRunState; - limit?: number; - offset?: number; - orderBy?: string; - owners?: string[]; - paused?: boolean; - tags?: string[]; - tagsMatchMode?: "any" | "all"; -} = {}, queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDagServiceGetDagsKeyFn({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }, queryKey), queryFn: () => DagService.getDags({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }) as TData, ...options }); -/** * Get Dag * Get basic information about a DAG. * @param data The data for the request. @@ -1569,6 +1622,78 @@ export const useDagRunServiceGetListDagRunsBatch = ({ mutationFn: ({ dagId, requestBody }) => DagRunService.getListDagRunsBatch({ dagId, requestBody }) as unknown as Promise, ...options }); +/** + * Favorite Dag + * Mark the DAG as favorite. + * @param data The data for the request. + * @param data.dagId + * @returns DAGResponse Successful Response + * @throws ApiError + */ +export const useDagServiceFavoriteDag = < + TData = Common.DagServiceFavoriteDagMutationResult, + TError = unknown, + TContext = unknown, +>( + options?: Omit< + UseMutationOptions< + TData, + TError, + { + dagId: string; + }, + TContext + >, + "mutationFn" + >, +) => + useMutation< + TData, + TError, + { + dagId: string; + }, + TContext + >({ + mutationFn: ({ dagId }) => DagService.favoriteDag({ dagId }) as unknown as Promise, + ...options, + }); +/** + * Unfavorite Dag + * Unmark the DAG as favorite. + * @param data The data for the request. + * @param data.dagId + * @returns DAGResponse Successful Response + * @throws ApiError + */ +export const useDagServiceUnfavoriteDag = < + TData = Common.DagServiceUnfavoriteDagMutationResult, + TError = unknown, + TContext = unknown, +>( + options?: Omit< + UseMutationOptions< + TData, + TError, + { + dagId: string; + }, + TContext + >, + "mutationFn" + >, +) => + useMutation< + TData, + TError, + { + dagId: string; + }, + TContext + >({ + mutationFn: ({ dagId }) => DagService.unfavoriteDag({ dagId }) as unknown as Promise, + ...options, + }); /** * Get Task Instances Batch * Get list of task instances. @@ -1688,46 +1813,6 @@ export const useBackfillServiceCancelBackfill = , "mutationFn">) => useMutation({ mutationFn: ({ backfillId }) => BackfillService.cancelBackfill({ backfillId }) as unknown as Promise, ...options }); -/** - * Favorite Dag - * Favorite the specific DAG. - * @param data The data for the request. - * @param data.dagId - * @param data.requestBody - * @returns DAGResponse Successful Response - * @throws ApiError - */ -export const useDagServiceFavoriteDag = < - TData = Common.DagServiceFavoriteDagMutationResult, - TError = unknown, - TContext = unknown, ->( - options?: Omit< - UseMutationOptions< - TData, - TError, - { - dagId: string; - requestBody: DAGFavoriteBody; - }, - TContext - >, - "mutationFn" - >, -) => - useMutation< - TData, - TError, - { - dagId: string; - requestBody: DAGFavoriteBody; - }, - TContext - >({ - mutationFn: ({ dagId, requestBody }) => - DagService.favoriteDag({ dagId, requestBody }) as unknown as Promise, - ...options, - }); /** * Reparse Dag File * Request re-parsing a DAG file. diff --git a/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts b/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts index 66bb2b598b5f9..28b5d02b105b9 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts @@ -383,66 +383,120 @@ export const useDagWarningServiceListDagWarningsSuspense = , "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDagWarningServiceListDagWarningsKeyFn({ dagId, limit, offset, orderBy, warningType }, queryKey), queryFn: () => DagWarningService.listDagWarnings({ dagId, limit, offset, orderBy, warningType }) as TData, ...options }); /** - * Get Favorite Dags - * Get DAGs favorited by the user. + * Get Dags + * Get all DAGs. + * @param data The data for the request. + * @param data.favorites + * @param data.limit + * @param data.offset + * @param data.tags + * @param data.tagsMatchMode + * @param data.owners + * @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. + * @param data.excludeStale + * @param data.paused + * @param data.lastDagRunState + * @param data.dagRunStartDateGte + * @param data.dagRunStartDateLte + * @param data.dagRunEndDateGte + * @param data.dagRunEndDateLte + * @param data.dagRunState + * @param data.orderBy * @returns DAGCollectionResponse Successful Response * @throws ApiError */ -export const useDagServiceGetFavoriteDagsSuspense = < - TData = Common.DagServiceGetFavoriteDagsDefaultResponse, +export const useDagServiceGetDagsSuspense = < + TData = Common.DagServiceGetDagsDefaultResponse, TError = unknown, TQueryKey extends Array = unknown[], >( + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }: { + dagDisplayNamePattern?: string; + dagIdPattern?: string; + dagRunEndDateGte?: string; + dagRunEndDateLte?: string; + dagRunStartDateGte?: string; + dagRunStartDateLte?: string; + dagRunState?: string[]; + excludeStale?: boolean; + favorites?: boolean; + lastDagRunState?: DagRunState; + limit?: number; + offset?: number; + orderBy?: string; + owners?: string[]; + paused?: boolean; + tags?: string[]; + tagsMatchMode?: "any" | "all"; + } = {}, queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">, ) => useSuspenseQuery({ - queryKey: Common.UseDagServiceGetFavoriteDagsKeyFn(queryKey), - queryFn: () => DagService.getFavoriteDags() as TData, + queryKey: Common.UseDagServiceGetDagsKeyFn( + { + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }, + queryKey, + ), + queryFn: () => + DagService.getDags({ + dagDisplayNamePattern, + dagIdPattern, + dagRunEndDateGte, + dagRunEndDateLte, + dagRunStartDateGte, + dagRunStartDateLte, + dagRunState, + excludeStale, + favorites, + lastDagRunState, + limit, + offset, + orderBy, + owners, + paused, + tags, + tagsMatchMode, + }) as TData, ...options, }); /** -* Get Dags -* Get all DAGs. -* @param data The data for the request. -* @param data.limit -* @param data.offset -* @param data.tags -* @param data.tagsMatchMode -* @param data.owners -* @param data.dagIdPattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.dagDisplayNamePattern SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. -* @param data.excludeStale -* @param data.paused -* @param data.lastDagRunState -* @param data.dagRunStartDateGte -* @param data.dagRunStartDateLte -* @param data.dagRunEndDateGte -* @param data.dagRunEndDateLte -* @param data.dagRunState -* @param data.orderBy -* @returns DAGCollectionResponse Successful Response -* @throws ApiError -*/ -export const useDagServiceGetDagsSuspense = = unknown[]>({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }: { - dagDisplayNamePattern?: string; - dagIdPattern?: string; - dagRunEndDateGte?: string; - dagRunEndDateLte?: string; - dagRunStartDateGte?: string; - dagRunStartDateLte?: string; - dagRunState?: string[]; - excludeStale?: boolean; - lastDagRunState?: DagRunState; - limit?: number; - offset?: number; - orderBy?: string; - owners?: string[]; - paused?: boolean; - tags?: string[]; - tagsMatchMode?: "any" | "all"; -} = {}, queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDagServiceGetDagsKeyFn({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }, queryKey), queryFn: () => DagService.getDags({ dagDisplayNamePattern, dagIdPattern, dagRunEndDateGte, dagRunEndDateLte, dagRunStartDateGte, dagRunStartDateLte, dagRunState, excludeStale, lastDagRunState, limit, offset, orderBy, owners, paused, tags, tagsMatchMode }) as TData, ...options }); -/** * Get Dag * Get basic information about a DAG. * @param data The data for the request. diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts index a14818384d58c..8efd3e111efb1 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts @@ -1952,20 +1952,6 @@ export const $DAGDetailsResponse = { description: 'Specific serializer for DAG Details responses.' } as const; -export const $DAGFavoriteBody = { - properties: { - is_favorite: { - type: "boolean", - title: "Is Favorite", - }, - }, - additionalProperties: false, - type: "object", - required: ["is_favorite"], - title: "DAGFavoriteBody", - description: "Dag Serializer for updatable bodies.", -} as const; - export const $DAGPatchBody = { properties: { is_paused: { diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts index 5685dbc1fb557..b6e8a1706ff47 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { GetAssetsData, GetAssetsResponse, GetAssetAliasesData, GetAssetAliasesResponse, GetAssetAliasData, GetAssetAliasResponse, GetAssetEventsData, GetAssetEventsResponse, CreateAssetEventData, CreateAssetEventResponse, MaterializeAssetData, MaterializeAssetResponse, GetAssetQueuedEventsData, GetAssetQueuedEventsResponse, DeleteAssetQueuedEventsData, DeleteAssetQueuedEventsResponse, GetAssetData, GetAssetResponse, GetDagAssetQueuedEventsData, GetDagAssetQueuedEventsResponse, DeleteDagAssetQueuedEventsData, DeleteDagAssetQueuedEventsResponse, GetDagAssetQueuedEventData, GetDagAssetQueuedEventResponse, DeleteDagAssetQueuedEventData, DeleteDagAssetQueuedEventResponse, NextRunAssetsData, NextRunAssetsResponse, ListBackfillsData, ListBackfillsResponse, CreateBackfillData, CreateBackfillResponse, GetBackfillData, GetBackfillResponse, PauseBackfillData, PauseBackfillResponse, UnpauseBackfillData, UnpauseBackfillResponse, CancelBackfillData, CancelBackfillResponse, CreateBackfillDryRunData, CreateBackfillDryRunResponse, ListBackfillsUiData, ListBackfillsUiResponse, DeleteConnectionData, DeleteConnectionResponse, GetConnectionData, GetConnectionResponse, PatchConnectionData, PatchConnectionResponse, GetConnectionsData, GetConnectionsResponse, PostConnectionData, PostConnectionResponse, BulkConnectionsData, BulkConnectionsResponse, TestConnectionData, TestConnectionResponse, CreateDefaultConnectionsResponse, HookMetaDataResponse, GetDagRunData, GetDagRunResponse, DeleteDagRunData, DeleteDagRunResponse, PatchDagRunData, PatchDagRunResponse, GetUpstreamAssetEventsData, GetUpstreamAssetEventsResponse, ClearDagRunData, ClearDagRunResponse, GetDagRunsData, GetDagRunsResponse, TriggerDagRunData, TriggerDagRunResponse, GetListDagRunsBatchData, GetListDagRunsBatchResponse, GetDagSourceData, GetDagSourceResponse, GetDagStatsData, GetDagStatsResponse, GetDagReportsData, GetDagReportsResponse, GetConfigData, GetConfigResponse, GetConfigValueData, GetConfigValueResponse, GetConfigsResponse, ListDagWarningsData, ListDagWarningsResponse, GetDagsData, GetDagsResponse, PatchDagsData, PatchDagsResponse, GetDagData, GetDagResponse, PatchDagData, PatchDagResponse, DeleteDagData, DeleteDagResponse, GetDagDetailsData, GetDagDetailsResponse, GetDagTagsData, GetDagTagsResponse, GetDagsUiData, GetDagsUiResponse, GetEventLogData, GetEventLogResponse, GetEventLogsData, GetEventLogsResponse, GetExtraLinksData, GetExtraLinksResponse, GetTaskInstanceData, GetTaskInstanceResponse, PatchTaskInstanceData, PatchTaskInstanceResponse, DeleteTaskInstanceData, DeleteTaskInstanceResponse, GetMappedTaskInstancesData, GetMappedTaskInstancesResponse, GetTaskInstanceDependenciesByMapIndexData, GetTaskInstanceDependenciesByMapIndexResponse, GetTaskInstanceDependenciesData, GetTaskInstanceDependenciesResponse, GetTaskInstanceTriesData, GetTaskInstanceTriesResponse, GetMappedTaskInstanceTriesData, GetMappedTaskInstanceTriesResponse, GetMappedTaskInstanceData, GetMappedTaskInstanceResponse, PatchTaskInstanceByMapIndexData, PatchTaskInstanceByMapIndexResponse, GetTaskInstancesData, GetTaskInstancesResponse, BulkTaskInstancesData, BulkTaskInstancesResponse, GetTaskInstancesBatchData, GetTaskInstancesBatchResponse, GetTaskInstanceTryDetailsData, GetTaskInstanceTryDetailsResponse, GetMappedTaskInstanceTryDetailsData, GetMappedTaskInstanceTryDetailsResponse, PostClearTaskInstancesData, PostClearTaskInstancesResponse, PatchTaskInstanceDryRunByMapIndexData, PatchTaskInstanceDryRunByMapIndexResponse, PatchTaskInstanceDryRunData, PatchTaskInstanceDryRunResponse, GetLogData, GetLogResponse, GetExternalLogUrlData, GetExternalLogUrlResponse, GetImportErrorData, GetImportErrorResponse, GetImportErrorsData, GetImportErrorsResponse, GetJobsData, GetJobsResponse, GetPluginsData, GetPluginsResponse, ImportErrorsResponse, DeletePoolData, DeletePoolResponse, GetPoolData, GetPoolResponse, PatchPoolData, PatchPoolResponse, GetPoolsData, GetPoolsResponse, PostPoolData, PostPoolResponse, BulkPoolsData, BulkPoolsResponse, GetProvidersData, GetProvidersResponse, GetXcomEntryData, GetXcomEntryResponse, UpdateXcomEntryData, UpdateXcomEntryResponse, GetXcomEntriesData, GetXcomEntriesResponse, CreateXcomEntryData, CreateXcomEntryResponse, GetTasksData, GetTasksResponse, GetTaskData, GetTaskResponse, DeleteVariableData, DeleteVariableResponse, GetVariableData, GetVariableResponse, PatchVariableData, PatchVariableResponse, GetVariablesData, GetVariablesResponse, PostVariableData, PostVariableResponse, BulkVariablesData, BulkVariablesResponse, ReparseDagFileData, ReparseDagFileResponse, GetDagVersionData, GetDagVersionResponse, GetDagVersionsData, GetDagVersionsResponse, GetHealthResponse, GetVersionResponse, LoginData, LoginResponse, LogoutData, LogoutResponse, GetAuthMenusResponse, GetDependenciesData, GetDependenciesResponse, HistoricalMetricsData, HistoricalMetricsResponse, DagStatsResponse2, StructureDataData, StructureDataResponse2, GridDataData, GridDataResponse, GetDagStructureData, GetDagStructureResponse, GetGridRunsData, GetGridRunsResponse, GetGridTiSummariesData, GetGridTiSummariesResponse, GetLatestRunData, GetLatestRunResponse, GetCalendarData, GetCalendarResponse, FavoriteDagData, FavoriteDagResponse } from './types.gen'; +import type { GetAssetsData, GetAssetsResponse, GetAssetAliasesData, GetAssetAliasesResponse, GetAssetAliasData, GetAssetAliasResponse, GetAssetEventsData, GetAssetEventsResponse, CreateAssetEventData, CreateAssetEventResponse, MaterializeAssetData, MaterializeAssetResponse, GetAssetQueuedEventsData, GetAssetQueuedEventsResponse, DeleteAssetQueuedEventsData, DeleteAssetQueuedEventsResponse, GetAssetData, GetAssetResponse, GetDagAssetQueuedEventsData, GetDagAssetQueuedEventsResponse, DeleteDagAssetQueuedEventsData, DeleteDagAssetQueuedEventsResponse, GetDagAssetQueuedEventData, GetDagAssetQueuedEventResponse, DeleteDagAssetQueuedEventData, DeleteDagAssetQueuedEventResponse, NextRunAssetsData, NextRunAssetsResponse, ListBackfillsData, ListBackfillsResponse, CreateBackfillData, CreateBackfillResponse, GetBackfillData, GetBackfillResponse, PauseBackfillData, PauseBackfillResponse, UnpauseBackfillData, UnpauseBackfillResponse, CancelBackfillData, CancelBackfillResponse, CreateBackfillDryRunData, CreateBackfillDryRunResponse, ListBackfillsUiData, ListBackfillsUiResponse, DeleteConnectionData, DeleteConnectionResponse, GetConnectionData, GetConnectionResponse, PatchConnectionData, PatchConnectionResponse, GetConnectionsData, GetConnectionsResponse, PostConnectionData, PostConnectionResponse, BulkConnectionsData, BulkConnectionsResponse, TestConnectionData, TestConnectionResponse, CreateDefaultConnectionsResponse, HookMetaDataResponse, GetDagRunData, GetDagRunResponse, DeleteDagRunData, DeleteDagRunResponse, PatchDagRunData, PatchDagRunResponse, GetUpstreamAssetEventsData, GetUpstreamAssetEventsResponse, ClearDagRunData, ClearDagRunResponse, GetDagRunsData, GetDagRunsResponse, TriggerDagRunData, TriggerDagRunResponse, GetListDagRunsBatchData, GetListDagRunsBatchResponse, GetDagSourceData, GetDagSourceResponse, GetDagStatsData, GetDagStatsResponse, GetDagReportsData, GetDagReportsResponse, GetConfigData, GetConfigResponse, GetConfigValueData, GetConfigValueResponse, GetConfigsResponse, ListDagWarningsData, ListDagWarningsResponse, GetDagsData, GetDagsResponse, PatchDagsData, PatchDagsResponse, GetDagData, GetDagResponse, PatchDagData, PatchDagResponse, DeleteDagData, DeleteDagResponse, GetDagDetailsData, GetDagDetailsResponse, GetDagTagsData, GetDagTagsResponse, GetDagsUiData, GetDagsUiResponse, GetEventLogData, GetEventLogResponse, GetEventLogsData, GetEventLogsResponse, GetExtraLinksData, GetExtraLinksResponse, GetTaskInstanceData, GetTaskInstanceResponse, PatchTaskInstanceData, PatchTaskInstanceResponse, DeleteTaskInstanceData, DeleteTaskInstanceResponse, GetMappedTaskInstancesData, GetMappedTaskInstancesResponse, GetTaskInstanceDependenciesByMapIndexData, GetTaskInstanceDependenciesByMapIndexResponse, GetTaskInstanceDependenciesData, GetTaskInstanceDependenciesResponse, GetTaskInstanceTriesData, GetTaskInstanceTriesResponse, GetMappedTaskInstanceTriesData, GetMappedTaskInstanceTriesResponse, GetMappedTaskInstanceData, GetMappedTaskInstanceResponse, PatchTaskInstanceByMapIndexData, PatchTaskInstanceByMapIndexResponse, GetTaskInstancesData, GetTaskInstancesResponse, BulkTaskInstancesData, BulkTaskInstancesResponse, GetTaskInstancesBatchData, GetTaskInstancesBatchResponse, GetTaskInstanceTryDetailsData, GetTaskInstanceTryDetailsResponse, GetMappedTaskInstanceTryDetailsData, GetMappedTaskInstanceTryDetailsResponse, PostClearTaskInstancesData, PostClearTaskInstancesResponse, PatchTaskInstanceDryRunByMapIndexData, PatchTaskInstanceDryRunByMapIndexResponse, PatchTaskInstanceDryRunData, PatchTaskInstanceDryRunResponse, GetLogData, GetLogResponse, GetExternalLogUrlData, GetExternalLogUrlResponse, GetImportErrorData, GetImportErrorResponse, GetImportErrorsData, GetImportErrorsResponse, GetJobsData, GetJobsResponse, GetPluginsData, GetPluginsResponse, ImportErrorsResponse, DeletePoolData, DeletePoolResponse, GetPoolData, GetPoolResponse, PatchPoolData, PatchPoolResponse, GetPoolsData, GetPoolsResponse, PostPoolData, PostPoolResponse, BulkPoolsData, BulkPoolsResponse, GetProvidersData, GetProvidersResponse, GetXcomEntryData, GetXcomEntryResponse, UpdateXcomEntryData, UpdateXcomEntryResponse, GetXcomEntriesData, GetXcomEntriesResponse, CreateXcomEntryData, CreateXcomEntryResponse, GetTasksData, GetTasksResponse, GetTaskData, GetTaskResponse, DeleteVariableData, DeleteVariableResponse, GetVariableData, GetVariableResponse, PatchVariableData, PatchVariableResponse, GetVariablesData, GetVariablesResponse, PostVariableData, PostVariableResponse, BulkVariablesData, BulkVariablesResponse, ReparseDagFileData, ReparseDagFileResponse, GetDagVersionData, GetDagVersionResponse, GetDagVersionsData, GetDagVersionsResponse, GetHealthResponse, GetVersionResponse, LoginData, LoginResponse, LogoutData, LogoutResponse, GetAuthMenusResponse, GetDependenciesData, GetDependenciesResponse, HistoricalMetricsData, HistoricalMetricsResponse, DagStatsResponse2, StructureDataData, StructureDataResponse2, GridDataData, GridDataResponse, GetDagStructureData, GetDagStructureResponse, GetGridRunsData, GetGridRunsResponse, GetGridTiSummariesData, GetGridTiSummariesResponse, GetLatestRunData, GetLatestRunResponse, GetCalendarData, GetCalendarResponse, FavoriteDagData, FavoriteDagResponse, UnfavoriteDagData, UnfavoriteDagResponse } from './types.gen'; export class AssetService { /** @@ -1281,27 +1281,11 @@ export class DagWarningService { } export class DagService { - /** - * Get Favorite Dags - * Get DAGs favorited by the user. - * @returns DAGCollectionResponse Successful Response - * @throws ApiError - */ - public static getFavoriteDags(): CancelablePromise { - return __request(OpenAPI, { - method: "GET", - url: "/api/v2/dags/favorite", - errors: { - 401: "Unauthorized", - 403: "Forbidden", - }, - }); - } - /** * Get Dags * Get all DAGs. * @param data The data for the request. + * @param data.favorites * @param data.limit * @param data.offset * @param data.tags @@ -1326,6 +1310,7 @@ export class DagService { method: "GET", url: "/api/v2/dags", query: { + favorites: data.favorites, limit: data.limit, offset: data.offset, tags: data.tags, @@ -1454,22 +1439,43 @@ export class DagService { /** * Favorite Dag - * Favorite the specific DAG. + * Mark the DAG as favorite. * @param data The data for the request. * @param data.dagId - * @param data.requestBody * @returns DAGResponse Successful Response * @throws ApiError */ public static favoriteDag(data: FavoriteDagData): CancelablePromise { return __request(OpenAPI, { - method: "PUT", - url: "/api/v2/dags/{dag_id}", + method: "POST", + url: "/api/v2/dags/{dag_id}/favorite", + path: { + dag_id: data.dagId, + }, + errors: { + 401: "Unauthorized", + 403: "Forbidden", + 404: "Not Found", + 422: "Validation Error", + }, + }); + } + + /** + * Unfavorite Dag + * Unmark the DAG as favorite. + * @param data The data for the request. + * @param data.dagId + * @returns DAGResponse Successful Response + * @throws ApiError + */ + public static unfavoriteDag(data: UnfavoriteDagData): CancelablePromise { + return __request(OpenAPI, { + method: "POST", + url: "/api/v2/dags/{dag_id}/unfavorite", path: { dag_id: data.dagId, }, - body: data.requestBody, - mediaType: "application/json", errors: { 401: "Unauthorized", 403: "Forbidden", diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts index b82c9e6ad90f7..782f5fbe81934 100644 --- a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts +++ b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts @@ -546,13 +546,6 @@ export type DAGDetailsResponse = { readonly latest_dag_version: DagVersionResponse | null; }; -/** - * Dag Serializer for updatable bodies. - */ -export type DAGFavoriteBody = { - is_favorite: boolean; -}; - /** * Dag Serializer for updatable bodies. */ @@ -2273,8 +2266,6 @@ export type ListDagWarningsData = { export type ListDagWarningsResponse = DAGWarningCollectionResponse; -export type GetFavoriteDagsResponse = DAGCollectionResponse; - export type GetDagsData = { /** * SQL LIKE expression — use `%` / `_` wildcards (e.g. `%customer_%`). Regular expressions are **not** supported. @@ -2290,6 +2281,7 @@ export type GetDagsData = { dagRunStartDateLte?: string | null; dagRunState?: Array<(string)>; excludeStale?: boolean; + favorites?: boolean | null; lastDagRunState?: DagRunState | null; limit?: number; offset?: number; @@ -2334,13 +2326,6 @@ export type PatchDagData = { export type PatchDagResponse = DAGResponse; -export type FavoriteDagData = { - dagId: string; - requestBody: DAGFavoriteBody; -}; - -export type FavoriteDagResponse = DAGResponse; - export type DeleteDagData = { dagId: string; }; @@ -2353,6 +2338,18 @@ export type GetDagDetailsData = { export type GetDagDetailsResponse = DAGDetailsResponse; +export type FavoriteDagData = { + dagId: string; +}; + +export type FavoriteDagResponse = DAGResponse; + +export type UnfavoriteDagData = { + dagId: string; +}; + +export type UnfavoriteDagResponse = DAGResponse; + export type GetDagTagsData = { limit?: number; offset?: number; @@ -4196,24 +4193,6 @@ export type $OpenApiTs = { }; }; }; - "/api/v2/dags/favorite": { - get: { - res: { - /** - * Successful Response - */ - 200: DAGCollectionResponse; - /** - * Unauthorized - */ - 401: HTTPExceptionResponse; - /** - * Forbidden - */ - 403: HTTPExceptionResponse; - }; - }; - }; '/api/v2/dags': { get: { req: GetDagsData; @@ -4325,13 +4304,17 @@ export type $OpenApiTs = { 422: HTTPValidationError; }; }; - put: { - req: FavoriteDagData; + delete: { + req: DeleteDagData; res: { /** * Successful Response */ - 200: DAGResponse; + 200: unknown; + /** + * Bad Request + */ + 400: HTTPExceptionResponse; /** * Unauthorized */ @@ -4345,18 +4328,20 @@ export type $OpenApiTs = { */ 404: HTTPExceptionResponse; /** - * Validation Error + * Unprocessable Entity */ - 422: HTTPValidationError; + 422: HTTPExceptionResponse; }; }; - delete: { - req: DeleteDagData; + }; + "/api/v2/dags/{dag_id}/details": { + get: { + req: GetDagDetailsData; res: { /** * Successful Response */ - 200: unknown; + 200: DAGDetailsResponse; /** * Bad Request */ @@ -4374,25 +4359,48 @@ export type $OpenApiTs = { */ 404: HTTPExceptionResponse; /** - * Unprocessable Entity + * Validation Error */ - 422: HTTPExceptionResponse; + 422: HTTPValidationError; }; }; }; - '/api/v2/dags/{dag_id}/details': { - get: { - req: GetDagDetailsData; + '/api/v2/dags/{dag_id}/favorite': { + post: { + req: FavoriteDagData; res: { /** * Successful Response */ - 200: DAGDetailsResponse; + 200: DAGResponse; + /** + * Unauthorized + */ + 401: HTTPExceptionResponse; /** - * Bad Request + * Forbidden + */ + 403: HTTPExceptionResponse; + /** + * Not Found */ - 400: HTTPExceptionResponse; + 404: HTTPExceptionResponse; /** + * Validation Error + */ + 422: HTTPValidationError; + }; + }; + }; + "/api/v2/dags/{dag_id}/unfavorite": { + post: { + req: UnfavoriteDagData; + res: { + /** + * Successful Response + */ + 200: DAGResponse; + /** * Unauthorized */ 401: HTTPExceptionResponse; diff --git a/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json b/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json index 3722e0de8bc2f..ad342531253d9 100644 --- a/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json +++ b/airflow-core/src/airflow/ui/public/i18n/locales/en/dashboard.json @@ -1,11 +1,11 @@ { - "group": "Group", "favorite": { "favoriteDags": "Favorite Dags", "noFavoriteDags": "No favorites yet. Click the star icon next to a DAG in the list to add it to your favorites.", "showLess": "Show Less", "showMore": "Show More" }, + "group": "Group", "health": { "dagProcessor": "Dag Processor", "health": "Health", diff --git a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx index e685fc5544f0e..d13f99287a4c0 100644 --- a/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx +++ b/airflow-core/src/airflow/ui/src/components/DagActions/FavoriteDagButton.tsx @@ -21,8 +21,9 @@ import { useCallback, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { FiStar } from "react-icons/fi"; -import { useDagServiceGetFavoriteDags } from "openapi/queries"; +import { useDagServiceGetDags } from "openapi/queries"; import { useFavoriteDag } from "src/queries/useFavoriteDag"; +import { useUnfavoriteDag } from "src/queries/useUnfavoriteDag"; import ActionButton from "../ui/ActionButton"; @@ -33,30 +34,28 @@ type FavoriteDagButtonProps = { export const FavoriteDagButton = ({ dagId, withText = true }: FavoriteDagButtonProps) => { const { t: translate } = useTranslation("dags"); - const { data: favorites, refetch } = useDagServiceGetFavoriteDags(); + const { data: favorites, refetch } = useDagServiceGetDags({ favorites: true }); const isFavorite = useMemo( () => favorites?.dags.some((fav) => fav.dag_id === dagId) ?? false, [favorites, dagId], ); - const { mutate: toggleFavorite } = useFavoriteDag({ dagId }); + const { mutate: favoriteDag } = useFavoriteDag({ dagId }); + const { mutate: unfavoriteDag } = useUnfavoriteDag({ dagId }); const onToggle = useCallback(() => { - toggleFavorite( - { - dagId, - requestBody: { - is_favorite: !isFavorite, - }, - }, + const mutationFn = isFavorite ? unfavoriteDag : favoriteDag; + + mutationFn( + { dagId }, { onSuccess: () => { void refetch(); }, }, ); - }, [dagId, isFavorite, toggleFavorite, refetch]); + }, [dagId, isFavorite, favoriteDag, unfavoriteDag, refetch]); return ( diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx index b50f8fd65c504..8844d24214330 100644 --- a/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDagCard.tsx @@ -38,24 +38,20 @@ export const FavoriteDagCard = ({ dagId }: FavoriteDagProps) => {