Skip to content

feat: show summary if unable to edit org #14214

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

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: show summary if unable to edit org
This can happen if you can edit the members, for example, but not the
organization settings.  In this case you will see a new summary page
instead of the edit form.
  • Loading branch information
code-asher committed Aug 9, 2024
commit 8da0a3a706a3fefdd1a9040d4858f58dcf3ffcb6
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,24 @@ describe("OrganizationSettingsPage", () => {
await renderPage("the-endless-void");
await screen.findByText("Organization not found");
});

it("cannot edit organization", async () => {
server.use(
http.get("/api/v2/organizations", () => {
return HttpResponse.json([MockDefaultOrganization]);
}),
http.post("/api/v2/authcheck", async () => {
return HttpResponse.json({
viewDeploymentValues: true,
});
}),
);
// No form since they cannot edit, instead sees the summary view.
await renderPage(MockDefaultOrganization.name);
expect(screen.queryByTestId("org-settings-form")).not.toBeInTheDocument();
await screen.findByRole("heading", {
level: 1,
name: MockDefaultOrganization.display_name,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useOrganizationSettings,
} from "./ManagementSettingsLayout";
import { OrganizationSettingsPageView } from "./OrganizationSettingsPageView";
import { OrganizationSummaryPageView } from "./OrganizationSummaryPageView";

const OrganizationSettingsPage: FC = () => {
const { organization: organizationName } = useParams() as {
Expand Down Expand Up @@ -65,12 +66,18 @@ const OrganizationSettingsPage: FC = () => {
return <EmptyState message="Organization not found" />;
}

// The user may not be able to edit this org but they can still see it because
// they can edit members, etc. In this case they will be shown a read-only
// summary page instead of the settings form.
if (!permissions[organization.id]?.editOrganization) {
return <OrganizationSummaryPageView organization={organization} />;
}

const error =
updateOrganizationMutation.error ?? deleteOrganizationMutation.error;

return (
<OrganizationSettingsPageView
canEdit={permissions[organization.id]?.editOrganization ?? false}
organization={organization}
error={error}
onSubmit={async (values) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const meta: Meta<typeof OrganizationSettingsPageView> = {
component: OrganizationSettingsPageView,
args: {
organization: MockOrganization,
canEdit: true,
},
};

Expand All @@ -24,9 +23,3 @@ export const DefaultOrg: Story = {
organization: MockDefaultOrganization,
},
};

export const CannotEdit: Story = {
args: {
canEdit: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ interface OrganizationSettingsPageViewProps {
error: unknown;
onSubmit: (values: UpdateOrganizationRequest) => Promise<void>;
onDeleteOrganization: () => void;
canEdit: boolean;
}

export const OrganizationSettingsPageView: FC<
OrganizationSettingsPageViewProps
> = ({ organization, error, onSubmit, onDeleteOrganization, canEdit }) => {
> = ({ organization, error, onSubmit, onDeleteOrganization }) => {
const form = useFormik<UpdateOrganizationRequest>({
initialValues: {
name: organization.name,
Expand Down Expand Up @@ -85,7 +84,7 @@ export const OrganizationSettingsPageView: FC<
description="The name and description of the organization."
>
<fieldset
disabled={form.isSubmitting || !canEdit}
disabled={form.isSubmitting}
css={{ border: "unset", padding: 0, margin: 0, width: "100%" }}
>
<FormFields>
Expand Down Expand Up @@ -117,10 +116,10 @@ export const OrganizationSettingsPageView: FC<
</FormFields>
</fieldset>
</FormSection>
{canEdit && <FormFooter isLoading={form.isSubmitting} />}
<FormFooter isLoading={form.isSubmitting} />
</HorizontalForm>

{canEdit && !organization.is_default && (
{!organization.is_default && (
<HorizontalContainer css={{ marginTop: 48 }}>
<HorizontalSection
title="Settings"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from "@storybook/react";
import {
MockDefaultOrganization,
MockOrganization,
} from "testHelpers/entities";
import { OrganizationSummaryPageView } from "./OrganizationSummaryPageView";

const meta: Meta<typeof OrganizationSummaryPageView> = {
title: "pages/OrganizationSummaryPageView",
component: OrganizationSummaryPageView,
args: {
organization: MockOrganization,
},
};

export default meta;
type Story = StoryObj<typeof OrganizationSummaryPageView>;

export const DefaultOrg: Story = {
args: {
organization: MockDefaultOrganization,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { FC } from "react";
import type { Organization } from "api/typesGenerated";
import {
PageHeader,
PageHeaderTitle,
PageHeaderSubtitle,
} from "components/PageHeader/PageHeader";
import { Stack } from "components/Stack/Stack";
import { UserAvatar } from "components/UserAvatar/UserAvatar";

interface OrganizationSummaryPageViewProps {
organization: Organization;
}

export const OrganizationSummaryPageView: FC<
OrganizationSummaryPageViewProps
> = (props) => {
return (
<div>
<PageHeader
css={{
// The deployment settings layout already has padding.
paddingTop: 0,
}}
>
<Stack direction="row" spacing={3} alignItems="center">
<UserAvatar
key={props.organization.id}
size="xl"
username={
props.organization.display_name || props.organization.name
}
avatarURL={props.organization.icon}
/>
<div>
<PageHeaderTitle>
{props.organization.display_name || props.organization.name}
</PageHeaderTitle>
{props.organization.description && (
<PageHeaderSubtitle>
{props.organization.description}
</PageHeaderSubtitle>
)}
</div>
</Stack>
</PageHeader>
You are a member of this organization.
</div>
);
};