-
Notifications
You must be signed in to change notification settings - Fork 667
Scheduler - Simplify Form scheduler proxy to config-based initialization #33422
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
base: 26_1
Are you sure you want to change the base?
Changes from 1 commit
d8e4a76
cb358bc
cc5b876
561378d
0e6d51c
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,7 @@ import type Popup from '@ts/ui/popup/m_popup'; | |||||
|
|
||||||
| import timeZoneUtils from '../m_utils_time_zone'; | ||||||
| import type { SafeAppointment } from '../types'; | ||||||
| import type { AppointmentDataAccessor } from '../utils/data_accessor/appointment_data_accessor'; | ||||||
| import type { ResourceLoader } from '../utils/loader/resource_loader'; | ||||||
| import { DEFAULT_ICONS_SHOW_MODE } from '../utils/options/constants'; | ||||||
| import { getAppointmentGroupIndex, getRawAppointmentGroupValues, getSafeGroupValues } from '../utils/resource_manager/appointment_groups_utils'; | ||||||
|
|
@@ -37,6 +38,16 @@ import { customizeFormItems } from './m_customize_form_items'; | |||||
| import { RecurrenceForm } from './m_recurrence_form'; | ||||||
| import { createFormIconTemplate, getStartDateCommonConfig, RecurrenceRule } from './utils'; | ||||||
|
|
||||||
| export interface AppointmentFormConfig { | ||||||
| dataAccessors: AppointmentDataAccessor; | ||||||
| editing: SchedulerProperties['editing']; | ||||||
| resourceManager: ResourceManager; | ||||||
| firstDayOfWeek: number; | ||||||
| startDayHour: number; | ||||||
| createComponent: (element: dxElementWrapper, Component: any, options: any) => any; | ||||||
| getCalculatedEndDate: (startDate: Date) => Date; | ||||||
| } | ||||||
|
|
||||||
| const CLASSES = { | ||||||
| form: 'dx-scheduler-form', | ||||||
| icon: 'dx-icon', | ||||||
|
|
@@ -118,9 +129,7 @@ const RESOURCES_GROUP_ICON_NAME = 'resourcesGroupIcon'; | |||||
| const DESCRIPTION_ICON_NAME = 'descriptionIcon'; | ||||||
|
|
||||||
| export class AppointmentForm { | ||||||
| private readonly scheduler: any; | ||||||
|
|
||||||
| private readonly resourceManager!: ResourceManager; | ||||||
| private readonly config: AppointmentFormConfig; | ||||||
|
|
||||||
| private dxFormInstance?: dxForm; | ||||||
|
|
||||||
|
|
@@ -132,6 +141,10 @@ export class AppointmentForm { | |||||
|
|
||||||
| private $recurrenceGroup?: dxElementWrapper; | ||||||
|
|
||||||
| private get resourceManager(): ResourceManager { | ||||||
| return this.config.resourceManager; | ||||||
| } | ||||||
|
|
||||||
| get dxForm(): dxForm { | ||||||
| return this.dxFormInstance as dxForm; | ||||||
| } | ||||||
|
|
@@ -158,29 +171,28 @@ export class AppointmentForm { | |||||
| } | ||||||
|
|
||||||
| get startDate(): Date | null { | ||||||
| const { startDateExpr } = this.scheduler.getDataAccessors().expr; | ||||||
| const { startDateExpr } = this.config.dataAccessors.expr; | ||||||
| const value = this.getFormDataField(startDateExpr); | ||||||
|
|
||||||
| return value ? new Date(dateSerialization.deserializeDate(value)) : null; | ||||||
| } | ||||||
|
|
||||||
| get endDate(): Date | null { | ||||||
| const { endDateExpr } = this.scheduler.getDataAccessors().expr; | ||||||
| const { endDateExpr } = this.config.dataAccessors.expr; | ||||||
| const value = this.getFormDataField(endDateExpr); | ||||||
|
|
||||||
| return value ? new Date(dateSerialization.deserializeDate(value)) : null; | ||||||
| } | ||||||
|
|
||||||
| get recurrenceRuleRaw(): string | null { | ||||||
| const { recurrenceRuleExpr } = this.scheduler.getDataAccessors().expr; | ||||||
| const { recurrenceRuleExpr } = this.config.dataAccessors.expr; | ||||||
| const value = this.getFormDataField(recurrenceRuleExpr) as string | undefined; | ||||||
|
|
||||||
| return value ?? null; | ||||||
| } | ||||||
|
|
||||||
| constructor(scheduler: any) { | ||||||
| this.scheduler = scheduler; | ||||||
| this.resourceManager = scheduler.getResourceManager(); | ||||||
| constructor(config: AppointmentFormConfig) { | ||||||
| this.config = config; | ||||||
| } | ||||||
|
|
||||||
| private getFormDataField(field: string): any { | ||||||
|
|
@@ -200,7 +212,10 @@ export class AppointmentForm { | |||||
|
|
||||||
| const mainGroup = this.createMainFormGroup(); | ||||||
|
|
||||||
| this.recurrenceForm = new RecurrenceForm(this.scheduler); | ||||||
| this.recurrenceForm = new RecurrenceForm({ | ||||||
| firstDayOfWeek: this.config.firstDayOfWeek, | ||||||
| createComponent: this.config.createComponent, | ||||||
| }); | ||||||
| const recurrenceGroup = this.recurrenceForm.createRecurrenceFormGroup(); | ||||||
|
|
||||||
| const items = [mainGroup, recurrenceGroup]; | ||||||
|
|
@@ -212,28 +227,28 @@ export class AppointmentForm { | |||||
| this.applyFormItemDefaults(mainGroup, showMainGroupIcons); | ||||||
| this.applyFormItemDefaults(recurrenceGroup, showRecurrenceGroupIcons); | ||||||
|
|
||||||
| const editingConfig = this.scheduler.getEditingConfig(); | ||||||
| const customizedItems = customizeFormItems(items, editingConfig?.form?.items); | ||||||
| const customizedItems = customizeFormItems(items, this.getEditingForm()?.items); | ||||||
|
|
||||||
| this.createForm(customizedItems); | ||||||
| } | ||||||
|
|
||||||
| private getIconsShowMode(): AppointmentFormIconsShowMode { | ||||||
| const editingConfig = this.scheduler.getEditingConfig() as SchedulerProperties['editing']; | ||||||
|
|
||||||
| if (isBoolean(editingConfig)) { | ||||||
| return DEFAULT_ICONS_SHOW_MODE; | ||||||
| private getEditingForm(): NonNullable<NonNullable<SchedulerProperties['editing']>['form']> | undefined { | ||||||
| const { editing } = this.config; | ||||||
| if (isBoolean(editing) || !editing) { | ||||||
| return undefined; | ||||||
| } | ||||||
| return editing.form ?? undefined; | ||||||
| } | ||||||
|
|
||||||
| return editingConfig?.form?.iconsShowMode ?? DEFAULT_ICONS_SHOW_MODE; | ||||||
| private getIconsShowMode(): AppointmentFormIconsShowMode { | ||||||
| return this.getEditingForm()?.iconsShowMode ?? DEFAULT_ICONS_SHOW_MODE; | ||||||
| } | ||||||
|
|
||||||
| private createForm(items: FormProperties['items']): dxForm { | ||||||
| const element = $('<div>'); | ||||||
| const editingConfig = this.scheduler.getEditingConfig(); | ||||||
| const { | ||||||
| items: formItems, onContentReady, onInitialized, ...customFormOptions | ||||||
|
||||||
| items: formItems, onContentReady, onInitialized, ...customFormOptions | |
| items: _formItems, onContentReady, onInitialized, ...customFormOptions |
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.
AppointmentFormConfig.createComponentis currently typed as(element: dxElementWrapper, Component: any, options: any) => any, but the scheduler’s_createComponenthelper can be called with non-wrapper element types (e.g., selector/HTML strings) and this mismatch is already forcing@ts-expect-errorat the call site. Consider widening theelementparameter type (or introducing a sharedCreateComponenttype used across scheduler internals) to avoid TS suppressions and keep this config-based API consistently type-safe.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.
fixed