Fix app iframe resolution (#2111)
* Fix app frame sizes * Update app frame height * App page functions refactor * Move useLocationState hook to apps * Update apps test snapshots
This commit is contained in:
parent
1c131053d6
commit
079c25f16d
7 changed files with 47 additions and 17 deletions
10
package-lock.json
generated
10
package-lock.json
generated
|
@ -10097,7 +10097,7 @@
|
||||||
"buffer-crc32": {
|
"buffer-crc32": {
|
||||||
"version": "0.2.13",
|
"version": "0.2.13",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
||||||
"integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
|
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"buffer-equal-constant-time": {
|
"buffer-equal-constant-time": {
|
||||||
|
@ -14970,7 +14970,7 @@
|
||||||
"pify": {
|
"pify": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||||
"integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==",
|
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15453,7 +15453,7 @@
|
||||||
"fd-slicer": {
|
"fd-slicer": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
|
||||||
"integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==",
|
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
|
@ -23602,7 +23602,7 @@
|
||||||
"ospath": {
|
"ospath": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz",
|
||||||
"integrity": "sha512-o6E5qJV5zkAbIDNhGSIlyOhScKXgQrSRMilfph0clDfM0nEnBOlKlH4sWDmG95BW/CvwNz0vmm7dJVtU2KlMiA==",
|
"integrity": "sha1-EnZjl3Sj+O8lcvf+QoDg6kVQwHs=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"p-cancelable": {
|
"p-cancelable": {
|
||||||
|
@ -24155,7 +24155,7 @@
|
||||||
"pend": {
|
"pend": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
||||||
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
|
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"performance-now": {
|
"performance-now": {
|
||||||
|
|
|
@ -87,7 +87,6 @@ export const AppPage: React.FC<AppPageProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<CardSpacer />
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,10 +51,15 @@ export const useStyles = makeStyles(
|
||||||
width: "100%",
|
width: "100%",
|
||||||
},
|
},
|
||||||
iframeContainer: {
|
iframeContainer: {
|
||||||
|
lineHeight: 0, // It removes extra space between iframe and container
|
||||||
"& > iframe": {
|
"& > iframe": {
|
||||||
border: "none",
|
border: "none",
|
||||||
minHeight: "75vh",
|
minHeight: "60vh",
|
||||||
|
height: `calc(100vh - 27.8rem)`,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
[theme.breakpoints.up("md")]: {
|
||||||
|
height: `calc(100vh - 23.4rem)`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
18
src/apps/hooks/useLocationState.ts
Normal file
18
src/apps/hooks/useLocationState.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { appsSection } from "@saleor/apps/urls";
|
||||||
|
import { matchPath, useLocation } from "react-router";
|
||||||
|
|
||||||
|
const isAppPath = (pathname: string) =>
|
||||||
|
!!matchPath(pathname, {
|
||||||
|
path: `${appsSection}:id`,
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use detailed information about the current location.
|
||||||
|
*/
|
||||||
|
export const useLocationState = () => {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
return {
|
||||||
|
isAppPath: isAppPath(location.pathname),
|
||||||
|
};
|
||||||
|
};
|
|
@ -12,6 +12,7 @@ import {
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@saleor/macaw-ui";
|
} from "@saleor/macaw-ui";
|
||||||
import { isDarkTheme } from "@saleor/misc";
|
import { isDarkTheme } from "@saleor/misc";
|
||||||
|
import classNames from "classnames";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import useRouter from "use-react-router";
|
import useRouter from "use-react-router";
|
||||||
|
@ -99,6 +100,8 @@ const useStyles = makeStyles(
|
||||||
|
|
||||||
view: {
|
view: {
|
||||||
marginLeft: 0,
|
marginLeft: 0,
|
||||||
|
},
|
||||||
|
viewMargins: {
|
||||||
paddingBottom: theme.spacing(),
|
paddingBottom: theme.spacing(),
|
||||||
[theme.breakpoints.up("sm")]: {
|
[theme.breakpoints.up("sm")]: {
|
||||||
paddingBottom: theme.spacing(3),
|
paddingBottom: theme.spacing(3),
|
||||||
|
@ -117,10 +120,14 @@ const useStyles = makeStyles(
|
||||||
|
|
||||||
interface AppLayoutProps {
|
interface AppLayoutProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
fullSize?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppLayout: React.FC<AppLayoutProps> = ({ children }) => {
|
const AppLayout: React.FC<AppLayoutProps> = ({
|
||||||
const classes = useStyles({});
|
children,
|
||||||
|
fullSize = false,
|
||||||
|
}) => {
|
||||||
|
const classes = useStyles();
|
||||||
const { themeType, setTheme } = useTheme();
|
const { themeType, setTheme } = useTheme();
|
||||||
const { anchor: appActionAnchor } = useActionBar();
|
const { anchor: appActionAnchor } = useActionBar();
|
||||||
const appHeaderAnchor = useBacklink();
|
const appHeaderAnchor = useBacklink();
|
||||||
|
@ -222,7 +229,11 @@ const AppLayout: React.FC<AppLayoutProps> = ({ children }) => {
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
</div>
|
</div>
|
||||||
<main className={classes.view}>
|
<main
|
||||||
|
className={classNames(classes.view, {
|
||||||
|
[classes.viewMargins]: !fullSize,
|
||||||
|
})}
|
||||||
|
>
|
||||||
{appState.error
|
{appState.error
|
||||||
? appState.error.type === "unhandled" && (
|
? appState.error.type === "unhandled" && (
|
||||||
<ErrorPage
|
<ErrorPage
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { BrowserRouter, Route, Switch } from "react-router-dom";
|
||||||
|
|
||||||
import AppsSection from "./apps";
|
import AppsSection from "./apps";
|
||||||
import { ExternalAppProvider } from "./apps/components/ExternalAppContext";
|
import { ExternalAppProvider } from "./apps/components/ExternalAppContext";
|
||||||
|
import { useLocationState } from "./apps/hooks/useLocationState";
|
||||||
import { appsSection } from "./apps/urls";
|
import { appsSection } from "./apps/urls";
|
||||||
import AttributeSection from "./attributes";
|
import AttributeSection from "./attributes";
|
||||||
import { attributeSection } from "./attributes/urls";
|
import { attributeSection } from "./attributes/urls";
|
||||||
|
@ -121,12 +122,14 @@ const Routes: React.FC = () => {
|
||||||
|
|
||||||
const homePageLoading = (authenticated && !channelLoaded) || authenticating;
|
const homePageLoading = (authenticated && !channelLoaded) || authenticating;
|
||||||
|
|
||||||
|
const { isAppPath } = useLocationState();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={intl.formatMessage(commonMessages.dashboard)} />
|
<WindowTitle title={intl.formatMessage(commonMessages.dashboard)} />
|
||||||
{DEMO_MODE && <DemoBanner />}
|
{DEMO_MODE && <DemoBanner />}
|
||||||
{homePageLoaded ? (
|
{homePageLoaded ? (
|
||||||
<AppLayout>
|
<AppLayout fullSize={isAppPath}>
|
||||||
<ErrorBoundary
|
<ErrorBoundary
|
||||||
onError={e => {
|
onError={e => {
|
||||||
const errorId = errorTracker.captureException(e);
|
const errorId = errorTracker.captureException(e);
|
||||||
|
|
|
@ -24713,9 +24713,6 @@ exports[`Storyshots Views / Apps / App default 1`] = `
|
||||||
<div
|
<div
|
||||||
class="AppPage-iframeContainer-id"
|
class="AppPage-iframeContainer-id"
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
class="CardSpacer-spacer-id"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -25111,9 +25108,6 @@ exports[`Storyshots Views / Apps / App settings 1`] = `
|
||||||
<div
|
<div
|
||||||
class="AppPage-iframeContainer-id"
|
class="AppPage-iframeContainer-id"
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
class="CardSpacer-spacer-id"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in a new issue