bbovenzi commented on PR #34887: URL: https://github.com/apache/airflow/pull/34887#issuecomment-1819160336
> > I don't see why we need a custom context provider. I would prefer we try to have a `useEffect` inside of `useGridData` to detect only the first time `runId` is specified in the url params. > > It's been some time now so i don't remember the exact details, i think i tried that as first version but it didn't work for some reason. I wouldn't add context unnecessarily, as a I'm normally very anti global variables. :D > > The context is needed to transfer the first selection between `useSelection` and `useGridData`. There are 14 different usages of these and it's today not 100% clear how they are connected, because the data is transferred between them using the already global variable `useQuery` and `setSearchParams` :) The alternative would have been to use the return value of `useSelection` and prop-drill it into every use of `useGridData` instead. > > The use of query params also introduces an ordering problem. If `useGridData` is created after `useSelection`. Then there is a risk that `setSearchParams` inside `useSelection` is called before any `useGridData` tries to read `searchParams` to lock the runId. I think this was actually the main problem that prevented me from storing the first selection inside `useGridData`, but i can't remember for sure. > > (The placement of `firstRunIdSetByUrl = useContext(DagRunSelectionContext)` inside `useSelection` is purely cosmetic, to centralize all selection logic in one place. That is possible to easily move into `useGridData`) > > If you see any better way to do this, i would be more than happy to use some other approach instead. Also feel free to overwrite this PR if you have some other example for this already. That makes sense. You are right the ordering is a bit tricky since selection/griddata also edit the url params. Let me pull this down locally and poke around today. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org