-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Implement multisort in DAGs table #47849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Were you able to test this with a working backend ? (What I mean by that is you should be able to test that when you try sorting on multiple criteria the table should re-order itself appropriately.)
For this I believe you would need to rebase your branch on top of #47440
I tested this with #47440's backend and the part related to the frontend (the setting of the URL) worked correctly as shown in the picture in #46383 (comment). The actual sorting wasn't perfect in some cases as I also mentioned in the comment above which is why I asked if the backend had been tested for examples like the one I shared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to modify components so that the request that is send to the backend passes the appropriateorder_by
list of query parameters.
For now the url is correctly set and updated via the table component, but the requests send to the backend do not specify the multisort, this is why you do not have the expected response.
I think the backend implementation is functional and you should observe the appropriate behavior based on #47440
Thanks for the insights! I'll check on that and update on my progress |
bbc5fe5
to
d19d25a
Compare
I've corrected the code to also pass the sort parameters to the backend URL. When tested with the backend everything seemed to work as expected, including the previously mentioned example. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mariana-marcal-santana,
Looking good, will do a final testing and review once the backend is merged.
A few things need to be adjusted.
@@ -166,8 +166,7 @@ export const DagsList = () => { | |||
searchParams.get(NAME_PATTERN_PARAM) ?? undefined, | |||
); | |||
|
|||
const [sort] = sorting; | |||
const orderBy = sort ? `${sort.desc ? "-" : ""}${sort.id}` : "-last_run_start_date"; | |||
const orderBy = new URLSearchParams(globalThis.location.search).getAll("sort"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing the default sorting value.
By default if sort wasn't defined it would default to -last_run_start_date
, that's lost with the new implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there are plenty of other places where we do sorting like that and that need to be updated to work with a list:
AssetList
, Variables
, Connections
etc.... (you can search for const [sort] = sorting
in the code base)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I'll start working on this asap!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One quick comment and could you rebase when you have a chance?
After rebasing I'll do some more manual usability testing
airflow/ui/src/pages/Asset/Asset.tsx
Outdated
const orderBy = new URLSearchParams(globalThis.location.search).getAll("sort").length === 0 ? | ||
["-timestamp"] : new URLSearchParams(globalThis.location.search).getAll("sort"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const orderBy = new URLSearchParams(globalThis.location.search).getAll("sort").length === 0 ? | |
["-timestamp"] : new URLSearchParams(globalThis.location.search).getAll("sort"); | |
const sortParam = new URLSearchParams(globalThis.location.search).getAll("sort") | |
const orderBy = sortParam.length === 0 ? | |
["-timestamp"] : sortParam; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't comment on every single occurrence but let's try to keep our code DRY.
Since this is so common, maybe we can even pull it into its own util function or hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bbovenzi @pierrejeambrun !
I've created the function and used it in all places mentioned in #47849 (comment).
I've also rebased the repo (yesterday) as requested.
I would appreciate any feedback on the implementation! Thanks!
Frontend: Implement multisort for DAGs when displayed in a table; The URL displays extra sorting attributes when Shift+click is used on the column to sort by. This implements the UI portion of apache#46383
Frontend: Implement multisort for DAGs when displayed in a table; The browser and backend URLs display extra sorting attributes when Shift+click is used on the column to sort by. This implements the UI portion of apache#46383
Frontend: Implement multisort for DAGs when displayed in a table; Add default to the sorting parameters; Add support for multiple sort parameters in more lists This implements the UI portion of apache#46383
Frontend: Implement multisort for DAGs when displayed in a table; Add function to get default sorting parameters This implements the UI portion of apache#46383
2bd2e69
to
6827b2e
Compare
Frontend: Implement multisort for DAGs when displayed in a table; Add support for multiple sort parameters in new lists This implements the UI portion of apache#46383
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
Do you mind running pnpm lint && pnpm format
inside your local airflow-core/src/airflow/ui
directory?
export const getOrderBy = (pre_defined?: string): string[] => { | ||
const sortParam = new URLSearchParams(globalThis.location.search).getAll("sort"); | ||
return (sortParam.length === 0 && pre_defined != undefined) ? [pre_defined] : sortParam; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const getOrderBy = (pre_defined?: string): string[] => { | |
const sortParam = new URLSearchParams(globalThis.location.search).getAll("sort"); | |
return (sortParam.length === 0 && pre_defined != undefined) ? [pre_defined] : sortParam; | |
}; | |
export const getOrderBy = (defaultOrder?: string): string[] => { | |
const sortParam = new URLSearchParams(globalThis.location.search).getAll("sort"); | |
return (sortParam.length === 0 && defaultOrder !== undefined) ? [defaultOrder] : sortParam; | |
}; | |
We generally don't want to use snake_case in our typescript code. The only ones we do have are generated from the python API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bbovenzi !
In my last commit I fixed the casing, ran the afore mentioned commands and fixed the things marked in the lint command (that were from my commits).
Anything else I should change?
Also, I noticed that the code failed these tests: https://github.com/apache/airflow/actions/runs/14682302749/job/41221555783. How should I fix it?
I noticed that it fails where I changed orderBy?: string to orderBy?: string[]. From what I saw, I think it's because it clashes with the definition on the file airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml (that I changed but I believe it got overwritten).
Could you confirm this please?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pnpm format
should help solve most of those static checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may also need to make sure we generate the API spec docs before we run pnpm format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bbovenzi !
I ran pnpm format but the static checks still failed...
When you say API spec docs do you mean this file: airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml? And if so how can I generate it? I changed it locally, adapted the code that depended on it and everything seems to be working on my machine. What do I need to do to pass the static checks?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think this is an order of operations with pre-commit
pre-commit run generate-openapi-spec
and then pre-commit run ts-compile-format-lint-ui
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bbovenzi !
I had previously ran these operations and noticed that the first one changes the v1-rest-api-generated.yaml file like so:
This is what is causing the errors in the CI because the Order by argument now has to be an array and it keeps changing to string (which doesn't go along with the changes in the code for the multisort).
Given this, what I meant was if there was a way to define the file and the pre-commit to allow the Order By to be an array? From what I know, it seems like this could fix the CI errors.
Thank you!
Implement multisort for DAGs when displayed in a table; Fix casing and formatting This implements the UI portion of apache#46383
type: array | ||
items: | ||
type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't modify this manually, the file is auto generated based on the backend, and currently the backend specify a string
not an array. You'll need to wait for the backend PR to be done and rebase on top of that, this way the order_by
will have the appropriate array
type.
Unfortunately the backend PR is not progressing. I trying pinging the contributor but we might want to take it at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @pierrejeambrun @bbovenzi !
Thanks for clarifying! Given this, should I fix the editions in this file now or only after the backend PR is merged to have a better sense of the necessary changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the backend PR is merged, rebasing on latest main will automatically give you that change. (The updated openapi spec).
We can't merge this PR until the backend is done, until then I think we can keep things like that (manually edited spec), this way from a frontend
point of view the backend interface is correct and you can work without disrupting your workflow (eslint errors etc), but the CI static check won't be able to succeed. Once the backend is done we remove the manual change to the openapi spec and rebase on main to get the updated spec.
Implement multisort for DAGs when displayed in a table; The URL displays extra sorting attributes when Shift+click is used on the column to sort by.
This implements the UI portion of #46383 and is dependent on the backend part implemented in #47440.
cc @pierrejeambrun @bbovenzi