-
Notifications
You must be signed in to change notification settings - Fork 663
CardView - implement headerPanel #28842
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b581e6a
implement
pomahtri 90243e7
fix: forgotten files from cherry-pick
pomahtri 622b5a3
fix: add todo comment for magic number
pomahtri 4f38150
review fix: remove undefined classes
pomahtri 29acb9e
Merge branch 'grids/cardview/main' into grids/cardview/header_panel
pomahtri fe495a5
review fix: add types for sortable events
pomahtri 99dd05b
review fix: if statement -> ternar op
pomahtri cc2b7e9
review fix: decrease nesting
pomahtri 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
30 changes: 30 additions & 0 deletions
30
...evextreme/js/__internal/grids/new/card_view/header_panel/__snapshots__/item.test.tsx.snap
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,30 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Item should render sort icons 1`] = ` | ||
| <div> | ||
| <div | ||
| class="dx-cardview-header-item " | ||
| tabindex="0" | ||
| > | ||
| Column 1 | ||
| <span | ||
| class="dx-cardview-header-item-sorting" | ||
| > | ||
| <i | ||
| class="dx-icon dx-icon-sortup" | ||
| /> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`Item should use column caption as text 1`] = ` | ||
| <div> | ||
| <div | ||
| class="dx-cardview-header-item " | ||
| tabindex="0" | ||
| > | ||
| my column caption | ||
| </div> | ||
| </div> | ||
| `; |
156 changes: 156 additions & 0 deletions
156
...extreme/js/__internal/grids/new/card_view/header_panel/__snapshots__/options.test.ts.snap
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,156 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`ColumnProperties headerItemCssClass should override content of headerPanel item 1`] = ` | ||
| <div | ||
| class="test-container" | ||
| > | ||
| <div | ||
| class="dx-cardview-headers" | ||
| > | ||
| <div | ||
| class="dx-scrollable dx-visibility-change-handler dx-scrollable-horizontal dx-scrollable-simulated" | ||
| > | ||
| <div | ||
| class="dx-scrollable-wrapper" | ||
| > | ||
| <div | ||
| class="dx-scrollable-container" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-scrollable-content" | ||
| style="left: 0px; top: 0px; transform: none;" | ||
| > | ||
| <div | ||
| class="dx-cardview-headers-content" | ||
| > | ||
| <div | ||
| class="dx-cardview-header-item my-css-class " | ||
| tabindex="0" | ||
| > | ||
| Column 1 | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-scrollable-scrollbar dx-widget dx-scrollbar-horizontal" | ||
| style="display: none;" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll dx-state-invisible" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll-content" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`Options headerPanel itemCssClass should add css class to headerPanel item 1`] = ` | ||
| <div | ||
| class="dx-scrollable dx-visibility-change-handler dx-scrollable-horizontal dx-scrollable-simulated" | ||
| > | ||
| <div | ||
| class="dx-scrollable-wrapper" | ||
| > | ||
| <div | ||
| class="dx-scrollable-container" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-scrollable-content" | ||
| style="left: 0px; top: 0px; transform: none;" | ||
| > | ||
| <div | ||
| class="dx-cardview-headers-content" | ||
| > | ||
| <div | ||
| class="dx-cardview-header-item my-class" | ||
| tabindex="0" | ||
| > | ||
| Column 1 | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-scrollable-scrollbar dx-widget dx-scrollbar-horizontal" | ||
| style="display: none;" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll dx-state-invisible" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll-content" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`Options headerPanel visible when it is false should hide headerPanel 1`] = ` | ||
| <div | ||
| class="test-container" | ||
| > | ||
|
|
||
| </div> | ||
| `; | ||
|
|
||
| exports[`Options headerPanel visible when it is true should show headerPanel 1`] = ` | ||
| <div | ||
| class="test-container" | ||
| > | ||
| <div | ||
| class="dx-cardview-headers" | ||
| > | ||
| <div | ||
| class="dx-scrollable dx-visibility-change-handler dx-scrollable-horizontal dx-scrollable-simulated" | ||
| > | ||
| <div | ||
| class="dx-scrollable-wrapper" | ||
| > | ||
| <div | ||
| class="dx-scrollable-container" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-scrollable-content" | ||
| style="left: 0px; top: 0px; transform: none;" | ||
| > | ||
| <div | ||
| class="dx-cardview-headers-content" | ||
| > | ||
| <div | ||
| class="dx-cardview-header-item " | ||
| tabindex="0" | ||
| > | ||
| Column 1 | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-scrollable-scrollbar dx-widget dx-scrollbar-horizontal" | ||
| style="display: none;" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll dx-state-invisible" | ||
| > | ||
| <div | ||
| class="dx-scrollable-scroll-content" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
| `; |
141 changes: 141 additions & 0 deletions
141
packages/devextreme/js/__internal/grids/new/card_view/header_panel/column_sortable.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,141 @@ | ||
| import $ from '@js/core/renderer'; | ||
| import type { ComponentType, InfernoNode } from 'inferno'; | ||
| import { Component, render } from 'inferno'; | ||
|
|
||
| import type { Column } from '../../grid_core/columns_controller/types'; | ||
| import type { Props as SortableProps } from '../../grid_core/inferno_wrappers/sortable'; | ||
| import { Sortable } from '../../grid_core/inferno_wrappers/sortable'; | ||
|
|
||
| export type Status = 'forbid' | 'show' | 'moving' | 'none'; | ||
|
|
||
| export interface Props extends Omit<SortableProps, 'onAdd' | 'onReorder' | 'dragTemplate'> { | ||
| source: string; | ||
|
|
||
| visibleColumns: Column[]; | ||
|
|
||
| allowColumnReordering: boolean; | ||
|
|
||
| onMove: (column: Column, toIndex: number, source: string) => void; | ||
|
|
||
| dragTemplate?: ComponentType<{ column: Column; status: Status }>; | ||
| } | ||
|
|
||
| interface State { | ||
| status: Status; | ||
| } | ||
|
|
||
| export class ColumnSortable extends Component<Props, State> { | ||
| status: Status = 'moving'; | ||
|
|
||
| dragItemProps?: { | ||
| container: HTMLElement; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| props: any; | ||
| }; | ||
|
|
||
| private readonly onDragStart = (e): void => { | ||
| const column = this.props.visibleColumns[e.fromIndex]; | ||
|
|
||
| if (!column.allowReordering) { | ||
| e.cancel = true; | ||
| return; | ||
| } | ||
|
|
||
| e.itemData = { | ||
| column, | ||
| source: this.props.source, | ||
| }; | ||
| }; | ||
|
|
||
| private readonly onDragMove = (e): void => { | ||
| const containerCoords = $(e.element).get(0).getBoundingClientRect(); | ||
| const dragCoords = { | ||
| x: e.event.clientX, | ||
| y: e.event.clientY, | ||
| }; | ||
|
|
||
| const yDistance = Math.min( | ||
| Math.abs(dragCoords.y - containerCoords.y), | ||
| Math.abs(dragCoords.y - containerCoords.y + containerCoords.height), | ||
| ); | ||
|
|
||
| // TODO: move to scss variable | ||
| if (yDistance <= 64) { | ||
pomahtri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.status = 'moving'; | ||
| } else { | ||
| this.status = 'forbid'; | ||
| } | ||
pomahtri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| this.renderDragTemplate(); | ||
| }; | ||
|
|
||
| private readonly onDragChange = (e): void => { | ||
| if (this.status === 'forbid') { | ||
| e.cancel = true; | ||
| } | ||
| }; | ||
|
|
||
| private readonly onMove = (e): void => { | ||
| this.props.onMove( | ||
| e.itemData.column, | ||
| e.toIndex, | ||
| e.itemData.source, | ||
| ); | ||
| }; | ||
|
|
||
| // TODO: move all none-native approaches to sortable wrapper | ||
| private readonly renderDragTemplate = (): void => { | ||
| if (this.dragItemProps) { | ||
pomahtri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| const DragTemplate = this.props.dragTemplate!; | ||
| render( | ||
| // @ts-expect-error | ||
| <DragTemplate | ||
| column={this.dragItemProps.props.itemData.column} | ||
| status={this.status} | ||
| />, | ||
| this.dragItemProps.container, | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| render(): InfernoNode { | ||
| if (!this.props.allowColumnReordering) { | ||
| // @ts-expect-error | ||
| return this.props.children; | ||
| } | ||
|
|
||
| const { | ||
| source, | ||
| visibleColumns, | ||
| dragTemplate, | ||
| dropFeedbackMode, | ||
| ...restProps | ||
| } = this.props; | ||
|
|
||
| const sortableDragTemplate = dragTemplate ? (e, container): void => { | ||
| this.dragItemProps = { | ||
| props: e, | ||
| // @ts-expect-error | ||
| container: $(container).get(0), | ||
| }; | ||
| this.renderDragTemplate(); | ||
| } : undefined; | ||
|
|
||
| return ( | ||
| <Sortable | ||
| {...restProps} | ||
| dropFeedbackMode={dropFeedbackMode ?? 'indicate'} | ||
| onDragStart={this.onDragStart} | ||
| group='dx-cardview-columns' | ||
| onAdd={this.onMove} | ||
| onReorder={this.onMove} | ||
| onDragMove={this.onDragMove} | ||
| onDragChange={this.onDragChange} | ||
| dragTemplate={sortableDragTemplate} | ||
| > | ||
| {this.props.children} | ||
| </Sortable> | ||
| ); | ||
| } | ||
| } | ||
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.