mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
Compare commits
3 Commits
4.3.3
...
randomize-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
928c586e75 | ||
|
|
fc066551b5 | ||
|
|
7b1c7f95de |
@@ -100,6 +100,11 @@ export const MatrixQuestionForm = ({
|
|||||||
label: t("environments.surveys.edit.randomize_all_except_last"),
|
label: t("environments.surveys.edit.randomize_all_except_last"),
|
||||||
show: true,
|
show: true,
|
||||||
},
|
},
|
||||||
|
exceptLastTwo: {
|
||||||
|
id: "exceptLastTwo",
|
||||||
|
label: t("environments.surveys.edit.randomize_all_except_last_two"),
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
/// Auto animate
|
/// Auto animate
|
||||||
const [parent] = useAutoAnimate();
|
const [parent] = useAutoAnimate();
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ export const MultipleChoiceQuestionForm = ({
|
|||||||
label: t("environments.surveys.edit.randomize_all_except_last"),
|
label: t("environments.surveys.edit.randomize_all_except_last"),
|
||||||
show: true,
|
show: true,
|
||||||
},
|
},
|
||||||
|
exceptLastTwo: {
|
||||||
|
id: "exceptLastTwo",
|
||||||
|
label: t("environments.surveys.edit.randomize_all_except_last_two"),
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateChoice = (choiceIdx: number, updatedAttributes: { label: TI18nString }) => {
|
const updateChoice = (choiceIdx: number, updatedAttributes: { label: TI18nString }) => {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ interface ShuffleOptionsTypes {
|
|||||||
none?: ShuffleOptionType;
|
none?: ShuffleOptionType;
|
||||||
all?: ShuffleOptionType;
|
all?: ShuffleOptionType;
|
||||||
exceptLast?: ShuffleOptionType;
|
exceptLast?: ShuffleOptionType;
|
||||||
|
exceptLastTwo?: ShuffleOptionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ShuffleOptionSelectProps {
|
interface ShuffleOptionSelectProps {
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ export const getShuffledRowIndices = (n: number, shuffleOption: TShuffleOption):
|
|||||||
shuffle(array);
|
shuffle(array);
|
||||||
array.push(lastElement);
|
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;
|
return array;
|
||||||
};
|
};
|
||||||
@@ -45,22 +51,37 @@ export const getShuffledChoicesIds = (
|
|||||||
const otherOption = choices.find((choice) => {
|
const otherOption = choices.find((choice) => {
|
||||||
return choice.id === "other";
|
return choice.id === "other";
|
||||||
});
|
});
|
||||||
|
|
||||||
const shuffledChoices = otherOption ? [...choices.filter((choice) => choice.id !== "other")] : [...choices];
|
const shuffledChoices = otherOption ? [...choices.filter((choice) => choice.id !== "other")] : [...choices];
|
||||||
|
|
||||||
if (shuffleOption === "all") {
|
if (shuffleOption === "all") {
|
||||||
shuffle(shuffledChoices);
|
shuffle(shuffledChoices);
|
||||||
} else if (shuffleOption === "exceptLast") {
|
}
|
||||||
if (otherOption) {
|
if (shuffleOption === "exceptLast") {
|
||||||
|
const lastElement = shuffledChoices.pop();
|
||||||
|
if (lastElement) {
|
||||||
shuffle(shuffledChoices);
|
shuffle(shuffledChoices);
|
||||||
} else {
|
shuffledChoices.push(lastElement);
|
||||||
const lastElement = shuffledChoices.pop();
|
}
|
||||||
if (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);
|
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);
|
return shuffledChoices.map((choice) => choice.id);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ export const ZSurveyConsentQuestion = ZSurveyQuestionBase.extend({
|
|||||||
|
|
||||||
export type TSurveyConsentQuestion = z.infer<typeof ZSurveyConsentQuestion>;
|
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>;
|
export type TShuffleOption = z.infer<typeof ZShuffleOption>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user