Improved grouping for master statistical
This commit is contained in:
@@ -361,7 +361,7 @@ export default function MasterCorporateDashboard({user}: Props) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const groupedByNameCorporates = groupBy(corporates, (x: CorporateUser) => x.corporateInformation?.companyInformation?.name);
|
const groupedByNameCorporates = groupBy(corporates, (x: CorporateUser) => x.corporateInformation?.companyInformation?.name || 'N/A');
|
||||||
const groupedByNameCorporatesKeys = Object.keys(groupedByNameCorporates);
|
const groupedByNameCorporatesKeys = Object.keys(groupedByNameCorporates);
|
||||||
const groupedByNameCorporateIds = groupedByNameCorporatesKeys.reduce((accm, x) => {
|
const groupedByNameCorporateIds = groupedByNameCorporatesKeys.reduce((accm, x) => {
|
||||||
const corporateUserIds = (groupedByNameCorporates[x] as CorporateUser[]).map((y) => y.id);
|
const corporateUserIds = (groupedByNameCorporates[x] as CorporateUser[]).map((y) => y.id);
|
||||||
|
|||||||
@@ -132,21 +132,23 @@ const MasterStatistical = (props: Props) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCorporatesScoresHash = (data: string[]) => data.reduce(
|
const getCorporatesScoresHash = (data: string[]) =>
|
||||||
(accm, id) => ({
|
data.reduce(
|
||||||
...accm,
|
(accm, id) => ({
|
||||||
[id]: getCorporateScores(id),
|
...accm,
|
||||||
}),
|
[id]: getCorporateScores(id),
|
||||||
{}
|
}),
|
||||||
) as Record<string, UserCount>;
|
{}
|
||||||
|
) as Record<string, UserCount>;
|
||||||
|
|
||||||
const getConsolidateScore = (data: Record<string, UserCount>) => Object.values(data).reduce(
|
const getConsolidateScore = (data: Record<string, UserCount>) =>
|
||||||
(acc: UserCount, { userCount, maxUserCount }: UserCount) => ({
|
Object.values(data).reduce(
|
||||||
userCount: acc.userCount + userCount,
|
(acc: UserCount, { userCount, maxUserCount }: UserCount) => ({
|
||||||
maxUserCount: acc.maxUserCount + maxUserCount,
|
userCount: acc.userCount + userCount,
|
||||||
}),
|
maxUserCount: acc.maxUserCount + maxUserCount,
|
||||||
{ userCount: 0, maxUserCount: 0 }
|
}),
|
||||||
)
|
{ userCount: 0, maxUserCount: 0 }
|
||||||
|
);
|
||||||
|
|
||||||
const corporateScores = getCorporatesScoresHash(corporates);
|
const corporateScores = getCorporatesScoresHash(corporates);
|
||||||
const consolidateScore = getConsolidateScore(corporateScores);
|
const consolidateScore = getConsolidateScore(corporateScores);
|
||||||
@@ -297,7 +299,9 @@ const MasterStatistical = (props: Props) => {
|
|||||||
/>
|
/>
|
||||||
{Object.keys(corporateUsers).map((corporateName) => {
|
{Object.keys(corporateUsers).map((corporateName) => {
|
||||||
const group = corporateUsers[corporateName];
|
const group = corporateUsers[corporateName];
|
||||||
const isSelected = group.every((id) => selectedCorporates.includes(id));
|
const isSelected = group.every((id) =>
|
||||||
|
selectedCorporates.includes(id)
|
||||||
|
);
|
||||||
|
|
||||||
const valueHash = getCorporatesScoresHash(group);
|
const valueHash = getCorporatesScoresHash(group);
|
||||||
const value = getConsolidateScoreStr(getConsolidateScore(valueHash));
|
const value = getConsolidateScoreStr(getConsolidateScore(valueHash));
|
||||||
@@ -310,10 +314,14 @@ const MasterStatistical = (props: Props) => {
|
|||||||
color="purple"
|
color="purple"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
setSelectedCorporates(((prev) => prev.filter((x) => !group.includes(x))));
|
setSelectedCorporates((prev) =>
|
||||||
|
prev.filter((x) => !group.includes(x))
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSelectedCorporates((prev) => [...new Set([...prev, ...group])]);
|
setSelectedCorporates((prev) => [
|
||||||
|
...new Set([...prev, ...group]),
|
||||||
|
]);
|
||||||
}}
|
}}
|
||||||
isSelected={isSelected}
|
isSelected={isSelected}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user