Skip to content

Commit

Permalink
fix: Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 29, 2023
1 parent ac363db commit b177ca1
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import QuestionHeader from "@planx/components/shared/Preview/QuestionHeader";
import { PrivateFileUpload } from "@planx/components/shared/PrivateFileUpload/PrivateFileUpload";
import type { PublicProps } from "@planx/components/ui";
import buffer from "@turf/buffer";
import { type GeometryObject,point } from "@turf/helpers";
import { type GeometryObject, point } from "@turf/helpers";
import { Store, useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useRef, useState } from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";
Expand Down Expand Up @@ -42,10 +42,13 @@ export default function Component(props: Props) {
const [boundary, setBoundary] = useState<Boundary>(previousBoundary);
const [slots, setSlots] = useState<FileUploadSlot[]>(previousFile ?? []);
const [area, setArea] = useState<number | undefined>(previousArea);
const addressPoint = passport?.data?._address?.longitude && passport?.data?._address?.latitude && point([
Number(passport?.data?._address?.longitude),
Number(passport?.data?._address?.latitude),
]);
const addressPoint =
passport?.data?._address?.longitude &&
passport?.data?._address?.latitude &&
point([
Number(passport?.data?._address?.longitude),
Number(passport?.data?._address?.latitude),
]);
const environment = useStore((state) => state.previewEnvironment);

useEffect(() => {
Expand Down Expand Up @@ -120,9 +123,12 @@ export default function Component(props: Props) {
drawMode
drawPointer="crosshair"
drawGeojsonData={JSON.stringify(boundary)}
clipGeojsonData={addressPoint && JSON.stringify(
buffer(addressPoint, BUFFER_IN_METERS, { units: "meters" }),
)}
clipGeojsonData={
addressPoint &&
JSON.stringify(
buffer(addressPoint, BUFFER_IN_METERS, { units: "meters" }),
)
}
zoom={20}
maxZoom={23}
latitude={Number(passport?.data?._address?.latitude)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { screen } from "@testing-library/react";
import { vanillaStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { setup } from "testUtils";

import FileUploadAndLabelComponent from "./Editor";
import { vanillaStore } from "pages/FlowEditor/lib/store";

const { getState } = vanillaStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ const SelectMultiple = (props: SelectMultipleProps) => {
<Typography variant="h4" component="h3" pr={3}>
Select all labels that apply
</Typography>
<Button variant="contained" onClick={handleClose} aria-label="Close list">
<Button
variant="contained"
onClick={handleClose}
aria-label="Close list"
>
Done
</Button>
</ListHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
"road.classified": {
name: "Classified road",
plural: "Classified roads",
text: "This will effect your project if you are looking to add a dropped kerb. It may also impact some agricultural or forestry projects within 25 metres of a classified road."
text: "This will effect your project if you are looking to add a dropped kerb. It may also impact some agricultural or forestry projects within 25 metres of a classified road.",
},
},
constraints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
"road.classified": {
name: "Classified road",
plural: "Classified roads",
text: "This will effect your project if you are looking to add a dropped kerb. It may also impact some agricultural or forestry projects within 25 metres of a classified road."
text: "This will effect your project if you are looking to add a dropped kerb. It may also impact some agricultural or forestry projects within 25 metres of a classified road.",
},
},
constraints: {
Expand Down
5 changes: 1 addition & 4 deletions editor.planx.uk/src/@planx/components/Section/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ function SectionComponent(props: Props) {
return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
<ModalSectionContent
title="Section marker"
Icon={ICONS[TYPES.Section]}
>
<ModalSectionContent title="Section marker" Icon={ICONS[TYPES.Section]}>
<InputRow>
<Input
required
Expand Down
14 changes: 12 additions & 2 deletions editor.planx.uk/src/@planx/components/Section/Public.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import Section, { SectionsOverviewList } from "./Public";
describe("Section component", () => {
it("renders correctly", () => {
const handleSubmit = jest.fn();
setup(<Section title="Section one" description="Description of section one" handleSubmit={handleSubmit} />);
setup(
<Section
title="Section one"
description="Description of section one"
handleSubmit={handleSubmit}
/>,
);

expect(screen.getByText("Application incomplete.")).toBeInTheDocument();
expect(screen.getByText("Continue")).toBeInTheDocument();
Expand All @@ -19,7 +25,11 @@ describe("Section component", () => {
const handleSubmit = jest.fn();

const { container } = setup(
<Section title="Section one" description="Description of section one" handleSubmit={handleSubmit} />,
<Section
title="Section one"
description="Description of section one"
handleSubmit={handleSubmit}
/>,
);

const results = await axe(container);
Expand Down
45 changes: 26 additions & 19 deletions editor.planx.uk/src/@planx/components/Section/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,33 @@ export function SectionsOverviewList({
<DescriptionList>
{Object.entries(sectionNodes).map(([sectionId, sectionNode]) => (
<SectionRow key={sectionId}>
<SectionTitle>
{showChange &&
sectionStatuses[sectionId] === SectionStatus.Completed ? (
<Link
onClick={() => changeFirstAnswerInSection(sectionId)}
component="button"
<SectionTitle>
{showChange &&
sectionStatuses[sectionId] === SectionStatus.Completed ? (
<Link
onClick={() => changeFirstAnswerInSection(sectionId)}
component="button"
>
<Typography
variant="subtitle1"
component="h4"
color="primary"
align="left"
>
<Typography variant="subtitle1" component="h4" color="primary" align="left">
<span style={visuallyHidden}>{`Change `}</span>
<strong>{sectionNode.data.title}</strong>
</Typography>
</Link>
) : (
<Typography variant="subtitle1" component="h4" color="inherit"><strong>{sectionNode.data.title}</strong></Typography>
)}
<ReactMarkdownOrHtml
source={sectionNode.data.description}
openLinksOnNewTab
/>
</SectionTitle>
<span style={visuallyHidden}>{`Change `}</span>
<strong>{sectionNode.data.title}</strong>
</Typography>
</Link>
) : (
<Typography variant="subtitle1" component="h4" color="inherit">
<strong>{sectionNode.data.title}</strong>
</Typography>
)}
<ReactMarkdownOrHtml
source={sectionNode.data.description}
openLinksOnNewTab
/>
</SectionTitle>
<SectionState> {getTag(sectionStatuses[sectionId])} </SectionState>
</SectionRow>
))}
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export const _public = new CoreDomainClient({

export const _client = new CoreDomainClient({
targetURL: process.env.REACT_APP_HASURA_URL!,
auth: { jwt: getCookie("jwt") || "" }
})
auth: { jwt: getCookie("jwt") || "" },
});
4 changes: 2 additions & 2 deletions editor.planx.uk/src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe("Header Component - Editor Route", () => {
isPlatformAdmin: false,
teams: [],
id: 123,
email: "[email protected]"
}
email: "[email protected]",
},
}),
);

Expand Down
127 changes: 64 additions & 63 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ const EditorToolbar: React.FC<{
route: Route;
}> = ({ headerRef, route }) => {
const [open, setOpen] = useState(false);
const [ togglePreview, user ] = useStore((state) => [
const [togglePreview, user] = useStore((state) => [
state.togglePreview,
state.getUser(),
]);
Expand Down Expand Up @@ -452,72 +452,73 @@ const EditorToolbar: React.FC<{
</InnerContainer>
</Container>
</StyledToolbar>
{ user &&
<StyledPopover
open={open}
anchorEl={headerRef.current}
onClose={handleClose}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
>
<StyledPaper>
<MenuItem disabled>
<ListItemIcon>
<Person fontSize="small" />
</ListItemIcon>
<ListItemText>
{user.email}
</ListItemText>
</MenuItem>
{(user.isPlatformAdmin || user.teams.length > 0) && (
{user && (
<StyledPopover
open={open}
anchorEl={headerRef.current}
onClose={handleClose}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
>
<StyledPaper>
<MenuItem disabled>
<ListItemIcon>
<Edit />
<Person fontSize="small" />
</ListItemIcon>
<ListItemText>
{user.isPlatformAdmin ? `All teams` : user.teams.map((team) => team.team.name).concat(["Templates"]).join(", ")}
</ListItemText>
</MenuItem>
)}
{!user.isPlatformAdmin && (
<MenuItem disabled divider>
<ListItemIcon>
<Visibility />
</ListItemIcon>
<ListItemText>
All teams
</ListItemText>
</MenuItem>
)}

{/* only show flow settings link if inside a flow route */}
{route.data.flow && (
<MenuItem
onClick={() =>
handleClick([rootFlowPath(true), "settings"].join("/"))
}
>
Settings
<ListItemText>{user.email}</ListItemText>
</MenuItem>
)}

{/* Only show global settings link from top-level admin view */}
{!route.data.flow && !route.data.team && (
<MenuItem onClick={() => navigate("/global-settings")}>
Global Settings
</MenuItem>
)}

<MenuItem onClick={() => navigate("/logout")}>Log out</MenuItem>
</StyledPaper>
</StyledPopover>
}
{(user.isPlatformAdmin || user.teams.length > 0) && (
<MenuItem disabled>
<ListItemIcon>
<Edit />
</ListItemIcon>
<ListItemText>
{user.isPlatformAdmin
? `All teams`
: user.teams
.map((team) => team.team.name)
.concat(["Templates"])
.join(", ")}
</ListItemText>
</MenuItem>
)}
{!user.isPlatformAdmin && (
<MenuItem disabled divider>
<ListItemIcon>
<Visibility />
</ListItemIcon>
<ListItemText>All teams</ListItemText>
</MenuItem>
)}

{/* only show flow settings link if inside a flow route */}
{route.data.flow && (
<MenuItem
onClick={() =>
handleClick([rootFlowPath(true), "settings"].join("/"))
}
>
Settings
</MenuItem>
)}

{/* Only show global settings link from top-level admin view */}
{!route.data.flow && !route.data.team && (
<MenuItem onClick={() => navigate("/global-settings")}>
Global Settings
</MenuItem>
)}

<MenuItem onClick={() => navigate("/logout")}>Log out</MenuItem>
</StyledPaper>
</StyledPopover>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const Hanger: React.FC<HangerProps> = ({ before, parent, hidden = false }) => {
};

return (
<li className={classnames("hanger", { hidden: hidden || hideHangerFromUser })} ref={drop}>
<li
className={classnames("hanger", { hidden: hidden || hideHangerFromUser })}
ref={drop}
>
<Link
href={buildHref(before, parent)}
prefetch={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const DesignSettings: React.FC = () => {
</>
);
};
export default DesignSettings;
export default DesignSettings;
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const ServiceFlags: React.FC = () => {
</>
);
};
export default ServiceFlags;
export default ServiceFlags;
4 changes: 3 additions & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ export const editorStore: StateCreator<
moveFlow(flowId: string, teamSlug: string) {
const valid = get().canUserEditTeam(teamSlug);
if (!valid) {
alert(`You do not have permission to move this flow into ${teamSlug}, try again`);
alert(
`You do not have permission to move this flow into ${teamSlug}, try again`,
);
return Promise.resolve();
}

Expand Down
Loading

0 comments on commit b177ca1

Please sign in to comment.