Skip to content

Commit

Permalink
fix: show warning and skip Send event creation if `DISABLE_SAVE_AND_R…
Browse files Browse the repository at this point in the history
…ETURN` feature flag is enabled (#2416)
  • Loading branch information
jessicamcinchak authored Nov 13, 2023
1 parent 2b0f6af commit 07f57d1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
28 changes: 28 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/Public.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator";
import { hasFeatureFlag } from "lib/featureFlags";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect } from "react";
import { useAsync } from "react-use";
Expand All @@ -19,6 +20,33 @@ export type Props = PublicProps<Send>;
const SendComponent: React.FC<Props> = ({
destinations = [DEFAULT_DESTINATION],
...props
}) => {
// If testing with the feature flag, skip scheduled event creation because no stored lowcal_session to generate payloads
const testSession = hasFeatureFlag("DISABLE_SAVE_AND_RETURN");

useEffect(() => {
if (testSession) {
props.handleSubmit?.({
...makeData(props, true, "skippedEvents"),
auto: true,
});
}
}, []);

if (testSession) {
return (
<Card>
<DelayedLoadingIndicator text={`Skipping test submission...`} />
</Card>
);
} else {
return <SendEvents destinations={destinations} {...props} />;
}
};

const SendEvents: React.FC<Props> = ({
destinations = [DEFAULT_DESTINATION],
...props
}) => {
const [passport, sessionId, teamSlug] = useStore((state) => [
state.computePassport(),
Expand Down
54 changes: 54 additions & 0 deletions editor.planx.uk/src/components/FeatureFlagBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import ReportIcon from "@mui/icons-material/Report";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Container from "@mui/material/Container";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import { hasFeatureFlag } from "lib/featureFlags";
import React, { useState } from "react";

const TestEnvironmentWarning = styled(Box)(({ theme }) => ({
display: "flex",
backgroundColor: theme.palette.background.paper,
color: theme.palette.text.primary,
justifyContent: "space-between",
alignItems: "center",
padding: "0.2em 0",
}));

const FeatureFlagBanner: React.FC = () => {
const [showWarning, setShowWarning] = useState(true);

const isUsingFeatureFlag = () => hasFeatureFlag("DISABLE_SAVE_AND_RETURN");

return (
<>
{isUsingFeatureFlag() && showWarning && (
<TestEnvironmentWarning>
<Container
maxWidth={false}
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Box display="flex" alignItems="center">
<ReportIcon color="error" />
<Typography variant="body2" ml={1}>
You have <strong>disabled save and return</strong> via feature
flag. This means you cannot save or submit your test
applications.
</Typography>
</Box>
<Button size="small" onClick={() => setShowWarning(false)}>
Hide
</Button>
</Container>
</TestEnvironmentWarning>
)}
</>
);
};

export default FeatureFlagBanner;
2 changes: 2 additions & 0 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Reset from "ui/icons/Reset";
import { useStore } from "../pages/FlowEditor/lib/store";
import { rootFlowPath } from "../routes/utils";
import AnalyticsDisabledBanner from "./AnalyticsDisabledBanner";
import FeatureFlagBanner from "./FeatureFlagBanner";
import TestEnvironmentBanner from "./TestEnvironmentBanner";

export const HEADER_HEIGHT = 74;
Expand Down Expand Up @@ -376,6 +377,7 @@ const PublicToolbar: React.FC<{
<NavBar />
<AnalyticsDisabledBanner />
<TestEnvironmentBanner />
<FeatureFlagBanner />
</>
);
};
Expand Down
6 changes: 3 additions & 3 deletions scripts/seed-database/write/flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ INSERT INTO flows (
version,
settings,
copied_from,
null as analytics_link,
analytics_link
)
SELECT
id,
Expand All @@ -35,7 +35,7 @@ SELECT
version,
settings,
copied_from,
analytics_link
NULL
FROM sync_flows
ON CONFLICT (id) DO UPDATE
SET
Expand All @@ -46,7 +46,7 @@ SET
version = EXCLUDED.version,
settings = EXCLUDED.settings,
copied_from = EXCLUDED.copied_from,
analytics_link = null;
analytics_link = NULL;

-- ensure that original flows.version is overwritten to match new operation inserted below, else sharedb will fail
UPDATE flows SET version = 1;
Expand Down

0 comments on commit 07f57d1

Please sign in to comment.