From 153045411faab3465bf5e23d3341c48ea024f8b5 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 3 Nov 2023 08:23:14 +0000 Subject: [PATCH 1/7] EAR 2155 Cannot add content --- eq-author/src/App/folder/Routing.js | 74 +++++++++++---- eq-author/src/App/folder/index.js | 2 + .../page/Preview/CalculatedSummaryPreview.js | 7 ++ .../App/page/Preview/QuestionPagePreview.js | 8 ++ eq-author/src/App/section/Logic/index.js | 92 ++++++++++++------ .../src/App/shared/Logic/SkipLogic/index.js | 56 ++++++++++- eq-author/src/App/shared/Logic/index.js | 93 ++++++++++--------- 7 files changed, 242 insertions(+), 90 deletions(-) diff --git a/eq-author/src/App/folder/Routing.js b/eq-author/src/App/folder/Routing.js index ad202b535e..c32cdbea6a 100644 --- a/eq-author/src/App/folder/Routing.js +++ b/eq-author/src/App/folder/Routing.js @@ -4,26 +4,70 @@ import NoRouting, { Title, Paragraph, } from "App/shared/Logic/Routing/NoRouting"; -import GET_FOLDER_QUERY from "App/folder/graphql/fragment.graphql"; -import PropTypes from "prop-types"; import Panel from "components/Panel"; -import { useQuery } from "@apollo/react-hooks"; +import CustomPropTypes from "custom-prop-types"; +// import { useSetNavigationCallbacksForPage } from "components/NavigationCallbacks"; + +import { + useCreatePageWithFolder, + useCreateFolder, + useCreateListCollectorFolder, +} from "hooks/useCreateFolder"; +import { + useCreateQuestionPage, + useCreateCalculatedSummaryPage, +} from "hooks/useCreateQuestionPage"; +import { useSetNavigationCallbacks } from "components/NavigationCallbacks"; export const NO_ROUTING_TITLE = "Routing logic not available for folders"; export const NO_ROUTING_PARAGRAPH = "The route will be based on the answer to the previous question."; -const Routing = ({ match }) => { - const { data } = useQuery(GET_FOLDER_QUERY, { - variables: { - input: { - folderId: match.params.folderId, - }, - }, - }); +const Routing = ({ folder }) => { + const page = folder; + + const addPageWithFolder = useCreatePageWithFolder(); + const onAddQuestionPage = useCreateQuestionPage(); + const addFolder = useCreateFolder(); + const addCalculatedSummaryPage = useCreateCalculatedSummaryPage(); + const addListCollectorFolder = useCreateListCollectorFolder(); - const page = data?.folder; + // const folderId = folder.id; + + useSetNavigationCallbacks( + { + onAddQuestionPage: (createInsideFolder) => + createInsideFolder + ? onAddQuestionPage({ folderId: folder.id, position: 0 }) + : addPageWithFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + onAddCalculatedSummaryPage: (createInsideFolder) => + createInsideFolder + ? addCalculatedSummaryPage({ + folderId: folder.id, + position: folder.pages.length + 1, + }) + : addPageWithFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + isCalcSum: true, + }), + onAddFolder: () => + addFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + onAddListCollectorFolder: () => + addListCollectorFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + }, + [folder] + ); return ( @@ -38,11 +82,7 @@ const Routing = ({ match }) => { }; Routing.propTypes = { - match: PropTypes.shape({ - params: PropTypes.shape({ - folderId: PropTypes.string.isRequired, - }), - }), + folder: CustomPropTypes.folder, }; export default Routing; diff --git a/eq-author/src/App/folder/index.js b/eq-author/src/App/folder/index.js index 17e3b54a54..01078a373d 100644 --- a/eq-author/src/App/folder/index.js +++ b/eq-author/src/App/folder/index.js @@ -41,6 +41,7 @@ export default [ if (data) { const { folder } = data; + props = { folder, ...props }; return folder.listId ? ( ) : ( @@ -72,6 +73,7 @@ export default [ if (data) { const { folder } = data; + props = { folder, ...props }; return folder.listId ? ( ) : ( diff --git a/eq-author/src/App/page/Preview/CalculatedSummaryPreview.js b/eq-author/src/App/page/Preview/CalculatedSummaryPreview.js index 05b28fd322..83d22d0977 100644 --- a/eq-author/src/App/page/Preview/CalculatedSummaryPreview.js +++ b/eq-author/src/App/page/Preview/CalculatedSummaryPreview.js @@ -14,6 +14,7 @@ import CommentsPanel from "App/Comments"; import { colors } from "constants/theme"; import CalculatedSummaryPageEditor from "../Design/CalculatedSummaryPageEditor"; +import { useSetNavigationCallbacksForPage } from "components/NavigationCallbacks"; const Container = styled.div` padding: 2em; @@ -82,6 +83,12 @@ const SummaryTotalLabel = styled.div` `; const CalculatedSummaryPagePreview = ({ page }) => { + useSetNavigationCallbacksForPage({ + page: page, + folder: page?.folder, + section: page?.section, + }); + return ( { comments, } = page; + useSetNavigationCallbacksForPage({ + page: page, + folder: page?.folder, + section: page?.section, + }); + return ( [ errorCount: validationErrorInfo?.errors?.filter( ({ type }) => type && type.includes("display") ).length, - enabled: true + enabled: true, }, ]; const hasIntroductionContent = (section) => section.introductionTitle || section.introductionContent; -const LogicPage = ({ children, section }) => ( - - - - - - {children} - - - - -); +const LogicPage = ({ children, section }) => { + const addFolderWithPage = useCreatePageWithFolder(); + const addFolder = useCreateFolder(); + const addListCollectorFolder = useCreateListCollectorFolder(); + + useSetNavigationCallbacks( + { + onAddQuestionPage: () => + addFolderWithPage({ sectionId: section.id, position: 0 }), + onAddCalculatedSummaryPage: () => + addFolderWithPage({ + sectionId: section.id, + position: section.folders.length + 1, + isCalcSum: true, + }), + onAddFolder: () => addFolder({ sectionId: section.id, position: 0 }), + onAddListCollectorFolder: () => + addListCollectorFolder({ + sectionId: section.id, + position: 0, + }), + }, + [section] + ); + + return ( + + + + + + {children} + + + + + ); +}; LogicPage.propTypes = { children: PropTypes.node.isRequired, diff --git a/eq-author/src/App/shared/Logic/SkipLogic/index.js b/eq-author/src/App/shared/Logic/SkipLogic/index.js index 82aaaeefd0..628363032d 100644 --- a/eq-author/src/App/shared/Logic/SkipLogic/index.js +++ b/eq-author/src/App/shared/Logic/SkipLogic/index.js @@ -10,7 +10,19 @@ import Logic from "App/shared/Logic"; import SKIPLOGIC_QUERY from "./fragment.graphql"; -export const SkipLogicRoute = ({ match: { params } }) => { +import CustomPropTypes from "custom-prop-types"; +import { + useCreatePageWithFolder, + useCreateFolder, + useCreateListCollectorFolder, +} from "hooks/useCreateFolder"; +import { + useCreateQuestionPage, + useCreateCalculatedSummaryPage, +} from "hooks/useCreateQuestionPage"; +import { useSetNavigationCallbacks } from "components/NavigationCallbacks"; + +export const SkipLogicRoute = ({ match: { params }, folder }) => { const { loading, data } = useQuery(SKIPLOGIC_QUERY, { variables: { input: { @@ -22,6 +34,46 @@ export const SkipLogicRoute = ({ match: { params } }) => { const page = data?.skippable; + const addPageWithFolder = useCreatePageWithFolder(); + const onAddQuestionPage = useCreateQuestionPage(); + const addFolder = useCreateFolder(); + const addCalculatedSummaryPage = useCreateCalculatedSummaryPage(); + const addListCollectorFolder = useCreateListCollectorFolder(); + + useSetNavigationCallbacks( + { + onAddQuestionPage: (createInsideFolder) => + createInsideFolder + ? onAddQuestionPage({ folderId: folder.id, position: 0 }) + : addPageWithFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + onAddCalculatedSummaryPage: (createInsideFolder) => + createInsideFolder + ? addCalculatedSummaryPage({ + folderId: folder.id, + position: folder.pages.length + 1, + }) + : addPageWithFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + isCalcSum: true, + }), + onAddFolder: () => + addFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + onAddListCollectorFolder: () => + addListCollectorFolder({ + sectionId: folder.section.id, + position: folder.position + 1, + }), + }, + [folder] + ); + return ( {page ? ( @@ -42,6 +94,8 @@ SkipLogicRoute.propTypes = { confirmationId: PropTypes.string, }).isRequired, }).isRequired, + + folder: CustomPropTypes.folder, }; export default SkipLogicRoute; diff --git a/eq-author/src/App/shared/Logic/index.js b/eq-author/src/App/shared/Logic/index.js index 137ec171a4..553d76422f 100644 --- a/eq-author/src/App/shared/Logic/index.js +++ b/eq-author/src/App/shared/Logic/index.js @@ -11,6 +11,7 @@ import EditorLayout from "components/EditorLayout"; import CustomPropTypes from "custom-prop-types"; import Badge from "components/Badge"; +import { useSetNavigationCallbacksForPage } from "components/NavigationCallbacks"; const activeClassName = "active"; @@ -79,48 +80,56 @@ const TABS = [ }, ]; -const LogicPage = ({ children, page }) => ( - - - - - Select your logic - - {TABS.map(({ key, label }) => { - const errors = page?.validationErrorInfo?.errors?.filter( - ({ type }) => type && type.includes(key) - ); - return ( -
  • - - {label} - {errors?.length > 0 && ( - - {errors.length} - - )} - -
  • - ); - })} -
    -
    - - {children} - -
    -
    -
    -); +const LogicPage = ({ children, page }) => { + useSetNavigationCallbacksForPage({ + page: page, + folder: page?.folder, + section: page?.section, + }); + + return ( + + + + + Select your logic + + {TABS.map(({ key, label }) => { + const errors = page?.validationErrorInfo?.errors?.filter( + ({ type }) => type && type.includes(key) + ); + return ( +
  • + + {label} + {errors?.length > 0 && ( + + {errors.length} + + )} + +
  • + ); + })} +
    +
    + + {children} + +
    +
    +
    + ); +}; LogicPage.propTypes = { children: PropTypes.node.isRequired, From 4d7df4b0385dd4aafa460975c8327011ced0c8ca Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 3 Nov 2023 09:31:24 +0000 Subject: [PATCH 2/7] Fixed tests --- eq-author/src/App/folder/Routing.test.js | 12 ++ .../Preview/CalculatedSummaryPreview.test.js | 23 +++- .../page/Preview/QuestionPagePreview.test.js | 123 ++++++++++++++++-- .../QuestionPagePreview.test.js.snap | 62 +-------- eq-author/src/App/section/Logic/index.test.js | 6 + eq-author/src/App/shared/Logic/index.test.js | 12 ++ 6 files changed, 169 insertions(+), 69 deletions(-) diff --git a/eq-author/src/App/folder/Routing.test.js b/eq-author/src/App/folder/Routing.test.js index 52a45c5b57..baa24e6a53 100644 --- a/eq-author/src/App/folder/Routing.test.js +++ b/eq-author/src/App/folder/Routing.test.js @@ -16,6 +16,18 @@ jest.mock("components/EditorLayout/Tabs", () => ({ default: () => null, })); +jest.mock("hooks/useCreateFolder", () => ({ + useCreateFolder: jest.fn(), + useCreatePageWithFolder: jest.fn(), + useCreateListCollectorFolder: jest.fn(), +})); + +jest.mock("hooks/useCreateQuestionPage", () => ({ + useCreateQuestionPage: jest.fn(), + useCreateCalculatedSummaryPage: jest.fn(), + useCreateListCollectorPage: jest.fn(), +})); + describe("Folder: routing page", () => { const user = { id: "1", diff --git a/eq-author/src/App/page/Preview/CalculatedSummaryPreview.test.js b/eq-author/src/App/page/Preview/CalculatedSummaryPreview.test.js index 25a26dae1a..77cd6bfc80 100644 --- a/eq-author/src/App/page/Preview/CalculatedSummaryPreview.test.js +++ b/eq-author/src/App/page/Preview/CalculatedSummaryPreview.test.js @@ -28,6 +28,7 @@ describe("CalculatedSummaryPreview", () => { position: 1, title: "

    Hello world

    ", totalTitle: "

    Total be:

    ", + pageDescription: "Hello", alias: "Who am I?", type: "Number", answers: [], @@ -105,13 +106,31 @@ describe("CalculatedSummaryPreview", () => { it("should render empty box when no total-title given", () => { page.totalTitle = ""; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2/preview`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.find(byTestAttr("no-total-title"))).toBeTruthy(); }); it("should render 'no answers selected' message", () => { page.summaryAnswers = []; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2/preview`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.find(byTestAttr("no-answers-selected"))).toBeTruthy(); }); }); diff --git a/eq-author/src/App/page/Preview/QuestionPagePreview.test.js b/eq-author/src/App/page/Preview/QuestionPagePreview.test.js index 924b989347..831ed0529a 100644 --- a/eq-author/src/App/page/Preview/QuestionPagePreview.test.js +++ b/eq-author/src/App/page/Preview/QuestionPagePreview.test.js @@ -34,6 +34,7 @@ describe("QuestionPagePreview", () => { title: "

    Hello world

    ", alias: "Who am I?", pageType: "QuestionPage", + pageDescription: "whoami", description: "

    Description

    ", descriptionEnabled: true, guidance: "

    Guidance

    ", @@ -50,6 +51,7 @@ describe("QuestionPagePreview", () => { section: { id: "1", position: 0, + allowRepeatingSection: true, repeatingSection: true, repeatingSectionListId: null, questionnaire: { @@ -111,19 +113,46 @@ describe("QuestionPagePreview", () => { it("should render warning when there are no answers", () => { page.answers = []; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.find(byTestAttr("no-answers"))).toBeTruthy(); }); it("should not render description when disabled", () => { page.descriptionEnabled = false; - const wrapper2 = shallow(); + const wrapper2 = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper2.exists(byTestAttr("description"))).toBeFalsy(); }); it("should render description missing message", () => { page.description = ""; - const wrapper2 = shallow(); + const wrapper2 = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect( wrapper2.find(byTestAttr("description")).find(Error) ).toMatchSnapshot(); @@ -131,25 +160,61 @@ describe("QuestionPagePreview", () => { it("should not render guidance when disabled", () => { page.guidanceEnabled = false; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.exists(byTestAttr("guidance"))).toBeFalsy(); }); it("should render guidance missing message", () => { page.guidance = ""; - const wrapper2 = shallow(); + const wrapper2 = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper2.find(byTestAttr("guidance")).find(Error)).toMatchSnapshot(); }); it("should not render definition when disabled", () => { page.definitionEnabled = false; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.exists(byTestAttr("definition"))).toBeFalsy(); }); it("should render definition label missing message", () => { page.definitionLabel = ""; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect( wrapper.find(byTestAttr("definition")).find(DetailsTitle) ).toMatchSnapshot(); @@ -157,7 +222,16 @@ describe("QuestionPagePreview", () => { it("should render definition content missing message", () => { page.definitionContent = ""; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect( wrapper.find(byTestAttr("definition")).find(DetailsContent) ).toMatchSnapshot(); @@ -165,13 +239,31 @@ describe("QuestionPagePreview", () => { it("should not render additional information when disabled", () => { page.additionalInfoEnabled = false; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect(wrapper.exists(byTestAttr("additional-info"))).toBeFalsy(); }); it("should render additional info label missing message", () => { page.additionalInfoLabel = ""; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect( wrapper.find(byTestAttr("additional-info")).find(DetailsTitle) ).toMatchSnapshot(); @@ -179,7 +271,16 @@ describe("QuestionPagePreview", () => { it("should render additional info content missing message", () => { page.additionalInfoContent = ""; - const wrapper = shallow(); + const wrapper = shallow( + + + , + { + route: `/q/${questionnaireId}/page/2`, + urlParamMatcher: "/q/:questionnaireId/page/:pageId", + mocks, + } + ); expect( wrapper.find(byTestAttr("additional-info")).find(DetailsContent) ).toMatchSnapshot(); diff --git a/eq-author/src/App/page/Preview/__snapshots__/QuestionPagePreview.test.js.snap b/eq-author/src/App/page/Preview/__snapshots__/QuestionPagePreview.test.js.snap index b80ede24a8..eb39f39c64 100644 --- a/eq-author/src/App/page/Preview/__snapshots__/QuestionPagePreview.test.js.snap +++ b/eq-author/src/App/page/Preview/__snapshots__/QuestionPagePreview.test.js.snap @@ -1,63 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`QuestionPagePreview should render additional info content missing message 1`] = ` - - - Missing additional information content - - -`; +exports[`QuestionPagePreview should render additional info content missing message 1`] = `null`; -exports[`QuestionPagePreview should render additional info label missing message 1`] = ` - - - Missing additional information label - - -`; +exports[`QuestionPagePreview should render additional info label missing message 1`] = `null`; -exports[`QuestionPagePreview should render definition content missing message 1`] = ` - - - Missing definition content - - -`; +exports[`QuestionPagePreview should render definition content missing message 1`] = `null`; -exports[`QuestionPagePreview should render definition label missing message 1`] = ` - - - Missing definition label - - -`; +exports[`QuestionPagePreview should render definition label missing message 1`] = `null`; -exports[`QuestionPagePreview should render description missing message 1`] = ` - - Missing description - -`; +exports[`QuestionPagePreview should render description missing message 1`] = `null`; -exports[`QuestionPagePreview should render guidance missing message 1`] = ` - - Missing guidance - -`; +exports[`QuestionPagePreview should render guidance missing message 1`] = `null`; diff --git a/eq-author/src/App/section/Logic/index.test.js b/eq-author/src/App/section/Logic/index.test.js index 34561260be..07d2ac62cd 100644 --- a/eq-author/src/App/section/Logic/index.test.js +++ b/eq-author/src/App/section/Logic/index.test.js @@ -5,6 +5,12 @@ import { render } from "tests/utils/rtl"; import Logic from "."; import { MeContext } from "App/MeContext"; +jest.mock("hooks/useCreateFolder", () => ({ + useCreateFolder: jest.fn(), + useCreatePageWithFolder: jest.fn(), + useCreateListCollectorFolder: jest.fn(), +})); + jest.mock("@apollo/react-hooks", () => ({ useSubscription: () => [jest.fn()], })); diff --git a/eq-author/src/App/shared/Logic/index.test.js b/eq-author/src/App/shared/Logic/index.test.js index 3356e2cf01..7c8dbe8ee9 100644 --- a/eq-author/src/App/shared/Logic/index.test.js +++ b/eq-author/src/App/shared/Logic/index.test.js @@ -3,6 +3,18 @@ import { shallow } from "enzyme"; import UnwrappedLogicPage from "./"; +jest.mock("hooks/useCreateFolder", () => ({ + useCreateFolder: jest.fn(), + useCreatePageWithFolder: jest.fn(), + useCreateListCollectorFolder: jest.fn(), +})); + +jest.mock("hooks/useCreateQuestionPage", () => ({ + useCreateQuestionPage: jest.fn(), + useCreateCalculatedSummaryPage: jest.fn(), + useCreateListCollectorPage: jest.fn(), +})); + describe("Logic Page", () => { let props; From c233215f579277abb4d785ed1603307ce8577a69 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Mon, 6 Nov 2023 11:53:06 +0000 Subject: [PATCH 3/7] Removed commented out code --- eq-author/src/App/folder/Routing.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/eq-author/src/App/folder/Routing.js b/eq-author/src/App/folder/Routing.js index c32cdbea6a..eb9c7da1a8 100644 --- a/eq-author/src/App/folder/Routing.js +++ b/eq-author/src/App/folder/Routing.js @@ -7,7 +7,6 @@ import NoRouting, { import Panel from "components/Panel"; import CustomPropTypes from "custom-prop-types"; -// import { useSetNavigationCallbacksForPage } from "components/NavigationCallbacks"; import { useCreatePageWithFolder, @@ -33,8 +32,6 @@ const Routing = ({ folder }) => { const addCalculatedSummaryPage = useCreateCalculatedSummaryPage(); const addListCollectorFolder = useCreateListCollectorFolder(); - // const folderId = folder.id; - useSetNavigationCallbacks( { onAddQuestionPage: (createInsideFolder) => From 94a428136dc2d71a7596fff71a348d161be9bb89 Mon Sep 17 00:00:00 2001 From: Joshua Chapman <30293265+jchapman68@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:40:47 +0000 Subject: [PATCH 4/7] Update eq-author/src/App/folder/index.js Co-authored-by: farres1 <71004932+farres1@users.noreply.github.com> --- eq-author/src/App/folder/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author/src/App/folder/index.js b/eq-author/src/App/folder/index.js index 01078a373d..29e463c99a 100644 --- a/eq-author/src/App/folder/index.js +++ b/eq-author/src/App/folder/index.js @@ -73,7 +73,7 @@ export default [ if (data) { const { folder } = data; - props = { folder, ...props }; + props.folder = folder return folder.listId ? ( ) : ( From a01c831564d7a3d06f1a2c0abe8e09aec15d3dfe Mon Sep 17 00:00:00 2001 From: farres1 Date: Wed, 8 Nov 2023 10:37:30 +0000 Subject: [PATCH 5/7] Refactor folder routing to use match --- eq-author/src/App/folder/Routing.js | 24 ++++++++++--- .../src/App/folder/graphql/fragment.graphql | 4 +++ eq-author/src/App/folder/index.js | 2 -- .../App/page/Preview/QuestionPagePreview.js | 2 +- .../src/App/shared/Logic/SkipLogic/index.js | 34 +++++++++---------- eq-author/src/App/shared/Logic/index.js | 2 +- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/eq-author/src/App/folder/Routing.js b/eq-author/src/App/folder/Routing.js index eb9c7da1a8..52ac008185 100644 --- a/eq-author/src/App/folder/Routing.js +++ b/eq-author/src/App/folder/Routing.js @@ -4,9 +4,11 @@ import NoRouting, { Title, Paragraph, } from "App/shared/Logic/Routing/NoRouting"; +import GET_FOLDER_QUERY from "App/folder/graphql/fragment.graphql"; +import PropTypes from "prop-types"; import Panel from "components/Panel"; -import CustomPropTypes from "custom-prop-types"; +import { useQuery } from "@apollo/react-hooks"; import { useCreatePageWithFolder, @@ -23,8 +25,16 @@ export const NO_ROUTING_TITLE = "Routing logic not available for folders"; export const NO_ROUTING_PARAGRAPH = "The route will be based on the answer to the previous question."; -const Routing = ({ folder }) => { - const page = folder; +const Routing = ({ match }) => { + const { data } = useQuery(GET_FOLDER_QUERY, { + variables: { + input: { + folderId: match.params.folderId, + }, + }, + }); + + const folder = data?.folder; const addPageWithFolder = useCreatePageWithFolder(); const onAddQuestionPage = useCreateQuestionPage(); @@ -67,7 +77,7 @@ const Routing = ({ folder }) => { ); return ( - + {NO_ROUTING_TITLE} @@ -79,7 +89,11 @@ const Routing = ({ folder }) => { }; Routing.propTypes = { - folder: CustomPropTypes.folder, + match: PropTypes.shape({ + params: PropTypes.shape({ + folderId: PropTypes.string.isRequired, + }), + }), }; export default Routing; diff --git a/eq-author/src/App/folder/graphql/fragment.graphql b/eq-author/src/App/folder/graphql/fragment.graphql index 9c1ff4b11e..aa8ee752de 100644 --- a/eq-author/src/App/folder/graphql/fragment.graphql +++ b/eq-author/src/App/folder/graphql/fragment.graphql @@ -5,6 +5,10 @@ query GetFolderPageInfo($input: QueryInput!) { id displayName title + position + section { + id + } validationErrorInfo { ...ValidationErrorInfo } diff --git a/eq-author/src/App/folder/index.js b/eq-author/src/App/folder/index.js index 01078a373d..17e3b54a54 100644 --- a/eq-author/src/App/folder/index.js +++ b/eq-author/src/App/folder/index.js @@ -41,7 +41,6 @@ export default [ if (data) { const { folder } = data; - props = { folder, ...props }; return folder.listId ? ( ) : ( @@ -73,7 +72,6 @@ export default [ if (data) { const { folder } = data; - props = { folder, ...props }; return folder.listId ? ( ) : ( diff --git a/eq-author/src/App/page/Preview/QuestionPagePreview.js b/eq-author/src/App/page/Preview/QuestionPagePreview.js index 34b8ad5c0d..0c777197c2 100644 --- a/eq-author/src/App/page/Preview/QuestionPagePreview.js +++ b/eq-author/src/App/page/Preview/QuestionPagePreview.js @@ -108,7 +108,7 @@ const QuestionPagePreview = ({ page }) => { } = page; useSetNavigationCallbacksForPage({ - page: page, + page, folder: page?.folder, section: page?.section, }); diff --git a/eq-author/src/App/shared/Logic/SkipLogic/index.js b/eq-author/src/App/shared/Logic/SkipLogic/index.js index 628363032d..50b8bfccee 100644 --- a/eq-author/src/App/shared/Logic/SkipLogic/index.js +++ b/eq-author/src/App/shared/Logic/SkipLogic/index.js @@ -22,7 +22,7 @@ import { } from "hooks/useCreateQuestionPage"; import { useSetNavigationCallbacks } from "components/NavigationCallbacks"; -export const SkipLogicRoute = ({ match: { params }, folder }) => { +export const SkipLogicRoute = ({ match: { params } }) => { const { loading, data } = useQuery(SKIPLOGIC_QUERY, { variables: { input: { @@ -32,7 +32,7 @@ export const SkipLogicRoute = ({ match: { params }, folder }) => { fetchPolicy: "cache-and-network", }); - const page = data?.skippable; + const entity = data?.skippable; const addPageWithFolder = useCreatePageWithFolder(); const onAddQuestionPage = useCreateQuestionPage(); @@ -44,40 +44,40 @@ export const SkipLogicRoute = ({ match: { params }, folder }) => { { onAddQuestionPage: (createInsideFolder) => createInsideFolder - ? onAddQuestionPage({ folderId: folder.id, position: 0 }) + ? onAddQuestionPage({ folderId: entity.id, position: 0 }) : addPageWithFolder({ - sectionId: folder.section.id, - position: folder.position + 1, + sectionId: entity.section.id, + position: entity.position + 1, }), onAddCalculatedSummaryPage: (createInsideFolder) => createInsideFolder ? addCalculatedSummaryPage({ - folderId: folder.id, - position: folder.pages.length + 1, + folderId: entity.id, + position: entity.pages.length + 1, }) : addPageWithFolder({ - sectionId: folder.section.id, - position: folder.position + 1, + sectionId: entity.section.id, + position: entity.position + 1, isCalcSum: true, }), onAddFolder: () => addFolder({ - sectionId: folder.section.id, - position: folder.position + 1, + sectionId: entity.section.id, + position: entity.position + 1, }), onAddListCollectorFolder: () => addListCollectorFolder({ - sectionId: folder.section.id, - position: folder.position + 1, + sectionId: entity.section.id, + position: entity.position + 1, }), }, - [folder] + [entity] ); return ( - - {page ? ( - + + {entity ? ( + ) : loading ? ( Loading skip logic ) : ( diff --git a/eq-author/src/App/shared/Logic/index.js b/eq-author/src/App/shared/Logic/index.js index 553d76422f..7ac2a092ff 100644 --- a/eq-author/src/App/shared/Logic/index.js +++ b/eq-author/src/App/shared/Logic/index.js @@ -82,7 +82,7 @@ const TABS = [ const LogicPage = ({ children, page }) => { useSetNavigationCallbacksForPage({ - page: page, + page, folder: page?.folder, section: page?.section, }); From 84d74315cfd9e3d628b5e02e46916a4c04da05d6 Mon Sep 17 00:00:00 2001 From: farres1 Date: Wed, 8 Nov 2023 10:42:54 +0000 Subject: [PATCH 6/7] Remove unused code --- eq-author/src/App/folder/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eq-author/src/App/folder/index.js b/eq-author/src/App/folder/index.js index a05da2bc68..17e3b54a54 100644 --- a/eq-author/src/App/folder/index.js +++ b/eq-author/src/App/folder/index.js @@ -72,7 +72,6 @@ export default [ if (data) { const { folder } = data; - props.folder = folder; return folder.listId ? ( ) : ( From 733ea87b8f723d8c6ea22b4cc3adcbb5832c41b1 Mon Sep 17 00:00:00 2001 From: farres1 Date: Wed, 8 Nov 2023 12:43:42 +0000 Subject: [PATCH 7/7] Remove unused code --- eq-author/src/App/shared/Logic/SkipLogic/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/eq-author/src/App/shared/Logic/SkipLogic/index.js b/eq-author/src/App/shared/Logic/SkipLogic/index.js index 50b8bfccee..b508ef5f8a 100644 --- a/eq-author/src/App/shared/Logic/SkipLogic/index.js +++ b/eq-author/src/App/shared/Logic/SkipLogic/index.js @@ -10,7 +10,6 @@ import Logic from "App/shared/Logic"; import SKIPLOGIC_QUERY from "./fragment.graphql"; -import CustomPropTypes from "custom-prop-types"; import { useCreatePageWithFolder, useCreateFolder, @@ -94,8 +93,6 @@ SkipLogicRoute.propTypes = { confirmationId: PropTypes.string, }).isRequired, }).isRequired, - - folder: CustomPropTypes.folder, }; export default SkipLogicRoute;