- Notifications
You must be signed in to change notification settings - Fork928
chore: consolidateManageSettingsLayout
code#14885
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
bf9ab32
05d1e80
602ffab
88bc231
445b82e
183c5db
c8eaa77
f4beba0
3af9601
16f6650
932f829
4288004
62b4575
6581e8d
0719fbd
6fea1be
fc7732c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
import type { DeploymentConfig } from "api/api"; | ||
import { deploymentConfig } from "api/queries/deployment"; | ||
import type { AuthorizationResponse, Organization } from "api/typesGenerated"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { Margins } from "components/Margins/Margins"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
import { RequirePermission } from "contexts/auth/RequirePermission"; | ||
import { useDashboard } from "modules/dashboard/useDashboard"; | ||
import { type FC, Suspense, createContext, useContext } from "react"; | ||
import { useQuery } from "react-query"; | ||
import { Outlet, useParams } from "react-router-dom"; | ||
import { Sidebar } from "./Sidebar"; | ||
export const ManagementSettingsContext = createContext< | ||
ManagementSettingsValue | undefined | ||
>(undefined); | ||
type ManagementSettingsValue = Readonly<{ | ||
aslilac marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
deploymentValues: DeploymentConfig; | ||
organizations: readonly Organization[]; | ||
organization?: Organization; | ||
}>; | ||
export const useManagementSettings = (): ManagementSettingsValue => { | ||
const context = useContext(ManagementSettingsContext); | ||
if (!context) { | ||
throw new Error( | ||
"useManagementSettings should be used inside of ManagementSettingsLayout", | ||
); | ||
} | ||
return context; | ||
}; | ||
/** | ||
@@ -43,13 +56,11 @@ export const canEditOrganization = ( | ||
*/ | ||
export const ManagementSettingsLayout: FC = () => { | ||
const { permissions } = useAuthenticated(); | ||
const deploymentConfigQuery = useQuery(deploymentConfig()); | ||
const { organizations } = useDashboard(); | ||
const { organization: orgName } = useParams() as { | ||
organization?: string; | ||
}; | ||
// The deployment settings page also contains users, audit logs, groups and | ||
// organizations, so this page must be visible if you can see any of these. | ||
@@ -59,24 +70,39 @@ export const ManagementSettingsLayout: FC = () => { | ||
permissions.editAnyOrganization || | ||
permissions.viewAnyAuditLog; | ||
if (deploymentConfigQuery.error) { | ||
return <ErrorAlert error={deploymentConfigQuery.error} />; | ||
} | ||
if (!deploymentConfigQuery.data) { | ||
return <Loader />; | ||
} | ||
const organization = | ||
organizations && orgName | ||
? organizations.find((org) => org.name === orgName) | ||
: undefined; | ||
return ( | ||
<RequirePermission isFeatureVisible={canViewDeploymentSettingsPage}> | ||
<ManagementSettingsContext.Provider | ||
value={{ | ||
deploymentValues: deploymentConfigQuery.data, | ||
organizations, | ||
organization, | ||
}} | ||
> | ||
<Margins> | ||
<Stack css={{ padding: "48px 0" }} direction="row" spacing={6}> | ||
<Sidebar /> | ||
<main css={{ width: "100%" }}> | ||
<Suspense fallback={<Loader />}> | ||
<Outlet /> | ||
</Suspense> | ||
</main> | ||
</Stack> | ||
</Margins> | ||
</ManagementSettingsContext.Provider> | ||
</RequirePermission> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -31,8 +31,6 @@ interface SidebarProps { | ||
organizations: OrganizationWithPermissions[] | undefined; | ||
/** Site-wide permissions. */ | ||
permissions: AuthorizationResponse; | ||
} | ||
/** | ||
@@ -43,25 +41,29 @@ export const SidebarView: FC<SidebarProps> = ({ | ||
activeOrganizationName, | ||
organizations, | ||
permissions, | ||
}) => { | ||
const { showOrganizations } = useDashboard(); | ||
// TODO: Do something nice to scroll to the active org. | ||
return ( | ||
<BaseSidebar> | ||
{showOrganizations && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Why would showOrganizations need to be true to show only the Deployment header? Is there some reason to show DeploymentSettingsNavigation without the Header text? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. it just looks weird for it to say deployment twice without the organizations section below. it's weird, but we'll get rid of this when we adopt the designs we went over with Christin. | ||
<header> | ||
<h2 css={styles.sidebarHeader}>Deployment</h2> | ||
</header> | ||
)} | ||
<DeploymentSettingsNavigation | ||
active={!activeOrganizationName && activeSettings} | ||
permissions={permissions} | ||
/> | ||
{showOrganizations && ( | ||
<OrganizationsSettingsNavigation | ||
activeOrganizationName={activeOrganizationName} | ||
organizations={organizations} | ||
permissions={permissions} | ||
/> | ||
)} | ||
</BaseSidebar> | ||
); | ||
}; | ||
@@ -71,8 +73,6 @@ interface DeploymentSettingsNavigationProps { | ||
active: boolean; | ||
/** Site-wide permissions. */ | ||
permissions: AuthorizationResponse; | ||
} | ||
/** | ||
@@ -85,7 +85,6 @@ interface DeploymentSettingsNavigationProps { | ||
const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({ | ||
active, | ||
permissions, | ||
}) => { | ||
return ( | ||
<div css={{ paddingBottom: 12 }}> | ||
@@ -144,16 +143,14 @@ const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({ | ||
</SidebarNavSubItem> | ||
)} | ||
{permissions.viewAllUsers && ( | ||
<SidebarNavSubItem href="users">Users</SidebarNavSubItem> | ||
)} | ||
<SidebarNavSubItem href="notifications"> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<span>Notifications</span> | ||
<FeatureStageBadge contentType="beta" size="sm" /> | ||
</Stack> | ||
</SidebarNavSubItem> | ||
</Stack> | ||
)} | ||
</div> | ||
@@ -387,49 +384,49 @@ const styles = { | ||
const classNames = { | ||
link: (css, theme) => css` | ||
color: inherit; | ||
display: block; | ||
font-size: 14px; | ||
text-decoration: none; | ||
padding: 10px 12px 10px 16px; | ||
border-radius: 4px; | ||
transition: background-color 0.15s ease-in-out; | ||
position: relative; | ||
&:hover { | ||
background-color: ${theme.palette.action.hover}; | ||
} | ||
border-left: 3px solid transparent; | ||
`, | ||
activeLink: (css, theme) => css` | ||
border-left-color: ${theme.palette.primary.main}; | ||
border-top-left-radius: 0; | ||
border-bottom-left-radius: 0; | ||
`, | ||
subLink: (css, theme) => css` | ||
color: ${theme.palette.text.secondary}; | ||
text-decoration: none; | ||
display: block; | ||
font-size: 13px; | ||
margin-left: 44px; | ||
padding: 4px 12px; | ||
border-radius: 4px; | ||
transition: background-color 0.15s ease-in-out; | ||
margin-bottom: 1px; | ||
position: relative; | ||
&:hover { | ||
color: ${theme.palette.text.primary}; | ||
background-color: ${theme.palette.action.hover}; | ||
} | ||
`, | ||
activeSubLink: (css, theme) => css` | ||
color: ${theme.palette.text.primary}; | ||
font-weight: 600; | ||
`, | ||
} satisfies Record<string, ClassName>; |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.