diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 8289ccf1..f5ab0a57 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -169,22 +169,30 @@ function CsComponent({ } }) - //предупреждаем добавленный вопрос о том, кто его родитель updateQuestion(targetQuestion.content.id, question => { question.content.rule.parentId = parentNodeContentId question.content.rule.main = [] + //Это листик. Сбросим ему на всякий случай не листиковые поля + question.content.rule.children = [] + question.content.rule.default = "" }) + + const noChild = parentQuestion.content.rule.children.length === 0 + //предупреждаем родителя о новом потомке (если он ещё не знает о нём) if (!parentQuestion.content.rule.children.includes(targetQuestion.content.id)) updateQuestion(parentNodeContentId, question => { question.content.rule.children = [...question.content.rule.children, targetQuestion.content.id] + //единственному ребёнку даём дефолт по-умолчанию + question.content.rule.default = noChild ? targetQuestion.content.id : question.content.rule.default }) - - //Если детей больше 1 - предупреждаем стор вопросов об открытии модалки ветвления - if (parentQuestion.content.rule.children >= 1) { + if (!noChild) {//детей больше 1 + //- предупреждаем стор вопросов об открытии модалки ветвления updateOpenedModalSettingsId(targetQuestion.content.id) } + + } diff --git a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx index 70ae0da0..eaf78b4b 100644 --- a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx +++ b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx @@ -179,10 +179,17 @@ export default function BranchingQuestions() { checked={parentQuestion.content.rule.default === targetQuestion.content.id} onClick={() => { let mutate = JSON.parse(JSON.stringify(parentQuestion)); - mutate.content.rule.default = - parentQuestion.content.rule.default === targetQuestion.content.id - ? "" - : targetQuestion.content.id; + + if (parentQuestion.content.rule.children.length === 1) { + //Если потомок 1 - можно только чекнуть чекбокс (по-умолчанию и так должен быть чекнут единственный) + mutate.content.rule.default = targetQuestion.content.id + } else {//Изменять чекбокс можно только если много потомков + mutate.content.rule.default = + parentQuestion.content.rule.default === targetQuestion.content.id + ? "" + : targetQuestion.content.id; + } + setParentQuestion(mutate); }} /> diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index 78671ca3..97e4b7fb 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -506,8 +506,10 @@ export const createResult = async ( } //Мы получили запрос на создание резулта. Анализируем существует ли такой. Если да - просто делаем его активным - const question = useQuestionsStore.getState().questions.find(q=> q.type !== null && q?.content.rule.parentContentId === parentContentId) + const question = useQuestionsStore.getState().questions.find(q=> q.type !== null && q?.content.rule.parentId === parentContentId) + console.log("Получил запрос на создание результа родителю ", parentContentId) + console.log("Ищу такой же результ в списке ", question) if (question) {//существует, делаем активным updateQuestion(question.id, (q) => {