Skip to content

Commit

Permalink
refactor: Import Node type from planx-core (#3656)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Sep 12, 2024
1 parent bd3376c commit 596a54e
Show file tree
Hide file tree
Showing 49 changed files with 290 additions and 270 deletions.
31 changes: 26 additions & 5 deletions editor.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@
},
{
"name": "@testing-library/react",
"importNames": ["render"],
"importNames": [
"render"
],
"message": "Please import setup() from testUtils to render test component"
},
{
"name": "@mui/styles",
"importNames": ["styled"],
"importNames": [
"styled"
],
"message": "Please import styled from '@mui/material/styles'. Reason: https://mui.com/system/styled/#what-problems-does-it-solve"
}
],
"patterns": ["@mui/*/*/*"]
"patterns": [
"@mui/*/*/*"
]
}
],
"@typescript-eslint/no-unused-vars": [
Expand All @@ -68,6 +74,19 @@
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "typeLike",
"format": [
"PascalCase"
],
"custom": {
"regex": "^[A-Z]",
"match": true
}
}
],
"no-nested-ternary": "error"
},
"settings": {
Expand All @@ -80,7 +99,9 @@
"files": [
"**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)"
],
"extends": ["plugin:testing-library/react"]
"extends": [
"plugin:testing-library/react"
]
}
]
}
}
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("When formatOutputForAutomations is false, Calculate writes a number and fu
expect(upcomingCardIds()).toEqual(["Question"]);
});

