Skip to content

Commit

Permalink
fix: Création d'une permission - services introuvables #374
Browse files Browse the repository at this point in the history
  • Loading branch information
pprev94 committed Jun 24, 2024
1 parent f63573c commit b459bf4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const AddPermissionForm: FC<AddPermissionFormProps> = ({ datastoreId }) => {
return Object.entries(communities).map(([id, name]) => ({ id: id, name: name }));
}, [user, publicCommunities]);

const privateOfferings = useMemo(() => {
return data?.filter((offering) => offering.open === false) ?? [];
}, [data]);

// Formulaire,
const form = useForm<AddPermissionFormType>({
mode: "onChange",
Expand Down Expand Up @@ -157,7 +161,7 @@ const AddPermissionForm: FC<AddPermissionFormProps> = ({ datastoreId }) => {
<Alert severity="error" closable title={error?.message} />
) : offeringsError ? (
<Alert severity="error" closable title={offeringsError?.message} />
) : data?.length === 0 ? (
) : privateOfferings.length === 0 ? (
<Alert severity="error" closable title={t("add_form.no_services")} />
) : (
<div>
Expand Down Expand Up @@ -226,7 +230,7 @@ const AddPermissionForm: FC<AddPermissionFormProps> = ({ datastoreId }) => {
name="offerings"
render={({ field: { onChange } }) => (
<ScrollOfferingList
offerings={data}
offerings={privateOfferings}
label={t("add_form.hint_services")}
hintText={t("add_form.hint_services")}
state={errors.offerings ? "error" : "default"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const DatastorePermissionsFrTranslations: Translations<"fr">["DatastorePe
"add_form.expiration_date": "Date d’expiration (optionnel)",
"add_form.services": "Services",
"add_form.hint_services": "Sélectionner les services auxquels cette permission donne accès",
"add_form.no_services": "Aucun service, impossible d’ajouter une permission",
"add_form.no_services": "Aucun service privé, impossible d’ajouter une permission",
"add_form.only_oath": "Authentification forte requise",
"add_form.hint_only_oath": "Ne permettre l’utilisation de cette permission qu'avec des clés de type OAUTH2",
"edit_form.document_title": ({ id }) => `Mise à jour de la permission ${id}`,
Expand Down Expand Up @@ -154,7 +154,7 @@ export const DatastorePermissionsEnTranslations: Translations<"en">["DatastorePe
"add_form.expiration_date": "Expiration date (optional)",
"add_form.services": "Services",
"add_form.hint_services": "Select the services to which this permission gives access",
"add_form.no_services": "No service, unable to add permission",
"add_form.no_services": "No private service, unable to add permission",
"add_form.only_oath": "Strong authentication required",
"add_form.hint_only_oath": "Only allow the use of this permission with OAUTH2 type keys",
"edit_form.document_title": ({ id }) => `Updating permission ${id}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const EditPermissionForm: FC<EditPermissionFormProps> = ({ datastoreId, permissi
},
});

const privateOfferings = useMemo(() => {
return offeringsQuery.data?.filter((offering) => offering.open === false) ?? [];
}, [offeringsQuery.data]);

const endDate = useMemo(() => {
if (permissionQuery.data && permissionQuery.data.end_date) {
return new Date(permissionQuery.data.end_date);
Expand Down Expand Up @@ -110,7 +114,7 @@ const EditPermissionForm: FC<EditPermissionFormProps> = ({ datastoreId, permissi
<Alert severity="error" closable title={offeringsQuery.error?.message} />
) : permissionQuery.error ? (
<Alert severity="error" closable title={permissionQuery.error?.message} />
) : offeringsQuery.data?.length === 0 ? (
) : privateOfferings.length === 0 ? (
<Alert severity="error" closable title={t("add_form.no_services")} />
) : (
<div>
Expand Down Expand Up @@ -144,7 +148,7 @@ const EditPermissionForm: FC<EditPermissionFormProps> = ({ datastoreId, permissi
hintText={t("add_form.hint_services")}
state={errors.offerings ? "error" : "default"}
stateRelatedMessage={errors?.offerings?.message?.toString()}
offerings={offeringsQuery.data}
offerings={privateOfferings}
value={value}
onChange={onChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ScrollOfferingListProps = {
stateRelatedMessage?: string;
onChange: (value: string[]) => void;
value?: string[];
offerings: OfferingListResponseDto[] | undefined;
offerings: OfferingListResponseDto[];
};

const ScrollOfferingList: FC<ScrollOfferingListProps> = (props) => {
Expand All @@ -34,8 +34,7 @@ const ScrollOfferingList: FC<ScrollOfferingListProps> = (props) => {

/* Calcul des options */
const options = useMemo(() => {
const privates = offerings?.filter((offering) => offering.open === false) ?? [];
return privates.map((offering) => ({
return offerings.map((offering) => ({
label: (
<span>
{offering.layer_name}
Expand Down

0 comments on commit b459bf4

Please sign in to comment.