From 95f5b15a034880e13cc9356a485ac372e59a2a65 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 30 Dec 2024 07:17:14 +0000 Subject: [PATCH] Remove using onConditionGetTitleCallback function fix #5097 (#6351) * Remove using onConditionGetTitleCallback function * Fix unit test --- .../survey-creator-core/src/creator-base.ts | 11 -------- .../src/creator-settings.ts | 10 ------- .../src/property-grid/condition-survey.ts | 7 +---- .../property-grid/condition-survey.tests.ts | 26 ------------------- 4 files changed, 1 insertion(+), 53 deletions(-) diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 33a119164b..4a42b48b1e 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -3455,17 +3455,6 @@ export class SurveyCreatorModel extends Base } return options.sortOrder; } - onConditionGetTitleCallback( - expression: string, - title: string - ): string { - var options = { - expression: expression, - title: title, - }; - this.onConditionGetTitle.fire(this, options); - return options.title; - } isConditionOperatorEnabled(questionName: string, question: Question, operator: string, isEnabled: boolean): boolean { if (this.onGetConditionOperator.isEmpty) return isEnabled; const options = { diff --git a/packages/survey-creator-core/src/creator-settings.ts b/packages/survey-creator-core/src/creator-settings.ts index 9cc1058636..a6a98621df 100644 --- a/packages/survey-creator-core/src/creator-settings.ts +++ b/packages/survey-creator-core/src/creator-settings.ts @@ -308,10 +308,6 @@ export interface ISurveyCreatorOptions { list: any[], variables: string[] ): string; - onConditionGetTitleCallback( - expression: string, - title: string - ): string; isConditionOperatorEnabled(questionName: string, question: Question, operator: string, isEnabled: boolean): boolean; onLogicGetTitleCallback( expression: string, @@ -474,12 +470,6 @@ export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions { list: any[], variables: string[] ): string { return "asc"; } - onConditionGetTitleCallback( - expression: string, - title: string - ): string { - return title; - } isConditionOperatorEnabled(questionName: string, question: Question, operator: string, isEnabled: boolean): boolean { return isEnabled; } onLogicGetTitleCallback( expression: string, diff --git a/packages/survey-creator-core/src/property-grid/condition-survey.ts b/packages/survey-creator-core/src/property-grid/condition-survey.ts index 8c1b03fef6..14e6b4ac09 100644 --- a/packages/survey-creator-core/src/property-grid/condition-survey.ts +++ b/packages/survey-creator-core/src/property-grid/condition-survey.ts @@ -999,13 +999,8 @@ export class ConditionEditor extends PropertyEditorSetupValue { panel.getQuestionByName("removeAction").visible = options.value.length !== 1; }); } - this.setTitle(); + this.title = this.isReady ? this.text : editorLocalization.getString("pe.ruleIsNotSet"); } - private setTitle() { - const text = this.isReady ? this.text : ""; - this.title = this.options.onConditionGetTitleCallback(text, text || editorLocalization.getString("pe.ruleIsNotSet")); - } - private showTextEditor(expression: string) { this.panel.visible = false; this.textEditor.value = expression; diff --git a/packages/survey-creator-core/tests/property-grid/condition-survey.tests.ts b/packages/survey-creator-core/tests/property-grid/condition-survey.tests.ts index 8db563aec2..08e5c3958c 100644 --- a/packages/survey-creator-core/tests/property-grid/condition-survey.tests.ts +++ b/packages/survey-creator-core/tests/property-grid/condition-survey.tests.ts @@ -80,32 +80,6 @@ test("Add condition", () => { expect(conditionEditor.text).toEqual("{q} = 1 and {q2} = 2"); expect(conditionEditor.title).toEqual("{q} = 1 and {q2} = 2"); }); -test("Custom text for condition title", () => { - const survey = new SurveyModel({ - questions: [ - { type: "text", name: "q1" }, - { type: "text", name: "q" }, - { type: "text", name: "q2" } - ] - }); - const options = new EmptySurveyCreatorOptions(); - options.onConditionGetTitleCallback = (expression: string, title: string): string => { - if (!expression) return "Please setup the expression"; - return "Your expression is: " + title; - }; - const conditionEditor = new ConditionEditor(survey, survey.getQuestionByName("q1"), options); - expect(conditionEditor.title).toEqual("Please setup the expression"); - conditionEditor.text = "{q} = 1"; - expect(conditionEditor.title).toEqual("Your expression is: {q} = 1"); - conditionEditor.panel.addPanel(); - expect(conditionEditor.title).toEqual("Please setup the expression"); - var editPanel = conditionEditor.panel.panels[1]; - var nameQuestion = editPanel.getQuestionByName("questionName"); - nameQuestion.value = "q2"; - editPanel.getQuestionByName("questionValue").value = 2; - expect(conditionEditor.title).toEqual("Your expression is: {q} = 1 and {q2} = 2"); -}); - test("Do not delete the only condition, but clear it", () => { var survey = new SurveyModel({ questions: [