Merge pull request #271 from Hexastack/270-bug-blockform-dialog-regex-pattern-extra-slashes-bug

fix(frontend): visual editor pattern UI representation
This commit is contained in:
Med Marrouchi 2024-10-28 09:03:03 +01:00 committed by GitHub
commit 8f7dce8d61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View File

@ -100,6 +100,7 @@
"no_content_type": "No content type available, please create one first", "no_content_type": "No content type available, please create one first",
"invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value", "invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value",
"regex_is_invalid": "Regex is invalid", "regex_is_invalid": "Regex is invalid",
"regex_is_empty": "Regex cannot be empty",
"attachment_not_found": "Attachment is not found", "attachment_not_found": "Attachment is not found",
"title_length_exceeded": "You have reached the maximum length", "title_length_exceeded": "You have reached the maximum length",
"no_label_found": "No label found", "no_label_found": "No label found",

View File

@ -100,6 +100,7 @@
"no_content_type": "Il n'y a aucun type de contenu pour le moment, veuillez en ajouter un.", "no_content_type": "Il n'y a aucun type de contenu pour le moment, veuillez en ajouter un.",
"invalid_max_fallback_attempt_limit": "La limite des tentatives de secours doit être un nombre positif.", "invalid_max_fallback_attempt_limit": "La limite des tentatives de secours doit être un nombre positif.",
"regex_is_invalid": "Le regex est invalide", "regex_is_invalid": "Le regex est invalide",
"regex_is_empty": "Le regex ne peut pas être vide",
"attachment_not_found": "La pièce jointe est introuvable", "attachment_not_found": "La pièce jointe est introuvable",
"title_length_exceeded": "Vous avez atteint la longueur maximale", "title_length_exceeded": "Vous avez atteint la longueur maximale",
"no_label_found": "Aucune étiquette trouvée", "no_label_found": "Aucune étiquette trouvée",

View File

@ -265,26 +265,26 @@ const PatternInput: FC<PatternInputProps> = ({
) : null} ) : null}
{typeof value === "string" && patternType === "regex" ? ( {typeof value === "string" && patternType === "regex" ? (
<RegexInput <RegexInput
{...registerInput(t("message.regex_is_invalid"), idx, { {...registerInput(t("message.regex_is_empty"), idx, {
validate: (pattern) => { validate: (pattern) => {
try { try {
if ( const parsedPattern = new RegExp(pattern.slice(1, -1));
pattern.at(0) === "/" &&
pattern.at(-1) === "/" && if (String(parsedPattern) !== pattern) {
typeof pattern === "string" throw t("message.regex_is_invalid");
) }
new RegExp(pattern.slice(1, -1));
return true; return true;
} catch (_e) { } catch (_e) {
return t("message.regex_is_invalid"); return t("message.regex_is_invalid");
} }
}, },
setValueAs: (v) => `/${v}/`, setValueAs: (v) => (isRegex(v) ? v : `/${v}/`),
})} })}
label={t("label.regex")} label={t("label.regex")}
value={value.slice(1, -1)} value={value.slice(1, -1)}
onChange={(v) => onChange(v)} onChange={(v) => onChange(v)}
required
/> />
) : null} ) : null}
{typeof value === "string" && patternType === "text" ? ( {typeof value === "string" && patternType === "text" ? (