-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Add UI to swap clauses in the notebook #39205
Conversation
@@ -65,6 +65,8 @@ export type OrderByDirection = "asc" | "desc"; | |||
declare const FilterClause: unique symbol; | |||
export type FilterClause = unknown & { _opaque: typeof FilterClause }; | |||
|
|||
export type Filterable = FilterClause | ExpressionClause | SegmentMetadata; |
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.
Similar to Aggregatable
58befcb
to
de77af6
Compare
const { attributes, listeners, setNodeRef, transform, transition } = | ||
useSortable({ | ||
id, | ||
animateLayoutChanges: () => false, |
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.
Disable animation after drag-n-drop because we don't have a stable ID
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.
This comment deserves to live in code
); | ||
} | ||
|
||
function getItemIdFromIndex(index: number) { |
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.
DnD kit doesn't like 0
as id
so we convert indexes to strings
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.
This comment deserves to live in code
|
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.
Works great 👍
export function swapClauses( | ||
query: Query, | ||
stageIndex: number, | ||
sourceClause: Clause, | ||
targetClause: Clause, | ||
): Query { |
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.
Seeing that every *Step
component has its own handleReorder*
implementation, I thought that the benefit is type safety - it should not be possible to swap an aggregation clause with a breakout clause, etc.
We could enforce it here:
export function swapClauses( | |
query: Query, | |
stageIndex: number, | |
sourceClause: Clause, | |
targetClause: Clause, | |
): Query { | |
export function swapClauses< | |
C extends | |
| AggregationClause | |
| ExpressionClause | |
| BreakoutClause | |
| FilterClause | |
| OrderByClause, | |
>(query: Query, stageIndex: number, sourceClause: C, targetClause: C): Query { |
["sum", ["field", ORDERS.SUBTOTAL, null]], | ||
["sum", ["field", ORDERS.TOTAL, null]], | ||
["avg", ["field", ORDERS.TOTAL, null]], | ||
], |
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 should also cover order clauses
const { attributes, listeners, setNodeRef, transform, transition } = | ||
useSortable({ | ||
id, | ||
animateLayoutChanges: () => false, |
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.
This comment deserves to live in code
); | ||
} | ||
|
||
function getItemIdFromIndex(index: number) { |
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.
This comment deserves to live in code
Epic #39210
Demo https://www.loom.com/share/46322c56db044c4d8d8de5c890510e62
Allows to drag-n-drop custom columns, filters, aggregations, and breakouts.
How to verify: