Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Heneghan committed Nov 6, 2023
1 parent a52b3bf commit 0479b44
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import Tooltip from "@mui/material/Tooltip";
import Typography from "@mui/material/Typography";
import formatDistanceToNow from "date-fns/formatDistanceToNow";
import React, { useState } from "react";
import { ExternalLink, Globe, RefreshCw, Terminal } from "react-feather";
import {
BarChart,
ExternalLink,
Globe,
RefreshCw,
Terminal,
} from "react-feather";
import { useAsync } from "react-use";
import Input from "ui/Input";

Expand Down Expand Up @@ -93,13 +99,15 @@ const PreviewBrowser: React.FC<{
const [showDebugConsole, setDebugConsoleVisibility] = useState(false);
const [
flowId,
flowMetabaseLink,
resetPreview,
publishFlow,
lastPublished,
lastPublisher,
validateAndDiffFlow,
] = useStore((state) => [
state.id,
state.flowMetabaseLink,
state.resetPreview,
state.publishFlow,
state.lastPublished,
Expand Down Expand Up @@ -163,6 +171,19 @@ const PreviewBrowser: React.FC<{
</Link>
</Tooltip>

{!!flowMetabaseLink && (
<Tooltip arrow title="Open analytics page">
<Link
href={flowMetabaseLink}
target="_blank"
rel="noopener noreferrer"
color="inherit"
>
<BarChart />
</Link>
</Tooltip>
)}

<Tooltip arrow title="Open published service">
<Link
href={props.url + "?analytics=false"}
Expand Down
3 changes: 3 additions & 0 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SharedStore extends Store.Store {
flow: Store.flow;
flowSlug: string;
flowName: string;
flowMetabaseLink: string;
id: string;
getNode: (id: Store.nodeId) => Store.node | undefined;
resetPreview: () => void;
Expand Down Expand Up @@ -51,6 +52,8 @@ export const sharedStore: StateCreator<

flowName: "",

flowMetabaseLink: "",

id: "",
previewEnvironment: "standalone",

Expand Down
17 changes: 13 additions & 4 deletions editor.planx.uk/src/routes/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ const nodeRoutes = mount({
"/:parent/nodes/:id/edit": editNode,
});

const getFlowSettings = async (
const getFlowMetadata = async (
flow: string,
team: string,
): Promise<FlowSettings> => {
): Promise<{ settings: FlowSettings; flowMetabaseLink: string }> => {
const { data } = await client.query({
query: gql`
query GetFlow($slug: String!, $team_slug: String!) {
Expand All @@ -186,6 +186,7 @@ const getFlowSettings = async (
) {
id
settings
flowMetabaseLink: metabase_link
}
}
`,
Expand All @@ -194,7 +195,11 @@ const getFlowSettings = async (
team_slug: team,
},
});
return data.flows[0]?.settings;
const metadata = {
settings: data.flows[0]?.settings,
flowMetabaseLink: data.flows[0]?.flowMetabaseLink,
};
return metadata;
};

const routes = compose(
Expand All @@ -204,8 +209,12 @@ const routes = compose(

withView(async (req) => {
const [flow, ...breadcrumbs] = req.params.flow.split(",");
const settings: FlowSettings = await getFlowSettings(flow, req.params.team);
const { settings, flowMetabaseLink } = await getFlowMetadata(
flow,
req.params.team,
);
useStore.getState().setFlowSettings(settings);
useStore.setState({ flowMetabaseLink });

return (
<>
Expand Down

0 comments on commit 0479b44

Please sign in to comment.