Skip to content

Commit

Permalink
MNTOR-3863 and MNTOR-3840 - Fix user dashboard state for manual remov…
Browse files Browse the repository at this point in the history
…al flag (#5473)

* fix user dashbaord state

* fix unit tests

* add feature flags to manualremovalview and welcome view

* add feature flag to resolution container

* add featureflag to monthly activity plus
  • Loading branch information
codemist authored Jan 14, 2025
1 parent d559e17 commit b8f0bf1
Show file tree
Hide file tree
Showing 13 changed files with 636 additions and 493 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 @@ -12,6 +12,7 @@ import styles from "./ResolutionContainer.module.scss";
import { ProgressCard } from "../../../../../../../components/client/ProgressCard";
import { StepDeterminationData } from "../../../../../../../functions/server/getRelevantGuidedSteps";
import { getDashboardSummary } from "../../../../../../../functions/server/dashboard";
import { FeatureFlagName } from "../../../../../../../../db/tables/featureFlags";

type ResolutionContainerProps = {
type: "highRisk" | "leakedPasswords" | "securityRecommendations";
Expand All @@ -25,6 +26,7 @@ type ResolutionContainerProps = {
data: StepDeterminationData;
label?: string;
cta?: ReactNode;
enabledFeatureFlags: FeatureFlagName[];
};

export const ResolutionContainer = (props: ResolutionContainerProps) => {
Expand All @@ -40,6 +42,7 @@ export const ResolutionContainer = (props: ResolutionContainerProps) => {
const resolutionSummary = getDashboardSummary(
props.data.latestScanData?.results ?? [],
props.data.subscriberBreaches,
props.enabledFeatureFlags,
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function ManualRemoveView(props: Props) {
const l10n = useL10n();
const [activeExposureCardKey, setActiveExposureCardKey] = useState(0);

const summary = getDashboardSummary(props.scanData.results, props.breaches);
const summary = getDashboardSummary(
props.scanData.results,
props.breaches,
props.enabledFeatureFlags,
);

const countOfDataBrokerProfiles = props.scanData.results.length;
const estimatedTime = countOfDataBrokerProfiles * 10; // 10 minutes per data broker site.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function WelcomeToPlusView(props: Props) {
const summary = getDashboardSummary(
scanResultsInProgress,
props.data.subscriberBreaches,
props.enabledFeatureFlags,
);
const dataPointReduction = getDataPointReduction(summary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export function HighRiskBreachLayout(props: HighRiskBreachLayoutProps) {
illustration={illustration}
isPremiumUser={hasPremium(props.data.user)}
isEligibleForPremium={props.isEligibleForPremium}
enabledFeatureFlags={props.enabledFeatureFlags}
cta={
!isStepDone && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export function LeakedPasswordsLayout(props: LeakedPasswordsLayoutProps) {
title={title}
illustration={illustration}
isPremiumUser={hasPremium(props.data.user)}
enabledFeatureFlags={props.enabledFeatureFlags}
cta={
!isStepDone && (
<>
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function SecurityRecommendationsLayout(
title={title}
illustration={illustration}
isPremiumUser={hasPremium(props.data.user)}
enabledFeatureFlags={props.enabledFeatureFlags}
cta={
!isStepDone && (
<Button
Expand Down
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
Loading

0 comments on commit b8f0bf1

Please sign in to comment.