-
Notifications
You must be signed in to change notification settings - Fork 62
[WC-1784] DG: Column drag and drop enhancements #1989
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
Open
yordan-st
wants to merge
16
commits into
main
Choose a base branch
from
feat/WC-1784_DG-coldrag-enhance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6a281bf
refactor: migrate event controllers from DI to React Context for simp…
iobuhov 6df1cb4
refactor: migrate event handlers to container
iobuhov 7638ed2
refactor: extract drag & drop state and logic to mobx
yordan-st 2522e80
refactor: update components to use new state management
yordan-st 2ac0312
refactor: remove obsolete tests and snapshots, create for new component
yordan-st 193e2c3
refactor: rewrite columnreszier to use injection hooks
yordan-st 3f39964
refactor: enhance ColumnResizer test structure and update snapshot
yordan-st 27616ac
refactor: fix failing test
yordan-st 789652b
feat: enhance drag-and-drop functionality with DragHandle component
yordan-st fe799de
refactor: fix lint errors
yordan-st 35155a1
refactor: standardize use of brandi
yordan-st e3065e4
refactor: improve naming, consistency and clean up
yordan-st 1c240a3
refactor: ensure consistent naming, prop destructuring, update tests
yordan-st 939bc1d
fix: update SelectActionHandler initialization to use null instead of…
yordan-st ba52a60
fix: restore sort icon state, add dragndropdesign mode and react icon
yordan-st 5331e71
fix: update sorting tests to check visibility of SVG icons instead of…
yordan-st File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+245 Bytes
(100%)
...rid-web/e2e/DataGrid.spec.js-snapshots/dataGridColumnContent-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-609 Bytes
(94%)
...Widgets/datagrid-web/e2e/DataGrid.spec.js-snapshots/datagrid-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.8 KB
(110%)
...eb/e2e/DataGrid.spec.js-snapshots/datagrid-virtual-scrolling-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+475 Bytes
(100%)
...idSelection.spec.js-snapshots/datagridMultiSelectionCheckbox-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+671 Bytes
(100%)
...idSelection.spec.js-snapshots/datagridMultiSelectionRowClick-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+377 Bytes
(100%)
...dSelection.spec.js-snapshots/datagridSingleSelectionCheckbox-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+497 Bytes
(100%)
...dSelection.spec.js-snapshots/datagridSingleSelectionRowClick-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.2 KB
(100%)
...ngIntegration.spec.js-snapshots/datagridFilteringIntegration-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.98 KB
(110%)
...ridFilteringSingle.spec.js-snapshots/datagridFilteringSingle-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/pluggableWidgets/datagrid-web/src/components/ColumnContainer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import classNames from "classnames"; | ||
| import { ReactElement } from "react"; | ||
| import { ColumnHeader } from "./ColumnHeader"; | ||
| import { useColumn, useColumnsStore, useDatagridConfig, useHeaderDragnDropVM } from "../model/hooks/injection-hooks"; | ||
| import { ColumnResizerProps } from "./ColumnResizer"; | ||
| import { observer } from "mobx-react-lite"; | ||
|
|
||
| export interface ColumnContainerProps { | ||
| isLast?: boolean; | ||
| resizer: ReactElement<ColumnResizerProps>; | ||
| } | ||
|
|
||
| export const ColumnContainer = observer(function ColumnContainer(props: ColumnContainerProps): ReactElement { | ||
| const { columnsFilterable, id: gridId } = useDatagridConfig(); | ||
| const { columnFilters } = useColumnsStore(); | ||
| const column = useColumn(); | ||
| const { canSort, columnId, columnIndex, canResize, sortDir, header } = column; | ||
| const vm = useHeaderDragnDropVM(); | ||
| const caption = header.trim(); | ||
|
|
||
| return ( | ||
| <div | ||
| aria-sort={getAriaSort(canSort, sortDir)} | ||
| className={classNames("th", { | ||
| [`drop-${vm.dropTarget?.[1]}`]: columnId === vm.dropTarget?.[0], | ||
| dragging: columnId === vm.dragging?.[1], | ||
| "dragging-over-self": columnId === vm.dragging?.[1] && !vm.dropTarget | ||
| })} | ||
| role="columnheader" | ||
| style={!canSort ? { cursor: "unset" } : undefined} | ||
| title={caption} | ||
| ref={ref => column.setHeaderElementRef(ref)} | ||
| data-column-id={columnId} | ||
| onDrop={vm.handleOnDrop} | ||
| onDragEnter={vm.handleDragEnter} | ||
| onDragOver={vm.handleDragOver} | ||
| > | ||
| <div className={classNames("column-container")} id={`${gridId}-column${columnId}`}> | ||
| <ColumnHeader /> | ||
| {columnsFilterable && ( | ||
| <div className="filter" style={{ pointerEvents: vm.dragging ? "none" : undefined }}> | ||
| {columnFilters[columnIndex]?.renderFilterWidgets()} | ||
| </div> | ||
| )} | ||
| </div> | ||
| {canResize ? props.resizer : null} | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| function getAriaSort(canSort: boolean, sortDir: string | undefined): "ascending" | "descending" | "none" | undefined { | ||
| if (!canSort) { | ||
| return undefined; | ||
| } | ||
|
|
||
| switch (sortDir) { | ||
| case "asc": | ||
| return "ascending"; | ||
| case "desc": | ||
| return "descending"; | ||
| default: | ||
| return "none"; | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
packages/pluggableWidgets/datagrid-web/src/components/ColumnHeader.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import classNames from "classnames"; | ||
| import { HTMLAttributes, KeyboardEvent, ReactElement, ReactNode } from "react"; | ||
| import { DragHandle } from "./DragHandle"; | ||
| import { FaArrowsAltV } from "./icons/FaArrowsAltV"; | ||
| import { FaLongArrowAltDown } from "./icons/FaLongArrowAltDown"; | ||
| import { FaLongArrowAltUp } from "./icons/FaLongArrowAltUp"; | ||
| import { useColumn, useHeaderDragnDropVM } from "../model/hooks/injection-hooks"; | ||
| import { observer } from "mobx-react-lite"; | ||
| import { SortDirection } from "../typings/sorting"; | ||
|
|
||
| interface SortIconProps { | ||
| direction: SortDirection | undefined; | ||
| } | ||
|
|
||
| export const ColumnHeader = observer(function ColumnHeader(): ReactElement { | ||
| const column = useColumn(); | ||
| const { header, canSort, alignment } = column; | ||
| const caption = header.trim(); | ||
| const sortProps = canSort ? getSortProps(() => column.toggleSort()) : null; | ||
| const vm = useHeaderDragnDropVM(); | ||
|
|
||
| return ( | ||
| <div | ||
| className={classNames("column-header", { clickable: canSort }, `align-column-${alignment}`)} | ||
| style={{ pointerEvents: vm.dragging ? "none" : undefined }} | ||
| {...sortProps} | ||
| aria-label={canSort ? "sort " + caption : caption} | ||
| > | ||
| {vm.isDraggable && ( | ||
| <DragHandle draggable={vm.isDraggable} onDragStart={vm.handleDragStart} onDragEnd={vm.handleDragEnd} /> | ||
| )} | ||
| <span className="column-caption">{caption.length > 0 ? caption : "\u00a0"}</span> | ||
| {canSort ? <SortIcon direction={column.sortDir} /> : null} | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| function SortIcon({ direction }: SortIconProps): ReactNode { | ||
| switch (direction) { | ||
| case "asc": | ||
| return <FaLongArrowAltUp />; | ||
| case "desc": | ||
| return <FaLongArrowAltDown />; | ||
| default: | ||
| return <FaArrowsAltV />; | ||
| } | ||
| } | ||
|
|
||
| function getSortProps(toggleSort: () => void): HTMLAttributes<HTMLDivElement> { | ||
| return { | ||
| onClick: () => { | ||
| toggleSort(); | ||
| }, | ||
| onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => { | ||
| if (e.key === "Enter" || e.key === " ") { | ||
| e.preventDefault(); | ||
| toggleSort(); | ||
| } | ||
| }, | ||
| role: "button", | ||
| tabIndex: 0 | ||
| }; | ||
| } |
28 changes: 11 additions & 17 deletions
28
packages/pluggableWidgets/datagrid-web/src/components/ColumnResizer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/pluggableWidgets/datagrid-web/src/components/DragHandle.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { DragEvent, DragEventHandler, MouseEvent, ReactElement } from "react"; | ||
| import { FaGripVertical } from "./icons/FaGripVertical"; | ||
|
|
||
| interface DragHandleProps { | ||
| draggable: boolean; | ||
| onDragStart?: DragEventHandler<HTMLSpanElement>; | ||
| onDragEnd?: DragEventHandler<HTMLSpanElement>; | ||
| } | ||
| export function DragHandle({ draggable, onDragStart, onDragEnd }: DragHandleProps): ReactElement { | ||
| const handleMouseDown = (e: MouseEvent<HTMLSpanElement>): void => { | ||
| // Only stop propagation, don't prevent default - we need default for drag to work | ||
| e.stopPropagation(); | ||
| }; | ||
|
|
||
| const handleClick = (e: MouseEvent<HTMLSpanElement>): void => { | ||
| // Stop click events from bubbling to prevent sorting | ||
| e.stopPropagation(); | ||
| e.preventDefault(); | ||
| }; | ||
|
|
||
| const handleDragStart = (e: DragEvent<HTMLSpanElement>): void => { | ||
| // Don't stop propagation here - let the drag start properly | ||
| if (onDragStart) { | ||
| onDragStart(e); | ||
| } | ||
| }; | ||
|
|
||
| const handleDragEnd = (e: DragEvent<HTMLSpanElement>): void => { | ||
| if (onDragEnd) { | ||
| onDragEnd(e); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <span | ||
| className="drag-handle" | ||
| draggable={draggable} | ||
| onDragStart={handleDragStart} | ||
| onDragEnd={handleDragEnd} | ||
| onMouseDown={handleMouseDown} | ||
| onClick={handleClick} | ||
| > | ||
| <FaGripVertical /> | ||
| </span> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.