Skip to content

Commit

Permalink
fix user dashbaord state
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Jan 9, 2025
1 parent 5edcb11 commit fde294e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export const DashboardTopBannerContent = (props: DashboardTopBannerProps) => {
);
}

const relevantGuidedStep = getNextGuidedStep(stepDeterminationData);
const relevantGuidedStep = getNextGuidedStep(
stepDeterminationData,
props.enabledFeatureFlags,
);

const contentProps = {
relevantGuidedStep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const View = (props: Props) => {
const removalTimeEstimate = isScanResult(exposure)
? props.removalTimeEstimates.find(({ d }) => d === exposure.data_broker)
: undefined;

return (
<li key={exposureCardKey} className={styles.exposureListItem}>
<ExposureCard
Expand Down Expand Up @@ -253,6 +254,7 @@ export const View = (props: Props) => {
const dataSummary = getDashboardSummary(
adjustedScanResults,
props.userBreaches,
props.enabledFeatureFlags,
);

const hasExposures = combinedArray.length > 0;
Expand Down Expand Up @@ -513,6 +515,7 @@ export const View = (props: Props) => {
bannerData={getDashboardSummary(
adjustedScanResults,
props.userBreaches,
props.enabledFeatureFlags,
)}
stepDeterminationData={{
countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getScanResultsWithBroker } from "../../../../../../../../db/tables/oner
import { getServerSession } from "../../../../../../../functions/server/getServerSession";
import { refreshStoredScanResults } from "../../../../../../../functions/server/refreshStoredScanResults";
import { hasPremium } from "../../../../../../../functions/universal/user";
import { getEnabledFeatureFlags } from "../../../../../../../../db/tables/featureFlags";

export default async function FixPage() {
const session = await getServerSession();
Expand All @@ -31,6 +32,9 @@ export default async function FixPage() {
if (typeof profileId === "number") {
await refreshStoredScanResults(profileId);
}
const enabledFeatureFlags = await getEnabledFeatureFlags({
email: session.user.email,
});

const scanData = await getScanResultsWithBroker(
profileId,
Expand All @@ -43,6 +47,9 @@ export default async function FixPage() {
latestScanData: scanData,
};

const nextStep = getNextGuidedStep(stepDeterminationData);
const nextStep = getNextGuidedStep(
stepDeterminationData,
enabledFeatureFlags,
);
redirect(nextStep.href);
}
39 changes: 24 additions & 15 deletions src/app/functions/server/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { OnerepScanResultDataBrokerRow } from "knex/types/tables";
import { BreachDataTypes } from "../universal/breach";
import { RemovalStatusMap } from "../universal/scanResult";
import { SubscriberBreach } from "../../../utils/subscriberBreaches";
import { DataBrokerRemovalStatusMap } from "../universal/dataBroker";
import { FeatureFlagName } from "../../../db/tables/featureFlags";

export type DataPoints = {
// shared
Expand Down Expand Up @@ -96,6 +98,7 @@ export const dataClassKeyMap: Record<keyof DataPoints, string> = {
export function getDashboardSummary(
scannedResults: OnerepScanResultDataBrokerRow[],
subscriberBreaches: SubscriberBreach[],
enabledFeatureFlags?: FeatureFlagName[],
): DashboardSummary {
const summary: DashboardSummary = {
dataBreachTotalNum: 0,
Expand Down Expand Up @@ -204,15 +207,22 @@ export function getDashboardSummary(
r.status === RemovalStatusMap.WaitingForVerification) &&
!isManuallyResolved;

// TODO: Waiting for criteria for data brokers under maintenance to be determined
// const isRemovalUnderMaintenance =
// r.broker_status === DataBrokerRemovalStatusMap.RemovalUnderMaintenance;
// TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag
// If the flag is disabled, include the data.
// If the flag is enabled, include the data only if the broker status is not
const isRemovalUnderMaintenance =
r.broker_status === DataBrokerRemovalStatusMap.RemovalUnderMaintenance;

// The condition ensures that removal under maintenance is only considered when the flag is enabled.
/* c8 ignore next 3 */
const countRemovalUnderMaintenanceData =
!enabledFeatureFlags?.includes("EnableRemovalUnderMaintenanceStep") ||
!isRemovalUnderMaintenance;

if (isInProgress) {
// TODO: Waiting for criteria for data brokers under maintenance to be determined
// if (!isRemovalUnderMaintenance) {
summary.dataBrokerInProgressNum++;
// }
if (countRemovalUnderMaintenanceData) {
summary.dataBrokerInProgressNum++;
}
} else if (isAutoFixed) {
summary.dataBrokerAutoFixedNum++;
} else if (isManuallyResolved) {
Expand All @@ -234,14 +244,13 @@ export function getDashboardSummary(
summary.allDataPoints.familyMembers += r.relatives.length;

if (isInProgress) {
// TODO: Waiting for criteria for data brokers under maintenance to be determined
// if (!isRemovalUnderMaintenance) {
summary.inProgressDataPoints.emailAddresses += r.emails.length;
summary.inProgressDataPoints.phoneNumbers += r.phones.length;
summary.inProgressDataPoints.addresses += r.addresses.length;
summary.inProgressDataPoints.familyMembers += r.relatives.length;
summary.dataBrokerInProgressDataPointsNum += dataPointsIncrement;
// }
if (countRemovalUnderMaintenanceData) {
summary.inProgressDataPoints.emailAddresses += r.emails.length;
summary.inProgressDataPoints.phoneNumbers += r.phones.length;
summary.inProgressDataPoints.addresses += r.addresses.length;
summary.inProgressDataPoints.familyMembers += r.relatives.length;
summary.dataBrokerInProgressDataPointsNum += dataPointsIncrement;
}
}

// for fixed data points: email, phones, addresses, relatives, full name (1)
Expand Down
2 changes: 1 addition & 1 deletion src/app/functions/server/getRelevantGuidedSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function isGuidedResolutionInProgress(stepId: StepLink["id"]) {

export function getNextGuidedStep(
data: StepDeterminationData,
enabledFeatureFlags?: FeatureFlagName[],
enabledFeatureFlags: FeatureFlagName[],
afterStep?: StepLink["id"],
): StepLink {
// Resisting the urge to add a state machine... ^.^
Expand Down

0 comments on commit fde294e

Please sign in to comment.