-
Notifications
You must be signed in to change notification settings - Fork 667
Scheduler: Encapsulate old view model and add collector tests #30861
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
Changes from 5 commits
3e60323
641f329
effedd4
6314c13
8d2b4d0
976e1d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { | ||
| describe, expect, it, | ||
| } from '@jest/globals'; | ||
|
|
||
| import { VIEW_TYPES } from '../../utils/options/constants_view'; | ||
| import type { ViewType } from '../../utils/options/types'; | ||
| import { getDeltaTime } from './get_delta_time'; | ||
|
|
||
| describe('getDeltaTime', () => { | ||
| VIEW_TYPES.forEach((view) => { | ||
| it(`should return zero for not resized appointment in ${view} view`, () => { | ||
| expect(getDeltaTime( | ||
| { width: 100, height: 100 }, | ||
| { width: 100, height: 100 }, | ||
| { | ||
| viewType: view, | ||
| cellSize: { width: 50, height: 50 }, | ||
| resizableStep: 50, | ||
| cellDurationInMinutes: 30, | ||
| isAllDay: true, | ||
| }, | ||
| )).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| ['day', 'week', 'workWeek'].forEach((view) => { | ||
| it(`should return correct delta in px for resized appointment in vertical ${view} view`, () => { | ||
| expect(getDeltaTime( | ||
| { width: 100, height: 50 }, | ||
| { width: 100, height: 100 }, | ||
| { | ||
| viewType: view as ViewType, | ||
| cellSize: { width: 50, height: 50 }, | ||
| resizableStep: 50, | ||
| cellDurationInMinutes: 30, | ||
| isAllDay: false, | ||
| }, | ||
| )).toBe(-30 * 60_000); | ||
| }); | ||
|
|
||
| it(`should return correct delta in px for resized all day appointment in vertical ${view} view`, () => { | ||
| expect(getDeltaTime( | ||
| { width: 50, height: 100 }, | ||
| { width: 100, height: 100 }, | ||
| { | ||
| viewType: view as ViewType, | ||
| cellSize: { width: 50, height: 50 }, | ||
| resizableStep: 50, | ||
| cellDurationInMinutes: 30, | ||
| isAllDay: true, | ||
| }, | ||
| )).toBe(-24 * 3600_000); | ||
| }); | ||
| }); | ||
|
|
||
| ['timelineMonth', 'month'].forEach((view) => { | ||
| it(`should return correct delta in px for resized appointment in ${view} view`, () => { | ||
| expect(getDeltaTime( | ||
| { width: 50, height: 100 }, | ||
| { width: 100, height: 100 }, | ||
| { | ||
| viewType: view as ViewType, | ||
| cellSize: { width: 50, height: 50 }, | ||
| resizableStep: 50, | ||
| cellDurationInMinutes: 30, | ||
| isAllDay: false, | ||
| }, | ||
| )).toBe(-24 * 3600_000); | ||
| }); | ||
| }); | ||
|
|
||
| ['timelineDay', 'timelineWeek', 'timelineWorkWeek'].forEach((view) => { | ||
| it(`should return zero for not resized appointment in horizontal ${view} view`, () => { | ||
| expect(getDeltaTime( | ||
| { width: 50, height: 100 }, | ||
| { width: 100, height: 100 }, | ||
| { | ||
| viewType: view as ViewType, | ||
| cellSize: { width: 50, height: 50 }, | ||
| resizableStep: 50, | ||
| cellDurationInMinutes: 30, | ||
| isAllDay: false, | ||
| }, | ||
| )).toBe(-30 * 60_000); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import dateUtils from '@js/core/utils/date'; | ||
|
|
||
| import type { ViewType } from '../../types'; | ||
|
|
||
| const toMs = dateUtils.dateToMilliseconds; | ||
| const VERTICAL_VIEW_TYPES = ['day', 'week', 'workWeek']; | ||
|
|
||
| interface Size { | ||
| width: number; | ||
| height: number; | ||
| } | ||
| interface Options { | ||
| viewType: ViewType; | ||
| cellSize: Size; | ||
| cellDurationInMinutes: number; | ||
| resizableStep: number; | ||
| isAllDay: boolean; | ||
| } | ||
|
|
||
| const MIN_RESIZABLE_STEP = 2; | ||
| const getAllDayDeltaWidth = (args: Size, initialSize: Size, resizableStep: number): number => { | ||
| const intervalWidth = resizableStep || MIN_RESIZABLE_STEP; | ||
| const initialWidth = initialSize.width; | ||
|
|
||
| return Math.round((args.width - initialWidth) / intervalWidth); | ||
| }; | ||
| const getHorizontalDeltaTime = (args: Size, initialSize: Size, { | ||
| cellSize, | ||
| cellDurationInMinutes, | ||
| }: Options): number => { | ||
| const deltaWidth = args.width - initialSize.width; | ||
| const deltaTime = toMs('minute') * Math.round((deltaWidth * cellDurationInMinutes) / cellSize.width); | ||
| return deltaTime; | ||
| }; | ||
| const getVerticalDeltaTime = (args: Size, initialSize: Size, { | ||
| cellSize, | ||
| cellDurationInMinutes, | ||
| }: Options): number => { | ||
| const deltaHeight = args.height - initialSize.height; | ||
| const deltaTime = toMs('minute') * Math.round((deltaHeight * cellDurationInMinutes) / cellSize.height); | ||
| return deltaTime; | ||
| }; | ||
|
|
||
| export const getDeltaTime = ( | ||
| args: Size, | ||
| initialSize: Size, | ||
| options: Options, | ||
| ): number => { | ||
| const { viewType, resizableStep, isAllDay } = options; | ||
| switch (true) { | ||
| case ['timelineMonth', 'month'].includes(viewType): | ||
| return getAllDayDeltaWidth(args, initialSize, resizableStep) * toMs('day'); | ||
| case viewType === 'agenda': | ||
| return 0; | ||
| case VERTICAL_VIEW_TYPES.includes(viewType) && !isAllDay: | ||
| return getVerticalDeltaTime(args, initialSize, options); | ||
| default: | ||
| return isAllDay | ||
| ? getAllDayDeltaWidth(args, initialSize, resizableStep) * toMs('day') | ||
| : getHorizontalDeltaTime(args, initialSize, options); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,6 @@ const APPOINTMENT_COLLECTOR_CLASS = 'dx-scheduler-appointment-collector'; | |
| const COMPACT_APPOINTMENT_COLLECTOR_CLASS = `${APPOINTMENT_COLLECTOR_CLASS}-compact`; | ||
| const APPOINTMENT_COLLECTOR_CONTENT_CLASS = `${APPOINTMENT_COLLECTOR_CLASS}-content`; | ||
|
|
||
| const WEEK_VIEW_COLLECTOR_OFFSET = 5; | ||
| const COMPACT_THEME_WEEK_VIEW_COLLECTOR_OFFSET = 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was unused code |
||
|
|
||
| export class CompactAppointmentsHelper { | ||
| elements: any[] = []; | ||
|
|
||
|
|
@@ -104,16 +101,6 @@ export class CompactAppointmentsHelper { | |
| }; | ||
| } | ||
|
|
||
| _getCollectorOffset(width, cellWidth) { | ||
| return cellWidth - width - this._getCollectorRightOffset(); | ||
| } | ||
|
|
||
| _getCollectorRightOffset() { | ||
| return this.instance.getRenderingStrategyInstance()._isCompactTheme() | ||
| ? COMPACT_THEME_WEEK_VIEW_COLLECTOR_OFFSET | ||
| : WEEK_VIEW_COLLECTOR_OFFSET; | ||
| } | ||
|
|
||
| _setPosition(element, position) { | ||
| move(element, { | ||
| top: position.top, | ||
|
|
||
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 think you can use
case isAllDay:instead of the ternary operationso you don’t need to branch further inside the default.