Merge branch 'randomize-last-two' of https://github.com/formbricks/formbricks into randomize-last-two

This commit is contained in:
Johannes
2025-03-13 14:49:29 +01:00
5 changed files with 32 additions and 1 deletions
@@ -100,6 +100,11 @@ export const MatrixQuestionForm = ({
label: t("environments.surveys.edit.randomize_all_except_last"),
show: true,
},
exceptLastTwo: {
id: "exceptLastTwo",
label: t("environments.surveys.edit.randomize_all_except_last_two"),
show: true,
},
};
/// Auto animate
const [parent] = useAutoAnimate();
@@ -70,6 +70,11 @@ export const MultipleChoiceQuestionForm = ({
label: t("environments.surveys.edit.randomize_all_except_last"),
show: true,
},
exceptLastTwo: {
id: "exceptLastTwo",
label: t("environments.surveys.edit.randomize_all_except_last_two"),
show: true,
},
};
const updateChoice = (choiceIdx: number, updatedAttributes: { label: TI18nString }) => {
@@ -25,6 +25,7 @@ interface ShuffleOptionsTypes {
none?: ShuffleOptionType;
all?: ShuffleOptionType;
exceptLast?: ShuffleOptionType;
exceptLastTwo?: ShuffleOptionType;
}
interface ShuffleOptionSelectProps {
+20
View File
@@ -34,6 +34,12 @@ export const getShuffledRowIndices = (n: number, shuffleOption: TShuffleOption):
shuffle(array);
array.push(lastElement);
}
} else if (shuffleOption === "exceptLastTwo") {
if (array.length >= 2) {
const lastTwo = array.splice(array.length - 2, 2);
shuffle(array);
array.push(...lastTwo);
}
}
return array;
};
@@ -57,6 +63,20 @@ export const getShuffledChoicesIds = (
shuffle(shuffledChoices);
shuffledChoices.push(lastElement);
}
} else if (shuffleOption === "exceptLastTwo") {
if (otherOption) {
if (shuffledChoices.length >= 1) {
// Keep the last element fixed (the one before "other")
const lastElement = shuffledChoices.pop();
shuffle(shuffledChoices);
if (lastElement) shuffledChoices.push(lastElement);
}
} else if (shuffledChoices.length >= 2) {
// No "other" option, keep last two elements fixed
const lastTwo = shuffledChoices.splice(shuffledChoices.length - 2, 2);
shuffle(shuffledChoices);
shuffledChoices.push(...lastTwo);
}
}
if (otherOption) {
+1 -1
View File
@@ -570,7 +570,7 @@ export const ZSurveyConsentQuestion = ZSurveyQuestionBase.extend({
export type TSurveyConsentQuestion = z.infer<typeof ZSurveyConsentQuestion>;
export const ZShuffleOption = z.enum(["none", "all", "exceptLast"]);
export const ZShuffleOption = z.enum(["none", "all", "exceptLast", "exceptLastTwo"]);
export type TShuffleOption = z.infer<typeof ZShuffleOption>;