Skip to content

Commit

Permalink
fix resource destroy problem
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Dec 23, 2022
1 parent 5883f67 commit da9fd1b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
50 changes: 50 additions & 0 deletions lib/src/full-calendar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CalendarOptions } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import listPlugin from '@fullcalendar/list';
import resourceTimelinePlugin from '@fullcalendar/resource-timeline';

const DEFAULT_OPTIONS = {
plugins: [dayGridPlugin, interactionPlugin],
Expand Down Expand Up @@ -424,6 +425,55 @@ describe('with list-view, customContent, and state mutation in datesSet', () =>
})


// Integration test
// https://github.com/fullcalendar/fullcalendar/issues/7105

@Component({
template: `
<full-calendar #calendar [options]="calendarOptions">
<ng-template #resourceLabelContent let-arg>
<b>{{ arg.resource.title }}</b>
</ng-template>
</full-calendar>
`
})
class LameComponent {
calendarOptions: CalendarOptions = {
plugins: [resourceTimelinePlugin],
initialView: 'resourceTimelineWeek',
resources: [{ id: 'a', title: 'a' }]
};

@ViewChild('calendar') calendarComponent?: FullCalendarComponent;

removeResource() {
const resource = this.calendarComponent!.getApi().getResourceById('a')!
resource.remove()
}
}

describe('with resource-timeline view', () => {
let component: LameComponent;
let fixture: ComponentFixture<LameComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [FullCalendarModule],
declarations: [LameComponent]
}).compileComponents();

fixture = TestBed.createComponent(LameComponent);
component = fixture.componentInstance;
fixture.detectChanges(); // necessary for initializing change detection system
});

it('doesn\'t throw any errors when removing a resource', () => {
component.removeResource()
expect(Boolean(fixture)).toBe(true)
})
})


// FullCalendar data utils

function buildEvent() {
Expand Down
10 changes: 9 additions & 1 deletion lib/src/utils/transport-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class TransportContainerComponent implements OnChanges, AfterViewInit, On

replaceEl(rootEl, this.inPlaceOf);
applyElAttrs(rootEl, undefined, this.elAttrs);

// insurance for if Preact recreates and reroots inPlaceOf element
this.inPlaceOf.style.display = 'none';

this.reportEl(rootEl as HTMLElement);
}

Expand Down Expand Up @@ -62,7 +66,11 @@ export class TransportContainerComponent implements OnChanges, AfterViewInit, On

// invoked BEFORE component removed from DOM
ngOnDestroy() {
dummyContainer.removeChild(this.inPlaceOf);
// protect against Preact recreating and rerooting inPlaceOf element
if (this.inPlaceOf.parentNode === dummyContainer) {
dummyContainer.removeChild(this.inPlaceOf);
}

this.reportEl(null);
}
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@fullcalendar/daygrid": "~6.0.1",
"@fullcalendar/interaction": "~6.0.1",
"@fullcalendar/list": "~6.0.1",
"@fullcalendar/resource": "~6.0.1",
"@fullcalendar/resource-timeline": "~6.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
Expand Down

0 comments on commit da9fd1b

Please sign in to comment.