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

#6635 The removeSubItems function doesn't remove corresponding input types in a property grid #6651

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
16 changes: 7 additions & 9 deletions packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
selectedAction = action;
selectedSubactions = item.items;
}
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
const subactions = [];
Expand All @@ -591,8 +590,8 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
if (selectedSubactionLocal) {
selectedAction = action;
selectedSubaction = selectedSubactionLocal;
selectedSubactions = subactions;
}
selectedSubactions = subactions;
}
lastItem = item;
newItems.push(action);
Expand Down Expand Up @@ -621,12 +620,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
cssClasses: listComponentCss,
});
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
if (listModel.actions.length == 0) return null;

const propName = QuestionToolbox.getSubTypePropertyName(this.surveyElement.getType());
if (!listModel.selectedItem && !propName) return null;
const actionData: IAction = {
id: "convertInputType",
visibleIndex: 1,
title: listModel.selectedItem?.title || "SUBTYPE",
title: listModel.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, this.surveyElement.getPropertyValue(propName)) || "SUBTYPE",
disableShrink: true,
iconName: "icon-chevron_16x16"
};
Expand All @@ -637,14 +636,13 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
}
});

this.surveyElement.registerFunctionOnPropertiesValueChanged(
["inputType", "rateType"],
() => {
[propName],
(newValue) => {
const popup = newAction.popupModel;
const list = popup.contentComponentData.model;
this.updateQuestionTypeOrSubtypeListModel(list, true);
newAction.title = list.selectedItem.title;
newAction.title = list.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, newValue) || "SUBTYPE";
},
"inputTypeAdorner"
);
Expand Down
34 changes: 34 additions & 0 deletions packages/survey-creator-core/tests/question-adorner.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,40 @@ test("Check question adorners popups display mode", (): any => {
expect(convertToAction.popupModel.displayMode).toBe("overlay");
});

test("Check question converter with removed subitems", (): any => {
surveySettings.animationEnabled = false;
const creator = new CreatorTester();

// create subitems from new items (the same type, different json)

const ratingItem = creator.toolbox.getItemByName("rating");

// Remove Default Subitems
ratingItem.removeSubitem("stars");

ratingItem.title = "Rating Scale";

creator.JSON = {
elements: [
{ type: "rating", name: "q1", rateType: "stars" },
]
};
const question = creator.survey.getQuestionByName("q1");
let questionAdorner = new QuestionAdornerViewModel(
creator,
question,
<any>undefined
);
let convertInputTypeAction = questionAdorner.actionContainer.getActionById("convertInputType");
expect(convertInputTypeAction.title).toBe("Stars");
question.rateType = "smileys";
expect(convertInputTypeAction.title).toBe("Smileys");
question.rateType = "stars";
expect(convertInputTypeAction.title).toBe("Stars");

surveySettings.animationEnabled = true;
});

test("Check question adorners icons", (): any => {
const creator = new CreatorTester();
creator.JSON = {
Expand Down