Skip to content

Add support for favorite/pin dags to dashboard. #45207

Closed

Description

@tirkarthi

Description

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 :

image

Use case/motivation

Allow users to quickly visit their favorite dags from dashboard.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    area:UI
    AIP-38
    on Dec 25, 2024
  2. tirkarthi commented on Dec 25, 2024

    @tirkarthi
    ContributorAuthor

    Related #21720

  3. tirkarthi commented on Dec 25, 2024

    @tirkarthi
    ContributorAuthor
  4. bbovenzi commented on Jan 7, 2025

    @bbovenzi
    Contributor

    Yes, I imagined we would use localStorage for this.

  5. pierrejeambrun commented on Jan 8, 2025

    @pierrejeambrun
    Member

    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.

  6. tirkarthi commented on Jan 8, 2025

    @tirkarthi
    ContributorAuthor

    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.

  7. pierrejeambrun commented on Jan 8, 2025

    @pierrejeambrun
    Member

    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 ?

  8. tirkarthi commented on Jan 8, 2025

    @tirkarthi
    ContributorAuthor

    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.

  9. pierrejeambrun commented on Jan 8, 2025

    @pierrejeambrun
    Member

    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.)

  10. bbovenzi commented on Jan 8, 2025

    @bbovenzi
    Contributor

    We can check url changes via useLocation and useEffect in a wrapper component:

    const location = useLocation();
    useEffect(() => {
       console.log("if contains a dag_id, update view count")
    }, [location]);
    

    Other DB-supported methods to filter the dashboard could include owner or tags. The problem is that everyone organizes their dags very differently

  11. tirkarthi commented on Jan 8, 2025

    @tirkarthi
    ContributorAuthor

    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

  12. rawwar commented on Jan 23, 2025

    @rawwar
    Contributor

    should we limit favourites/pins to DAGs or also allow tasks?

  13. bbovenzi commented on Jan 23, 2025

    @bbovenzi
    Contributor

    should we limit favourites/pins to DAGs or also allow tasks?

    I don't see why not?

  14. added this to the Airflow 3.1+ milestone on Apr 22, 2025
  15. PNL0 commented on Apr 24, 2025

    @PNL0
    Contributor

    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.

  16. bbovenzi commented on Apr 24, 2025

    @bbovenzi
    Contributor

    @PNL0 all yours. What do you have in mind for the backend work?

  17. PNL0 commented on Apr 24, 2025

    @PNL0
    Contributor

    @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.

  18. bbovenzi commented on Apr 24, 2025

    @bbovenzi
    Contributor

    @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

  19. mariana-marcal-santana commented on Apr 24, 2025

    @mariana-marcal-santana
    Contributor

    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!

  20. PNL0 commented on Apr 25, 2025

    @PNL0
    Contributor

    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

  21. pierrejeambrun commented on Apr 28, 2025

    @pierrejeambrun
    Member

    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..)

  22. PNL0 commented on May 1, 2025

    @PNL0
    Contributor

    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.

  23. pierrejeambrun commented on May 5, 2025

    @pierrejeambrun
    Member

    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).

  24. removed this from the Airflow 3.1+ milestone on Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

AIP-38area:UIkind:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions