Skip to content

Commit

Permalink
correction progress circle
Browse files Browse the repository at this point in the history
  • Loading branch information
SophieLab committed Oct 22, 2024
1 parent 441c93a commit c79122c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 63 deletions.
8 changes: 4 additions & 4 deletions src/admin/modalities/ModalitiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ModalitiesTable: React.FC<ModalitiesTableProps> = ({
onDeleteAet,
onEchoAet,
}) => {

const columns: ColumnDef<Modality>[] = [
{
accessorKey: "name",
Expand All @@ -41,7 +41,7 @@ const ModalitiesTable: React.FC<ModalitiesTableProps> = ({
header: "Actions",
id: "actions",
cell: ({ row }) => (
<div className="flex justify-center items-center gap-2.5">
<div className="sticky right-0 z-10 bg-white">
<Button
onClick={() => onEchoAet(row.original.name)}
color={Colors.secondary}
Expand All @@ -63,8 +63,8 @@ const ModalitiesTable: React.FC<ModalitiesTableProps> = ({
<Table
columns={columns}
data={aetData}
headerColor={Colors.white}
headerTextSize="xs"
headerColor={Colors.white}
headerTextSize="xs"
className="bg-gray-100"
enableColumnFilters
enableSorting
Expand Down
1 change: 1 addition & 0 deletions src/delete/DeleteRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const DeleteRoot = () => {
[[]],
{
onSuccess: (uuid) => {
console.log("Queue created with UUID:", uuid); // Log pour vérifier l'UUID
setQueueUuid(uuid);
},
}
Expand Down
17 changes: 11 additions & 6 deletions src/queue/ProgressQueueCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import { Cancel } from "../icons";
import { Queue } from "../utils/types";

type ProgressQueueProps = {
queueData: Queue,
onDelete: (event: React.MouseEvent) => void
queueData: Queue;
onDelete: (event: React.MouseEvent) => void;
colors: { background: string; progress: string }; // Ajout des couleurs
};

const ProgressQueueCircle = ({ queueData, onDelete }: ProgressQueueProps) => {

const ProgressQueueCircle = ({ queueData, onDelete, colors }: ProgressQueueProps) => {
return (
<div className="flex-col items-center justify-center">
<ProgressCircle text={queueData?.state} progress={queueData?.progress || 0} size={150}>
<ProgressCircle
text={queueData?.state}
progress={queueData?.progress || 0}
size={150}
className={colors.background} // Utiliser la couleur de fond
>
<div className="flex justify-center">
<Cancel
className={`text-sm text-danger cursor-pointer hover:text-danger-hover `}
className={`text-sm ${colors.progress} cursor-pointer hover:text-danger-hover`} // Utiliser la couleur de progression
onClick={onDelete}
/>
</div>
Expand Down
54 changes: 49 additions & 5 deletions src/root/Dashboard/CardAnon.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
import Button from "../../ui/Button";
import Card, { CardHeader, CardBody, CardFooter } from "../../ui/Card";
import AnonQueues from "../../anonymize/AnonQueues";
import { Colors } from "../../utils/enums";
import { Colors } from "../../utils/enums"; // Assurez-vous que `Colors.primary` est défini ici
import { useSelector } from "react-redux";
import { getExistingAnonymizeQueues, getAnonymizeQueue } from "../../services/queues";
import { useCustomQuery } from "../../utils";
import { useMemo } from "react";
import ProgressQueueCircle from "../../queue/ProgressQueueCircle";
import { Spinner } from "../../ui";
import { AnonQueue } from "../../utils/types";

const CardAnon = () => {
const currentUserId = useSelector((state) => state.user.currentUserId);

const { data: existingAnonymizeQueues } = useCustomQuery<string[]>(
['queue', 'anonymize', currentUserId?.toString() || ''],
() => getExistingAnonymizeQueues(currentUserId)
);

const firstQueue = existingAnonymizeQueues?.[0];

const { data, isPending, isFetching } = useCustomQuery<AnonQueue[]>(
['queue', 'anonymize', firstQueue],
() => getAnonymizeQueue(firstQueue),
{
refetchInterval: 2000,
enabled: firstQueue != null,
}
);

const globalProgress = useMemo(() => {
if (!data || data.length === 0) return 0;
const totalJobs = data.length;
const completedJobs = data.filter(job => job.state === 'completed' || job.state === 'in progress').length;

return totalJobs === 0 ? 0 : (completedJobs / totalJobs) * 100;
}, [data]);

if (!firstQueue) return null;
if (isPending || isFetching) return <Spinner />;

return (
<Card className="flex-1">
<CardHeader centerTitle title="Anonymisation" color={Colors.blueCustom} />
<CardBody color={Colors.light}>
<AnonQueues circle={true} showResults={false}
<CardBody className="flex items-center justify-center" color={Colors.light}>
<ProgressQueueCircle
onDelete={() => { }}
queueData={{
progress: globalProgress,
state: "",
id: "",
results: undefined,
userId: 0
}}
colors={{ background: 'text-gray-300', progress: Colors.primary }}
/>
</CardBody>
<CardFooter color={Colors.light}>
<Button className="self-center" color={Colors.blueCustom}>
Empty List
Vider la liste
</Button>
</CardFooter>
</Card>
Expand Down
104 changes: 56 additions & 48 deletions src/ui/ProgressCircle.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,65 @@
type ProgressCircleProps = {
progress: number;
text?: string;
size?: number; // This defines the size of the circle
children?: React.ReactNode;
progress: number;
text?: string;
size?: number; // This defines the size of the circle
children?: React.ReactNode;
className?: string; // Prop for custom CSS class
progressColor?: string; // Ajout pour la couleur de progression
};

const ProgressCircle = ({ progress, text = '%', size = 100, children }: ProgressCircleProps) => { // Reduced default size
const radius = 12; // Reduced radius for a smaller circle
const circumference = 2 * Math.PI * radius;
const progressValue = (progress / 100) * circumference;
const ProgressCircle = ({
progress,
text = 'Average',
size = 120,
children,
className = '', // Default to an empty string if no class is provided
progressColor = 'text-orange-600', // Couleur de progression par défaut
}: ProgressCircleProps) => {
const radius = 15; // Increased radius for a larger circle
const circumference = 2 * Math.PI * radius;
const progressValue = (progress / 100) * circumference;

return (
<div className="relative" style={{ width: size, height: size }}>
<svg
className="rotate-[135deg] w-full h-full"
viewBox="0 0 36 36"
xmlns="http://www.w3.org/2000/svg"
>
{/* Background circle */}
<circle
cx="18"
cy="18"
r={radius}
fill="none"
className="stroke-current text-primary dark:text-neutral-700"
strokeWidth="2"
strokeDasharray="75 100"
/>
return (
<div className={`relative flex items-center justify-center ${className}`} style={{ width: size, height: size }}>
<svg
className="rotate-[135deg] w-full h-full"
viewBox="0 0 36 36"
xmlns="http://www.w3.org/2000/svg"
>
{/* Background circle */}
<circle
cx="18"
cy="18"
r={radius}
fill="none"
className={`stroke-current text-neutral-300 dark:text-neutral-700`}
strokeWidth="3" // Increased stroke width for better visibility
/>

{/* Progress circle */}
<circle
cx="18"
cy="18"
r={radius}
fill="none"
className="stroke-current text-primary dark:text-primary"
strokeWidth="2"
strokeDasharray={`${progressValue} ${circumference}`}
/>
</svg>
{/* Progress circle */}
<circle
cx="18"
cy="18"
r={radius}
fill="none"
className={`stroke-current ${progressColor}`} // Utilisation de la couleur de progression
strokeWidth="3" // Increased stroke width for better visibility
strokeDasharray={`${progressValue} ${circumference}`}
/>
</svg>

{/* Centered text */}
<div className="absolute text-center transform -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2">
<span className="text-xl font-bold text-primary dark:text-primary"> {/* Reduced text size */}
{progress}
</span>
<span className="block text-sm text-darj dark:text-primary">{text}</span>
<span>
{children}
</span>
</div>
</div>
);
{/* Centered text in black color */}
<div className="absolute text-center transform -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2">
<span className="text-3xl font-bold text-black">
{progress}
</span>
<span className="block text-sm text-black">
{text}
</span>
{children}
</div>
</div>
);
};

export default ProgressCircle;

0 comments on commit c79122c

Please sign in to comment.