From 373a941a30e55cc8d505221670e092d44a681246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 3 Oct 2023 17:29:25 +0100 Subject: [PATCH] chore: Linting --- .../src/components/Header.test.tsx | 6 ++-- editor.planx.uk/src/lib/dataMergedHotfix.ts | 6 ++-- .../lib/__tests__/externalPortals.test.ts | 2 +- .../mocks/multipleExternalPortals.json | 33 +++++-------------- .../__tests__/mocks/singleExternalPortal.json | 24 ++++---------- .../src/pages/FlowEditor/lib/store/team.ts | 4 +-- .../src/pages/FlowEditor/lib/store/user.ts | 4 +-- editor.planx.uk/src/routes/authenticated.tsx | 2 +- editor.planx.uk/src/routes/team.tsx | 2 +- editor.planx.uk/src/routes/views/team.tsx | 13 ++++---- 10 files changed, 35 insertions(+), 61 deletions(-) diff --git a/editor.planx.uk/src/components/Header.test.tsx b/editor.planx.uk/src/components/Header.test.tsx index 483361cb05..ac64dcebc0 100644 --- a/editor.planx.uk/src/components/Header.test.tsx +++ b/editor.planx.uk/src/components/Header.test.tsx @@ -27,9 +27,9 @@ const mockTeam2: Team = { slug: "closedsystemslab", }; -jest.spyOn(ReactNavi, "useNavigation").mockReturnValue(({ - navigate: jest.fn() -}) as any); +jest.spyOn(ReactNavi, "useNavigation").mockReturnValue({ + navigate: jest.fn(), +} as any); describe("Header Component - Editor Route", () => { beforeAll(() => { diff --git a/editor.planx.uk/src/lib/dataMergedHotfix.ts b/editor.planx.uk/src/lib/dataMergedHotfix.ts index 2e1d40c309..48228f173c 100644 --- a/editor.planx.uk/src/lib/dataMergedHotfix.ts +++ b/editor.planx.uk/src/lib/dataMergedHotfix.ts @@ -25,11 +25,13 @@ const getFlowData = async (id: string) => { // in order to load frontend /preview routes for flows that are not published export const dataMerged = async (id: string, ob: Record = {}) => { // get the primary flow data - const { slug, data }: { slug: string; data: Record } = await getFlowData(id); + const { slug, data }: { slug: string; data: Record } = + await getFlowData(id); // recursively get and flatten internal portals & external portals for (const [nodeId, node] of Object.entries(data)) { - const isExternalPortalRoot = nodeId === "_root" && Object.keys(ob).length > 0; + const isExternalPortalRoot = + nodeId === "_root" && Object.keys(ob).length > 0; const isExternalPortal = node.type === TYPES.ExternalPortal; const isMerged = ob[node.data?.flowId]; diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/externalPortals.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/externalPortals.test.ts index 564469d48e..6646cafadd 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/externalPortals.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/externalPortals.test.ts @@ -60,4 +60,4 @@ describe("A flow with repeated external portals can be navigated as expected", ( record("withinExternalPortal", { answers: [] }); expect(upcomingCardIds()[0]).toEqual("finalNode"); }); -}); \ No newline at end of file +}); diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/multipleExternalPortals.json b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/multipleExternalPortals.json index b2693fa5e4..4ea6daea92 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/multipleExternalPortals.json +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/multipleExternalPortals.json @@ -1,15 +1,10 @@ { "_root": { - "edges": [ - "firstNode", - "finalNode" - ] + "edges": ["firstNode", "finalNode"] }, "externalPortal1": { "type": 300, - "edges": [ - "externalFlowId" - ] + "edges": ["externalFlowId"] }, "option3": { "data": { @@ -19,29 +14,21 @@ }, "externalPortal2": { "type": 300, - "edges": [ - "externalFlowId" - ] + "edges": ["externalFlowId"] }, "firstNode": { "data": { "text": "This is a question" }, "type": 100, - "edges": [ - "option1", - "option2", - "option3" - ] + "edges": ["option1", "option2", "option3"] }, "option2": { "data": { "text": "Option 2" }, "type": 200, - "edges": [ - "externalPortal2" - ] + "edges": ["externalPortal2"] }, "finalNode": { "data": { @@ -65,17 +52,13 @@ "text": "Option 1" }, "type": 200, - "edges": [ - "externalPortal1" - ] + "edges": ["externalPortal1"] }, "externalFlowId": { "data": { "text": "daf-external-portal-test" }, "type": 300, - "edges": [ - "withinExternalPortal" - ] + "edges": ["withinExternalPortal"] } -} \ No newline at end of file +} diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/singleExternalPortal.json b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/singleExternalPortal.json index dea585a6dc..7b408035a9 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/singleExternalPortal.json +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/singleExternalPortal.json @@ -1,9 +1,6 @@ { "_root": { - "edges": [ - "firstNode", - "finalNode" - ] + "edges": ["firstNode", "finalNode"] }, "option2": { "data": { @@ -21,28 +18,21 @@ }, "externalPortal": { "type": 300, - "edges": [ - "externalFlowId" - ] + "edges": ["externalFlowId"] }, "firstNode": { "data": { "text": "This is a question with many options" }, "type": 100, - "edges": [ - "option1", - "option2" - ] + "edges": ["option1", "option2"] }, "option1": { "data": { "text": "Option 1" }, "type": 200, - "edges": [ - "externalPortal" - ] + "edges": ["externalPortal"] }, "withinExternalPortal": { "data": { @@ -58,8 +48,6 @@ "text": "test-external-portal" }, "type": 300, - "edges": [ - "withinExternalPortal" - ] + "edges": ["withinExternalPortal"] } -} \ No newline at end of file +} diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index d120327e6d..8eeaed720d 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -7,7 +7,7 @@ import { Team } from "types"; import type { StateCreator } from "zustand"; export interface TeamStore { - teamId: number, + teamId: number; teamTheme?: TeamTheme; teamName: string; teamSettings?: TeamSettings; @@ -88,7 +88,7 @@ export const teamStore: StateCreator = ( get().setTeam(team); }, - clearTeamStore: () => + clearTeamStore: () => set({ teamId: 0, teamTheme: undefined, diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts index a102b1f6f5..0f8cec17fd 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts @@ -35,8 +35,8 @@ export const userStore: StateCreator = ( }, async initUserStore(jwt: string) { - const { getUser, setUser } = get(); - + const { getUser, setUser } = get(); + if (getUser()) return; const id = (jwtDecode(jwt) as any)["sub"]; diff --git a/editor.planx.uk/src/routes/authenticated.tsx b/editor.planx.uk/src/routes/authenticated.tsx index eb6a45ac85..d8a7966536 100644 --- a/editor.planx.uk/src/routes/authenticated.tsx +++ b/editor.planx.uk/src/routes/authenticated.tsx @@ -27,7 +27,7 @@ const editorRoutes = compose( }); useStore.getState().clearTeamStore(); - + return { title: makeTitle("Teams"), view: , diff --git a/editor.planx.uk/src/routes/team.tsx b/editor.planx.uk/src/routes/team.tsx index 3c70c7a521..12e3f355b2 100644 --- a/editor.planx.uk/src/routes/team.tsx +++ b/editor.planx.uk/src/routes/team.tsx @@ -19,7 +19,7 @@ const routes = compose( mount({ "/": route(() => ({ title: makeTitle(useStore.getState().teamName), - view: , + view: , })), "/:flow": lazy(async (req) => { diff --git a/editor.planx.uk/src/routes/views/team.tsx b/editor.planx.uk/src/routes/views/team.tsx index bbf1898d6e..3a2a02d296 100644 --- a/editor.planx.uk/src/routes/views/team.tsx +++ b/editor.planx.uk/src/routes/views/team.tsx @@ -1,7 +1,7 @@ -import { NaviRequest, NotFoundError } from "navi" +import { NaviRequest, NotFoundError } from "navi"; import { useStore } from "pages/FlowEditor/lib/store"; import React from "react"; -import { View } from "react-navi" +import { View } from "react-navi"; import { getTeamFromDomain } from "routes/utils"; /** @@ -10,7 +10,8 @@ import { getTeamFromDomain } from "routes/utils"; */ export const teamView = async (req: NaviRequest) => { const { initTeamStore, teamSlug: currentSlug } = useStore.getState(); - const routeSlug = req.params.team || await getTeamFromDomain(window.location.hostname) + const routeSlug = + req.params.team || (await getTeamFromDomain(window.location.hostname)); if (currentSlug !== routeSlug) { try { @@ -19,6 +20,6 @@ export const teamView = async (req: NaviRequest) => { throw new NotFoundError(`Team not found: ${error}`); } } - - return -} \ No newline at end of file + + return ; +};