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

Merged
merged 8 commits into from
Feb 13, 2024
2 changes: 1 addition & 1 deletion api.planx.uk/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("getEnvironment function", () => {

test("Development env", () => {
process.env.NODE_ENV = "development";
expect(getFormattedEnvironment()).toBe("Development");
expect(getFormattedEnvironment()).toBe("Local");
});
});

Expand Down
4 changes: 4 additions & 0 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ const getFormattedEnvironment = (): string => {
const pizzaNumber = new URL(process.env.API_URL_EXT!).href.split(".")[1];
environment += ` ${pizzaNumber}`;
}
// For readability redefine development as local for slack warnings
if (environment === "development") {
environment = "local";
}
return capitalize(environment);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ export const mockGetExpiredSessionIdsQuery = {
lowcal_sessions: [{ id: "id1" }, { id: "id2" }, { id: "id3" }],
},
};

export const mockDeleteFeedbackMutation = {
name: "DeleteFeedback",
matchOnVariables: false,
data: {
feedback: {
returning: mockIds,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mockSanitiseUniformApplicationsMutation,
mockGetExpiredSessionIdsQuery,
mockDeletePaymentRequests,
mockDeleteFeedbackMutation,
} from "./mocks/queries";
import {
deleteHasuraEventLogs,
Expand All @@ -23,6 +24,7 @@ import {
deleteApplicationFiles,
deletePaymentRequests,
deleteHasuraScheduledEventsForSubmittedSessions,
deleteFeedback,
} from "./operations";

jest.mock("../../../../lib/hasura/schema");
Expand Down Expand Up @@ -142,6 +144,10 @@ describe("Data sanitation operations", () => {
operation: deletePaymentRequests,
query: mockDeletePaymentRequests,
},
{
operation: deleteFeedback,
query: mockDeleteFeedbackMutation,
},
];

for (const { operation, query } of testCases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const getOperations = (): Operation[] => [

// Queued up scheduled events (backup method to PG function/trigger)
deleteHasuraScheduledEventsForSubmittedSessions,

// Feedback records
deleteFeedback,
];

export const operationHandler = async (
Expand Down Expand Up @@ -292,3 +295,23 @@ export const deleteHasuraScheduledEventsForSubmittedSessions: Operation =
const [_column_name, ...ids] = response?.result?.flat() || [];
return ids;
};

export const deleteFeedback: Operation = async () => {
const mutation = gql`
mutation DeleteFeedback($retentionPeriod: timestamptz) {
feedback: delete_feedback(
where: { created_at: { _lt: $retentionPeriod } }
) {
returning {
id
}
}
}
`;
const {
feedback: { returning: result },
} = await $api.client.request<{ feedback: Result }>(mutation, {
retentionPeriod: getRetentionPeriod(),
});
return result;
};
10 changes: 10 additions & 0 deletions editor.planx.uk/src/@planx/components/Confirmation/Public.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { axe, setup } from "testUtils";

import ConfirmationComponent from "./Public";

jest.mock("@opensystemslab/planx-core", () => {
return {
CoreDomainClient: jest.fn().mockImplementation(() => ({
export: {
csvData: () => jest.fn(),
},
})),
};
});

it("should not have any accessibility violations", async () => {
const { container } = setup(
<ConfirmationComponent
Expand Down
49 changes: 23 additions & 26 deletions editor.planx.uk/src/@planx/components/Confirmation/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import Check from "@mui/icons-material/Check";
import Box from "@mui/material/Box";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import { QuestionAndResponses } from "@opensystemslab/planx-core/types";
import Card from "@planx/components/shared/Preview/Card";
import { PublicProps } from "@planx/components/ui";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import React, { useEffect, useState } from "react";
import Banner from "ui/public/Banner";
import FileDownload from "ui/public/FileDownload";
import NumberedList from "ui/public/NumberedList";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml";

import { makeCsvData } from "../Send/uniform";
import type { Confirmation } from "./model";

const Table = styled("table")(({ theme }) => ({
Expand All @@ -31,23 +31,27 @@ const Table = styled("table")(({ theme }) => ({
export type Props = PublicProps<Confirmation>;

export default function ConfirmationComponent(props: Props) {
const [breadcrumbs, flow, passport, sessionId, flowName] = useStore(
(state) => [
state.breadcrumbs,
state.flow,
state.computePassport(),
state.sessionId,
state.flowName,
],
);
const [data, setData] = useState<QuestionAndResponses[]>([]);

const [sessionId, saveToEmail, $public] = useStore((state) => [
state.sessionId,
state.saveToEmail,
state.$public,
]);

useEffect(() => {
const makeCsvData = async () => {
if (sessionId && saveToEmail) {
const csvData = await $public({
session: { sessionId: sessionId, email: saveToEmail },
}).export.csvData(sessionId);
setData(csvData);
}
};

// make a CSV data structure based on the payloads we Send to BOPs/Uniform
const data = makeCsvData({
breadcrumbs,
flow,
flowName,
passport,
sessionId,
if (data?.length < 1) {
makeCsvData();
}
});

return (
Expand Down Expand Up @@ -80,14 +84,7 @@ export default function ConfirmationComponent(props: Props) {
</Table>
)}

{
<FileDownload
data={data}
filename={
props.details?.["Planning Application Reference"] || "application"
}
/>
}
{<FileDownload data={data} filename={sessionId || "application"} />}

{props.nextSteps && Boolean(props.nextSteps?.length) && (
<Box pt={3}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Breadcrumbs } from "@opensystemslab/planx-core/types";
import { PASSPORT_REQUESTED_FILES_KEY } from "@planx/components/FileUploadAndLabel/model";
import { screen } from "@testing-library/react";
import axios from "axios";
import { useStore, vanillaStore } from "pages/FlowEditor/lib/store";
import { vanillaStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { act } from "react-dom/test-utils";
import { axe, setup } from "testUtils";
Expand Down Expand Up @@ -341,9 +341,7 @@ test("appends to existing '_requestedFiles' value", async () => {
);

// Check current passport setup
const passport = getState().computePassport();
const existingRequestedFiles = passport.data?.[PASSPORT_REQUESTED_FILES_KEY];
expect(existingRequestedFiles).toBeDefined();
const existingRequestedFiles = getState().requestedFiles();
expect(existingRequestedFiles).toMatchObject({
required: ["floorPlan", "utilityBill"],
recommended: ["elevations.existing"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export default function Component(props: Props) {
DrawBoundaryUserAction.Upload;

// Track as requested file
const { required, recommended, optional } = passport.data?.[
PASSPORT_REQUESTED_FILES_KEY
] || { required: [], recommended: [], optional: [] };
const { required, recommended, optional } = useStore
.getState()
.requestedFiles();

newPassportData[PASSPORT_REQUESTED_FILES_KEY] = {
required: [...required, PASSPORT_UPLOAD_KEY],
Expand Down
10 changes: 1 addition & 9 deletions editor.planx.uk/src/@planx/components/FileUpload/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ const FileUpload: React.FC<Props> = (props) => {
);

const updatedRequestedFiles = () => {
// const { required, recommended, optional } = useStore
// .getState()
// .requestedFiles();

const { required, recommended, optional } = useStore
.getState()
.computePassport().data?.[PASSPORT_REQUESTED_FILES_KEY] || {
required: [],
recommended: [],
optional: [],
};
.requestedFiles();

return {
[PASSPORT_REQUESTED_FILES_KEY]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,9 @@ const hasSlots = (userFile: UserFile): userFile is UserFileWithSlots =>
Boolean(userFile?.slots);

const getUpdatedRequestedFiles = (fileList: FileList) => {
// const { required, recommended, optional } = useStore
// .getState()
// .requestedFiles();

const { required, recommended, optional } = useStore
.getState()
.computePassport().data?.[PASSPORT_REQUESTED_FILES_KEY] || {
required: [],
recommended: [],
optional: [],
};
.requestedFiles();

return {
[PASSPORT_REQUESTED_FILES_KEY]: {
Expand Down
Loading
Loading