mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-21 13:40:31 -06:00
Compare commits
3 Commits
4.0.0
...
randomize-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
928c586e75 | ||
|
|
fc066551b5 | ||
|
|
7b1c7f95de |
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -45,22 +51,37 @@ export const getShuffledChoicesIds = (
|
||||
const otherOption = choices.find((choice) => {
|
||||
return choice.id === "other";
|
||||
});
|
||||
|
||||
const shuffledChoices = otherOption ? [...choices.filter((choice) => choice.id !== "other")] : [...choices];
|
||||
|
||||
if (shuffleOption === "all") {
|
||||
shuffle(shuffledChoices);
|
||||
} else if (shuffleOption === "exceptLast") {
|
||||
if (otherOption) {
|
||||
}
|
||||
if (shuffleOption === "exceptLast") {
|
||||
const lastElement = shuffledChoices.pop();
|
||||
if (lastElement) {
|
||||
shuffle(shuffledChoices);
|
||||
} else {
|
||||
const lastElement = shuffledChoices.pop();
|
||||
if (lastElement) {
|
||||
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);
|
||||
shuffledChoices.push(lastElement);
|
||||
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) shuffledChoices.push(otherOption);
|
||||
|
||||
if (otherOption) {
|
||||
shuffledChoices.push(otherOption);
|
||||
}
|
||||
|
||||
return shuffledChoices.map((choice) => choice.id);
|
||||
};
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user