Do not show sidebar if it is not needed (#3198)
This commit is contained in:
parent
6434f277e8
commit
0f81e158ce
17 changed files with 266 additions and 203 deletions
|
@ -36,7 +36,7 @@ export const CategoryCreatePage: React.FC<CategoryCreatePageProps> = ({
|
||||||
return (
|
return (
|
||||||
<CategoryCreateForm onSubmit={onSubmit} disabled={disabled}>
|
<CategoryCreateForm onSubmit={onSubmit} disabled={disabled}>
|
||||||
{({ data, change, handlers, submit, isSaveDisabled }) => (
|
{({ data, change, handlers, submit, isSaveDisabled }) => (
|
||||||
<DetailedContent>
|
<DetailedContent useSingleColumn>
|
||||||
<TopNav
|
<TopNav
|
||||||
href={backUrl}
|
href={backUrl}
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
|
|
|
@ -91,7 +91,7 @@ export const CategoryUpdatePage: React.FC<CategoryUpdatePageProps> = ({
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
{({ data, change, handlers, submit, isSaveDisabled }) => (
|
{({ data, change, handlers, submit, isSaveDisabled }) => (
|
||||||
<DetailedContent>
|
<DetailedContent useSingleColumn>
|
||||||
<TopNav href={backHref} title={category?.name} />
|
<TopNav href={backHref} title={category?.name} />
|
||||||
<Content>
|
<Content>
|
||||||
<CategoryDetailsForm
|
<CategoryDetailsForm
|
||||||
|
|
|
@ -60,8 +60,7 @@ const AppLayout: React.FC<AppLayoutProps> = ({ children }) => {
|
||||||
borderColor="neutralPlain"
|
borderColor="neutralPlain"
|
||||||
__maxWidth={contentMaxWidth}
|
__maxWidth={contentMaxWidth}
|
||||||
margin="auto"
|
margin="auto"
|
||||||
// @ts-ignore
|
zIndex="3"
|
||||||
__zIndex="3"
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
@ -1,17 +1,27 @@
|
||||||
import { Box } from "@saleor/macaw-ui/next";
|
import { Box } from "@saleor/macaw-ui/next";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { borderHeight, savebarHeight, topBarHeight } from "./consts";
|
import { useContentHeight } from "./useContentHeight";
|
||||||
|
|
||||||
interface ContentProps {
|
interface ContentProps {
|
||||||
[key: `data-${string}`]: string;
|
[key: `data-${string}`]: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
noSavebar?: boolean;
|
||||||
|
noTopNav?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Content: React.FC<ContentProps> = ({ children, ...rest }) => (
|
export const Content: React.FC<ContentProps> = ({
|
||||||
|
children,
|
||||||
|
noSavebar = false,
|
||||||
|
noTopNav = false,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
|
const { withoutSaveBar, withSaveBar } = useContentHeight();
|
||||||
|
|
||||||
|
return (
|
||||||
<Box
|
<Box
|
||||||
__gridArea="content"
|
__gridArea="content"
|
||||||
__height={`calc(100vh - ${topBarHeight} - ${savebarHeight} - ${borderHeight})`}
|
__height={noSavebar ? withoutSaveBar() : withSaveBar({ noTopNav })}
|
||||||
overflowY="auto"
|
overflowY="auto"
|
||||||
className="hide-scrollbar"
|
className="hide-scrollbar"
|
||||||
{...rest}
|
{...rest}
|
||||||
|
@ -19,3 +29,4 @@ export const Content: React.FC<ContentProps> = ({ children, ...rest }) => (
|
||||||
{children}
|
{children}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -7,17 +7,21 @@ import { borderHeight, savebarHeight } from "./consts";
|
||||||
interface RightSidebarProps {
|
interface RightSidebarProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
noSavebar?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RightSidebar: React.FC<RightSidebarProps> = ({
|
export const RightSidebar: React.FC<RightSidebarProps> = ({
|
||||||
children,
|
children,
|
||||||
|
noSavebar = false,
|
||||||
className,
|
className,
|
||||||
}) => (
|
}) => (
|
||||||
<Box
|
<Box
|
||||||
borderStyle="solid"
|
borderStyle="solid"
|
||||||
borderColor="neutralPlain"
|
borderColor="neutralPlain"
|
||||||
borderLeftWidth={1}
|
borderLeftWidth={1}
|
||||||
__height={`calc(100vh - ${savebarHeight} - ${borderHeight})`}
|
__height={
|
||||||
|
noSavebar ? "100%" : `calc(100vh - ${savebarHeight} - ${borderHeight})`
|
||||||
|
}
|
||||||
position="sticky"
|
position="sticky"
|
||||||
top={0}
|
top={0}
|
||||||
overflowY="auto"
|
overflowY="auto"
|
||||||
|
|
24
src/components/AppLayout/useContentHeight.test.ts
Normal file
24
src/components/AppLayout/useContentHeight.test.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { useContentHeight } from "./useContentHeight";
|
||||||
|
|
||||||
|
describe("useContentHeight", () => {
|
||||||
|
it("should return the correct height without savebar", () => {
|
||||||
|
const { withoutSaveBar } = useContentHeight();
|
||||||
|
const height = withoutSaveBar();
|
||||||
|
|
||||||
|
expect(height).toEqual("calc(100vh - 77px - 1px)");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the correct height with savebar", () => {
|
||||||
|
const { withSaveBar } = useContentHeight();
|
||||||
|
const height = withSaveBar({ noTopNav: false });
|
||||||
|
|
||||||
|
expect(height).toEqual("calc(100vh - 77px - 64px - 1px)");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the correct height with savebar and no top nav", () => {
|
||||||
|
const { withSaveBar } = useContentHeight();
|
||||||
|
const height = withSaveBar({ noTopNav: true });
|
||||||
|
|
||||||
|
expect(height).toEqual("calc(100vh - 0px - 64px - 1px)");
|
||||||
|
});
|
||||||
|
});
|
14
src/components/AppLayout/useContentHeight.ts
Normal file
14
src/components/AppLayout/useContentHeight.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { borderHeight, savebarHeight, topBarHeight } from "./consts";
|
||||||
|
|
||||||
|
export const useContentHeight = () => {
|
||||||
|
const withoutSaveBar = () =>
|
||||||
|
`calc(100vh - ${topBarHeight} - ${borderHeight})`;
|
||||||
|
|
||||||
|
const withSaveBar = ({ noTopNav }) => {
|
||||||
|
const topHeight = noTopNav ? "0px" : topBarHeight;
|
||||||
|
|
||||||
|
return `calc(100vh - ${topHeight} - ${savebarHeight} - ${borderHeight})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return { withoutSaveBar, withSaveBar };
|
||||||
|
};
|
|
@ -99,7 +99,7 @@ export const ConfigurationPage: React.FC<ConfigurationPageProps> = props => {
|
||||||
<TopNav title={intl.formatMessage(sectionNames.configuration)}>
|
<TopNav title={intl.formatMessage(sectionNames.configuration)}>
|
||||||
{isSmUp && renderVersionInfo}
|
{isSmUp && renderVersionInfo}
|
||||||
</TopNav>
|
</TopNav>
|
||||||
<Content>
|
<Content noSavebar>
|
||||||
<Box paddingX={9} __maxWidth={"1024px"} margin="auto">
|
<Box paddingX={9} __maxWidth={"1024px"} margin="auto">
|
||||||
{menus
|
{menus
|
||||||
.filter(menu =>
|
.filter(menu =>
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { Content } from "@dashboard/components/AppLayout/Content";
|
import {
|
||||||
|
borderHeight,
|
||||||
|
topBarHeight,
|
||||||
|
} from "@dashboard/components/AppLayout/consts";
|
||||||
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
||||||
import { Button } from "@dashboard/components/Button";
|
import { Button } from "@dashboard/components/Button";
|
||||||
import { TableButtonWrapper } from "@dashboard/components/TableButtonWrapper/TableButtonWrapper";
|
import { TableButtonWrapper } from "@dashboard/components/TableButtonWrapper/TableButtonWrapper";
|
||||||
|
@ -46,8 +49,10 @@ const CustomAppListPage: React.FC<CustomAppListPageProps> = ({
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</TopNav>
|
</TopNav>
|
||||||
<Content>
|
<Box
|
||||||
<Box padding={9}>
|
padding={9}
|
||||||
|
__height={`calc(100vh - ${topBarHeight} - ${borderHeight})`}
|
||||||
|
>
|
||||||
<Box marginBottom={4}>
|
<Box marginBottom={4}>
|
||||||
<Text as="p">
|
<Text as="p">
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -111,7 +116,6 @@ const CustomAppListPage: React.FC<CustomAppListPageProps> = ({
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</ResponsiveTable>
|
</ResponsiveTable>
|
||||||
</Box>
|
</Box>
|
||||||
</Content>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { createCountryHandler } from "@dashboard/components/AddressEdit/createCountryHandler";
|
import { createCountryHandler } from "@dashboard/components/AddressEdit/createCountryHandler";
|
||||||
import { Content } from "@dashboard/components/AppLayout/Content";
|
import { Content } from "@dashboard/components/AppLayout/Content";
|
||||||
|
import { DetailedContent } from "@dashboard/components/AppLayout/DetailedContent";
|
||||||
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
||||||
import { CardSpacer } from "@dashboard/components/CardSpacer";
|
import { CardSpacer } from "@dashboard/components/CardSpacer";
|
||||||
import Form from "@dashboard/components/Form";
|
import Form from "@dashboard/components/Form";
|
||||||
import Grid from "@dashboard/components/Grid";
|
|
||||||
import Savebar from "@dashboard/components/Savebar";
|
import Savebar from "@dashboard/components/Savebar";
|
||||||
import { customerListUrl } from "@dashboard/customers/urls";
|
import { customerListUrl } from "@dashboard/customers/urls";
|
||||||
import {
|
import {
|
||||||
|
@ -152,7 +152,7 @@ const CustomerCreatePage: React.FC<CustomerCreatePageProps> = ({
|
||||||
const handleCountrySelect = createCountryHandler(countrySelect, set);
|
const handleCountrySelect = createCountryHandler(countrySelect, set);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<DetailedContent useSingleColumn>
|
||||||
<TopNav
|
<TopNav
|
||||||
href={customerListUrl()}
|
href={customerListUrl()}
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
|
@ -162,7 +162,6 @@ const CustomerCreatePage: React.FC<CustomerCreatePageProps> = ({
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Content>
|
<Content>
|
||||||
<Grid>
|
|
||||||
<div>
|
<div>
|
||||||
<CustomerCreateDetails
|
<CustomerCreateDetails
|
||||||
data={data}
|
data={data}
|
||||||
|
@ -188,7 +187,6 @@ const CustomerCreatePage: React.FC<CustomerCreatePageProps> = ({
|
||||||
onChange={change}
|
onChange={change}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
|
||||||
<Savebar
|
<Savebar
|
||||||
disabled={isSaveDisabled}
|
disabled={isSaveDisabled}
|
||||||
state={saveButtonBar}
|
state={saveButtonBar}
|
||||||
|
@ -196,7 +194,7 @@ const CustomerCreatePage: React.FC<CustomerCreatePageProps> = ({
|
||||||
onCancel={() => navigate(customerListUrl())}
|
onCancel={() => navigate(customerListUrl())}
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>
|
||||||
</>
|
</DetailedContent>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
@ -80,7 +80,7 @@ const HomePage: React.FC<HomePageProps> = props => {
|
||||||
return (
|
return (
|
||||||
<DetailedContent>
|
<DetailedContent>
|
||||||
<TopNav title={<HomeHeader userName={userName} />} />
|
<TopNav title={<HomeHeader userName={userName} />} />
|
||||||
<Content>
|
<Content noSavebar>
|
||||||
<Box paddingLeft={9} paddingRight={11}>
|
<Box paddingLeft={9} paddingRight={11}>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<RequirePermissions
|
<RequirePermissions
|
||||||
|
@ -155,7 +155,7 @@ const HomePage: React.FC<HomePageProps> = props => {
|
||||||
</Box>
|
</Box>
|
||||||
</Content>
|
</Content>
|
||||||
{activities && (
|
{activities && (
|
||||||
<RightSidebar>
|
<RightSidebar noSavebar>
|
||||||
<RequirePermissions
|
<RequirePermissions
|
||||||
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
||||||
>
|
>
|
||||||
|
|
|
@ -86,8 +86,8 @@ const MenuDetailsPage: React.FC<MenuDetailsPageProps> = ({
|
||||||
return (
|
return (
|
||||||
<Form confirmLeave initial={initialForm} onSubmit={handleSubmit}>
|
<Form confirmLeave initial={initialForm} onSubmit={handleSubmit}>
|
||||||
{({ change, data, submit }) => (
|
{({ change, data, submit }) => (
|
||||||
<DetailedContent>
|
<DetailedContent useSingleColumn>
|
||||||
<Content>
|
<Content noTopNav>
|
||||||
<Box padding={9} margin="auto" height="100vh">
|
<Box padding={9} margin="auto" height="100vh">
|
||||||
<Backlink href={menuListUrl()}>
|
<Backlink href={menuListUrl()}>
|
||||||
{intl.formatMessage(sectionNames.navigation)}
|
{intl.formatMessage(sectionNames.navigation)}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import {
|
||||||
|
borderHeight,
|
||||||
|
topBarHeight,
|
||||||
|
} from "@dashboard/components/AppLayout/consts";
|
||||||
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
||||||
import { Button } from "@dashboard/components/Button";
|
import { Button } from "@dashboard/components/Button";
|
||||||
import { configurationMenuUrl } from "@dashboard/configuration";
|
import { configurationMenuUrl } from "@dashboard/configuration";
|
||||||
|
@ -5,6 +9,7 @@ import { MenuFragment } from "@dashboard/graphql";
|
||||||
import { sectionNames } from "@dashboard/intl";
|
import { sectionNames } from "@dashboard/intl";
|
||||||
import { menuListUrl, MenuListUrlSortField } from "@dashboard/navigation/urls";
|
import { menuListUrl, MenuListUrlSortField } from "@dashboard/navigation/urls";
|
||||||
import { ListActions, PageListProps, SortPage } from "@dashboard/types";
|
import { ListActions, PageListProps, SortPage } from "@dashboard/types";
|
||||||
|
import { Box } from "@saleor/macaw-ui/next";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
@ -38,7 +43,9 @@ const MenuListPage: React.FC<MenuListPageProps> = ({ ...listProps }) => {
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</TopNav>
|
</TopNav>
|
||||||
|
<Box __height={`calc(100vh - ${topBarHeight} - ${borderHeight})`}>
|
||||||
<MenuList {...listProps} />
|
<MenuList {...listProps} />
|
||||||
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ import TableRowLink from "@dashboard/components/TableRowLink";
|
||||||
import { AttributeFragment, AttributeTypeEnum } from "@dashboard/graphql";
|
import { AttributeFragment, AttributeTypeEnum } from "@dashboard/graphql";
|
||||||
import { renderCollection } from "@dashboard/misc";
|
import { renderCollection } from "@dashboard/misc";
|
||||||
import { ListActions, ReorderAction } from "@dashboard/types";
|
import { ListActions, ReorderAction } from "@dashboard/types";
|
||||||
import { Card, TableCell } from "@material-ui/core";
|
import { Card, CardContent, TableCell } from "@material-ui/core";
|
||||||
import { DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui";
|
import { DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
@ -95,6 +95,7 @@ const PageTypeAttributes: React.FC<PageTypeAttributesProps> = props => {
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<CardContent>
|
||||||
<ResponsiveTable>
|
<ResponsiveTable>
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col className={classes.colGrab} />
|
<col className={classes.colGrab} />
|
||||||
|
@ -182,6 +183,7 @@ const PageTypeAttributes: React.FC<PageTypeAttributesProps> = props => {
|
||||||
)}
|
)}
|
||||||
</SortableTableBody>
|
</SortableTableBody>
|
||||||
</ResponsiveTable>
|
</ResponsiveTable>
|
||||||
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -118,7 +118,7 @@ const PageTypeDetailsPage: React.FC<PageTypeDetailsPageProps> = props => {
|
||||||
const changeMetadata = makeMetadataChangeHandler(change);
|
const changeMetadata = makeMetadataChangeHandler(change);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DetailedContent>
|
<DetailedContent useSingleColumn>
|
||||||
<TopNav href={pageTypeListUrl()} title={pageTitle} />
|
<TopNav href={pageTypeListUrl()} title={pageTitle} />
|
||||||
<Content>
|
<Content>
|
||||||
<Grid
|
<Grid
|
||||||
|
|
|
@ -49,10 +49,10 @@ const ShippingZonesListPage: React.FC<ShippingZonesListPageProps> = ({
|
||||||
description: "header",
|
description: "header",
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Content>
|
<Content noSavebar>
|
||||||
<ShippingZonesList disabled={disabled} {...listProps} />
|
<ShippingZonesList disabled={disabled} {...listProps} />
|
||||||
</Content>
|
</Content>
|
||||||
<RightSidebar>
|
<RightSidebar noSavebar>
|
||||||
<RequirePermissions
|
<RequirePermissions
|
||||||
requiredPermissions={[PermissionEnum.MANAGE_SETTINGS]}
|
requiredPermissions={[PermissionEnum.MANAGE_SETTINGS]}
|
||||||
>
|
>
|
||||||
|
|
|
@ -139,7 +139,7 @@ const SiteSettingsPage: React.FC<SiteSettingsPageProps> = props => {
|
||||||
const handleCountrySelect = createCountryHandler(countrySelect, set);
|
const handleCountrySelect = createCountryHandler(countrySelect, set);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DetailedContent>
|
<DetailedContent useSingleColumn>
|
||||||
<TopNav
|
<TopNav
|
||||||
href={configurationMenuUrl}
|
href={configurationMenuUrl}
|
||||||
title={intl.formatMessage(commonMessages.generalInformations)}
|
title={intl.formatMessage(commonMessages.generalInformations)}
|
||||||
|
|
Loading…
Reference in a new issue