From cd21388ebf457245f25caaca5af79f4c2e6a38dc Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Fri, 4 Oct 2024 20:13:02 +0300 Subject: [PATCH] resolve #5931 Translation Tab - A language selector shows "No data to display" --- .../src/components/tabs/translation.ts | 8 +++- .../tests/tabs/translation.tests.ts | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/survey-creator-core/src/components/tabs/translation.ts b/packages/survey-creator-core/src/components/tabs/translation.ts index 2ea591d123..8590c045a5 100644 --- a/packages/survey-creator-core/src/components/tabs/translation.ts +++ b/packages/survey-creator-core/src/components/tabs/translation.ts @@ -733,7 +733,6 @@ export class Translation extends Base implements ITranslationLocales { if (!this.root) return; this.root.deleteLocaleStrings(locale); this.removeLocale(locale); - this.updateChooseLanguageActions(); this.reset(); } private removingLocale: string; @@ -788,6 +787,12 @@ export class Translation extends Base implements ITranslationLocales { private calcIsChooseLanguageEnabled() { this.isChooseLanguageEnabled = this.chooseLanguageActions.filter((item: IAction) => item.visible).length > 0; } + private refreshAddLanguageActionListModel() { + const listModel = this.addLanguageAction.data; + if (listModel) { + listModel.refresh(); + } + } private updateLocales() { var res = [""]; @@ -1169,6 +1174,7 @@ export class Translation extends Base implements ITranslationLocales { if (Array.isArray(actions)) { actions.forEach(item => item.visible = this.isLocaleVisible(locales, item.data.value)); } + this.refreshAddLanguageActionListModel(); this.calcIsChooseLanguageEnabled(); } public resetLocales(): void { diff --git a/packages/survey-creator-core/tests/tabs/translation.tests.ts b/packages/survey-creator-core/tests/tabs/translation.tests.ts index 23e55056fd..675257a1ff 100644 --- a/packages/survey-creator-core/tests/tabs/translation.tests.ts +++ b/packages/survey-creator-core/tests/tabs/translation.tests.ts @@ -543,6 +543,51 @@ test("Make invisible locales in language selector, that has been already choosen expect(list.actions[1].visible).toBeFalsy(); surveyLocalization.supportedLocales = []; }); +test("A language selector shows 'No data to display'", () => { + surveyLocalization.supportedLocales = ["en", "fr"]; + const creator = new CreatorTester(); + creator.JSON = { + pages: [ + { + name: "page1", + elements: [{ type: "text", name: "question1" }] + }, + { + name: "page2", + elements: [{ type: "text", name: "question2" }] + } + ] + }; + const tabTranslation = new TabTranslationPlugin(creator); + tabTranslation.activate(); + const translation = tabTranslation.model; + const question = translation.settingsSurvey.getQuestionByName("locales"); + + const addLanguageAction = translation["addLanguageAction"]; + const list = translation["addLanguageAction"].data; + expect(translation["isChooseLanguageEnabled"]).toBeTruthy(); + expect(addLanguageAction.popupModel.isVisible).toBeFalsy(); + expect(list.isEmpty).toBeFalsy(); + + addLanguageAction.action(); + expect(addLanguageAction.popupModel.isVisible).toBeTruthy(); + expect(list.isEmpty).toBeFalsy(); + expect(list.actions[1].visible).toBeTruthy(); + + list.onItemClick(list.actions[1]); + expect(addLanguageAction.popupModel.isVisible).toBeFalsy(); + expect(list.isEmpty).toBeTruthy(); + + question.removeRow(1, false); + expect(list.isEmpty).toBeFalsy(); + + addLanguageAction.action(); + expect(addLanguageAction.popupModel.isVisible).toBeTruthy(); + expect(list.isEmpty).toBeFalsy(); + expect(list.actions[1].visible).toBeTruthy(); + + surveyLocalization.supportedLocales = []; +}); test("Make invisible locales in language selector, that has been already choosen", () => { const survey = new SurveyModel({ pages: [