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

Fix Custom Views issues #3343

Merged
merged 5 commits into from
Dec 13, 2023
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
6 changes: 6 additions & 0 deletions .changeset/olive-pots-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-frontend/application-components': patch
'@commercetools-frontend/application-shell': patch
---

Fixes for Custom Views related to styling issues when using Page Layout components and inner routing.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { designTokens as appKitDesignTokens } from '../../theming';

export const ContentWrapper = styled.div`
flex: 1;
flex-basis: 0;
flex-basis: 0%;
margin: ${appKitDesignTokens.marginForPageContent};
overflow: auto;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Divider = styled.hr`

export const MainPageContent = styled.div`
flex: 1;
flex-basis: 0;
flex-basis: 0%;
overflow: auto;
// NOTE: do not change to "padding" as this breaks sticky DataTable styles
margin: ${appKitDesignTokens.marginForPageContent};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { type ReactNode } from 'react';
import { PageUnauthorized } from '@commercetools-frontend/application-components';
import {
PageUnauthorized,
themesOverrides,
} from '@commercetools-frontend/application-components';
import { entryPointUriPathToPermissionKeys } from '@commercetools-frontend/application-config/ssr';
import { ApplicationContextProvider } from '@commercetools-frontend/application-shell-connectors';
import {
CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH,
type ApplicationWindow,
type CustomViewData,
} from '@commercetools-frontend/constants';
import { CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH } from '@commercetools-frontend/constants';
import {
AsyncLocaleData,
type TAsyncLocaleDataProps,
Expand Down Expand Up @@ -79,7 +82,10 @@ function CustomViewShellAuthenticated(
environment={props.environment}
>
<>
<ThemeProvider theme="default" />
<ThemeProvider
theme="default"
themeOverrides={themesOverrides.default}
/>

<FetchProject projectKey={props.projectKey}>
{({ isLoading: isProjectLoading, project }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ import {
Suspense,
StrictMode,
type ReactNode,
RefObject,
} from 'react';
import { ApolloClient, type NormalizedCacheObject } from '@apollo/client';
import { PageUnauthorized } from '@commercetools-frontend/application-components';
import { Route } from 'react-router-dom';
import {
PageUnauthorized,
PortalsContainer,
} from '@commercetools-frontend/application-components';
import { CustomViewContextProvider } from '@commercetools-frontend/application-shell-connectors';
import {
type ApplicationWindow,
CUSTOM_VIEWS_EVENTS_NAMES,
CustomViewData,
DOMAINS,
} from '@commercetools-frontend/constants';
import {
AsyncLocaleData,
type TAsyncLocaleDataProps,
} from '@commercetools-frontend/i18n';
import { NotificationsList } from '@commercetools-frontend/react-notifications';
import ApplicationLoader from '../application-loader/application-loader';
import ApplicationShellProvider from '../application-shell-provider';
import { getBrowserLocale } from '../application-shell-provider/utils';
Expand Down Expand Up @@ -59,6 +66,33 @@ type TStrictModeEnablementProps = {
children?: ReactNode;
};

type TNotificationsContainerProps = {
notificationsGlobalRef: RefObject<HTMLDivElement>;
notificationsPageRef: RefObject<HTMLDivElement>;
};
function NotificationsContainer(props: TNotificationsContainerProps) {
return (
<>
<div
ref={props.notificationsGlobalRef}
role="region"
aria-live="polite"
style={{
gridRow: 1,
gridColumn: '1/3',
}}
>
<div id="above-top-navigation" />
<NotificationsList domain={DOMAINS.GLOBAL} />
</div>
<div ref={props.notificationsPageRef}>
<NotificationsList domain={DOMAINS.PAGE} />
</div>
<NotificationsList domain={DOMAINS.SIDE} />
</>
);
}

function StrictModeEnablement(props: TStrictModeEnablementProps) {
if (props.enableReactStrictMode) {
return <StrictMode>{props.children}</StrictMode>;
Expand All @@ -70,6 +104,15 @@ function StrictModeEnablement(props: TStrictModeEnablementProps) {
function CustomViewShell(props: TCustomViewShellProps) {
const [hostContext, setHostContext] = useState<THostContext>();
const iFrameCommunicationPort = useRef<MessagePort>();
const notificationsGlobalRef = useRef<HTMLDivElement>(null);
const notificationsPageRef = useRef<HTMLDivElement>(null);
const layoutRefs = useRef<{
notificationsGlobalRef: RefObject<HTMLDivElement>;
notificationsPageRef: RefObject<HTMLDivElement>;
}>({
notificationsGlobalRef,
notificationsPageRef,
});

const hostMessageHandler = useCallback(
(event: MessageEvent<THostEventData>) => {
Expand Down Expand Up @@ -152,7 +195,20 @@ function CustomViewShell(props: TCustomViewShellProps) {
projectKey={hostContext.projectKey}
customViewConfig={hostContext.customViewConfig}
>
{props.children}
<PortalsContainer
// @ts-ignore
ref={layoutRefs}
/>
<NotificationsContainer
notificationsGlobalRef={notificationsGlobalRef}
notificationsPageRef={notificationsPageRef}
/>

<Route
path={`/custom-views/${hostContext.customViewConfig.id}/projects/${hostContext.projectKey}`}
>
{props.children}
</Route>
</CustomViewShellAuthenticated>
</CustomViewContextProvider>
);
Expand Down
Loading