Skip to content
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

Fix warnings when clearing survey #5964

Merged
merged 2 commits into from
Oct 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e

protected detachElement(surveyElement: T): void {
if (surveyElement) {
if (surveyElement.getPropertyValue(SurveyElementAdornerBase.AdornerValueName) === this) {
if (surveyElement.getPropertyValue(SurveyElementAdornerBase.AdornerValueName) === this && !surveyElement.isDisposed) {
surveyElement.setPropertyValue(SurveyElementAdornerBase.AdornerValueName, null);
}
surveyElement.onPropertyChanged.remove(this.selectedPropPageFunc);
this.updateActionsContainer(surveyElement, true);
this.cleanActionsContainer();
}
}
protected attachElement(surveyElement: T): void {
Expand Down Expand Up @@ -366,15 +366,16 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
}
};
}
protected updateActionsContainer(surveyElement: SurveyElement, clear: boolean = false) {
if(clear) {
this.actionContainer.actions.forEach(action => action.dispose && action.dispose());
} else {
const actions: Array<Action> = [];
this.buildActions(actions);
this.creator.onElementMenuItemsChanged(surveyElement, actions);
this.actionContainer.setItems(actions);
}
protected cleanActionsContainer() {
const actions = this.actionContainer.actions;
this.actionContainer.setItems([]);
actions.forEach(action => action.dispose && action.dispose());
}
protected updateActionsContainer(surveyElement: SurveyElement) {
const actions: Array<Action> = [];
this.buildActions(actions);
this.creator.onElementMenuItemsChanged(surveyElement, actions);
this.actionContainer.setItems(actions);
}
protected updateActionsProperties(): void {
if (this.isDisposed) return;
Expand Down
8 changes: 2 additions & 6 deletions packages/survey-creator-core/src/components/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class PageAdorner extends SurveyElementAdornerBase<PageModel> {
protected updateActionVisibility(id: string, isVisible: boolean) {
super.updateActionVisibility(id, !this.isGhost && isVisible);
}
protected updateActionsContainer(surveyElement: SurveyElement, clear?: boolean): void {
super.updateActionsContainer(surveyElement, clear);
protected updateActionsContainer(surveyElement: SurveyElement): void {
super.updateActionsContainer(surveyElement);
if (this.creator.expandCollapseButtonVisibility != "never") this.actionContainer.addAction(this.expandCollapseAction);
}
protected get dragInsideCollapsedContainer(): boolean {
Expand Down Expand Up @@ -132,10 +132,6 @@ export class PageAdorner extends SurveyElementAdornerBase<PageModel> {
addGhostPage();
};
}
public dispose(): void {
this.detachElement(this.page);
super.dispose();
}
protected calcIsGhostPage(page: PageModel) {
return this.creator.survey.pages.indexOf(page) < 0;
}
Expand Down
23 changes: 23 additions & 0 deletions testCafe/designer/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,26 @@ test("Check responsiveness is working correctly after model update", async t =>
.resizeWindow(1920, 1080)
.expect(mobileSelector.exists).notOk();
});

test("Check cleaning json doesn't cause warnings", async t => {
await ClientFunction(() => {
// eslint-disable-next-line
console.error = (msg) => {
throw new Error(msg);
};
// eslint-disable-next-line
console.warn = (msg) => {
throw new Error(msg);
};
})();
await setJSON({
elements: [
{
type: "text",
name: "q1"
}
]
});
await setJSON({});
});

Loading