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

Production deploy #3280

Merged
merged 10 commits into from
Jun 18, 2024
Merged
6 changes: 6 additions & 0 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { $public, getClient } from "./client";

export interface FlowData {
slug: string;
name: string;
data: Flow["data"];
team_id: number;
team: { slug: string };
Expand All @@ -28,6 +29,7 @@ const getFlowData = async (id: string): Promise<FlowData> => {
flow: flows_by_pk(id: $id) {
slug
data
name
team_id
team {
slug
Expand Down Expand Up @@ -62,6 +64,7 @@ interface InsertFlow {
const insertFlow = async (
teamId: number,
slug: string,
name: string,
flowData: Flow["data"],
creatorId?: number,
copiedFrom?: Flow["id"],
Expand All @@ -75,6 +78,7 @@ const insertFlow = async (
mutation InsertFlow(
$team_id: Int!
$slug: String!
$name: String!
$data: jsonb = {}
$creator_id: Int
$copied_from: uuid
Expand All @@ -83,6 +87,7 @@ const insertFlow = async (
object: {
team_id: $team_id
slug: $slug
name: $name
data: $data
version: 1
creator_id: $creator_id
Expand All @@ -96,6 +101,7 @@ const insertFlow = async (
{
team_id: teamId,
slug: slug,
name: name,
data: flowData,
creator_id: creatorId,
copied_from: copiedFrom,
Expand Down
2 changes: 2 additions & 0 deletions api.planx.uk/modules/flows/copyFlow/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const copyFlow = async (
// Check if copied flow data should be inserted into `flows` table, or just returned for reference
if (insert) {
const newSlug = flow.slug + "-copy";
const newName = flow.name + " (copy)";
const creatorId = userContext.getStore()?.user?.sub;
if (!creatorId) throw Error("User details missing from request");

// Insert the flow and an associated operation
await insertFlow(
flow.team_id,
newSlug,
newName,
uniqueFlowData,
parseInt(creatorId),
flowId,
Expand Down
51 changes: 51 additions & 0 deletions api.planx.uk/modules/flows/validate/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
ComponentType,
FlowGraph,
Node,
} from "@opensystemslab/planx-core/types";
import { Entry } from "type-fest";

export const isComponentType = (
entry: Entry<FlowGraph>,
type: ComponentType,
): entry is [string, Node] => {
const [nodeId, node] = entry;
if (nodeId === "_root") return false;
return Boolean(node?.type === type);
};

export const hasComponentType = (
flowGraph: FlowGraph,
type: ComponentType,
fn?: string,
): boolean => {
const nodeIds = Object.entries(flowGraph).filter(
(entry): entry is [string, Node] => isComponentType(entry, type),
);
if (fn) {
nodeIds
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn)
?.map(([nodeId, _nodeData]) => nodeId);
} else {
nodeIds?.map(([nodeId, _nodeData]) => nodeId);
}
return Boolean(nodeIds?.length);
};

export const numberOfComponentType = (
flowGraph: FlowGraph,
type: ComponentType,
fn?: string,
): number => {
const nodeIds = Object.entries(flowGraph).filter(
(entry): entry is [string, Node] => isComponentType(entry, type),
);
if (fn) {
nodeIds
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn)
?.map(([nodeId, _nodeData]) => nodeId);
} else {
nodeIds?.map(([nodeId, _nodeData]) => nodeId);
}
return nodeIds?.length;
};
Loading
Loading