Skip to content

Commit ddd5e1d

Browse files
authored
Pages Collection Editor - The Trash Bin (Remove) button is unavailabl… (#6652)
* Pages Collection Editor - The Trash Bin (Remove) button is unavailable when you use the Add Page button fix Bug#6645 * FIx unit tests
1 parent 8ffa6ed commit ddd5e1d

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

packages/survey-creator-core/src/creator-settings.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Base, IAction, ItemValue,
33
JsonObjectProperty, MatrixDropdownColumn, Question,
4-
SurveyModel, ILocalizableString, PopupBaseViewModel, SurveyElement
4+
SurveyModel, ILocalizableString, PopupBaseViewModel, PageModel
55
} from "survey-core";
66

77
/**
@@ -353,6 +353,7 @@ export interface ISurveyCreatorOptions {
353353
context?: { element: Base, item?: any, elementType?: string, propertyName?: string }
354354
): void;
355355
translationLocalesOrder: Array<string>;
356+
canAddPage(pageToAdd?: PageModel): boolean;
356357
}
357358

358359
export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions {
@@ -514,4 +515,5 @@ export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions {
514515
doMachineTranslation(fromLocale: string, toLocale: string, strings: Array<string>, callback: (translated: Array<string>) => void): void { }
515516
chooseFiles(input: HTMLInputElement, callback: (files: File[]) => void, context?: { element: Base, item?: any, elementType?: string, propertyName?: string }): void { }
516517
translationLocalesOrder: Array<string> = [];
518+
canAddPage(pageToAdd?: PageModel): boolean { return true; }
517519
}

packages/survey-creator-core/src/property-grid/matrices.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Base, ComputedUpdater, IAction, ISurveyData, ItemValue, JsonMetadata, JsonMetadataClass, JsonObjectProperty, MatrixDropdownColumn, MatrixDropdownRowModelBase, MatrixDynamicRowModel, PanelModel, Question, QuestionHtmlModel, QuestionMatrixDropdownModelBase, QuestionMatrixDropdownRenderedRow, QuestionMatrixDynamicModel, QuestionRatingModel, renamedIcons, Serializer, SurveyElement } from "survey-core";
1+
import { Base, ComputedUpdater, IAction, ISurveyData, ItemValue, JsonMetadata, JsonMetadataClass, JsonObjectProperty, MatrixDropdownColumn, MatrixDropdownRowModelBase, MatrixDynamicRowModel, PanelModel, Question, QuestionHtmlModel, QuestionMatrixDropdownModelBase, QuestionMatrixDropdownRenderedRow, QuestionMatrixDynamicModel, QuestionRatingModel, renamedIcons, Serializer, SurveyElement, SurveyModel } from "survey-core";
22
import { editorLocalization } from "../editorLocalization";
33
import { SurveyQuestionProperties } from "../question-editor/properties";
44
import { ISurveyCreatorOptions, settings } from "../creator-settings";
@@ -12,7 +12,6 @@ import {
1212
} from "./index";
1313
import { updateMatixActionsClasses, updateMatrixRemoveAction } from "../utils/actions";
1414
import { QuestionRatingAdornerViewModel } from "../components/question-rating";
15-
import { CreatorBase } from "../creator-base";
1615
import { ISurveyPropertyGridDefinition } from "../question-editor/definition";
1716

1817
Serializer.addProperty("itemvalue",
@@ -671,7 +670,9 @@ export class PropertyGridEditorMatrixPages extends PropertyGridEditorMatrix {
671670
return prop.type == "surveypages";
672671
}
673672
protected addItem(creator: ISurveyCreatorOptions, obj: Base, question: QuestionMatrixDynamicModel) {
674-
(creator as CreatorBase).addPage(undefined, false);
673+
if(creator.canAddPage()) {
674+
super.addItem(creator, obj, question);
675+
}
675676
}
676677
protected getColumnClassName(obj: Base, prop: JsonObjectProperty): string {
677678
return "page@" + obj.getType();

packages/survey-creator-core/tests/property-grid/property-grid.tests.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {
3333
ComponentCollection,
3434
QuestionBooleanModel,
3535
QuestionRadiogroupModel,
36-
PageModel
36+
PageModel,
37+
ActionContainer
3738
} from "survey-core";
3839
import {
3940
EmptySurveyCreatorOptions,
@@ -3111,9 +3112,11 @@ test("Do not select page on adding new page in the property grid #5564", () => {
31113112
expect(creator.survey.pages).toHaveLength(1);
31123113
creator.selectElement(creator.survey);
31133114
const pagesQuestion = <QuestionMatrixDynamicModel>creator.propertyGrid.getQuestionByName("pages");
3115+
expect(pagesQuestion.visibleRows).toHaveLength(1);
31143116
const actions = pagesQuestion.getTitleActions();
31153117
actions[actions.length - 1].action();
31163118
expect(creator.survey.pages).toHaveLength(2);
3119+
expect(pagesQuestion.visibleRows).toHaveLength(2);
31173120
expect((<any>creator.selectedElement).pages).toHaveLength(2);
31183121
});
31193122
test("Setup correct categories for dynamic properties in components", () => {
@@ -3684,4 +3687,29 @@ test("Undo for deleting validator in multiple text item, Bug#6295", () => {
36843687
creator.undo();
36853688
expect(item1.validators).toHaveLength(1);
36863689
expect(matrix.visibleRows).toHaveLength(1);
3687-
});
3690+
});
3691+
test("Pages Collection Editor - The Trash Bin (Remove) button is unavailable when you use the Add Page button Bug#6645", () => {
3692+
const creator = new CreatorTester();
3693+
const propertyGrid = new PropertyGridModelTester(creator.survey, creator);
3694+
const pagesQuestion = <QuestionMatrixDynamicModel>propertyGrid.survey.getQuestionByName("pages");
3695+
expect(pagesQuestion.visibleRows).toHaveLength(0);
3696+
const action = pagesQuestion.getTitleActions().filter(action => action.id === "add-item")[0];
3697+
expect(action).toBeTruthy();
3698+
action.action();
3699+
action.action();
3700+
expect(pagesQuestion.visibleRows).toHaveLength(2);
3701+
3702+
const rows = pagesQuestion.renderedTable.rows;
3703+
expect(rows[0].isErrorsRow).toBeFalsy();
3704+
expect(rows[0].hasEndActions).toBeTruthy();
3705+
let cell = rows[0].cells[rows[0].cells.length - 1];
3706+
expect(cell.isActionsCell).toBeTruthy();
3707+
let container = <ActionContainer>cell.item.value;
3708+
expect(container.getActionById("remove-row")).toBeTruthy();
3709+
expect(rows[2].isErrorsRow).toBeFalsy();
3710+
expect(rows[2].hasEndActions).toBeTruthy();
3711+
cell = rows[2].cells[rows[2].cells.length - 1];
3712+
expect(cell.isActionsCell).toBeTruthy();
3713+
container = <ActionContainer>cell.item.value;
3714+
expect(container.getActionById("remove-row")).toBeTruthy();
3715+
});

0 commit comments

Comments
 (0)