Skip to content

Commit f100eb9

Browse files
committed
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 0faa138 commit f100eb9

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
StylesManager, Base, IAction, ItemValue,
33
JsonObjectProperty, MatrixDropdownColumn, Question,
4-
SurveyModel, ILocalizableString, PopupBaseViewModel, SurveyElement
4+
SurveyModel, ILocalizableString, PopupBaseViewModel, PageModel
55
} from "survey-core";
66

77
/**
@@ -333,6 +333,7 @@ export interface ISurveyCreatorOptions {
333333
context?: { element: Base, item?: any, elementType?: string, propertyName?: string }
334334
): void;
335335
translationLocalesOrder: Array<string>;
336+
canAddPage(pageToAdd?: PageModel): boolean;
336337
}
337338

338339
export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions {
@@ -487,6 +488,7 @@ export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions {
487488
doMachineTranslation(fromLocale: string, toLocale: string, strings: Array<string>, callback: (translated: Array<string>) => void): void { }
488489
chooseFiles(input: HTMLInputElement, callback: (files: File[]) => void, context?: { element: Base, item?: any, elementType?: string, propertyName?: string }): void { }
489490
translationLocalesOrder: Array<string> = [];
491+
canAddPage(pageToAdd?: PageModel): boolean { return true; }
490492
}
491493

492494
StylesManager.applyTheme("defaultV2");

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",
@@ -669,7 +668,9 @@ export class PropertyGridEditorMatrixPages extends PropertyGridEditorMatrix {
669668
return prop.type == "surveypages";
670669
}
671670
protected addItem(creator: ISurveyCreatorOptions, obj: Base, question: QuestionMatrixDynamicModel) {
672-
(creator as CreatorBase).addPage(undefined, false);
671+
if(creator.canAddPage()) {
672+
super.addItem(creator, obj, question);
673+
}
673674
}
674675
protected getColumnClassName(obj: Base, prop: JsonObjectProperty): string {
675676
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,
@@ -3108,9 +3109,11 @@ test("Do not select page on adding new page in the property grid #5564", () => {
31083109
expect(creator.survey.pages).toHaveLength(1);
31093110
creator.selectElement(creator.survey);
31103111
const pagesQuestion = <QuestionMatrixDynamicModel>creator.propertyGrid.getQuestionByName("pages");
3112+
expect(pagesQuestion.visibleRows).toHaveLength(1);
31113113
const actions = pagesQuestion.getTitleActions();
31123114
actions[actions.length - 1].action();
31133115
expect(creator.survey.pages).toHaveLength(2);
3116+
expect(pagesQuestion.visibleRows).toHaveLength(2);
31143117
expect((<any>creator.selectedElement).pages).toHaveLength(2);
31153118
});
31163119
test("Setup correct categories for dynamic properties in components", () => {
@@ -3665,4 +3668,29 @@ test("Undo for deleting validator in multiple text item, Bug#6295", () => {
36653668
creator.undo();
36663669
expect(item1.validators).toHaveLength(1);
36673670
expect(matrix.visibleRows).toHaveLength(1);
3668-
});
3671+
});
3672+
test("Pages Collection Editor - The Trash Bin (Remove) button is unavailable when you use the Add Page button Bug#6645", () => {
3673+
const creator = new CreatorTester();
3674+
const propertyGrid = new PropertyGridModelTester(creator.survey, creator);
3675+
const pagesQuestion = <QuestionMatrixDynamicModel>propertyGrid.survey.getQuestionByName("pages");
3676+
expect(pagesQuestion.visibleRows).toHaveLength(0);
3677+
const action = pagesQuestion.getTitleActions().filter(action => action.id === "add-item")[0];
3678+
expect(action).toBeTruthy();
3679+
action.action();
3680+
action.action();
3681+
expect(pagesQuestion.visibleRows).toHaveLength(2);
3682+
3683+
const rows = pagesQuestion.renderedTable.rows;
3684+
expect(rows[0].isErrorsRow).toBeFalsy();
3685+
expect(rows[0].hasEndActions).toBeTruthy();
3686+
let cell = rows[0].cells[rows[0].cells.length - 1];
3687+
expect(cell.isActionsCell).toBeTruthy();
3688+
let container = <ActionContainer>cell.item.value;
3689+
expect(container.getActionById("remove-row")).toBeTruthy();
3690+
expect(rows[2].isErrorsRow).toBeFalsy();
3691+
expect(rows[2].hasEndActions).toBeTruthy();
3692+
cell = rows[2].cells[rows[2].cells.length - 1];
3693+
expect(cell.isActionsCell).toBeTruthy();
3694+
container = <ActionContainer>cell.item.value;
3695+
expect(container.getActionById("remove-row")).toBeTruthy();
3696+
});

0 commit comments

Comments
 (0)