From b8b249e73c48b1bf20baf94f04a33f682d26979a Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Mon, 20 Nov 2023 12:19:08 +0000 Subject: [PATCH] --wip-- [skip ci] --- .../FlowEditor/lib/__tests__/preview.test.ts | 22 +++++++++++++++++++ .../src/pages/FlowEditor/lib/store/preview.ts | 21 ++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts index c9338e4e25..a849e5214c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts @@ -577,6 +577,28 @@ describe("changeAnswer", () => { expect(getState().breadcrumbs).not.toContain(originalAnswer); expect(getState().cachedBreadcrumbs).toStrictEqual(originalAnswer); }); + + test.only("should return only whitelist answers when the option is passed", () => { + const breadcrumbs = breadcrumbsDependentOnPassport; + const flow = { ...flowWithPassportComponents }; + + setState({ + flow, + breadcrumbs, + cachedBreadcrumbs: {}, + }); + console.log('Here') + console.log('Full passport', computePassport()) + console.log('Whitelist passport', computePassport({whiteList: true})) + + // Assert our initial passport state is correct + expect(computePassport({whiteList: true})).toEqual({ + data: { + "application.fee.exemption.disability": ["true"], + }, + }); + + }); }); describe("resetPreview", () => { diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts index a2a1795d3b..7c57311b32 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts @@ -31,6 +31,15 @@ import type { SharedStore } from "./shared"; const SUPPORTED_DECISION_TYPES = [TYPES.Checklist, TYPES.Statement]; let memoizedPreviousCardId: string | undefined = undefined; let memoizedBreadcrumb: Store.breadcrumbs | undefined = undefined; + + +// const WHITE_LIST_QUESTIONS = ["proposal.ProjectType"] +const WHITE_LIST_QUESTIONS = ["application.fee.exemption.disability"] + +interface ComputePassportOptions { + whiteList?: boolean; +} + export interface PreviewStore extends Store.Store { collectedFlags: ( upToNodeId: Store.nodeId, @@ -43,7 +52,7 @@ export interface PreviewStore extends Store.Store { upcomingCardIds?: Store.nodeId[], ) => Store.nodeId | undefined; canGoBack: (node: Store.node | null) => boolean; - computePassport: () => Readonly; + computePassport: (options?: ComputePassportOptions) => Readonly; record: (id: Store.nodeId, userData?: Store.userData) => void; resultData: ( flagSet?: string, @@ -196,7 +205,7 @@ export const previewStore: StateCreator< ); }, - computePassport: () => { + computePassport: (options?: ComputePassportOptions) => { const { flow, breadcrumbs } = get(); const passport = Object.entries(breadcrumbs).reduce( (acc, [id, { data = {}, answers = [] }]) => { @@ -230,6 +239,14 @@ export const previewStore: StateCreator< ); passportData[key] = uniq(combined); + + // Check if key is in the white list, skip if not + console.log('Options', options) + console.log('Whitelist options', options?.whiteList) + console.log(WHITE_LIST_QUESTIONS) + if (options && options?.whiteList && !WHITE_LIST_QUESTIONS.includes(key)) { + return acc; + } } }