Skip to content

Commit

Permalink
remove changes to dashboard.js
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Jul 27, 2023
1 parent 95af3dc commit 0988cea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export const DashboardTopBanner = (props: DashboardTopBannerProps) => {
}
);

const breachChartData: [string, number][] =
props.bannerData.sanitizedBreachExposures.map((obj) => {
const [key, value] = Object.entries(obj)[0];
return [l10n.getString(key), value];
});

const contentData = {
LetsFixDataContent: {
headline: l10n.getString("dashboard-top-banner-protect-your-data-title"),
Expand Down Expand Up @@ -130,6 +124,7 @@ export const DashboardTopBanner = (props: DashboardTopBannerProps) => {
};

const content = contentData[props.type];
console.log(props.hasRunScan);

return (
<div className={styles.container}>
Expand All @@ -147,7 +142,7 @@ export const DashboardTopBanner = (props: DashboardTopBannerProps) => {
)}
</div>
<div className={styles.chart}>
<Chart data={props.hasRunScan ? chartData : breachChartData} />
<Chart hasRunScan={props.hasRunScan} data={chartData} />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const View = (props: Props) => {
? "DataBrokerScanUpsellContent"
: "LetsFixDataContent"
}
hasRunScan={!isScanResultItemsEmpty}
/>
<section className={styles.exposuresArea}>
<h2 className={styles.exposuresAreaHeadline}>
Expand Down
21 changes: 11 additions & 10 deletions src/app/components/client/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Link from "next/link";

export type Props = {
data: Array<[string, number]>;
hasRunScan: boolean;
};

export const DoughnutChart = (props: Props) => {
Expand Down Expand Up @@ -96,6 +97,15 @@ export const DoughnutChart = (props: Props) => {
</div>
);

const prompt = (
<div className={styles.prompt}>
<p>{l10n.getString("exposure-chart-returning-user-upgrade-prompt")}</p>
<Link href="/redesign/user/welcome">
{l10n.getString("exposure-chart-returning-user-upgrade-prompt-cta")}
</Link>
</div>
);

return (
<>
<figure className={styles.chartContainer}>
Expand Down Expand Up @@ -178,16 +188,7 @@ export const DoughnutChart = (props: Props) => {
))}
</tbody>
</table>
<div className={styles.prompt}>
<p>
{l10n.getString("exposure-chart-returning-user-upgrade-prompt")}
</p>
<Link href="/redesign/user/welcome">
{l10n.getString(
"exposure-chart-returning-user-upgrade-prompt-cta"
)}
</Link>
</div>
{!props.hasRunScan ? prompt : null}
</div>
</div>
<figcaption>
Expand Down
25 changes: 2 additions & 23 deletions src/app/functions/server/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface DashboardSummary {
securityQuestions: number;
};
sanitizedExposures: Array<Record<string, number>>;
sanitizedBreachExposures: Array<Record<string, number>>;
}

const exposureKeyMap: Record<string, string> = {
Expand Down Expand Up @@ -73,7 +72,6 @@ export function dashboardSummary(
securityQuestions: 0,
},
sanitizedExposures: [],
sanitizedBreachExposures: [],
};

// calculate broker summary from scanned results
Expand Down Expand Up @@ -112,7 +110,7 @@ export function dashboardSummary(
uniqueBreaches.add(b.Name);
const dataClasses = b.DataClasses ?? [];

// TODO: add email addresses count from data breach after MNTOR-1947 tech debt
// TODO: add count email addresses from data breach after MNTOR-1947 tech debt

// count password
if (dataClasses.includes(BreachDataTypes.Passwords)) {
Expand Down Expand Up @@ -169,40 +167,21 @@ export function dashboardSummary(

function sanitizeExposures(summary: DashboardSummary): DashboardSummary {
const NUM_OF_TOP_EXPOSURES = 4;
const NUM_OF_EXPOSURES_BEFORE_SCAN = 2;
const { allExposures } = summary;

const sanitizedExposures = Object.entries(allExposures)
.sort((a, b) => b[1] - a[1])
.map((e) => {
const key = exposureKeyMap[e[0]];
return { [key]: e[1] };
})
.splice(0, NUM_OF_TOP_EXPOSURES);

// Returning user who hasn't run a scan
const breachSanitizedExposures = Object.entries(allExposures)
.sort((a, b) => b[1] - a[1])
.map((e) => {
const key = exposureKeyMap[e[0]];
if (key === "email-addresses" || key === "phone-numbers") {
return { [key]: e[1] };
}
return null;
})
.filter((entry): entry is Record<string, number> => entry !== null)
.splice(0, NUM_OF_EXPOSURES_BEFORE_SCAN);

const other = sanitizedExposures.reduce(
(total, cur) => total - (Object.values(cur).pop() || 0),
summary.totalExposures
);

sanitizedExposures.push({ ["other-data-class"]: other });
breachSanitizedExposures.push({ ["other-data-class"]: other });

summary.sanitizedExposures = sanitizedExposures;
summary.sanitizedBreachExposures = breachSanitizedExposures;

console.debug({ sanitizedExposures });
return summary;
}

0 comments on commit 0988cea

Please sign in to comment.