From 76819ec8921298c21076e3fbf7abcd45053f40db Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Tue, 17 Oct 2023 16:27:36 +0200 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20l'ordre=20d'affichage=20de=20?= =?UTF-8?q?chaque=20champ=20dans=20les=20stats=20suit=20l'ordre=20avec=20l?= =?UTF-8?q?equel=20on=20a=20fait=20le=20param=C3=A9trage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/scenes/stats/CustomFieldsStats.js | 115 ++++++++---------- dashboard/src/scenes/stats/General.js | 2 +- dashboard/src/scenes/stats/Persons.js | 2 +- 3 files changed, 53 insertions(+), 66 deletions(-) diff --git a/dashboard/src/scenes/stats/CustomFieldsStats.js b/dashboard/src/scenes/stats/CustomFieldsStats.js index a93371bd6..a235fb98c 100644 --- a/dashboard/src/scenes/stats/CustomFieldsStats.js +++ b/dashboard/src/scenes/stats/CustomFieldsStats.js @@ -5,13 +5,6 @@ import { BlockDateWithTime, BlockTotal } from './Blocks'; import Card from '../../components/Card'; import { getMultichoiceBarData, getPieData } from './utils'; -function getColsSize(totalCols) { - if (totalCols === 1) return 'full'; - if (totalCols === 2) return '1/2'; - if (totalCols % 4 === 0) return '1/3'; - return '1/4'; -} - const CustomFieldsStats = ({ customFields, data, additionalCols = [], dataTestId = '', help, onSliceClick, totalTitleForMultiChoice }) => { const team = useRecoilValue(currentTeamState); @@ -20,69 +13,63 @@ const CustomFieldsStats = ({ customFields, data, additionalCols = [], dataTestId .filter((f) => f.enabled || f.enabledTeams?.includes(team._id)) .filter((f) => f.showInStats); - const customFieldsNumber = customFieldsInStats.filter((field) => ['number'].includes(field.type)); - const customFieldsDate = customFieldsInStats.filter((field) => ['date', 'date-with-time'].includes(field.type)); - const customFieldsResponsivePie = customFieldsInStats.filter((field) => ['boolean', 'yes-no', 'enum'].includes(field.type)); - const customFieldsResponsiveBar = customFieldsInStats.filter((field) => ['multi-choice'].includes(field.type)); - - const totalCols = customFieldsNumber.length + customFieldsDate.length + additionalCols.length; - - const colSize = getColsSize(totalCols); - return ( <> - {totalCols > 0 && ( - <> - {/* tailwind doesn't comile dynamic classes, so we need to declare them */} -
-
- {additionalCols.map((col) => ( -
- {/* TODO: fix alignment. */} -
} dataTestId={dataTestId} help={help?.(col.title.capitalize())} /> -
- ))} - {customFieldsNumber.map((field) => ( -
+
+ {additionalCols.map((col) => ( +
+ {/* TODO: fix alignment. */} +
} dataTestId={dataTestId} help={help?.(col.title.capitalize())} /> +
+ ))} + {customFieldsInStats.map((field) => { + if (['number'].includes(field.type)) { + return ( +
- ))} - {customFieldsDate.map((field) => ( -
+ ); + } + if (['date', 'date-with-time'].includes(field.type)) { + return ( +
- ))} -
- - )} - {customFieldsResponsivePie.map((field) => ( - onSliceClick?.(newSlice, field.name) : undefined} - key={field.name} - data={getPieData(data, field.name, { - options: field.options, - isBoolean: field.type === 'boolean', - })} - /> - ))} - {customFieldsResponsiveBar.map((field) => { - return ( - onSliceClick?.(newSlice, field.name) : undefined} - key={field.name} - isMultiChoice - axisTitleY="File active" - axisTitleX={field.name} - totalForMultiChoice={data.length} - totalTitleForMultiChoice={totalTitleForMultiChoice} - data={getMultichoiceBarData(data, field.name, { options: field.options })} - /> - ); - })} + ); + } + if (['boolean', 'yes-no', 'enum'].includes(field.type)) { + return ( + onSliceClick?.(newSlice, field.name) : undefined} + key={field.name} + data={getPieData(data, field.name, { + options: field.options, + isBoolean: field.type === 'boolean', + })} + /> + ); + } + if (['multi-choice'].includes(field.type)) { + return ( + onSliceClick?.(newSlice, field.name) : undefined} + key={field.name} + isMultiChoice + axisTitleY="File active" + axisTitleX={field.name} + totalForMultiChoice={data.length} + totalTitleForMultiChoice={totalTitleForMultiChoice} + data={getMultichoiceBarData(data, field.name, { options: field.options })} + /> + ); + } + return null; + })} +
); }; diff --git a/dashboard/src/scenes/stats/General.js b/dashboard/src/scenes/stats/General.js index 39407955b..0b08f3971 100644 --- a/dashboard/src/scenes/stats/General.js +++ b/dashboard/src/scenes/stats/General.js @@ -19,7 +19,7 @@ const GeneralStats = ({
-
+

Statistiques des {title}

-
+