Skip to content

Commit

Permalink
fix: Set flowId in /
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 23, 2024
1 parent b6c2b72 commit 039b444
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion editor.planx.uk/src/routes/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { client } from "../lib/graphql";
import { useStore } from "../pages/FlowEditor/lib/store";
import Team from "../pages/Team";
import { makeTitle } from "./utils";
import { getFlowEditorData } from "./views/flowEditor";
import { teamView } from "./views/team";

let cached: { flowSlug?: string; teamSlug?: string } = {
Expand All @@ -17,7 +18,9 @@ let cached: { flowSlug?: string; teamSlug?: string } = {

const setFlowAndLazyLoad = (importComponent: Parameters<typeof lazy>[0]) => {
return map(async (request) => {
useStore.getState().setFlowSlug(request.params.flow);
const data = await getFlowEditorData(request.params.flow, request.params.team);
useStore.setState({ ...data, flowSlug: request.params.flow });

return lazy(importComponent);
});
};
Expand Down
22 changes: 13 additions & 9 deletions editor.planx.uk/src/routes/views/flowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { View } from "react-navi";
import { client } from "../../lib/graphql";
import { useStore } from "../../pages/FlowEditor/lib/store";

interface FlowMetadata {
interface FlowEditorData {
id: string,
flowAnalyticsLink: string;
isFlowPublished: boolean;
}

interface GetFlowMetadata {
interface GetFlowEditorData {
flows: {
id: string,
flowAnalyticsLink: string;
publishedFlowsAggregate: {
aggregate: {
Expand All @@ -23,13 +25,13 @@ interface GetFlowMetadata {
}[];
}

const getFlowMetadata = async (
export const getFlowEditorData = async (
flowSlug: string,
team: string,
): Promise<FlowMetadata> => {
): Promise<FlowEditorData> => {
const {
data: { flows },
} = await client.query<GetFlowMetadata>({
} = await client.query<GetFlowEditorData>({
query: gql`
query GetFlowMetadata($slug: String!, $team_slug: String!) {
flows(
Expand All @@ -55,23 +57,25 @@ const getFlowMetadata = async (
const flow = flows[0];
if (!flows) throw new NotFoundError(`Flow ${flowSlug} not found for ${team}`);

const metadata = {
const flowEditorData: FlowEditorData = {
id: flow.id,
flowAnalyticsLink: flow.flowAnalyticsLink,
isFlowPublished: flow.publishedFlowsAggregate?.aggregate.count > 0,
};
return metadata;

return flowEditorData;
};

/**
* View wrapper for all flowEditor routes
*/
export const flowEditorView = async (req: NaviRequest) => {
const [flow] = req.params.flow.split(",");
const { flowAnalyticsLink, isFlowPublished } = await getFlowMetadata(
const { id, flowAnalyticsLink, isFlowPublished } = await getFlowEditorData(
flow,
req.params.team,
);
useStore.setState({ flowAnalyticsLink, isFlowPublished });
useStore.setState({ id, flowAnalyticsLink, isFlowPublished });

return (
<FlowEditorLayout>
Expand Down

0 comments on commit 039b444

Please sign in to comment.