Skip to content

Commit

Permalink
Fix Custom Views issues (#3343)
Browse files Browse the repository at this point in the history
* fix(application-components): fix page layout components ui issues when used within custom views

* refactor(application-shell): wrap custom views within its main route

* refactor(application-shell): include portals-container in custom-view-shell component

* refactor(application-shell): include notifications containers in custom views

* chore: changeset added
  • Loading branch information
CarlosCortizasCT authored Dec 13, 2023
1 parent 5314f16 commit e7b84b1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
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

2 comments on commit e7b84b1

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-i4zew4jzu-commercetools.vercel.app

Built with commit e7b84b1.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for application-kit-custom-views ready!

✅ Preview
https://application-kit-custom-views-m572dld5y-commercetools.vercel.app

Built with commit e7b84b1.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.