const flowWithAutomation: Store.flow = {
const flowWithAutomation: Store.Flow = {
_root: {
edges: ["Calculate", "Question"],
},
Expand Down Expand Up @@ -95,7 +95,7 @@ const flowWithAutomation: Store.flow = {
},
};

const flowWithoutAutomation: Store.flow = {
const flowWithoutAutomation: Store.Flow = {
_root: {
edges: ["Calculate", "Question"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function Presentational(props: PresentationalProps) {
}

// TODO - Retire in favor of ODP Schema application type descriptions or fallback to flowName
function getWorkStatus(passport: Store.passport): string | undefined {
function getWorkStatus(passport: Store.Passport): string | undefined {
switch (passport?.data?.["application.type"]?.toString()) {
case "ldc.existing":
return "existing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function Component(props: Props) {
}, [boundary]);

const validateAndSubmit = () => {
const newPassportData: Store.userData["data"] = {};
const newPassportData: Store.UserData["data"] = {};

// Used the map
if (page === "draw") {
Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/FileUpload/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MoreInformation } from "@planx/components/shared";
import Card from "@planx/components/shared/Preview/Card";
import CardHeader from "@planx/components/shared/Preview/CardHeader";
import { Store, useStore } from "pages/FlowEditor/lib/store";
import type { handleSubmit } from "pages/Preview/Node";
import type { HandleSubmit } from "pages/Preview/Node";
import React, { useEffect, useRef, useState } from "react";
import { FileWithPath } from "react-dropzone";
import ErrorWrapper from "ui/shared/ErrorWrapper";
Expand All @@ -17,8 +17,8 @@ interface Props extends MoreInformation {
title?: string;
fn: string;
description?: string;
handleSubmit: handleSubmit;
previouslySubmittedData?: Store.userData;
handleSubmit: HandleSubmit;
previouslySubmittedData?: Store.UserData;
}

export interface FileUploadSlot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
describe("createFileList function", () => {
it("adds 'AlwaysRequired' FileTypes to the 'required' array", () => {
const fileTypes = [mockFileTypes[Condition.AlwaysRequired]];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [mockFileTypes[Condition.AlwaysRequired]],
Expand All @@ -44,7 +44,7 @@ describe("createFileList function", () => {

it("adds 'AlwaysRecommended' FileTypes to the 'recommended' array", () => {
const fileTypes = [mockFileTypes[Condition.AlwaysRecommended]];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [],
Expand All @@ -58,7 +58,7 @@ describe("createFileList function", () => {

it("adds 'RequiredIf' FileTypes to the 'required' array if the rule is met", () => {
const fileTypes = [mockFileTypes[Condition.RequiredIf]];
const passport: Store.passport = { data: { testFn: "testVal" } };
const passport: Store.Passport = { data: { testFn: "testVal" } };

const expected: FileList = {
required: [mockFileTypes[Condition.RequiredIf]],
Expand All @@ -72,7 +72,7 @@ describe("createFileList function", () => {

it("does not add 'RequiredIf' FileTypes to the 'required' array if the rule is not met", () => {
const fileTypes = [mockFileTypes[Condition.RequiredIf]];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [],
Expand All @@ -86,7 +86,7 @@ describe("createFileList function", () => {

it("adds 'RecommendedIf' FileTypes to the 'recommended' array if the rule is met", () => {
const fileTypes = [mockFileTypes[Condition.RecommendedIf]];
const passport: Store.passport = { data: { testFn: "testVal" } };
const passport: Store.Passport = { data: { testFn: "testVal" } };

const expected: FileList = {
required: [],
Expand All @@ -100,7 +100,7 @@ describe("createFileList function", () => {

it("does not add 'RecommendedIf' FileTypes to the 'recommended' array if the rule is not met", () => {
const fileTypes = [mockFileTypes[Condition.RecommendedIf]];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [],
Expand All @@ -114,7 +114,7 @@ describe("createFileList function", () => {

it("adds 'NotRequired' FileTypes to the 'optional' array", () => {
const fileTypes = [mockFileTypes[Condition.NotRequired]];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [],
Expand All @@ -132,7 +132,7 @@ describe("createFileList function", () => {
mockFileTypes[Condition.AlwaysRequired],
mockFileTypes[Condition.AlwaysRequired],
];
const passport: Store.passport = { data: {} };
const passport: Store.Passport = { data: {} };

const expected: FileList = {
required: [mockFileTypes[Condition.AlwaysRequired]],
Expand All @@ -152,7 +152,7 @@ describe("createFileList function", () => {
mockFileTypes[Condition.RecommendedIf],
mockFileTypes[Condition.NotRequired],
];
const passport: Store.passport = { data: { testFn: "testVal" } };
const passport: Store.Passport = { data: { testFn: "testVal" } };

const expected: FileList = {
required: [mockFileTypes[Condition.AlwaysRequired]],
Expand Down Expand Up @@ -197,7 +197,7 @@ describe("createFileList function", () => {
},
},
];
const passport: Store.passport = {
const passport: Store.Passport = {
data: {
"documentA.required": ["true"],
"documentB.recommended": ["true"],
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("createFileList function", () => {
},
},
];
const passport: Store.passport = {
const passport: Store.Passport = {
data: { "required.file": "true", "recommended.file": ["true"] },
};

Expand Down Expand Up @@ -355,7 +355,7 @@ describe("createFileList function", () => {
},
},
];
const passport: Store.passport = {
const passport: Store.Passport = {
data: { "required.file": "true", "recommended.file": ["true"] },
};

Expand Down Expand Up @@ -433,7 +433,7 @@ describe("getRecoveredData function", () => {
};

// Mock breadcrumb data with FileType.fn -> UserFile mapped
const previouslySubmittedData: Store.userData = {
const previouslySubmittedData: Store.UserData = {
data: {
requiredFileFn: [
{
Expand Down Expand Up @@ -592,21 +592,21 @@ describe("isRuleMet function", () => {
};

it("matches on an exact value", () => {
const mockPassport: Store.passport = { data: { testFn: "testValue" } };
const mockPassport: Store.Passport = { data: { testFn: "testValue" } };
const result = isRuleMet(mockPassport, mockRule);

expect(result).toBe(true);
});

it("does not match if an exact value is not present", () => {
const mockPassport: Store.passport = { data: { testFn: "missingValue" } };
const mockPassport: Store.Passport = { data: { testFn: "missingValue" } };
const result = isRuleMet(mockPassport, mockRule);

expect(result).toBe(false);
});

it("does not match if the passport key is not present", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: { missingKey: "missingValue" },
};
const result = isRuleMet(mockPassport, mockRule);
Expand All @@ -615,7 +615,7 @@ describe("isRuleMet function", () => {
});

it("matches on an exact value in an array", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: { testFn: ["value1", "value2", "testValue"] },
};
const result = isRuleMet(mockPassport, mockRule);
Expand All @@ -624,7 +624,7 @@ describe("isRuleMet function", () => {
});

it("matches on an granular value", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: {
testFn: ["value1.more.value", "value2", "testValue.more.detail"],
},
Expand All @@ -635,7 +635,7 @@ describe("isRuleMet function", () => {
});

it("does not match on a partial granular value (prefix)", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: { testFn: ["somethingtestValue.more.detail"] },
};
const result = isRuleMet(mockPassport, mockRule);
Expand All @@ -644,7 +644,7 @@ describe("isRuleMet function", () => {
});

it("does not match on a partial granular value (suffix)", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: { testFn: ["testValueSomething.more.detail"] },
};
const result = isRuleMet(mockPassport, mockRule);
Expand All @@ -653,7 +653,7 @@ describe("isRuleMet function", () => {
});

it("does not match on a granular which is not a 'parent'", () => {
const mockPassport: Store.passport = {
const mockPassport: Store.Passport = {
data: { testFn: ["parent.child.testValue"] },
};
const result = isRuleMet(mockPassport, mockRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const createFileList = ({
passport,
fileTypes,
}: {
passport: Readonly<Store.passport>;
passport: Readonly<Store.Passport>;
fileTypes: FileType[];
}): FileList => {
const fileList: FileList = { required: [], recommended: [], optional: [] };
Expand Down Expand Up @@ -160,7 +160,7 @@ const populateFileList = ({
}: {
fileList: FileList;
fileType: FileType;
passport: Store.passport;
passport: Store.Passport;
}): boolean => {
switch (fileType.rule.condition) {
case Condition.AlwaysRequired:
Expand Down Expand Up @@ -192,7 +192,7 @@ const populateFileList = ({
};

export const isRuleMet = (
passport: Store.passport,
passport: Store.Passport,
rule: ConditionalRule<Condition.RequiredIf | Condition.RecommendedIf>,
): boolean => {
const passportVal = passport.data?.[rule.fn];
Expand Down Expand Up @@ -254,8 +254,8 @@ const getUpdatedRequestedFiles = (fileList: FileList) => {
* Generate payload for FileUploadAndLabel breadcrumb
* Not responsible for validation - this happens at the component level
*/
export const generatePayload = (fileList: FileList): Store.userData => {
const newPassportData: Store.userData["data"] = {};
export const generatePayload = (fileList: FileList): Store.UserData => {
const newPassportData: Store.UserData["data"] = {};

const uploadedFiles = [
...fileList.required,
Expand All @@ -279,14 +279,14 @@ export const generatePayload = (fileList: FileList): Store.userData => {

const getCachedSlotsFromPreviousData = (
userFile: UserFile,
previouslySubmittedData: Store.userData | undefined,
previouslySubmittedData: Store.UserData | undefined,
): FileUploadSlot[] =>
previouslySubmittedData?.data?.[userFile.fn]?.map(
(file: FormattedUserFile) => file.cachedSlot,
);

const getRecoveredSlots = (
previouslySubmittedData: Store.userData | undefined,
previouslySubmittedData: Store.UserData | undefined,
fileList: FileList,
) => {
const allFiles = [
Expand All @@ -307,7 +307,7 @@ const getRecoveredSlots = (
};

const getRecoveredFileList = (
previouslySubmittedData: Store.userData | undefined,
previouslySubmittedData: Store.UserData | undefined,
fileList: FileList,
) => {
const recoveredFileList = cloneDeep(fileList);
Expand All @@ -327,7 +327,7 @@ const getRecoveredFileList = (
};

export const getRecoveredData = (
previouslySubmittedData: Store.userData | undefined,
previouslySubmittedData: Store.UserData | undefined,
fileList: FileList,
) => {
const recoveredSlots = getRecoveredSlots(previouslySubmittedData, fileList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Component(props: Props) {
}

if (address) {
const newPassportData: Store.userData["data"] = {};
const newPassportData: Store.UserData["data"] = {};
newPassportData["_address"] = address;
if (address?.planx_value) {
newPassportData["property.type"] = [address.planx_value];
Expand Down
Loading

0 comments on commit 596a54e

Please sign in to comment.