Skip to content

Commit

Permalink
feat: Use BaseNodeData to add tags property to all component types (
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Oct 4, 2024
1 parent 934b242 commit da15b40
Show file tree
Hide file tree
Showing 42 changed files with 137 additions and 133 deletions.
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#7712ff7",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#5781880",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
8 changes: 4 additions & 4 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 @@ -7,7 +7,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#7712ff7",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#5781880",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
8 changes: 4 additions & 4 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.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postinstall": "./install-dependencies.sh"
},
"dependencies": {
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#7712ff7",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#5781880",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/ui-driven/pnpm-lock.yaml

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

6 changes: 3 additions & 3 deletions editor.planx.uk/docs/adding-a-new-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ SetValue = 380,
3. `model.ts`

```typescript
import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export interface SetValue extends MoreInformation {
export interface SetValue extends BaseNodeData {
fn: string;
}

export const parseContent = (
data: Record<string, any> | undefined,
): SetValue => ({
fn: data?.fn || "",
...parseMoreInformation(data),
...parseBaseNodeData(data),
});
```

Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#7712ff7",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#5781880",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

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

6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/AddressInput/model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SchemaOf } from "yup";
import { object, string } from "yup";

import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export type Address = {
line1: string;
Expand All @@ -21,7 +21,7 @@ export const userDataSchema: SchemaOf<Address> = object({
country: string(),
});

export interface AddressInput extends MoreInformation {
export interface AddressInput extends BaseNodeData {
title: string;
description?: string;
fn?: string;
Expand All @@ -33,5 +33,5 @@ export const parseAddressInput = (
title: data?.title || "",
description: data?.description,
fn: data?.fn || "",
...parseMoreInformation(data),
...parseBaseNodeData(data),
});
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/Calculate/model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as math from "mathjs";

import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export interface Calculate extends MoreInformation {
export interface Calculate extends BaseNodeData {
title?: string;
output: string;
defaults: Record<string, number>;
Expand All @@ -19,7 +19,7 @@ export interface Input {
export const parseCalculate = (
data: Record<string, any> | undefined,
): Calculate => ({
...parseMoreInformation(data),
...parseBaseNodeData(data),
output: data?.output || "",
defaults: data?.defaults || {},
formula: data?.formula || "",
Expand Down
11 changes: 3 additions & 8 deletions editor.planx.uk/src/@planx/components/Checklist/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Input from "ui/shared/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";

import { Option, parseMoreInformation } from "../shared";
import { BaseNodeData, Option, parseBaseNodeData } from "../shared";
import PermissionSelect from "../shared/PermissionSelect";
import { ICONS, InternalNotes, MoreInformation } from "../ui";
import type { Category, Checklist, Group } from "./model";
Expand All @@ -35,16 +35,11 @@ export interface ChecklistProps extends Checklist {
data?: {
allRequired?: boolean;
categories?: Array<Category>;
definitionImg?: string;
description?: string;
fn?: string;
howMeasured?: string;
img?: string;
info?: string;
notes?: string;
policyRef?: string;
text: string;
};
} & BaseNodeData;
};
}

Expand Down Expand Up @@ -295,7 +290,7 @@ export const ChecklistComponent: React.FC<ChecklistProps> = (props) => {
img: props.node?.data?.img || "",
options: props.options,
text: props.node?.data?.text || "",
...parseMoreInformation(props.node?.data),
...parseBaseNodeData(props.node?.data),
},
onSubmit: ({ options, groupedOptions, ...values }) => {
const sourceOptions = options?.length
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/Checklist/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { array } from "yup";

import { MoreInformation, Option } from "../shared";
import { BaseNodeData, Option } from "../shared";
import { ChecklistLayout } from "./Public";

export interface Group<T> {
Expand All @@ -13,7 +13,7 @@ export interface Category {
count: number;
}

export interface Checklist extends MoreInformation {
export interface Checklist extends BaseNodeData {
fn?: string;
description?: string;
text?: string;
Expand Down
4 changes: 3 additions & 1 deletion editor.planx.uk/src/@planx/components/Confirmation/model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BaseNodeData } from "../shared";

export interface Step {
title: string;
description: string;
}

export interface Confirmation {
export interface Confirmation extends BaseNodeData {
heading?: string;
description?: string;
color?: { text: string; background: string };
Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/ContactInput/model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SchemaOf } from "yup";
import { object, string } from "yup";

import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export type Contact = {
title?: string;
Expand Down Expand Up @@ -41,7 +41,7 @@ export const userDataSchema: SchemaOf<Contact> = object({
},
});

export interface ContactInput extends MoreInformation {
export interface ContactInput extends BaseNodeData {
title: string;
description?: string;
fn?: string;
Expand All @@ -53,5 +53,5 @@ export const parseContactInput = (
title: data?.title || "",
description: data?.description,
fn: data?.fn || "",
...parseMoreInformation(data),
...parseBaseNodeData(data),
});
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/Content/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export interface Content extends MoreInformation {
export interface Content extends BaseNodeData {
content: string;
color?: string;
}
Expand All @@ -10,5 +10,5 @@ export const parseContent = (
): Content => ({
content: data?.content || "",
color: data?.color,
...parseMoreInformation(data),
...parseBaseNodeData(data),
});
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/DateInput/model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isValid, parseISO } from "date-fns";
import { object, SchemaOf, string } from "yup";

import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

// Expected format: YYYY-MM-DD
export type UserData = string;

export interface DateInput extends MoreInformation {
export interface DateInput extends BaseNodeData {
title: string;
description?: string;
fn?: string;
Expand Down Expand Up @@ -129,7 +129,7 @@ export const parseDateInput = (
fn: data?.fn,
min: data?.min,
max: data?.max,
...parseMoreInformation(data),
...parseBaseNodeData(data),
});

export const editorValidationSchema = () =>
Expand Down
10 changes: 3 additions & 7 deletions editor.planx.uk/src/@planx/components/DrawBoundary/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, parseBaseNodeData } from "../shared";

export enum DrawBoundaryUserAction {
Accept = "Accepted the title boundary",
Expand All @@ -7,24 +7,20 @@ export enum DrawBoundaryUserAction {
Upload = "Uploaded a location plan",
}

export interface DrawBoundary extends MoreInformation {
export interface DrawBoundary extends BaseNodeData {
title: string;
description: string;
titleForUploading: string;
descriptionForUploading: string;
hideFileUpload?: boolean;
dataFieldBoundary: string;
dataFieldArea: string;
info?: string;
policyRef?: string;
howMeasured?: string;
definitionImg?: string;
}

export const parseDrawBoundary = (
data: Record<string, any> | undefined,
): DrawBoundary => ({
...parseMoreInformation(data),
...parseBaseNodeData(data),
title: data?.title || defaultContent?.["title"],
description: data?.description || defaultContent?.["description"],
titleForUploading:
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/FileUpload/model.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MoreInformation } from "@planx/components/shared";
import { BaseNodeData } from "@planx/components/shared";
import { Store } from "pages/FlowEditor/lib/store";
import type { HandleSubmit } from "pages/Preview/Node";
import { FileWithPath } from "react-dropzone";
import { array } from "yup";

export interface FileUpload extends MoreInformation {
export interface FileUpload extends BaseNodeData {
id?: string;
title?: string;
fn: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Store, useStore } from "pages/FlowEditor/lib/store";
import { FileWithPath } from "react-dropzone";

import { FileUploadSlot } from "../FileUpload/model";
import { MoreInformation, parseMoreInformation } from "../shared";
import { BaseNodeData, MoreInformation, parseBaseNodeData } from "../shared";

export const PASSPORT_REQUESTED_FILES_KEY = "_requestedFiles" as const;

Expand Down Expand Up @@ -67,7 +67,7 @@ export interface FileType {
moreInformation?: MoreInformation;
}

export interface FileUploadAndLabel extends MoreInformation {
export interface FileUploadAndLabel extends BaseNodeData {
title: string;
description?: string;
fn?: string;
Expand All @@ -83,7 +83,7 @@ export const parseContent = (
fn: data?.fn || "",
fileTypes: cloneDeep(data?.fileTypes) || [newFileType()],
hideDropZone: data?.hideDropZone || false,
...parseMoreInformation(data),
...parseBaseNodeData(data),
});

const DEFAULT_TITLE = "Upload and label";
Expand Down
Loading

0 comments on commit da15b40

Please sign in to comment.