diff --git a/packages/devextreme/js/__internal/scheduler/appointments/appointment/m_types.ts b/packages/devextreme/js/__internal/scheduler/appointments/appointment/m_types.ts index 4b0e3bd34090..890a589ca966 100644 --- a/packages/devextreme/js/__internal/scheduler/appointments/appointment/m_types.ts +++ b/packages/devextreme/js/__internal/scheduler/appointments/appointment/m_types.ts @@ -1,5 +1,5 @@ import type { Orientation } from '@js/common'; -import type NotifyScheduler from '@ts/scheduler/base/m_widget_notify_scheduler'; +import type NotifyScheduler from '@ts/scheduler/base/widget_notify_scheduler'; import type { TimeZoneCalculator } from '@ts/scheduler/r1/timezone_calculator/calculator'; import type { SafeAppointment } from '@ts/scheduler/types'; import type { AppointmentDataAccessor } from '@ts/scheduler/utils/data_accessor/appointment_data_accessor'; diff --git a/packages/devextreme/js/__internal/scheduler/base/m_widget_notify_scheduler.ts b/packages/devextreme/js/__internal/scheduler/base/widget_notify_scheduler.ts similarity index 88% rename from packages/devextreme/js/__internal/scheduler/base/m_widget_notify_scheduler.ts rename to packages/devextreme/js/__internal/scheduler/base/widget_notify_scheduler.ts index 8312f57b98ef..675435a957d0 100644 --- a/packages/devextreme/js/__internal/scheduler/base/m_widget_notify_scheduler.ts +++ b/packages/devextreme/js/__internal/scheduler/base/widget_notify_scheduler.ts @@ -12,6 +12,7 @@ class NotifyScheduler { funcName: Subject, ...args: Parameters ): ReturnType { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return this.scheduler.fire(funcName, ...args); } } diff --git a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts index 1d18449f611f..dec7c5fd7e84 100644 --- a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts +++ b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts @@ -42,7 +42,7 @@ import { AppointmentPopup } from './appointment_popup/m_popup'; import AppointmentCollection from './appointments/m_appointment_collection'; import type { AppointmentsProperties } from './appointments_new/appointments'; import { Appointments } from './appointments_new/appointments'; -import NotifyScheduler from './base/m_widget_notify_scheduler'; +import NotifyScheduler from './base/widget_notify_scheduler'; import { SchedulerHeader } from './header/header'; import type { HeaderOptions } from './header/types'; import { CompactAppointmentsHelper } from './m_compact_appointments_helper'; diff --git a/packages/devextreme/js/__internal/scheduler/view_model/m_appointment_data_source.ts b/packages/devextreme/js/__internal/scheduler/view_model/m_appointment_data_source.ts index ff11cdf6b0f2..456fcfb4fb36 100644 --- a/packages/devextreme/js/__internal/scheduler/view_model/m_appointment_data_source.ts +++ b/packages/devextreme/js/__internal/scheduler/view_model/m_appointment_data_source.ts @@ -1,51 +1,61 @@ +import type { DataSource } from '@js/common/data'; +import type { DeferredObj } from '@js/core/utils/deferred'; import { Deferred } from '@js/core/utils/deferred'; +import type { StoreEventName } from '@js/data/store'; -const STORE_EVENTS = { +import type { SafeAppointment } from '../types'; + +const STORE_EVENTS: Record = { updating: 'updating', push: 'push', }; +interface UpdatedAppointmentKey { + key: string; + value: unknown; +} + export class AppointmentDataSource { - protected updatedAppointmentKeys: any[]; + protected updatedAppointmentKeys: UpdatedAppointmentKey[] = []; - protected dataSource: any; + protected dataSource?: DataSource; - protected updatedAppointment: any; + protected updatedAppointment: SafeAppointment | null = null; - constructor(dataSource) { + constructor(dataSource: DataSource) { this.setDataSource(dataSource); this.updatedAppointmentKeys = []; } - get keyName() { - const store = this.dataSource.store(); - return store.key(); + get keyName(): string { + const store = this.dataSource?.store(); + return store?.key() as string; } - get isDataSourceInit() { + get isDataSourceInit(): boolean { return Boolean(this.dataSource); } - private getStoreKey(target) { - const store = this.dataSource.store(); + private getStoreKey(target: SafeAppointment): unknown { + const store = this.dataSource?.store(); - return store.keyOf(target); + return store?.keyOf(target); } - setDataSource(dataSource) { + setDataSource(dataSource: DataSource): void { this.dataSource = dataSource; this.cleanState(); this.initStoreChangeHandlers(); } - private initStoreChangeHandlers() { + private initStoreChangeHandlers(): void { const { dataSource } = this; const store = dataSource?.store(); - if (store) { + if (dataSource && store) { store.on(STORE_EVENTS.updating, (key) => { - const keyName = store.key(); + const keyName = store.key() as string; if (keyName) { this.updatedAppointmentKeys.push({ key: keyName, @@ -58,7 +68,7 @@ export class AppointmentDataSource { store.on(STORE_EVENTS.push, (pushItems) => { const items = dataSource.items(); - const keyName = store.key(); + const keyName = store.key() as string; pushItems.forEach((pushItem) => { const itemExists = items.filter((item) => item[keyName] === pushItem.key).length !== 0; @@ -70,39 +80,47 @@ export class AppointmentDataSource { }); } else { const { data } = pushItem; - data && items.push(data); + if (data) { + items.push(data); + } } }); + // eslint-disable-next-line @typescript-eslint/no-floating-promises dataSource.load(); }); } } - getUpdatedAppointment() { + getUpdatedAppointment(): SafeAppointment | null { return this.updatedAppointment; } - getUpdatedAppointmentKeys() { + getUpdatedAppointmentKeys(): UpdatedAppointmentKey[] { return this.updatedAppointmentKeys; } - cleanState() { + cleanState(): void { this.updatedAppointment = null; this.updatedAppointmentKeys = []; } - add(rawAppointment) { - return this.dataSource.store().insert(rawAppointment).done(() => this.dataSource.load()); + add(rawAppointment: SafeAppointment): DeferredObj { + // @eslint-disable-next-line + return this.dataSource!.store().insert(rawAppointment) + // @ts-expect-error + .done(() => this.dataSource.load()); } - update(target, data) { + update(target: SafeAppointment, data: SafeAppointment): DeferredObj { const key = this.getStoreKey(target); // @ts-expect-error const d = new Deferred(); - this.dataSource.store().update(key, data) + this.dataSource!.store().update(key, data) + // @ts-expect-error .done((result) => this.dataSource.load() + // @ts-expect-error .done(() => d.resolve(result)) .fail(d.reject)) .fail(d.reject); @@ -110,12 +128,14 @@ export class AppointmentDataSource { return d.promise(); } - remove(rawAppointment) { + remove(rawAppointment: SafeAppointment): DeferredObj { const key = this.getStoreKey(rawAppointment); - return this.dataSource.store().remove(key).done(() => this.dataSource.load()); + return this.dataSource!.store().remove(key) + // @ts-expect-error + .done(() => this.dataSource.load()); } - destroy() { + destroy(): void { const store = this.dataSource?.store(); if (store) { diff --git a/packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts b/packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts index d89814b209a0..ff34983428a9 100644 --- a/packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts +++ b/packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts @@ -52,7 +52,7 @@ import { import type { ViewType } from '@ts/scheduler/types'; import Scrollable from '@ts/ui/scroll_view/scrollable'; -import type NotifyScheduler from '../base/m_widget_notify_scheduler'; +import type NotifyScheduler from '../base/widget_notify_scheduler'; import { APPOINTMENT_SETTINGS_KEY } from '../constants'; import { Cache } from '../global_cache'; import AppointmentDragBehavior from '../m_appointment_drag_behavior';