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 #3885

Merged
merged 7 commits into from
Oct 31, 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
9 changes: 4 additions & 5 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Flow, Node } from "./types.js";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";
import { $public, getClient } from "./client/index.js";
import { userContext } from "./modules/auth/middleware.js";

export interface FlowData {
slug: string;
Expand Down Expand Up @@ -67,10 +68,11 @@ const insertFlow = async (
slug: string,
name: string,
flowData: Flow["data"],
creatorId?: number,
copiedFrom?: Flow["id"],
) => {
const { client: $client } = getClient();
const userId = userContext.getStore()?.user?.sub;

try {
const {
flow: { id },
Expand All @@ -81,7 +83,6 @@ const insertFlow = async (
$slug: String!
$name: String!
$data: jsonb = {}
$creator_id: Int
$copied_from: uuid
) {
flow: insert_flows_one(
Expand All @@ -91,7 +92,6 @@ const insertFlow = async (
name: $name
data: $data
version: 1
creator_id: $creator_id
copied_from: $copied_from
}
) {
Expand All @@ -104,7 +104,6 @@ const insertFlow = async (
slug: slug,
name: name,
data: flowData,
creator_id: creatorId,
copied_from: copiedFrom,
},
);
Expand All @@ -113,7 +112,7 @@ const insertFlow = async (
return { id };
} catch (error) {
throw Error(
`User ${creatorId} failed to insert flow to teamId ${teamId}. Please check permissions. Error: ${error}`,
`User ${userId} failed to insert flow to teamId ${teamId}. Please check permissions. Error: ${error}`,
);
}
};
Expand Down
12 changes: 1 addition & 11 deletions api.planx.uk/modules/flows/copyFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { makeUniqueFlow, getFlowData, insertFlow } from "../../../helpers.js";
import { userContext } from "../../auth/middleware.js";

const copyFlow = async (
flowId: string,
Expand All @@ -16,18 +15,9 @@ const copyFlow = async (
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,
);
await insertFlow(flow.team_id, newSlug, newName, uniqueFlowData, flowId);
}

return { flow, uniqueFlowData };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
Expand All @@ -9,6 +9,7 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";
import { AddressInput, parseAddressInput } from "./model";

export type Props = EditorProps<TYPES.AddressInput, AddressInput>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Card from "@planx/components/shared/Preview/Card";
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader";
import type { PublicProps } from "@planx/components/ui";
import type { PublicProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import InputLabel from "ui/public/InputLabel";
Expand Down
3 changes: 2 additions & 1 deletion editor.planx.uk/src/@planx/components/Calculate/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { styled } from "@mui/material/styles";
import Switch from "@mui/material/Switch";
import Typography from "@mui/material/Typography";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { FormikErrors, useFormik } from "formik";
import React from "react";
import InputGroup from "ui/editor/InputGroup";
Expand All @@ -13,6 +13,7 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";
import type { Calculate } from "./model";
import { evaluate, getVariables, parseCalculate } from "./model";

Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Calculate/Public.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PublicProps } from "@planx/components/shared/types";
import { makeData } from "@planx/components/shared/utils";
import type { PublicProps } from "@planx/components/ui";
import { useStore } from "pages/FlowEditor/lib/store";
import { useEffect } from "react";

Expand Down
33 changes: 5 additions & 28 deletions editor.planx.uk/src/@planx/components/Checklist/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,14 @@ import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";

import { BaseNodeData, Option, parseBaseNodeData } from "../shared";
import { Option, parseBaseNodeData } from "../shared";
import { ICONS } from "../shared/icons";
import PermissionSelect from "../shared/PermissionSelect";
import { ICONS } from "../ui";
import type { Category, Checklist, Group } from "./model";
import type { Checklist, Group } from "./model";
import { toggleExpandableChecklist } from "./model";
import { ChecklistProps, OptionEditorProps } from "./types";

export interface ChecklistProps extends Checklist {
text: string;
handleSubmit?: Function;
node?: {
data?: {
allRequired?: boolean;
neverAutoAnswer?: boolean;
categories?: Array<Category>;
description?: string;
fn?: string;
img?: string;
text: string;
} & BaseNodeData;
};
}

const OptionEditor: React.FC<{
index: number;
value: Option;
onChange: (newVal: Option) => void;
groupIndex?: number;
groups?: Array<string>;
onMoveToGroup?: (itemIndex: number, groupIndex: number) => void;
showValueField?: boolean;
}> = (props) => {
const OptionEditor: React.FC<OptionEditorProps> = (props) => {
return (
<div style={{ width: "100%" }}>
<InputRow>
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Checklist/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ErrorWrapper from "ui/shared/ErrorWrapper";
import { object } from "yup";

import { Option } from "../shared";
import type { PublicProps } from "../ui";
import type { PublicProps } from "../shared/types";

export type Props = PublicProps<Checklist>;

Expand Down
27 changes: 27 additions & 0 deletions editor.planx.uk/src/@planx/components/Checklist/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { BaseNodeData, Option } from "../shared";
import type { Category, Checklist } from "./model";

export interface ChecklistProps extends Checklist {
text: string;
handleSubmit?: Function;
node?: {
data?: {
allRequired?: boolean;
neverAutoAnswer?: boolean;
categories?: Array<Category>;
description?: string;
fn?: string;
img?: string;
text: string;
} & BaseNodeData;
};
}
export interface OptionEditorProps {
index: number;
value: Option;
onChange: (newVal: Option) => void;
groupIndex?: number;
groups?: Array<string>;
onMoveToGroup?: (itemIndex: number, groupIndex: number) => void;
showValueField?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Box from "@mui/material/Box";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React, { ChangeEvent } from "react";
import ListManager, {
Expand All @@ -12,6 +12,7 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";
import { Confirmation, parseNextSteps, Step } from "./model";

export type Props = EditorProps<TYPES.Confirmation, Confirmation>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Typography from "@mui/material/Typography";
import { QuestionAndResponses } from "@opensystemslab/planx-core/types";
import Card from "@planx/components/shared/Preview/Card";
import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList";
import { PublicProps } from "@planx/components/ui";
import { PublicProps } from "@planx/components/shared/types";
import { objectWithoutNullishValues } from "lib/objectHelpers";
import { Store, useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useState } from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
Expand All @@ -9,6 +9,7 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";
import { ContactInput, parseContactInput } from "./model";

export type Props = EditorProps<TYPES.ContactInput, ContactInput>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Card from "@planx/components/shared/Preview/Card";
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader";
import type { PublicProps } from "@planx/components/ui";
import type { PublicProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import InputLabel from "ui/public/InputLabel";
Expand Down
4 changes: 3 additions & 1 deletion editor.planx.uk/src/@planx/components/Content/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import type { Content } from "@planx/components/Content/model";
import { parseContent } from "@planx/components/Content/model";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import ColorPicker from "ui/editor/ColorPicker/ColorPicker";
Expand All @@ -11,6 +11,8 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";

export type Props = EditorProps<TYPES.Content, Content>;

const ContentComponent: React.FC<Props> = (props) => {
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Content/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import type { Content } from "@planx/components/Content/model";
import Card from "@planx/components/shared/Preview/Card";
import { PublicProps } from "@planx/components/ui";
import { PublicProps } from "@planx/components/shared/types";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analytics/provider";
import React from "react";
import { getContrastTextColor } from "styleUtils";
Expand Down
4 changes: 3 additions & 1 deletion editor.planx.uk/src/@planx/components/DateInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
paddedDate,
parseDateInput,
} from "@planx/components/DateInput/model";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
Expand All @@ -17,6 +17,8 @@ import DateInputUi from "ui/shared/DateInput/DateInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";

export type Props = EditorProps<TYPES.DateInput, DateInput>;

const DateInputComponent: React.FC<Props> = (props) => {
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/DateInput/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@planx/components/DateInput/model";
import Card from "@planx/components/shared/Preview/Card";
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader";
import { PublicProps } from "@planx/components/ui";
import { PublicProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import DateInputComponent from "ui/shared/DateInput/DateInput";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import InputGroup from "ui/editor/InputGroup";
Expand All @@ -12,6 +12,7 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";
import type { DrawBoundary } from "./model";
import { parseDrawBoundary } from "./model";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
MapFooter,
} from "@planx/components/shared/Preview/MapContainer";
import { PrivateFileUpload } from "@planx/components/shared/PrivateFileUpload/PrivateFileUpload";
import type { PublicProps } from "@planx/components/shared/types";
import { squareMetresToHectares } from "@planx/components/shared/utils";
import type { PublicProps } from "@planx/components/ui";
import buffer from "@turf/buffer";
import { point } from "@turf/helpers";
import { Feature } from "geojson";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";

import { ICONS } from "../ui";
import { ICONS } from "../shared/icons";

interface Flow {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Feedback/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "@mui/material/Link";
import Typography from "@mui/material/Typography";
import Card from "@planx/components/shared/Preview/Card";
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader";
import type { PublicProps } from "@planx/components/ui";
import type { PublicProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import React from "react";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
Expand Down
3 changes: 2 additions & 1 deletion editor.planx.uk/src/@planx/components/FileUpload/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { ICONS } from "@planx/components/ui";
import { useFormik } from "formik";
import React from "react";
import { ModalFooter } from "ui/editor/ModalFooter";
Expand All @@ -9,6 +8,8 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { ICONS } from "../shared/icons";

function Component(props: any) {
const formik = useFormik<{
color: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { styled } from "@mui/material/styles";
import Switch from "@mui/material/Switch";
import Typography from "@mui/material/Typography";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps, ICONS } from "@planx/components/ui";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
import { lowerCase, merge, upperFirst } from "lodash";
import React from "react";
Expand All @@ -25,6 +25,7 @@ import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";

import { ICONS } from "../shared/icons";
import {
checkIfConditionalRule,
Condition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ListItem from "@mui/material/ListItem";
import ListSubheader from "@mui/material/ListSubheader";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import { PublicProps } from "@planx/components/ui";
import { PublicProps } from "@planx/components/shared/types";
import { PrintButton } from "components/PrintButton";
import capitalize from "lodash/capitalize";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analytics/provider";
Expand Down
Loading