Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP computing white list answers from passport #2462

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
21 changes: 19 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,7 +52,7 @@ export interface PreviewStore extends Store.Store {
upcomingCardIds?: Store.nodeId[],
) => Store.nodeId | undefined;
canGoBack: (node: Store.node | null) => boolean;
computePassport: () => Readonly<Store.passport>;
computePassport: (options?: ComputePassportOptions) => Readonly<Store.passport>;
record: (id: Store.nodeId, userData?: Store.userData) => void;
resultData: (
flagSet?: string,
Expand Down Expand Up @@ -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 = [] }]) => {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
Loading