Skip to content

Commit 53b6ccb

Browse files
authored
Scheduler: remove redundant code (DataSourceProvider and loadedResources option) (#30787)
Co-authored-by: Vladimir Bushmanov <[email protected]>
1 parent fa590c3 commit 53b6ccb

22 files changed

+164
-352
lines changed

packages/devextreme/js/__internal/scheduler/appointments/m_appointment_collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class SchedulerAppointments extends CollectionWidget {
8686
return this.invoke('isVirtualScrolling');
8787
}
8888

89-
get appointmentDataProvider() {
90-
return this.option('getAppointmentDataProvider')();
89+
get appointmentDataSource() {
90+
return this.option('getAppointmentDataSource')();
9191
}
9292

9393
get dataAccessors(): AppointmentDataAccessor {
@@ -246,7 +246,7 @@ class SchedulerAppointments extends CollectionWidget {
246246
): ViewModelDiff[] {
247247
const elementsInRenderOrder = previousValue
248248
.map(({ sortedIndex }) => this.renderedElementsBySortedIndex[sortedIndex]);
249-
const diff = getViewModelDiff(previousValue, value, this.appointmentDataProvider);
249+
const diff = getViewModelDiff(previousValue, value, this.appointmentDataSource);
250250
diff
251251
.filter((item) => !isNeedToAdd(item))
252252
.forEach((item, index) => {

packages/devextreme/js/__internal/scheduler/appointments/utils/get_view_model_diff.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { equalByValue } from '@js/core/utils/common';
22

33
import type { SafeAppointment } from '../../types';
4-
import type { AppointmentDataProvider } from '../../view_model/generate_view_model/data_provider/m_appointment_data_provider';
4+
import type { AppointmentDataSource } from '../../view_model/generate_view_model/data_provider/m_appointment_data_source';
55
import type { AppointmentViewModelPlain } from '../../view_model/generate_view_model/types';
66
import type { DiffItem } from './get_arrays_diff';
77
import { getArraysDiff } from './get_arrays_diff';
@@ -41,28 +41,28 @@ const getObjectToCompare = (
4141

4242
const isDataChanged = (
4343
data: SafeAppointment,
44-
appointmentDataProvider: AppointmentDataProvider,
44+
appointmentDataSource: AppointmentDataSource,
4545
): boolean => {
46-
const updatedData = appointmentDataProvider.getUpdatedAppointment();
46+
const updatedData = appointmentDataSource.getUpdatedAppointment();
4747

48-
return updatedData === data || appointmentDataProvider
48+
return updatedData === data || appointmentDataSource
4949
.getUpdatedAppointmentKeys()
5050
.some((item) => data[item.key] === item.value);
5151
};
5252

53-
const compareViewModel = (appointmentDataProvider: AppointmentDataProvider) => (
53+
const compareViewModel = (appointmentDataSource: AppointmentDataSource) => (
5454
viewModelOld: AppointmentViewModelPlain,
5555
viewModelNext: AppointmentViewModelPlain,
5656
): boolean => viewModelOld.itemData === viewModelNext.itemData
57-
&& !isDataChanged(viewModelNext.itemData, appointmentDataProvider)
57+
&& !isDataChanged(viewModelNext.itemData, appointmentDataSource)
5858
&& equalByValue(getObjectToCompare(viewModelOld), getObjectToCompare(viewModelNext));
5959

6060
export const getViewModelDiff = (
6161
viewModelOld: AppointmentViewModelPlain[],
6262
viewModelNext: AppointmentViewModelPlain[],
63-
appointmentDataProvider: AppointmentDataProvider,
63+
appointmentDataSource: AppointmentDataSource,
6464
): DiffItem<AppointmentViewModelPlain, AppointmentViewModelPlain>[] => getArraysDiff(
6565
viewModelOld,
6666
viewModelNext,
67-
compareViewModel(appointmentDataProvider),
67+
compareViewModel(appointmentDataSource),
6868
);

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type { SubscribeKey, SubscribeMethods } from './m_subscribes';
4848
import subscribes from './m_subscribes';
4949
import { utils } from './m_utils';
5050
import timeZoneUtils, { type TimezoneLabel } from './m_utils_time_zone';
51+
import { combineRemoteFilter } from './r1/filterting/remote';
5152
import { createTimeZoneCalculator } from './r1/timezone_calculator/index';
5253
import {
5354
excludeFromRecurrence,
@@ -70,7 +71,7 @@ import { setAppointmentGroupValues } from './utils/resource_manager/appointment_
7071
import { getLeafGroupValues } from './utils/resource_manager/group_utils';
7172
import { createResourceEditorModel } from './utils/resource_manager/popup_utils';
7273
import { ResourceManager } from './utils/resource_manager/resource_manager';
73-
import { AppointmentDataProvider } from './view_model/generate_view_model/data_provider/m_appointment_data_provider';
74+
import { AppointmentDataSource } from './view_model/generate_view_model/data_provider/m_appointment_data_source';
7475
import type {
7576
AppointmentAgendaViewModel,
7677
AppointmentViewModelPlain,
@@ -168,7 +169,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
168169

169170
_appointments: any;
170171

171-
appointmentDataProvider!: AppointmentDataProvider;
172+
appointmentDataSource!: AppointmentDataSource;
172173

173174
_dataSource: any;
174175

@@ -238,9 +239,8 @@ class Scheduler extends SchedulerOptionsBaseWidget {
238239
// @ts-expect-error
239240
const resolveCallbacks = new Deferred();
240241

241-
whenLoaded.done((groupsResources) => {
242-
this.option('loadedResources', groupsResources);
243-
resolveCallbacks.resolve(groupsResources);
242+
whenLoaded.done(() => {
243+
resolveCallbacks.resolve();
244244
});
245245

246246
this._postponeDataSourceLoading(whenLoaded);
@@ -278,7 +278,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
278278
this._initDataSource();
279279

280280
this._postponeResourceLoading().done(() => {
281-
this.appointmentDataProvider.setDataSource(this._dataSource);
281+
this.appointmentDataSource.setDataSource(this._dataSource);
282282
this._filterAppointmentsByDate();
283283
this._updateOption('workSpace', 'showAllDayPanel', this.option('showAllDayPanel'));
284284
});
@@ -338,7 +338,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
338338
case 'resources':
339339
this.resourceManager?.dispose();
340340
this.resourceManager = new ResourceManager(this.option('resources'));
341-
this.updateInstances();
341+
this.updateAppointmentDataSource();
342342

343343
this._postponeResourceLoading().done(() => {
344344
this._appointments.option('items', []);
@@ -349,7 +349,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
349349
break;
350350
case 'startDayHour':
351351
case 'endDayHour':
352-
this.updateInstances();
352+
this.updateAppointmentDataSource();
353353

354354
this._appointments.option('items', []);
355355
this._updateOption('workSpace', name, value);
@@ -361,7 +361,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
361361
// TODO Vinogradov refactoring: merge it with startDayHour / endDayHour
362362
case 'offset':
363363

364-
this.updateInstances();
364+
this.updateAppointmentDataSource();
365365

366366
this._appointments.option('items', []);
367367
this._updateOption('workSpace', 'viewOffset', this.normalizeViewOffsetValue(value));
@@ -456,7 +456,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
456456
break;
457457
}
458458
case 'showAllDayPanel':
459-
this.updateInstances();
459+
this.updateAppointmentDataSource();
460460
this.repaint();
461461
break;
462462
case 'showCurrentTimeIndicator':
@@ -477,7 +477,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
477477
case 'recurrenceEditMode':
478478
case 'remoteFiltering':
479479
case 'timeZone':
480-
this.updateInstances();
480+
this.updateAppointmentDataSource();
481481
this.repaint();
482482
break;
483483
case 'dropDownAppointmentTemplate':
@@ -503,8 +503,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
503503
case 'recurrenceExceptionExpr':
504504
case 'disabledExpr':
505505
this._updateExpression(name, value);
506-
this.appointmentDataProvider.updateDataAccessors(this._dataAccessors);
507-
508506
this._initAppointmentTemplate();
509507
this.repaint();
510508
break;
@@ -518,7 +516,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
518516
this._updateOption('workSpace', args.fullName, value);
519517
break;
520518
case 'allDayPanelMode':
521-
this.updateInstances();
519+
this.updateAppointmentDataSource();
522520
this._updateOption('workSpace', args.fullName, value);
523521
break;
524522
case 'renovateRender':
@@ -532,8 +530,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
532530
? this._header.onToolbarOptionChanged(args.fullName, value)
533531
: this.repaint();
534532
break;
535-
case 'loadedResources':
536-
break;
537533
default:
538534
// @ts-expect-error
539535
super._optionChanged(args);
@@ -589,14 +585,35 @@ class Scheduler extends SchedulerOptionsBaseWidget {
589585
const startDate = this.timeZoneCalculator.createDate(dateRange[0], 'fromGrid');
590586
const endDate = this.timeZoneCalculator.createDate(dateRange[1], 'fromGrid');
591587

592-
this.appointmentDataProvider.filterByDate(
588+
this.setRemoteFilter(
593589
startDate,
594590
endDate,
595591
this.option('remoteFiltering'),
596592
this.option('dateSerializationFormat'),
597593
);
598594
}
599595

596+
setRemoteFilter(min, max, remoteFiltering = false, dateSerializationFormat?) {
597+
const dataSource = this._dataSource;
598+
const dataAccessors = this._dataAccessors;
599+
600+
if (!dataSource || !remoteFiltering) {
601+
return;
602+
}
603+
604+
const dataSourceFilter = dataSource.filter();
605+
const filter = combineRemoteFilter({
606+
dataSourceFilter,
607+
dataAccessors,
608+
min,
609+
max,
610+
dateSerializationFormat,
611+
forceIsoDateParsing: config().forceIsoDateParsing,
612+
});
613+
614+
dataSource.filter(filter);
615+
}
616+
600617
_reloadDataSource() {
601618
// @ts-expect-error
602619
const result = new Deferred();
@@ -733,7 +750,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
733750

734751
this._initEditing();
735752

736-
this.updateInstances();
753+
this.updateAppointmentDataSource();
737754

738755
this._initActions();
739756

@@ -750,35 +767,16 @@ class Scheduler extends SchedulerOptionsBaseWidget {
750767
this._notifyScheduler = new NotifyScheduler({ scheduler: this });
751768
}
752769

753-
createAppointmentDataProvider() {
754-
this.appointmentDataProvider?.destroy();
755-
this.appointmentDataProvider = new AppointmentDataProvider({
756-
dataSource: this._dataSource,
757-
dataAccessors: this._dataAccessors,
758-
timeZoneCalculator: this.timeZoneCalculator,
759-
dateSerializationFormat: this.option('dateSerializationFormat'),
760-
resources: this.option('resources'),
761-
startDayHour: () => this.getViewOption('startDayHour'),
762-
endDayHour: () => this.getViewOption('endDayHour'),
763-
viewOffset: () => this.getViewOffsetMs(),
764-
allDayPanelMode: () => this.getViewOption('allDayPanelMode'),
765-
showAllDayPanel: () => this.option('showAllDayPanel'),
766-
getResourceManager: () => this.resourceManager,
767-
getIsVirtualScrolling: () => this.isVirtualScrolling(),
768-
getSupportAllDayRow: () => this._workSpace.supportAllDayRow(),
769-
getViewType: () => this._workSpace.type,
770-
getViewDirection: () => this._workSpace.viewDirection,
771-
getDateRange: () => this._workSpace.getDateRange(),
772-
getGroupCount: () => this._workSpace._getGroupCount(),
773-
getViewDataProvider: () => this._workSpace.viewDataProvider,
774-
});
770+
createAppointmentDataSource() {
771+
this.appointmentDataSource?.destroy();
772+
this.appointmentDataSource = new AppointmentDataSource(this._dataSource);
775773
}
776774

777-
updateInstances() {
775+
updateAppointmentDataSource() {
778776
this._timeZoneCalculator = null;
779777

780778
if (this.getWorkSpace()) {
781-
this.createAppointmentDataProvider();
779+
this.createAppointmentDataSource();
782780
}
783781
}
784782

@@ -881,7 +879,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
881879
: [];
882880

883881
this._appointments.option('items', viewModel);
884-
this.appointmentDataProvider.cleanState();
882+
this.appointmentDataSource.cleanState();
885883
}
886884

887885
_getAppointmentsToRepaint(): AppointmentViewModelPlain[] {
@@ -987,9 +985,8 @@ class Scheduler extends SchedulerOptionsBaseWidget {
987985
this.setAria({ role: 'group' });
988986
}
989987

990-
_initMarkupOnResourceLoaded(groupsResources) {
988+
_initMarkupOnResourceLoaded() {
991989
if (!(this as any)._disposed) {
992-
this.option('loadedResources', groupsResources);
993990
this._initMarkupCore();
994991
this._reloadDataSource();
995992
}
@@ -1024,9 +1021,9 @@ class Scheduler extends SchedulerOptionsBaseWidget {
10241021

10251022
if (groups?.length) {
10261023
this.resourceManager.loadGroupResources(groups, true)
1027-
.then((groupsResources) => this._initMarkupOnResourceLoaded(groupsResources));
1024+
.then(() => this._initMarkupOnResourceLoaded());
10281025
} else {
1029-
this._initMarkupOnResourceLoaded([]);
1026+
this._initMarkupOnResourceLoaded();
10301027
}
10311028
}
10321029
}
@@ -1172,7 +1169,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
11721169
});
11731170
this._waitAsyncTemplate(() => this._workSpaceRecalculation?.resolve());
11741171

1175-
this.createAppointmentDataProvider();
1172+
this.createAppointmentDataSource();
11761173
this._filterAppointmentsByDate();
11771174
this._validateKeyFieldIfAgendaExist();
11781175
this._updateA11yStatus();
@@ -1234,7 +1231,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
12341231
getResourceManager: () => this.resourceManager,
12351232
getAppointmentColor: this.createGetAppointmentColor(),
12361233

1237-
getAppointmentDataProvider: () => this.appointmentDataProvider,
1234+
getAppointmentDataSource: () => this.appointmentDataSource,
12381235
dataAccessors: this._dataAccessors,
12391236
notifyScheduler: this._notifyScheduler,
12401237
onItemRendered: this._getAppointmentRenderedAction(),
@@ -1318,7 +1315,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13181315
}
13191316

13201317
_workSpaceConfig(currentViewOptions: NormalizedView) {
1321-
const groupsResources = this.option('loadedResources');
13221318
const scrolling = this.getViewOption('scrolling');
13231319
const isVirtualScrolling = scrolling.mode === 'virtual';
13241320
const horizontalVirtualScrollingAllowed = isVirtualScrolling
@@ -1377,7 +1373,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13771373
}, currentViewOptions);
13781374

13791375
result.notifyScheduler = this._notifyScheduler;
1380-
result.groups = groupsResources;
1376+
result.groups = this.resourceManager.groupResources();
13811377
result.onCellClick = this._createActionByOption('onCellClick');
13821378
result.onCellContextMenu = this._createActionByOption('onCellContextMenu');
13831379
result.currentDate = this.getViewOption('currentDate');
@@ -1387,7 +1383,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13871383
result.timeCellTemplate = result.timeCellTemplate ? this._getTemplate(result.timeCellTemplate) : null;
13881384
result.resourceCellTemplate = result.resourceCellTemplate ? this._getTemplate(result.resourceCellTemplate) : null;
13891385
result.dateCellTemplate = result.dateCellTemplate ? this._getTemplate(result.dateCellTemplate) : null;
1390-
result.getAppointmentDataProvider = () => this.appointmentDataProvider;
13911386

13921387
return result;
13931388
}
@@ -1524,7 +1519,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
15241519
delete singleRawAppointment[this._dataAccessors.expr.recurrenceExceptionExpr];
15251520
delete singleRawAppointment[this._dataAccessors.expr.recurrenceRuleExpr];
15261521

1527-
const keyPropertyName = this.appointmentDataProvider.keyName;
1522+
const keyPropertyName = this.appointmentDataSource.keyName;
15281523
delete singleRawAppointment[keyPropertyName];
15291524
/* eslint-enable @typescript-eslint/no-dynamic-delete */
15301525

@@ -1768,7 +1763,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
17681763
this._expandAllDayPanel(rawAppointment);
17691764

17701765
try {
1771-
deferred = this.appointmentDataProvider
1766+
deferred = this.appointmentDataSource
17721767
.update(target, rawAppointment)
17731768
.done(() => {
17741769
dragEvent?.cancel.resolve(false);
@@ -2080,7 +2075,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
20802075

20812076
this._expandAllDayPanel(serializedAppointment);
20822077

2083-
return this.appointmentDataProvider
2078+
return this.appointmentDataSource
20842079
.add(serializedAppointment)
20852080
.always((storeAppointment) => this._onDataPromiseCompleted(StoreEventNames.ADDED, storeAppointment));
20862081
});
@@ -2110,7 +2105,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
21102105
processDeleteAppointment(rawAppointment, deletingOptions) {
21112106
this._processActionResult(deletingOptions, function (canceled) {
21122107
if (!canceled) {
2113-
this.appointmentDataProvider
2108+
this.appointmentDataSource
21142109
.remove(rawAppointment)
21152110
.always((storeAppointment) => this._onDataPromiseCompleted(
21162111
StoreEventNames.DELETED,
@@ -2161,12 +2156,12 @@ class Scheduler extends SchedulerOptionsBaseWidget {
21612156
}
21622157

21632158
_validateKeyFieldIfAgendaExist() {
2164-
if (!this.appointmentDataProvider.isDataSourceInit) {
2159+
if (!this.appointmentDataSource.isDataSourceInit) {
21652160
return;
21662161
}
21672162

21682163
const hasAgendaView = this.hasAgendaView();
2169-
const isKeyNotExist = !this.appointmentDataProvider.keyName;
2164+
const isKeyNotExist = !this.appointmentDataSource.keyName;
21702165

21712166
if (hasAgendaView && isKeyNotExist) {
21722167
errors.log('W1023');

0 commit comments

Comments
 (0)