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

Merged
merged 3 commits into from
Sep 20, 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
2 changes: 1 addition & 1 deletion editor.planx.uk/src/lib/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// add/edit/remove feature flags in array below
const AVAILABLE_FEATURE_FLAGS = ["SEARCH", "ADD_NEW_EDITOR"] as const;
const AVAILABLE_FEATURE_FLAGS = [] as const;

type FeatureFlag = (typeof AVAILABLE_FEATURE_FLAGS)[number];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Link from "@mui/material/Link";
import { styled } from "@mui/material/styles";
import Tabs from "@mui/material/Tabs";
import Tooltip from "@mui/material/Tooltip";
import { hasFeatureFlag } from "lib/featureFlags";
import React, { useState } from "react";
import { rootFlowPath } from "routes/utils";
import Permission from "ui/editor/Permission";
Expand Down Expand Up @@ -175,9 +174,7 @@ const Sidebar: React.FC = React.memo(() => {
<Tabs onChange={handleChange} value={activeTab} aria-label="">
<StyledTab value="PreviewBrowser" label="Preview" />
<StyledTab value="History" label="History" />
{hasFeatureFlag("SEARCH") && (
<StyledTab value="Search" label="Search" />
)}
<StyledTab value="Search" label="Search" />
<StyledTab value="Console" label="Console" />
</Tabs>
</TabList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,20 @@ export const MembersTable = ({
</StyledTableRow>
))}
{showAddMemberButton && (
<TableRow>
<TableCell colSpan={3}>
<AddButton
onClick={() => {
setInitialValues(undefined);
setShowAddModal(true);
}}
>
Add a new editor
</AddButton>
</TableCell>
</TableRow>
<Permission.IsPlatformAdmin>
<TableRow>
<TableCell colSpan={3}>
<AddButton
onClick={() => {
setInitialValues(undefined);
setShowAddModal(true);
}}
>
Add a new editor
</AddButton>
</TableCell>
</TableRow>
</Permission.IsPlatformAdmin>
)}
</TableBody>
</Table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vi } from "vitest";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { alreadyExistingUser } from "./mocks/mockUsers";
import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers";

