Skip to content

Commit

Permalink
feat(stats): add global data on graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Nov 20, 2024
1 parent 5292260 commit 5f1b02d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 53 deletions.
1 change: 0 additions & 1 deletion client/src/components/graphs/contributions-by-name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const ContributionsGraphByTopContributors = ({
</div>
);
}

if (isError) {
return <div>Une erreur s'est produite</div>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Contribution {
comment: string;
team: string[];
created_at: string;
phone?: string;
type: string;
tags: string[];
objectId: string;
Expand Down Expand Up @@ -123,13 +124,12 @@ export interface StaffActionsProps {
url: string;
}

export interface Response {
team: string;

responseMessage: string;

export interface ThreadResponse {
team: string[];
timestamp: string;
responseMessage: string;
}

export interface Thread {
responses: Response[];
responses: ThreadResponse[];
}
80 changes: 49 additions & 31 deletions client/src/pages/stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,49 @@ import ContributionsGraphByTopContributors from "../../components/graphs/contrib
import ContributionsGraphByTime from "../../components/graphs/contributions-by-year";
import { ClipLoader } from "react-spinners";
import "./styles.scss";
import ContributionAllDatas from "../../api/contribution-api/getAllDatas";

const GetStats = () => {
const [filter, setFilter] = useState("contacts");
const [filter, setFilter] = useState("contact");
const [url, setUrl] = useState(() => buildStatsURL(filter));

const isDevelopment = import.meta.env.VITE_HEADER_TAG === "Development";
const prodUrl = import.meta.env.VITE_BASE_API_URL;
const baseUrl = isDevelopment
? "http://localhost:3000/api"
: `${prodUrl}/api`;

useEffect(() => {
const newUrl = buildStatsURL(filter);
setUrl(newUrl);
if (filter !== "global") {
setUrl(buildStatsURL(filter));
}
}, [filter]);

const { data, isLoading, isError } = ContributionData(url);
const {
data: allData,
isLoading: isLoadingAllData,
isError: isErrorAllData,
} = ContributionAllDatas(baseUrl);

const isGlobal = filter === "global";
const contributions = isGlobal
? allData?.flatMap((item) => item.data || [])
: data?.data;
const isLoadingGraphs = isGlobal ? isLoadingAllData : isLoading;
const isErrorGraphs = isGlobal ? isErrorAllData : isError;

if (isLoading) {
if (isLoadingGraphs) {
return (
<div className="loading-container">
<ClipLoader color="#123abc" size={50} />
</div>
);
}
if (isError) {
if (isErrorGraphs) {
return <div>Une erreur s'est produite</div>;
}

if (!Array.isArray(data?.data)) {
if (!Array.isArray(contributions)) {
return <div>Les données ne sont pas disponibles</div>;
}

Expand All @@ -41,8 +60,8 @@ const GetStats = () => {
<Col md="12">
<Title look="h5">Choisissez la table de données à afficher</Title>
<i>
Les boutons si dessous filtrent sur les différentes collection, par
objet étant les contributions visant un objet de scanR
Les boutons ci-dessous filtrent sur les différentes collections, par
objet étant les contributions visant un objet de scanR.
</i>
<div className="filter-buttons-container fr-mt-5w">
<button
Expand Down Expand Up @@ -73,55 +92,54 @@ const GetStats = () => {
>
Changement de nom
</button>
<button
className={`filter-button ${filter === "global" ? "active" : ""}`}
onClick={() => setFilter("global")}
>
Global
</button>
</div>
</Col>
<Row gutters>
<Col md="6">
<ContributionsGraphByTags
contributions={data?.data}
isLoading={isLoading}
isError={isError}
contributions={contributions}
isLoading={isLoadingGraphs}
isError={isErrorGraphs}
/>
</Col>
<Col md="6">
<ContributionsGraphByTeam
contributions={data?.data}
isLoading={isLoading}
isError={isError}
contributions={contributions}
isLoading={isLoadingGraphs}
isError={isErrorGraphs}
/>
</Col>
</Row>
<Row gutters>
<Col md="6">
<ContributionsGraphByStatus
contributions={data?.data}
isLoading={isLoading}
isError={isError}
contributions={contributions}
isLoading={isLoadingGraphs}
isError={isErrorGraphs}
/>
</Col>
<Col md="6">
<ContributionsGraphByTopContributors
contributions={data?.data}
isLoading={isLoading}
isError={isError}
contributions={contributions}
isLoading={isLoadingGraphs}
isError={isErrorGraphs}
/>
</Col>
</Row>
<Row gutters>
<Col md="6">
<ContributionsGraphByTime
contributions={data?.data}
isLoading={isLoading}
isError={isError}
contributions={contributions}
isLoading={isLoadingGraphs}
isError={isErrorGraphs}
/>
</Col>
{/* <Col md="6">
<ContributionsGraphByTopContributors
contributions={data?.data}
isLoading={isLoading}
isError={isError}
/>
</Col> */}
</Row>
</Container>
);
Expand Down
25 changes: 10 additions & 15 deletions client/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Thread } from "../pages/api-operation-page/types";

export interface Contribution {
[x: string]: any;
id: string;
name: string;
email: string;
phone: string;
phone?: string;
tags: string[];
status: string;
comment?: string;
Expand Down Expand Up @@ -94,14 +96,6 @@ export interface ChangeNameContribution {
threads?: Thread[];
}

export interface Thread {
team: [string];
responseMessage: string;
threadId: string;
responses?: Response[];
timestamp: string;
}

export interface Response {
read: boolean;
responseMessage: string;
Expand Down Expand Up @@ -151,6 +145,7 @@ export type Contribute_Production = {
tag: string;
id: string;
team: string[];
phone: string;
modified_at: string | number | Date;
comment: string;
treated_at: Date;
Expand All @@ -164,6 +159,12 @@ export type Contribute_Production = {
fromApplication: string;
};

export type TagSelectionModalProps = {
isOpen: boolean;
allTags: string[];
onClose: (selectedTags: string[]) => void;
};

export type EditModalProps = {
isOpen: boolean;
dataProduction: Contribute_Production[];
Expand All @@ -173,12 +174,6 @@ export type EditModalProps = {
allTags: string[];
};

export type TagSelectionModalProps = {
isOpen: boolean;
allTags: string[];
onClose: (selectedTags: string[]) => void;
};

export type Production = {
lastName: string;
firstName: string;
Expand Down

0 comments on commit 5f1b02d

Please sign in to comment.