-
Notifications
You must be signed in to change notification settings - Fork 667
Scheduler: Provide the SnapToCellsMode option #33021
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
sjbur
wants to merge
12
commits into
DevExpress:26_1
Choose a base branch
from
sjbur:v2_issue-3654_26_1
base: 26_1
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
12 commits
Select commit
Hold shift + click to select a range
d51dca8
feat: add snapToCellsMode type and default fallback
sjbur a1fc518
feat: implement snapToCellsMode logic
sjbur d37d2b3
tests: add tests
sjbur 7263bf7
feat: add storybook
sjbur fc05556
refactor: remove unused story
sjbur 7980fd5
test: remove test
sjbur d01b9f5
refactor: replace SnapToCellsModeType with SnapToCellsMode in schedul…
sjbur dea354c
refactor: exclude 'agenda' view from configByView in scheduler options
sjbur 05bef98
test: add integration tests for snapToCellsMode in scheduler
sjbur 999944c
refactor: update snapToCellsMode handling in scheduler view options
sjbur 64d461b
Revert "refactor: update snapToCellsMode handling in scheduler view o…
sjbur 6e4fccc
test: rewrite qunit test to jest
sjbur 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
88 changes: 88 additions & 0 deletions
88
apps/react-storybook/stories/scheduler/SchedulerSnapToCellsMode.stories.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,88 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-webpack5"; | ||
| import dxScheduler from "devextreme/ui/scheduler"; | ||
| import { wrapDxWithReact } from "../utils"; | ||
| import { resources } from "./data"; | ||
|
|
||
| const Scheduler = wrapDxWithReact(dxScheduler); | ||
|
|
||
| const data = [ | ||
| { | ||
| text: '1 minute', | ||
| roomId: 1, | ||
| assigneeId: [1], | ||
| priorityId: 1, | ||
| startDate: new Date(2026, 2, 15, 10, 0), | ||
| endDate: new Date(2026, 2, 15, 10, 1) | ||
| }, | ||
| { | ||
| text: '5 minutes', | ||
| roomId: 1, | ||
| assigneeId: [2], | ||
| priorityId: 1, | ||
| startDate: new Date(2026, 2, 16, 10, 0), | ||
| endDate: new Date(2026, 2, 16, 10, 5) | ||
| }, | ||
| { | ||
| text: '15 minutes', | ||
| roomId: 2, | ||
| assigneeId: [3], | ||
| priorityId: 2, | ||
| startDate: new Date(2026, 2, 17, 10, 0), | ||
| endDate: new Date(2026, 2, 17, 10, 15) | ||
| }, | ||
| { | ||
| text: '30 minutes', | ||
| roomId: 2, | ||
| assigneeId: [1], | ||
| priorityId: 2, | ||
| startDate: new Date(2026, 2, 18, 10, 0), | ||
| endDate: new Date(2026, 2, 18, 10, 30) | ||
| }, | ||
| { | ||
| text: '46 minutes', | ||
| roomId: 3, | ||
| assigneeId: [2], | ||
| priorityId: 1, | ||
| startDate: new Date(2026, 2, 19, 10, 0), | ||
| endDate: new Date(2026, 2, 19, 10, 46) | ||
| }, | ||
| { | ||
| text: '1 hour', | ||
| roomId: 2, | ||
| assigneeId: [4], | ||
| priorityId: 1, | ||
| startDate: new Date(2026, 2, 20, 10, 0), | ||
| endDate: new Date(2026, 2, 20, 11, 0) | ||
| }, | ||
| ]; | ||
|
|
||
| const viewNames = ['day', 'week', 'workWeek', 'month', 'agenda', 'timelineDay', 'timelineWeek', 'timelineWorkWeek', 'timelineMonth']; | ||
|
|
||
| const meta: Meta<typeof Scheduler> = { | ||
| title: 'Components/Scheduler/SnapToCellsMode', | ||
| component: Scheduler, | ||
| parameters: { layout: 'padded' }, | ||
| }; | ||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof Scheduler>; | ||
|
|
||
| export const Overview: Story = { | ||
| args: { | ||
| height: 600, | ||
| views: viewNames, | ||
| currentView: 'week', | ||
| currentDate: new Date(2026, 2, 15), | ||
| startDayHour: 9, | ||
| endDayHour: 22, | ||
| dataSource: data, | ||
| resources, | ||
| snapToCellsMode: 'auto', | ||
| }, | ||
| argTypes: { | ||
| height: { control: 'number' }, | ||
| views: { control: 'object' }, | ||
| snapToCellsMode: { control: 'select', options: ['always', 'auto', 'never'] }, | ||
| currentView: { control: 'select', options: viewNames }, | ||
| }, | ||
| }; |
86 changes: 86 additions & 0 deletions
86
packages/devextreme/js/__internal/scheduler/__tests__/snap_to_cells_mode.test.ts
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,86 @@ | ||
| import { | ||
| afterEach, beforeEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
|
|
||
| import { createScheduler } from './__mock__/create_scheduler'; | ||
| import { | ||
| DEFAULT_CELL_HEIGHT, | ||
| setupSchedulerTestEnvironment, | ||
| } from './__mock__/m_mock_scheduler'; | ||
|
|
||
| describe('snapToCellsMode', () => { | ||
| beforeEach(() => { | ||
| setupSchedulerTestEnvironment(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('default snapToCellsMode on day view', async () => { | ||
| const { POM } = await createScheduler({ | ||
| width: 800, | ||
| height: 600, | ||
| views: ['day'], | ||
| currentView: 'day', | ||
| currentDate: new Date(2026, 2, 15), | ||
| cellDuration: 30, | ||
| startDayHour: 9, | ||
| endDayHour: 18, | ||
| dataSource: [{ | ||
| text: 'short', | ||
| startDate: new Date(2026, 2, 15, 10, 0), | ||
| endDate: new Date(2026, 2, 15, 10, 10), | ||
| }], | ||
| }); | ||
|
|
||
| const appH = POM.getAppointment('short').getGeometry().height; | ||
|
|
||
| expect(appH).toBeLessThan(DEFAULT_CELL_HEIGHT * 0.45); | ||
| }); | ||
|
|
||
| it('root snapToCellsMode always overrides default on day view', async () => { | ||
| const { POM } = await createScheduler({ | ||
| width: 800, | ||
| height: 600, | ||
| views: ['day'], | ||
| currentView: 'day', | ||
| currentDate: new Date(2026, 2, 15), | ||
| cellDuration: 30, | ||
| startDayHour: 9, | ||
| endDayHour: 18, | ||
| dataSource: [{ | ||
| text: 'short', | ||
| startDate: new Date(2026, 2, 15, 10, 0), | ||
| endDate: new Date(2026, 2, 15, 10, 10), | ||
| }], | ||
| snapToCellsMode: 'always', | ||
| }); | ||
|
|
||
| const appH = POM.getAppointment('short').getGeometry().height; | ||
|
|
||
| expect(appH).toBeGreaterThan(DEFAULT_CELL_HEIGHT * 0.85); | ||
| }); | ||
|
|
||
| it('views[].snapToCellsMode always overrides default on day view', async () => { | ||
| const { POM } = await createScheduler({ | ||
| width: 800, | ||
| height: 600, | ||
| views: [{ type: 'day', snapToCellsMode: 'always' }], | ||
| currentView: 'day', | ||
| currentDate: new Date(2026, 2, 15), | ||
| cellDuration: 30, | ||
| startDayHour: 9, | ||
| endDayHour: 18, | ||
| dataSource: [{ | ||
| text: 'short', | ||
| startDate: new Date(2026, 2, 15, 10, 0), | ||
| endDate: new Date(2026, 2, 15, 10, 10), | ||
| }], | ||
| }); | ||
|
|
||
| const appH = POM.getAppointment('short').getGeometry().height; | ||
|
|
||
| expect(appH).toBeGreaterThan(DEFAULT_CELL_HEIGHT * 0.85); | ||
| }); | ||
| }); |
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
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
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.
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.
Can we add tests that check that scheduler.snapToCellsMode and scheduler.view.snapToCellsMode options actually have effect?
I mean if I have this config:
or this config:
then check that the option is applied
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.
Added integration test which tests 3 cases for day view