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