Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions packages/devextreme/js/__internal/scheduler/m_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {

this._postponeDataSourceLoading();
break;
// TODO Vinogradov refactoring: merge it with startDayHour / endDayHour
// TODO Vinogradov refactoring: merge it with startDayHour / endDayHour
case 'offset':

this.updateAppointmentDataSource();
Expand Down Expand Up @@ -850,12 +850,28 @@ class Scheduler extends SchedulerOptionsBaseWidget {
this._renderContentImpl();
}

_filterGroupsIfNeeded() {
const resourceManager = this._workSpace.option('getResourceManager')();
const allAppointments = this._workSpace.option('getFilteredItems')();

if (allAppointments.length > 0) {
resourceManager.filterGroupsByAppointments(allAppointments);
this._layoutManager.filterAppointments();

if (!isAgendaWorkspaceComponent(this._workSpace)) {
this._workSpace.renderWorkSpace();
this._dimensionChanged(null, true);
}
}
}

_dataSourceChangedHandler(result?: Appointment[]) {
if (this._readyToRenderAppointments) {
this._workSpaceRecalculation.done(() => {
this._layoutManager.prepareAppointments(result);
this._renderAppointments();
this._updateA11yStatus();
this._filterGroupsIfNeeded();
});
}
}
Expand Down Expand Up @@ -1338,13 +1354,13 @@ class Scheduler extends SchedulerOptionsBaseWidget {
const scrolling = this.getViewOption('scrolling');
const isVirtualScrolling = scrolling.mode === 'virtual';
const horizontalVirtualScrollingAllowed = isVirtualScrolling
&& (
!isDefined(scrolling.orientation)
|| ['horizontal', 'both'].includes(scrolling.orientation)
);
&& (
!isDefined(scrolling.orientation)
|| ['horizontal', 'both'].includes(scrolling.orientation)
);
const crossScrollingEnabled = this.option('crossScrollingEnabled')
|| horizontalVirtualScrollingAllowed
|| isTimelineView(currentViewOptions.type);
|| horizontalVirtualScrollingAllowed
|| isTimelineView(currentViewOptions.type);

const result = extend({
resources: this.option('resources'),
Expand Down Expand Up @@ -1653,8 +1669,8 @@ class Scheduler extends SchedulerOptionsBaseWidget {
const duration = appointmentEndDate.getTime() - appointmentStartDate.getTime();

const isKeepAppointmentHours = this._workSpace.keepOriginalHours()
&& dateUtilsTs.isValidDate(appointment.startDate)
&& dateUtilsTs.isValidDate(cellStartDate);
&& dateUtilsTs.isValidDate(appointment.startDate)
&& dateUtilsTs.isValidDate(cellStartDate);

if (isKeepAppointmentHours) {
const startDate = this.timeZoneCalculator.createDate(appointmentStartDate, 'toGrid');
Expand Down Expand Up @@ -2032,7 +2048,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
const isVirtualScrolling = mode === 'virtual';

return isVirtualScrolling
&& (orientation === 'horizontal' || orientation === 'both');
&& (orientation === 'horizontal' || orientation === 'both');
}

addAppointment(rawAppointment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { SafeAppointment } from '@ts/scheduler/types';

import type { ListEntity } from '../../view_model/types';
import { getResourceIndex } from '../data_accessor/appointment_resource_data_accessor';
import { ResourceLoader } from '../loader/resource_loader';
import type {
ResourceConfig,
ResourceId,
} from '../loader/types';
import { getAppointmentColor } from './appointment_color_utils';
import type { AppointmentResource } from './appointment_groups_utils';
Expand Down Expand Up @@ -54,6 +56,50 @@ export class ResourceManager {
return this.groupsLeafs.length;
}

public filterGroupsByAppointments(appointments: ListEntity[]): void {
if (!this.groups.length) {
return;
}

// Find all resource values used in appointments
const usedResourceValues = new Map<string, Set<ResourceId>>();

appointments.forEach((appointment) => {
this.groups.forEach((resourceIndex) => {
const resource = this.resourceById[resourceIndex];
if (resource) {
const values = resource.idsGetter(appointment.itemData);
if (!usedResourceValues.has(resourceIndex)) {
usedResourceValues.set(resourceIndex, new Set<ResourceId>());
}
const resourceValues = usedResourceValues.get(resourceIndex);
if (resourceValues) {
values.forEach((value: ResourceId) => {
resourceValues.add(value);
});
}
}
});
});

// Filter resource dataSources to include only used values
this.groups.forEach((resourceIndex) => {
const resource = this.resourceById[resourceIndex];
if (resource?.items) {
const usedValues = usedResourceValues.get(resourceIndex);
if (usedValues && usedValues.size > 0) {
const filteredItems = resource.items.filter((item) => usedValues.has(item.id));
resource.items = filteredItems;
}
}
});

// Rebuild groupsTree and groupsLeafs after filtering resources
const { groupTree, groupLeafs } = groupResources(this.resourceById, this.groups);
this.groupsTree = groupTree;
this.groupsLeafs = groupLeafs;
}

public groupResources(): ResourceLoader[] {
return this.groups
.map((group) => this.resourceById[group])
Expand Down
Loading