You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for favorite/pin dags to dashboard. #45207
There is a widget to show recent dags viewed. I was prototyping this by using useEffect on dags page on load to add the dag id to a local storage key and display it. The key could store 5 items. I guess it would be useful to allow users to favorite or pin the dags. Simplified approach would be local storage but it won't persist across browsers. There is no model to store this in the server side.
Sample screenshot :
Use case/motivation
Allow users to quickly visit their favorite dags from dashboard.
Yes, I imagined we would use localStorage for this.
That's definitely the easiest approach but feels like a workaround to avoid having to update the database and do the appropriate backend-work. Is losing favorites because we swap browser / computer, or use a private navigation a big deal ?
On the other hand doing it in the backend represent a much bigger effort.
We can always start small, with the local storage, so the front-end development can progress. And eventually if the user request it and if the front-end only solution is not enough, we can always do the backend part later.
Does react provide a way to run a function on every dag page and it's sub pages like dagruns, taskinstances etc ? Something that runs whenever dag/* path matches.
Does react provide a way to run a function on every dag page and it's sub pages like dagruns, taskinstances etc ? Something that runs whenever dag/* path matches.
Not that I am aware of. What are you trying to achieve ?
Sorry, the comment was slightly off topic and the query was more around use case to build recently viewed dags which was the initial dashboard design. I created this while working on that since I felt favourite dags are more useful than recently viewed dags.
Basically to get started we need 2 mutations (Create and Delete Favories) and 1 fetch (retrieve favorites).
You can wrap those read-write from the Local Storage into a rect-query. This way it's agnostic for our application code if the query is fetching data from the API or from the local storage benefiting from the powerful react-query interface (isLoading, isSuccess, Caching, retries, data sharing and invalidation etc.)
Right now, I have an implementation for this using localStorage, but before I create a PR, I would like to do the appropriate backend work, so the favorite dags persist between browsers.
@bbovenzi Thank you.
Could you assign also my colleague @mariana-marcal-santana?
We are looking for the best approach for the backend part, but when we have something more concrete, we could share here.
If you have something in mind, we are open to any suggestion.
I am not sure the best way to do this on the backend because we don't have any db concept of user settings which is why I recommended starting with localStorage
Hello @bbovenzi !
I'm @PNL0 's colleague.
Right now we're still working on the API calls to favorite/unfavorite the DAGs. We'll update with ideas for the backend as soon as possible!
Yes creating a many to many association table for storing dagid <=> userid favorites seems like the best approach. (to avoid persisting this on the client side, also on the client side there is no migration tool and it's harder to control, so when we will bring improvement / updates to the datamodel, we will have issue with retrieving from old localstorage etc..)
Couldn't we just update the is_favorite field in the DagModel of each favorite Dag?
Similar to what is done when you pause a DAG and use the patch_dag API function.
Right now, without any implementation of an association table, I tested the new functionality this way: breeze start-airflow, open new browser, favorite some DAGs, close browser, stop_airflow, breeze start-airflow again, open new browser, check if the DAGs are still favorite.
Since the state of the DAGs didn't change even when I close and reopen the airflow and changed browsers, I assume that the data is persisted in the database, but maybe I'm looking at this in the wrong way and there is other better way to test the functionality.
Also, if the association table is needed, do we also need to create a class that represents the user/user settings?
I found a definition of User in this file : providers/fab/src/airflow/providers/fab/auth_manager/models/init.py.
Maybe we could use that.
Couldn't we just update the is_favorite field in the DagModel of each favorite DAGs?
This field does not exist on the DagModel, I assume you want to create it - The problem with that approach is that all users of the cluster will have the same favorite DAGs. It will not be possible to customize favorites 'per user'. I don't think that's what we want. (UserA might be interested in some DAGs, and UserB in some other DAGs)
I found a definition of User in this file : providers/fab/src/airflow/providers/fab/auth_manager/models/init.py.
Each auth manager has its own User model. We don't need to add one, just the favorite / user relationship, based on the UserModel field that represents the identifier I think. (BaseModel.get_id I guess).
Activity
tirkarthi commentedon Dec 25, 2024
Related #21720
tirkarthi commentedon Dec 25, 2024
cc: @pierrejeambrun @bbovenzi
bbovenzi commentedon Jan 7, 2025
Yes, I imagined we would use localStorage for this.
pierrejeambrun commentedon Jan 8, 2025
That's definitely the easiest approach but feels like a workaround to avoid having to update the database and do the appropriate backend-work. Is losing favorites because we swap browser / computer, or use a private navigation a big deal ?
On the other hand doing it in the backend represent a much bigger effort.
We can always start small, with the local storage, so the front-end development can progress. And eventually if the user request it and if the front-end only solution is not enough, we can always do the backend part later.
tirkarthi commentedon Jan 8, 2025
Does react provide a way to run a function on every dag page and it's sub pages like dagruns, taskinstances etc ? Something that runs whenever dag/* path matches.
pierrejeambrun commentedon Jan 8, 2025
Not that I am aware of. What are you trying to achieve ?
tirkarthi commentedon Jan 8, 2025
Sorry, the comment was slightly off topic and the query was more around use case to build recently viewed dags which was the initial dashboard design. I created this while working on that since I felt favourite dags are more useful than recently viewed dags.
pierrejeambrun commentedon Jan 8, 2025
Basically to get started we need 2 mutations (Create and Delete Favories) and 1 fetch (retrieve favorites).
You can wrap those read-write from the Local Storage into a
rect-query. This way it's agnostic for our application code if the query is fetching data from the API or from the local storage benefiting from the powerful react-query interface (isLoading, isSuccess, Caching, retries, data sharing and invalidation etc.)bbovenzi commentedon Jan 8, 2025
We can check url changes via useLocation and useEffect in a wrapper component:
Other DB-supported methods to filter the dashboard could include
ownerortags. The problem is that everyone organizes their dags very differentlytirkarthi commentedon Jan 8, 2025
There seems to be a built in approach from react-query for interface to localstorage and other persistent storage.
https://tanstack.com/query/latest/docs/framework/react/plugins/persistQueryClient
rawwar commentedon Jan 23, 2025
should we limit favourites/pins to DAGs or also allow tasks?
bbovenzi commentedon Jan 23, 2025
I don't see why not?
PNL0 commentedon Apr 24, 2025
Hello,
Could I be assigned to this feature proposal?
Right now, I have an implementation for this using localStorage, but before I create a PR, I would like to do the appropriate backend work, so the favorite dags persist between browsers.
bbovenzi commentedon Apr 24, 2025
@PNL0 all yours. What do you have in mind for the backend work?
PNL0 commentedon Apr 24, 2025
@bbovenzi Thank you.
Could you assign also my colleague @mariana-marcal-santana?
We are looking for the best approach for the backend part, but when we have something more concrete, we could share here.
If you have something in mind, we are open to any suggestion.
bbovenzi commentedon Apr 24, 2025
@mariana-marcal-santana can you comment on the issue? and then I can assign you too.
I am not sure the best way to do this on the backend because we don't have any db concept of user settings which is why I recommended starting with localStorage
mariana-marcal-santana commentedon Apr 24, 2025
Hello @bbovenzi !
I'm @PNL0 's colleague.
Right now we're still working on the API calls to favorite/unfavorite the DAGs. We'll update with ideas for the backend as soon as possible!
PNL0 commentedon Apr 25, 2025
Hello @bbovenzi,
Me and @mariana-marcal-santana have got a solution that we believe that stores the favorite DAGs persistently in the database.
Instead of using localStorage, the frontend makes requests to favorite the dags and the backend handles this requests with functions that we created.
Could you give some feedback about this approach and check if it matches with what you were describing in #45207 (comment) ?
Thanks
pierrejeambrun commentedon Apr 28, 2025
Yes creating a many to many association table for storing
dagid<=>useridfavorites seems like the best approach. (to avoid persisting this on the client side, also on the client side there is nomigrationtool and it's harder to control, so when we will bring improvement / updates to the datamodel, we will have issue with retrieving from old localstorage etc..)PNL0 commentedon May 1, 2025
Hello @pierrejeambrun @bbovenzi
Couldn't we just update the is_favorite field in the DagModel of each favorite Dag?
Similar to what is done when you pause a DAG and use the patch_dag API function.
Right now, without any implementation of an association table, I tested the new functionality this way: breeze start-airflow, open new browser, favorite some DAGs, close browser, stop_airflow, breeze start-airflow again, open new browser, check if the DAGs are still favorite.
Since the state of the DAGs didn't change even when I close and reopen the airflow and changed browsers, I assume that the data is persisted in the database, but maybe I'm looking at this in the wrong way and there is other better way to test the functionality.
Also, if the association table is needed, do we also need to create a class that represents the user/user settings?
I found a definition of User in this file : providers/fab/src/airflow/providers/fab/auth_manager/models/init.py.
Maybe we could use that.
pierrejeambrun commentedon May 5, 2025
This field does not exist on the DagModel, I assume you want to create it - The problem with that approach is that all users of the cluster will have the same favorite DAGs. It will not be possible to customize favorites 'per user'. I don't think that's what we want. (UserA might be interested in some DAGs, and UserB in some other DAGs)
Each auth manager has its own User model. We don't need to add one, just the favorite / user relationship, based on the
UserModelfield that represents the identifier I think. (BaseModel.get_idI guess).