Skip to content

Commit

Permalink
chore: Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 3, 2023
1 parent 95d165e commit 373a941
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 61 deletions.
6 changes: 3 additions & 3 deletions editor.planx.uk/src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
6 changes: 4 additions & 2 deletions editor.planx.uk/src/lib/dataMergedHotfix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> = {}) => {
// get the primary flow data
const { slug, data }: { slug: string; data: Record<string, any> } = await getFlowData(id);
const { slug, data }: { slug: string; data: Record<string, any> } =
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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ describe("A flow with repeated external portals can be navigated as expected", (
record("withinExternalPortal", { answers: [] });
expect(upcomingCardIds()[0]).toEqual("finalNode");
});
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{
"_root": {
"edges": [
"firstNode",
"finalNode"
]
"edges": ["firstNode", "finalNode"]
},
"externalPortal1": {
"type": 300,
"edges": [
"externalFlowId"
]
"edges": ["externalFlowId"]
},
"option3": {
"data": {
Expand All @@ -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": {
Expand All @@ -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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"_root": {
"edges": [
"firstNode",
"finalNode"
]
"edges": ["firstNode", "finalNode"]
},
"option2": {
"data": {
Expand All @@ -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": {
Expand All @@ -58,8 +48,6 @@
"text": "test-external-portal"
},
"type": 300,
"edges": [
"withinExternalPortal"
]
"edges": ["withinExternalPortal"]
}
}
}
4 changes: 2 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +88,7 @@ export const teamStore: StateCreator<TeamStore, [], [], TeamStore> = (
get().setTeam(team);
},

clearTeamStore: () =>
clearTeamStore: () =>
set({
teamId: 0,
teamTheme: undefined,
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const userStore: StateCreator<UserStore, [], [], UserStore> = (
},

async initUserStore(jwt: string) {
const { getUser, setUser } = get();
const { getUser, setUser } = get();

if (getUser()) return;

const id = (jwtDecode(jwt) as any)["sub"];
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/routes/authenticated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const editorRoutes = compose(
});

useStore.getState().clearTeamStore();

return {
title: makeTitle("Teams"),
view: <Teams teams={data.teams} />,
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/routes/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const routes = compose(
mount({
"/": route(() => ({
title: makeTitle(useStore.getState().teamName),
view: <Team/>,
view: <Team />,
})),

"/:flow": lazy(async (req) => {
Expand Down
13 changes: 7 additions & 6 deletions editor.planx.uk/src/routes/views/team.tsx
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -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 {
Expand All @@ -19,6 +20,6 @@ export const teamView = async (req: NaviRequest) => {
throw new NotFoundError(`Team not found: ${error}`);
}
}
return <View/>
}

return <View />;
};

0 comments on commit 373a941

Please sign in to comment.