let initialState: FullStore;
vi.mock(
Expand All @@ -22,6 +22,7 @@ describe("when a user fills in the 'add a new editor' form correctly but there i
beforeEach(async () => {
useStore.setState({
teamMembers: [...mockTeamMembersData, alreadyExistingUser],
user: mockPlatformAdminUser,
});

const { user } = await setupTeamMembersScreen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vi } from "vitest";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { alreadyExistingUser } from "./mocks/mockUsers";
import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers";

vi.mock(
"pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx",
Expand All @@ -23,6 +23,7 @@ describe("when a user fills in the 'add a new editor' form correctly but the use
beforeEach(async () => {
useStore.setState({
teamMembers: [...mockTeamMembersData, alreadyExistingUser],
user: mockPlatformAdminUser,
});

const { user } = await setupTeamMembersScreen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useStore } from "pages/FlowEditor/lib/store";

import { TeamMember } from "../types";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { mockPlatformAdminUser } from "./mocks/mockUsers";

const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [
{
Expand All @@ -16,7 +17,10 @@ const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [

describe("when a user views the 'Team members' screen but there are no existing team editors listed", () => {
beforeEach(async () => {
useStore.setState({ teamMembers: mockTeamMembersDataWithNoTeamEditors });
useStore.setState({
teamMembers: mockTeamMembersDataWithNoTeamEditors,
user: mockPlatformAdminUser,
});
const { getByText } = await setupTeamMembersScreen();
getByText("No members found");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { EditorUpsertModal } from "../components/EditorUpsertModal";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { emptyTeamMemberObj } from "./mocks/mockUsers";
import {
emptyTeamMemberObj,
mockPlainUser,
mockPlatformAdminUser,
} from "./mocks/mockUsers";

vi.mock(
"pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx",
Expand All @@ -27,7 +31,11 @@ let initialState: FullStore;

describe("when a user presses 'add a new editor'", () => {
beforeEach(async () => {
useStore.setState({ teamMembers: mockTeamMembersData, teamSlug: "planx" });
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlatformAdminUser,
teamSlug: "planx",
});
const { user } = await setupTeamMembersScreen();

const teamEditorsTable = screen.getByTestId("team-editors");
Expand All @@ -45,8 +53,13 @@ describe("when a user presses 'add a new editor'", () => {

describe("when a user fills in the 'add a new editor' form correctly", () => {
afterAll(() => useStore.setState(initialState));

beforeEach(async () => {
useStore.setState({ teamMembers: mockTeamMembersData, teamSlug: "planx" });
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlatformAdminUser,
teamSlug: "planx",
});
const { user } = await setupTeamMembersScreen();
await userTriesToAddNewEditor(user);
});
Expand Down Expand Up @@ -97,6 +110,7 @@ describe("'add a new editor' button is hidden from Templates team", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlatformAdminUser,
teamSlug: "templates",
});
});
Expand All @@ -109,3 +123,21 @@ describe("'add a new editor' button is hidden from Templates team", () => {
expect(addEditorButton).not.toBeInTheDocument();
});
});

describe("when a user is not a platform admin", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlainUser,
teamSlug: "templates",
});
});

it("hides the button from non-admin users", async () => {
const { user: _user } = await setupTeamMembersScreen();
const teamEditorsTable = screen.getByTestId("team-editors");
const addEditorButton =
within(teamEditorsTable).queryByText("Add a new editor");
expect(addEditorButton).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ describe("when a user is not a platform admin", () => {

await setupTeamMembersScreen();
});

it("does not show an edit button", async () => {
const teamEditorsTable = screen.getByTestId("team-editors");
const addEditorButton =
Expand Down
10 changes: 10 additions & 0 deletions editor.planx.uk/src/pages/layout/LoadingLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator";
import React from "react";
import { useLoadingRoute, View } from "react-navi";

export const loadingView = () => <LoadingLayout />;

export const LoadingLayout = () => {
const isLoading = useLoadingRoute();
return isLoading ? <DelayedLoadingIndicator /> : <View />;
};
52 changes: 31 additions & 21 deletions editor.planx.uk/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { lazy, map, mount, redirect, route } from "navi";
import { compose, lazy, map, mount, redirect, route, withView } from "navi";
import { loadingView } from "pages/layout/LoadingLayout";
import * as React from "react";

import { client } from "../lib/graphql";
Expand Down Expand Up @@ -58,27 +59,36 @@ const editorRoutes = mount({

const mountPayRoutes = () =>
map(async () => {
compose(withView(loadingView));
return lazy(() => import("./pay"));
});

export default isPreviewOnlyDomain
? mount({
"/:team/:flow/published": lazy(() => import("./published")), // XXX: keeps old URL working, but only for the team listed in the domain.
"/:flow": lazy(() => import("./published")),
"/:flow/pay": mountPayRoutes(),
// XXX: We're not sure where to redirect `/` to so for now we'll just return the default 404
// "/": redirect("somewhere?"),
})
: mount({
"/:team/:flow/published": lazy(() => import("./published")), // loads current published flow if exists, or throws Not Found if unpublished
"/canterbury/find-out-if-you-need-planning-permission/preview": map(
async (req) =>
redirect(
`/canterbury/find-out-if-you-need-planning-permission/published${req?.search}`,
),
), // temporary redirect while Canterbury works with internal IT to update advertised service links
"/:team/:flow/preview": lazy(() => import("./preview")), // loads current draft flow and latest published external portals, or throws Not Found if any external portal is unpublished
"/:team/:flow/draft": lazy(() => import("./draft")), // loads current draft flow and draft external portals
"/:team/:flow/pay": mountPayRoutes(),
"*": editorRoutes,
});
? compose(
withView(loadingView),

mount({
"/:team/:flow/published": lazy(() => import("./published")), // XXX: keeps old URL working, but only for the team listed in the domain.
"/:flow": lazy(() => import("./published")),
"/:flow/pay": mountPayRoutes(),
// XXX: We're not sure where to redirect `/` to so for now we'll just return the default 404
// "/": redirect("somewhere?"),
}),
)
: compose(
withView(loadingView),

mount({
"/:team/:flow/published": lazy(() => import("./published")), // loads current published flow if exists, or throws Not Found if unpublished
"/canterbury/find-out-if-you-need-planning-permission/preview": map(
async (req) =>
redirect(
`/canterbury/find-out-if-you-need-planning-permission/published${req?.search}`,
),
), // temporary redirect while Canterbury works with internal IT to update advertised service links
"/:team/:flow/preview": lazy(() => import("./preview")), // loads current draft flow and latest published external portals, or throws Not Found if any external portal is unpublished
"/:team/:flow/draft": lazy(() => import("./draft")), // loads current draft flow and draft external portals
"/:team/:flow/pay": mountPayRoutes(),
"*": editorRoutes,
}),
);