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

feat: add AWS S3 bucket as "Send" destination for staging envs only #2999

Merged
merged 1 commit into from
Apr 9, 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
26 changes: 23 additions & 3 deletions editor.planx.uk/src/@planx/components/Send/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ const SendComponent: React.FC<Props> = (props) => {
},
];

// Show S3 option on staging only
if (process.env.REACT_APP_ENV !== "production") {
options.push({
value: Destination.S3,
label: "Upload to AWS S3 bucket",
});
}
Copy link
Member Author

@jessicamcinchak jessicamcinchak Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than introduce a feature-flag here which we'll then have to communicate to Editors how to use - I figure we can just only display this option on non-prod environments at first? It also throws an alert with warning message if anyone outside of Barnet selects it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this works well I think 👍


const changeCheckbox = (value: Destination) => (_checked: any) => {
let newCheckedValues: Destination[];

Expand All @@ -76,7 +84,8 @@ const SendComponent: React.FC<Props> = (props) => {

// Show warnings on selection of BOPS or Uniform for likely unsupported services
// Don't actually restrict selection because flowSlug matching is imperfect for some valid test cases
const flowSlug = window.location.pathname?.split("/")?.[1];
const teamSlug = window.location.pathname?.split("/")?.[1];
const flowSlug = window.location.pathname?.split("/")?.[2];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flowSlug index was actually wrong here, but only impacted the in-editor warning messages - now fixed throughout!

if (
value === Destination.BOPS &&
newCheckedValues.includes(value) &&
Expand All @@ -94,10 +103,21 @@ const SendComponent: React.FC<Props> = (props) => {
if (
value === Destination.Uniform &&
newCheckedValues.includes(value) &&
flowSlug !== "apply-for-a-lawful-development-certificate"
flowSlug !== "apply-for-a-lawful-development-certificate" &&
!["buckinghamshire", "lambeth", "southwark"].includes(teamSlug)
) {
alert(
"Uniform is only enabled for Bucks, Lambeth and Southwark to accept Lawful Development Certificate submissions. Please do not select if you're building another type of submission service!",
);
}

if (
value === Destination.S3 &&
newCheckedValues.includes(value) &&
teamSlug !== "barnet"
) {
alert(
"Uniform only accepts Lawful Development Certificate submissions. Please do not select if you're building another type of submission service!",
"AWS S3 uploads are currently being prototyped with Barnet only. Please do not select this option for other councils yet.",
);
}
};
Expand Down
10 changes: 10 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ const SendComponent: React.FC<Props> = ({
makeData(props, request.value.email?.event_id, "emailSendEventId"),
);
}

if (
destinations.includes(Destination.S3) &&
isReady &&
props.handleSubmit
) {
props.handleSubmit(
makeData(props, request.value.s3?.event_id, "s3SendEventId"),
);
}
}, [request.loading, request.error, request.value]);

if (request.loading) {
Expand Down
8 changes: 8 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Destination {
BOPS = "bops",
Uniform = "uniform",
Email = "email",
S3 = "s3",
}

export interface Send extends MoreInformation {
Expand Down Expand Up @@ -71,5 +72,12 @@ export function getCombinedEventsPayload({
};
}

if (destinations.includes(Destination.S3)) {
combinedEventsPayload[Destination.S3] = {
localAuthority: teamSlug,
body: { sessionId },
};
}

return combinedEventsPayload;
}
Loading