Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ajouter une nouvelle contribution #1524

Merged
merged 4 commits into from
Jan 20, 2025
Merged

Conversation

m-maillot
Copy link
Contributor

No description provided.

@@ -11,6 +11,12 @@ export const generateMetadata = (
contribution: DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumbs: Breadcrumb[]
): ContributionMetadata => {
if (breadcrumbs.length === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai remonté la condition pour le valider même si c'est une contribution générique. Sinon, on pouvait avoir une contrib générique sans thème et ça fait planter le front.
J'en ai profité pour revoir le message d'erreur.

});

export type QuestionFormData = z.infer<typeof formDataSchema>;

export const Form = ({
question,
messages,
onUpsert,
defaultOrder,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je passe un defaultOrder pour renseigné par défaut le prochain index disponible en BDD

}
label="Ordre"
fullWidth
disabled={question !== undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je désactive si on est en mode édition.

}
maxOrder: contribution_questions(order_by: { order: desc }, limit: 1) {
order
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici je récupère les messages blocks, la liste des CCs supportées (j'ai besoin de savoir si elles sont unextended pour une règle métier que je gère plus tard) et le maxOrder qui me permet d'avoir le prochain order disponible et de le renseigner par défaut dans le formulaire de création

messages: data.messages,
agreementIds: data.agreements
.flatMap((item) => item)
.concat([{ id: "0000", unextended: false }]),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici j'ajoute pour générer la réponse à la générique. Je ne sais pas si c'est pas mieux de le faire dans le code de création d'une nouvelle contrib.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça me choque pas ici

@@ -154,7 +154,7 @@ export const questionBaseSchema = z.object({
required_error: "Une question doit être renseignée",
})
.min(1, "Une question doit être renseignée"),
order: z.number(),
order: z.coerce.number(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cela permet d'obliger zod à convertir en number la valeur avant de la valider. C'est pour faire fonctionner avec le formulaire car l'input retourne un string.

Comment on lines +98 to +104
if (!contribution.cdtnId) {
postTreatment = async (document) => {
await this.contributionRepository.updateCdtnId(
contribution.id,
document.cdtn_id
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici ça corrige le soucis des états de publication qui n'étaient pas bon. Avant, on tentait de mettre à jour le cdtn_id à ce moment mais le document n'est pas encore créé. Du coup, on a une erreur hasura de foreign key. J'ai placé le processus dans un postTreatment que l'on va exécuté à la fin après avoir insérer le document.

@m-maillot m-maillot force-pushed the linked/feat/add-contribution branch from 1c475cc to 8901636 Compare January 9, 2025 08:08
Comment on lines +23 to +27
data: data.agreementIds.map((item) => ({
display_date: "01/01/2025",
agreement_id: item.id,
content_type: item.unextended ? "NOTHING" : undefined,
})),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On va créer les questions ici. Du coup, on utilise la liste des cc que l'on a récupéré auparavant.

La ligne content_type: item.unextended ? "NOTHING" : undefined permet de corriger le soucis du champ non éditable sur certaines réponses. En fait, pour les CCs non étendues (comme la 29), on désactive ce champ car elle ne peut être que dans l'état UNKNOWN pour indiquer la cc est non étendue et que l'on a pas le choix que de mettre une réponse à l'utilisateur. C'est géré dans le formulaire d'une réponse directement.

message_id: formData.message_id ? formData.message_id : undefined, // use to transform empty string sent by the form to undefined
answers: {
data: data.agreementIds.map((item) => ({
display_date: "01/01/2025",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A voir par la suite :

Ce champ n'est pas nullable actuellement. Mais c'est étrange de mettre une date à ce moment. Est ce que l'on met la date de création de la contribution ? Est ce que l'on ne met rien ? Il faudrait ajouter le message d'alerte quand on sauvegarde une réponse pour rappeler qu'il faut mettre à jour la date de mise à jour. Car il ça risque d'être oublier je pense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il faudrait mettre la date de création de la question. Une date en dur c'est un peu bizarre.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le soucis c'est qu'elle ne devrait pas être renseigné avant la publication car elle va changer :(

Comment on lines 62 to 66
annotations:
oblik.socialgouv.io/min-request-cpu: "500m"
oblik.socialgouv.io/min-request-memory: "500Mi"
oblik.socialgouv.io/min-limit-cpu: "1000m"
oblik.socialgouv.io/min-limit-memory: "1Gi"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On force kube à nous filer plus de ressources sinon la mise à jour des docs échouent.

@@ -98,7 +98,7 @@ export:

hasura:
~chart: hasura
~needs: [build-hasura, pg]
~needs: [ build-hasura, pg ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il manquait la dépendance sur pg et hasura se lançait avant pg et du coup ça plante le process de déploiement.

@@ -59,3 +59,8 @@ pg:
region:
~tpl~name: "cdtn-prod-backups-access-key"
key: bucket_region
annotations:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça on commit du coup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je dirai que oui pour ne pas être bloqué sur les branches de dev...

control={control}
hintText={
<>
Cette valeur est indicative. Vous pouvez modifier cette valeur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cette valeur est indicative. Vous pouvez modifier cette valeur
Cette valeur est indicative. Vous pouvez la modifier mais le numéro de question ne doit pas déjà être utilisée.

<>
Cette valeur est indicative. Vous pouvez modifier cette valeur
mais elle ne doit pas déjà être utilisée.{" "}
<b>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<b>
<strong>


export function ContributionsPage() {
return (
<Layout title="Contributions">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Layout title="Contributions">
<Layout title="Nouvelle Contribution">

@maxgfr maxgfr removed their request for review January 16, 2025 16:24
`/contributions/questions/${result.insert_contribution_questions_one.id}`
);
};
if (!data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lorsque je clique sur "créer" j'ai un message furtif d'erreur qui apparait. Cela n'est pas bloquant mais cela n'est pas un comportement normal attendu.

@m-maillot m-maillot force-pushed the linked/feat/add-contribution branch from 5d97fdb to 21c96ec Compare January 20, 2025 14:30
@m-maillot m-maillot force-pushed the linked/feat/add-contribution branch from 21c96ec to 56ce9db Compare January 20, 2025 15:04
@tokenbureau
Copy link

tokenbureau bot commented Jan 20, 2025

🎉 Deployment for commit 56ce9db :

Ingresses
Docker images
  • 📦 docker pull harbor.fabrique.social.gouv.fr/cdtn/cdtn-admin/export:sha-56ce9dbcf07831826e36eaf0745eb24f51d63f7e
  • 📦 docker pull harbor.fabrique.social.gouv.fr/cdtn/cdtn-admin/frontend:sha-56ce9dbcf07831826e36eaf0745eb24f51d63f7e
  • 📦 docker pull harbor.fabrique.social.gouv.fr/cdtn/cdtn-admin/hasura:sha-56ce9dbcf07831826e36eaf0745eb24f51d63f7e
Debug

@m-maillot m-maillot merged commit ec323b9 into master Jan 20, 2025
26 checks passed
@m-maillot m-maillot deleted the linked/feat/add-contribution branch January 20, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants