Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly populate flow settings and status #3412

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flowSettings is not needed here - it's only actually used and displayed when we navigate to the settings page.


return (
<FlowEditorLayout>
Expand Down
Loading