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

feat: automatically publish newly created flows #4230

Merged
merged 9 commits into from
Feb 3, 2025
Merged
14 changes: 9 additions & 5 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { gql } from "graphql-request";
import capitalize from "lodash/capitalize.js";
import type { Flow, Node } from "./types.js";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";
import { gql } from "graphql-request";
import capitalize from "lodash/capitalize.js";

import { $public, getClient } from "./client/index.js";
import { userContext } from "./modules/auth/middleware.js";
import { publishFlow } from "./modules/flows/publish/service.js";
import type { Flow, Node } from "./types.js";

export interface FlowData {
slug: string;
Expand Down Expand Up @@ -63,7 +65,7 @@ interface InsertFlow {
}

// Insert a new flow into the `flows` table
const insertFlow = async (
const createFlow = async (
teamId: number,
Copy link
Member Author

@jessicamcinchak jessicamcinchak Jan 31, 2025

Choose a reason for hiding this comment

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

In my opinion, the editor store function createFlow should be calling/sharing this API method instead of doing a separate/equivalent frontend mutation ! Have made a note of this for now, but intentionally choosing not to refactor here to keep momentum on templates as a whole - will revisit when adding methods for "createTemplatedFlow"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep - agreed - we want to be narrowing this down to (ideally) a single implementation.

slug: string,
name: string,
Expand Down Expand Up @@ -109,6 +111,8 @@ const insertFlow = async (
);

await createAssociatedOperation(id);
await publishFlow(id, "Created flow");

return { id };
} catch (error) {
throw Error(
Expand Down Expand Up @@ -357,7 +361,7 @@ export {
dataMerged,
getChildren,
makeUniqueFlow,
insertFlow,
createFlow,
isLiveEnv,
getFormattedEnvironment,
};
24 changes: 24 additions & 0 deletions api.planx.uk/modules/flows/copyFlow/copyFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ beforeEach(() => {
},
},
});

queryMock.mockQuery({
name: "GetMostRecentPublishedFlow",
matchOnVariables: false,
data: {
flow: {
publishedFlows: [
{
data: mockFlowData,
},
],
},
},
});

queryMock.mockQuery({
name: "PublishFlow",
matchOnVariables: false,
data: {
publishedFlow: {
data: mockFlowData,
},
},
});
});

const auth = authHeader({ role: "teamEditor" });
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/copyFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeUniqueFlow, getFlowData, insertFlow } from "../../../helpers.js";
import { makeUniqueFlow, getFlowData, createFlow } from "../../../helpers.js";

const copyFlow = async (
flowId: string,
Expand All @@ -17,7 +17,7 @@ const copyFlow = async (
const newName = flow.name + " (copy)";

// Insert the flow and an associated operation
await insertFlow(flow.team_id, newSlug, newName, uniqueFlowData, flowId);
await createFlow(flow.team_id, newSlug, newName, uniqueFlowData, flowId);
}

return { flow, uniqueFlowData };
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@airbrake/node": "^2.1.8",
"@aws-sdk/client-s3": "^3.696.0",
"@aws-sdk/s3-request-presigner": "^3.701.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#03de3e0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#db49201",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"axios": "^1.7.4",
Expand Down
93 changes: 5 additions & 88 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@cucumber/cucumber": "^11.1.1",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#03de3e0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#db49201",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
82 changes: 5 additions & 77 deletions e2e/tests/api-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions e2e/tests/api-driven/src/flowStatusHistory/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FlowStatus } from "@opensystemslab/planx-core/types";
import { $admin } from "../client.js";
import { createTeam } from "../globalHelpers.js";
import { createTeam, createUser } from "../globalHelpers.js";
import { gql } from "graphql-tag";

export const setup = async () => {
const teamId = await createTeam();
const userId = await createUser();

const world = { teamId };
const world = { teamId, userId };

return world;
};
Expand Down
Loading
Loading