Skip to content

Commit

Permalink
fix: Correctly populate flow settings and status (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jul 12, 2024
1 parent 1060db4 commit 80ae221
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const editorStore: StateCreator<
client.cache.reset();
const { data } = await client.query({
query: gql`
query GetFlow($teamId: Int!) {
query GetFlows($teamId: Int!) {
flows(where: { team: { id: { _eq: $teamId } } }) {
id
name
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/routes/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const routes = compose(
withView(SettingsContainer),

route(async (req) => ({
getData: getFlowSettings,
getData: await getFlowSettings(req),
title: makeTitle(
[req.params.team, req.params.flow, "service"].join("/"),
),
Expand All @@ -236,7 +236,7 @@ const routes = compose(
withView(SettingsContainer),

route(async (req) => ({
getData: getFlowSettings,
getData: await getFlowSettings(req),
title: makeTitle(
[req.params.team, req.params.flow, "service-flags"].join("/"),
),
Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/routes/flowSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ const flowSettingsRoutes = compose(
`User does not have access to ${req.originalUrl}`,
);

return route({
getData: getFlowSettings,
return route(async (req) => ({
getData: await getFlowSettings(req),
title: makeTitle(
[req.params.team, req.params.flow, "Flow Settings"].join("/"),
),
view: <Settings currentTab={req.params.tab} tabs={tabs} />,
});
}));
}),
}),
);
Expand Down
11 changes: 3 additions & 8 deletions editor.planx.uk/src/routes/views/flowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import { View } from "react-navi";

import { client } from "../../lib/graphql";
import { useStore } from "../../pages/FlowEditor/lib/store";
import type { FlowSettings } from "../../types";

interface FlowMetadata {
flowSettings: FlowSettings;
flowAnalyticsLink: string;
isFlowPublished: boolean;
}

interface GetFlowMetadata {
flows: {
flowSettings: FlowSettings;
flowAnalyticsLink: string;
publishedFlowsAggregate: {
aggregate: {
Expand All @@ -34,13 +31,12 @@ const getFlowMetadata = async (
data: { flows },
} = await client.query<GetFlowMetadata>({
query: gql`
query GetFlow($slug: String!, $team_slug: String!) {
query GetFlowMetadata($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 {
Expand All @@ -60,7 +56,6 @@ const getFlowMetadata = async (
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,
};
Expand All @@ -72,9 +67,9 @@ const getFlowMetadata = async (
*/
export const flowEditorView = async (req: NaviRequest) => {
const [flow] = req.params.flow.split(",");
const { flowSettings, flowAnalyticsLink, isFlowPublished } =
const { flowAnalyticsLink, isFlowPublished } =
await getFlowMetadata(flow, req.params.team);
useStore.setState({ flowSettings, flowAnalyticsLink, isFlowPublished });
useStore.setState({ flowAnalyticsLink, isFlowPublished });

return (
<FlowEditorLayout>
Expand Down

0 comments on commit 80ae221

Please sign in to comment.