-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34872a7
commit 6358329
Showing
3 changed files
with
163 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import EditorMenu from "pages/FlowEditor/components/EditorMenu"; | ||
import TestEnvironmentBanner from "components/TestEnvironmentBanner"; | ||
import Box from "@mui/material/Box"; | ||
import { styled } from "@mui/material/styles"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import ErrorFallback from "components/ErrorFallback"; | ||
|
||
const Root = styled(Box)(() => ({ | ||
display: "flex", | ||
alignItems: "stretch", | ||
overflow: "hidden", | ||
flexGrow: 1, | ||
})) | ||
|
||
const FlowEditorLayout: React.FC<PropsWithChildren> = ({ children }) => ( | ||
<Root> | ||
<EditorMenu /> | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
{children} | ||
</ErrorBoundary> | ||
</Root> | ||
); | ||
|
||
export default FlowEditorLayout; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { gql } from "@apollo/client"; | ||
import { NaviRequest, NotFoundError } from "navi"; | ||
import React from "react"; | ||
import { View } from "react-navi"; | ||
|
||
import { client } from "../../lib/graphql"; | ||
import { useStore } from "../../pages/FlowEditor/lib/store"; | ||
import type { FlowSettings } from "../../types"; | ||
|
||
import FlowEditorLayout from "../../pages/layout/FlowEditorLayout"; | ||
|
||
interface FlowMetadata { | ||
flowSettings: FlowSettings; | ||
flowAnalyticsLink: string; | ||
isFlowPublished: boolean; | ||
} | ||
|
||
interface GetFlowMetadata { | ||
flows: { | ||
flowSettings: FlowSettings; | ||
flowAnalyticsLink: string; | ||
publishedFlowsAggregate: { | ||
aggregate: { | ||
count: number; | ||
}; | ||
}; | ||
}[]; | ||
} | ||
|
||
const getFlowMetadata = async ( | ||
flowSlug: string, | ||
team: string, | ||
): Promise<FlowMetadata> => { | ||
const { | ||
data: { flows }, | ||
} = await client.query<GetFlowMetadata>({ | ||
query: gql` | ||
query GetFlow($slug: String!, $team_slug: String!) { | ||
flows( | ||
limit: 1 | ||
where: { slug: { _eq: $slug }, team: { slug: { _eq: $team_slug } } } | ||
) { | ||
id | ||
flowSettings: settings | ||
flowAnalyticsLink: analytics_link | ||
publishedFlowsAggregate: published_flows_aggregate { | ||
aggregate { | ||
count | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
slug: flowSlug, | ||
team_slug: team, | ||
}, | ||
}); | ||
|
||
const flow = flows[0]; | ||
if (!flows) throw new NotFoundError(`Flow ${flowSlug} not found for ${team}`); | ||
|
||
const metadata = { | ||
flowSettings: flow.flowSettings, | ||
flowAnalyticsLink: flow.flowAnalyticsLink, | ||
isFlowPublished: flow.publishedFlowsAggregate?.aggregate.count > 0, | ||
}; | ||
return metadata; | ||
}; | ||
|
||
|
||
/** | ||
* View wrapper for all flowEditor routes | ||
*/ | ||
export const flowEditorView = async (req: NaviRequest) => { | ||
const [ flow ] = req.params.flow.split(","); | ||
const { flowSettings, flowAnalyticsLink, isFlowPublished } = | ||
await getFlowMetadata(flow, req.params.team); | ||
useStore.setState({ flowSettings, flowAnalyticsLink, isFlowPublished }); | ||
|
||
return ( | ||
<FlowEditorLayout> | ||
<View /> | ||
</FlowEditorLayout> | ||
); | ||
}; |