Skip to content

Commit

Permalink
An exception raise on making Creator read-only when onMachineTranslat…
Browse files Browse the repository at this point in the history
…e event is used fix #5319 (#5320)
  • Loading branch information
andrewtelnov committed Mar 12, 2024
1 parent 7af4c6f commit 88ad8ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/survey-creator-core/src/components/tabs/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,19 @@ export class Translation extends Base implements ITranslationLocales {
});
res.onGetMatrixRowActions.add((sender, options) => {
updateMatrixRemoveAction(options.question, options.actions, options.row);
if (this.options.getHasMachineTranslation() && findAction(options.actions, "remove-row")) {
if (this.options.getHasMachineTranslation() && findAction(options.actions, "remove-row") &&
Array.isArray(options.question.value)) {
const q = options.question;
const rowIndex = q.visibleRows.indexOf(options.row);
const locale = q.value[rowIndex].name;
options.actions.splice(0, 0, new Action({
iconName: "icon-language",
locTooltipName: "ed.translateUsigAI",
location: "end",
action: () => this.showTranslationEditor(locale)
}));
if(rowIndex >= 0 && rowIndex < q.value.length) {
const locale = q.value[rowIndex].name;
options.actions.splice(0, 0, new Action({
iconName: "icon-language",
locTooltipName: "ed.translateUsigAI",
location: "end",
action: () => this.showTranslationEditor(locale)
}));
}
}
updateMatixActionsClasses(options.actions);
});
Expand Down
24 changes: 24 additions & 0 deletions packages/survey-creator-core/tests/tabs/translation.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1930,3 +1930,27 @@ test("If panel title then don't include it for 'Use string only' mode, Bug #5236
translation.reset();
expect(translation.root.allLocItems).toHaveLength(2);
});
test("Translation: readOnly & onMachineTranslate", () => {
let creator = new CreatorTester({ showTranslationTab: true });
creator.onActiveTabChanging.add((sender, options) => {
creator.readOnly = options.tabName !== "translation";
});
creator.onMachineTranslate.add((sender, options) => {});
creator.JSON = {
pages: [
{
name: "page2",
title: "Page title"
}
]
};
creator.activeTab = "translation";
expect(creator.readOnly).toBeFalsy();
const tabTranslationPlugin: TabTranslationPlugin = creator.getPlugin("translation");
const translation = tabTranslationPlugin.model;
expect(translation.localesQuestion.visibleRows).toHaveLength(1);
translation.addLocale("de");
expect(translation.localesQuestion.visibleRows).toHaveLength(2);
creator.activeTab = "designer";
expect(creator.readOnly).toBeTruthy();
});

0 comments on commit 88ad8ca

Please sign in to comment.