Skip to content

Commit

Permalink
fix: filtrage des caractères spéciaux dans les type names (WFS) #504 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrousseau1 authored Dec 10, 2024
1 parent 2464e4c commit fb07d63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions assets/entrepot/pages/service/wfs/WfsServiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import AdditionalInfo from "../metadatas/AdditionalInfo";
import Description from "../metadatas/Description";
import UploadMDFile from "../metadatas/UploadMDFile";
import TableInfosForm from "./TablesInfoForm";
import { regex } from "../../../../utils";

type TableInfoType = Record<string, WfsTableInfos>;

Expand Down Expand Up @@ -200,11 +201,18 @@ const WfsServiceForm: FC<WfsServiceFormProps> = ({ datastoreId, vectorDbId, offe
if (!selectedTableNamesList || selectedTableNamesList.length === 0) {
return yup.mixed().nullable().notRequired();
}

const table_schemas = {};
selectedTableNamesList.forEach((table) => {
table_schemas[table] = yup.object({
public_name: yup.string().default(table),
public_name: yup
.string()
.default(table)
.test("matches", t("public_name_regex"), (value) => {
if (!value || value.trim() === "") {
return true;
}
return regex.public_name.test(value);
}),
title: yup.string().trim(t("trimmed_error")).strict(true).required(`Le titre de la table ${table} est obligatoire`),
description: yup.string().trim(t("trimmed_error")).strict(true).required(`Le résumé du contenu de la table ${table} est obligatoire`),
keywords: yup.array().of(yup.string()),
Expand Down Expand Up @@ -398,6 +406,7 @@ export const { i18n } = declareComponentKeys<
| "modify.in_progress"
| "back_to_data_list"
| "trimmed_error"
| "public_name_regex"
>()({
WfsServiceForm,
});
Expand Down Expand Up @@ -431,6 +440,8 @@ export const WfsServiceFormFrTranslations: Translations<"fr">["WfsServiceForm"]
"modify.in_progress": "Modification des informations du service WFS en cours",
back_to_data_list: "Retour à mes données",
trimmed_error: "La chaîne de caractères ne doit contenir aucun espace en début et fin",
public_name_regex:
"Le nom public de la table ne doit contenir que des lettres, chiffres, tirets (-), underscores (_), ou points (.) et ne peut commencer que par une lettre ou un underscore",
};

export const WfsServiceFormEnTranslations: Translations<"en">["WfsServiceForm"] = {
Expand All @@ -447,4 +458,5 @@ export const WfsServiceFormEnTranslations: Translations<"en">["WfsServiceForm"]
"modify.in_progress": undefined,
back_to_data_list: undefined,
trimmed_error: undefined,
public_name_regex: undefined,
};
1 change: 1 addition & 0 deletions assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const regex = {
technical_name: /^[A-Za-z_][A-Za-z0-9_.-]*$/, // chaîne alphanumérique qui commence par une lettre ou un underscore et ne doit contenir que des lettres, chiffres, tirets (-), underscores (_), ou points (.)
email: /^[\w-.]+@([\w-]+\.)+[\w-]{2,}$/,
uuid: /^[A-F\d]{8}-[A-F\d]{4}-[A-F\d]{4}-[A-F\d]{4}-[A-F\d]{12}$/i,
public_name: /^[A-Za-z_][A-Za-z0-9_.-]*$/,
};

export type ContentRangeType = {
Expand Down

0 comments on commit fb07d63

Please sign in to comment.