intégration de l'analyse des avis dans l'interface admin

This commit is contained in:
Quentin Roussel
2023-04-02 20:28:12 +02:00
parent ef2c3cdce4
commit 1fa3b92e32
13 changed files with 114 additions and 21 deletions

View File

@@ -1,10 +1,19 @@
import React from 'react'
import { Card, Col, Row, Table } from 'react-bootstrap';
import { Alert, Card, Col, Row, Table } from 'react-bootstrap';
import { BsPersonFill } from 'react-icons/bs';
import styles from '../styles/Avis.module.css'
export default function Avis({review}) {
const {date, note_principale,notes_autres, commentaire, sexe_auteur, nom_source, age_auteur} = review;
function getAnalyse() {
let res = "Non calculé"
notes_autres.map(({ critere, note }) => {
if(critere === "analyse") {
res=note.toString();
}
})
return res
}
return (
<Card>
<Card.Title>Avis</Card.Title>
@@ -36,10 +45,12 @@ export default function Avis({review}) {
<td>{note_principale} / 10</td>
</tr>
{notes_autres && notes_autres.map(({ critere, note }) => {
return <tr key={critere}>
<td>{critere}</td>
<td>{note}/10</td>
</tr>
if(critere !== "analyse") {
return <tr key={critere}>
<td>{critere}</td>
<td>{note}/10</td>
</tr>
}
})}
</tbody>
</Table>
@@ -48,6 +59,9 @@ export default function Avis({review}) {
<Card>
<Card.Header>Commentaire</Card.Header>
<Card.Body>
<Alert variant={getAnalyse() > 0 ? "success" : "danger"}>
<p>Score de positivité : {getAnalyse()}</p>
</Alert>
{commentaire}
</Card.Body>
</Card>

View File

@@ -8,7 +8,12 @@ export default function AvisList({ avis }) {
function handleClick(id) {
router.push(`/avis/${id}`);
}
function truncateComment(text) {
if(text.length > 100) {
return text.substring(0, 100) + "..."
}
return text;
}
return (
<Table>
<thead>
@@ -16,15 +21,17 @@ export default function AvisList({ avis }) {
<th>Date</th>
<th>Note globale</th>
<th>Commentaire</th>
<th>Positivité</th>
<th>Source</th>
</tr>
</thead>
<tbody>
{avis.map(({ id, note_principale, commentaire, date, nom_source }) => {
{avis.map(({ id, note_principale, commentaire,analyse, date, nom_source }) => {
return <tr onClick={() => handleClick(id)} key={id} className={styles.row}>
<td>{date}</td>
<td>{note_principale} / 10</td>
<td>{commentaire}</td>
<td>{truncateComment(commentaire)}</td>
<td>{analyse}</td>
<td>{nom_source}</td>
</tr>
})}

View File

@@ -53,5 +53,3 @@
background-color: #C6C6C6;
pointer-events: none;
}