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

fix(dashboard): l'ordre d'affichage de chaque champ dans les stats suit l'ordre avec lequel on a fait le paramétrage #1733

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 51 additions & 64 deletions dashboard/src/scenes/stats/CustomFieldsStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 */}
<div className="tw-hidden tw-basis-1/4 tw-basis-1/2 tw-basis-1/3 tw-basis-full" />
<div className="-tw-mx-4 tw-flex tw-flex-wrap">
{additionalCols.map((col) => (
<div className={`tw-px-4 tw-py-2 tw-basis-${colSize}`} key={col.title}>
{/* TODO: fix alignment. */}
<Card title={col.title} count={col.value} children={<div></div>} dataTestId={dataTestId} help={help?.(col.title.capitalize())} />
</div>
))}
{customFieldsNumber.map((field) => (
<div className={`tw-px-4 tw-py-2 tw-basis-${colSize}`} key={field.name}>
<div className="-tw-mx-4 tw-flex tw-flex-wrap tw-justify-around">
{additionalCols.map((col) => (
<div className="tw-basis-1/4 tw-px-4 tw-py-2" key={col.title}>
{/* TODO: fix alignment. */}
<Card title={col.title} count={col.value} children={<div></div>} dataTestId={dataTestId} help={help?.(col.title.capitalize())} />
</div>
))}
{customFieldsInStats.map((field) => {
if (['number'].includes(field.type)) {
return (
<div className="tw-basis-1/4 tw-px-4 tw-py-2" key={field.name}>
<BlockTotal title={field.label} data={data} field={field.name} help={help?.(field.label.capitalize())} />
</div>
))}
{customFieldsDate.map((field) => (
<div className={`tw-px-4 tw-py-2 tw-basis-${colSize}`} key={field.name}>
);
}
if (['date', 'date-with-time'].includes(field.type)) {
return (
<div className="tw-basis-1/4 tw-px-4 tw-py-2" key={field.name}>
<BlockDateWithTime data={data} field={field} help={help?.(field.label.capitalize())} />
</div>
))}
</div>
</>
)}
{customFieldsResponsivePie.map((field) => (
<CustomResponsivePie
title={field.label}
help={help?.(field.label.capitalize())}
onItemClick={onSliceClick ? (newSlice) => onSliceClick?.(newSlice, field.name) : undefined}
key={field.name}
data={getPieData(data, field.name, {
options: field.options,
isBoolean: field.type === 'boolean',
})}
/>
))}
{customFieldsResponsiveBar.map((field) => {
return (
<CustomResponsiveBar
title={field.label}
help={help?.(field.label.capitalize())}
onItemClick={onSliceClick ? (newSlice) => 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 (
<CustomResponsivePie
title={field.label}
help={help?.(field.label.capitalize())}
onItemClick={onSliceClick ? (newSlice) => 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 (
<CustomResponsiveBar
title={field.label}
help={help?.(field.label.capitalize())}
onItemClick={onSliceClick ? (newSlice) => 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;
})}
</div>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/scenes/stats/General.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const GeneralStats = ({
<div className="tw-flex tw-basis-full tw-items-center">
<Filters title="Filtrer par personnes suivies:" base={filterBase} filters={filterPersons} onChange={setFilterPersons} />
</div>
<div className="-tw-mx-4 tw-flex tw-flex-wrap">
<div className="-tw-mx-4 tw-flex tw-flex-wrap tw-justify-around">
<Block
data={personsCreated}
title="Nombre de personnes créées"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/scenes/stats/Persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const PersonStats = ({
<>
<h3 className="tw-my-5 tw-text-xl">Statistiques des {title}</h3>
<Filters base={filterBase} filters={filterPersons} onChange={setFilterPersons} />
<div className="-tw-mx-4 tw-flex tw-flex-wrap">
<div className="-tw-mx-4 tw-flex tw-flex-wrap tw-justify-around">
<Block data={personsForStats} title={`Nombre de ${title}`} help={firstBlockHelp} />
<BlockCreatedAt persons={personsForStats} />
<BlockWanderingAt persons={personsForStats} />
Expand Down
Loading