Skip to content

Commit f3943e3

Browse files
committed
chore: Wrapping up (type adjustments, snapshot upd)
1 parent 29e7b36 commit f3943e3

File tree

11 files changed

+49
-34
lines changed

11 files changed

+49
-34
lines changed

src/app-layout/__integ__/multi-app-layout-global-drawer-child.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Visual refresh toolbar only', () => {
3333
test(
3434
'global drawers registered from child AppLayout render correctly when __disableRuntimeDrawers is set to true for parent AppLayout',
3535
setupTest(async page => {
36-
await expect(page.isDisplayed(wrapper.findDrawerTriggerById('circle-global').toSelector())).resolves.toBe(true);
36+
await expect(page.isClickable(wrapper.findDrawerTriggerById('circle-global').toSelector())).resolves.toBe(true);
3737
await page.runInsideIframe(iframeId, true, async () => {
3838
await expect(page.isDisplayed(findDrawerById(secondaryLayout, 'circle-global').toSelector())).resolves.toBe(
3939
true

src/app-layout/__tests__/__snapshots__/widget-contract-split-panel.test.tsx.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Map {
3434
"toolsWidth": 290,
3535
},
3636
"stateManager": {
37-
"current": {},
37+
"current": {
38+
"set": [Function],
39+
},
3840
},
3941
},
4042
[Function] => {
@@ -1297,7 +1299,9 @@ Map {
12971299
"toolsWidth": 290,
12981300
},
12991301
"stateManager": {
1300-
"current": {},
1302+
"current": {
1303+
"set": [Function],
1304+
},
13011305
},
13021306
},
13031307
[Function] => {

src/app-layout/utils/use-focus-control.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface FocusControlRefs {
1313
close: RefObject<Focusable>;
1414
slider: RefObject<HTMLDivElement>;
1515
onMount?: () => void;
16-
focusPromise?: any;
16+
focusPromise?: Deferred<HTMLElement>;
1717
}
1818

1919
export interface FocusControlState {
@@ -166,7 +166,7 @@ export function useAsyncFocusControl(
166166
restoreFocus = false,
167167
activeDrawerId?: string | null
168168
): FocusControlState {
169-
const focusPromise = useRef<Deferred<undefined>>(new Deferred());
169+
const focusPromise = useRef<Deferred<HTMLElement>>(new Deferred());
170170
const refs = {
171171
toggle: useRef<Focusable>(null),
172172
close: useRef<Focusable>(null),

src/app-layout/utils/use-split-panel-focus-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface SplitPanelFocusControlState {
1919
}
2020

2121
export function useSplitPanelFocusControl(dependencies: DependencyList): SplitPanelFocusControlState {
22-
const focusPromise = useRef<Deferred<undefined>>(new Deferred());
22+
const focusPromise = useRef<Deferred<HTMLElement>>(new Deferred());
2323

2424
const refs = {
2525
toggle: useRef<Focusable>(null),

src/app-layout/visual-refresh-toolbar/navigation/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import testutilStyles from '../../test-classes/styles.css.js';
1717
import styles from './styles.css.js';
1818

1919
interface AppLayoutNavigationImplementationProps {
20-
appLayoutInternals: AppLayoutInternals;
20+
appLayoutInternals: Partial<AppLayoutInternals>;
2121
}
2222

2323
export function AppLayoutNavigationImplementation({ appLayoutInternals }: AppLayoutNavigationImplementationProps) {
@@ -32,7 +32,7 @@ export function AppLayoutNavigationImplementation({ appLayoutInternals }: AppLay
3232
verticalOffsets,
3333
} = appLayoutInternals;
3434

35-
const { drawerTopOffset, drawerHeight } = getDrawerStyles(verticalOffsets, isMobile, placement);
35+
const { drawerTopOffset, drawerHeight } = getDrawerStyles(verticalOffsets!, isMobile!, placement!);
3636

3737
// Close the Navigation drawer on mobile when a user clicks a link inside.
3838
const onNavigationClick = (event: React.MouseEvent) => {
@@ -41,7 +41,7 @@ export function AppLayoutNavigationImplementation({ appLayoutInternals }: AppLay
4141
node => node.tagName === 'A' && !!(node as HTMLAnchorElement).href
4242
);
4343
if (hasLink && isMobile) {
44-
onNavigationToggle(false);
44+
onNavigationToggle?.(false);
4545
}
4646
};
4747
const closeMergedRef = useMergeRefs(navigationFocusControl?.refs?.close, navigationFocusControl?.refs?.onMount);
@@ -72,7 +72,7 @@ export function AppLayoutNavigationImplementation({ appLayoutInternals }: AppLay
7272
<InternalButton
7373
ariaLabel={ariaLabels?.navigationClose ?? undefined}
7474
iconName={isMobile ? 'close' : 'angle-left'}
75-
onClick={() => onNavigationToggle(false)}
75+
onClick={() => onNavigationToggle?.(false)}
7676
variant="icon"
7777
formAction="none"
7878
className={testutilStyles['navigation-close']}

src/app-layout/visual-refresh-toolbar/notifications/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import testutilStyles from '../../test-classes/styles.css.js';
1515
import styles from './styles.css.js';
1616

1717
export interface AppLayoutNotificationsImplementationProps {
18-
appLayoutInternals: AppLayoutInternals;
18+
appLayoutInternals: Partial<AppLayoutInternals>;
1919
children: React.ReactNode;
2020
}
2121

@@ -49,7 +49,7 @@ export function AppLayoutNotificationsImplementation({
4949
appLayoutInternals.headerVariant !== 'high-contrast' && styles['sticky-notifications-with-background']
5050
)}
5151
style={{
52-
insetBlockStart: stickyNotifications ? verticalOffsets.notifications : undefined,
52+
insetBlockStart: stickyNotifications ? verticalOffsets?.notifications : undefined,
5353
}}
5454
>
5555
<div className={testutilStyles.notifications} role="region" aria-label={ariaLabels?.notifications}>

src/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import styles from './styles.css.js';
1010

1111
interface BreadcrumbsSlotProps {
1212
ownBreadcrumbs: React.ReactNode;
13-
discoveredBreadcrumbs: BreadcrumbGroupProps | null;
13+
discoveredBreadcrumbs?: BreadcrumbGroupProps | null;
1414
}
1515

1616
export function BreadcrumbsSlot({ ownBreadcrumbs, discoveredBreadcrumbs }: BreadcrumbsSlotProps) {

src/app-layout/visual-refresh-toolbar/skeleton/index.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { fireNonCancelableEvent } from '../../../internal/events';
1313
import customCssProps from '../../../internal/generated/custom-css-properties';
1414
import { useGetGlobalBreadcrumbs } from '../../../internal/plugins/helpers/use-global-breadcrumbs';
1515
import { computeVerticalLayout } from '../compute-layout';
16-
import { AppLayoutInternalProps } from '../interfaces';
16+
import { AppLayoutInternalProps, AppLayoutInternals } from '../interfaces';
1717
import {
1818
AppLayoutSkeletonBottomContentSlot,
1919
AppLayoutSkeletonSideSlot,
@@ -27,10 +27,15 @@ import { useSkeletonSlotsAttributes } from './widget-slots/use-skeleton-slots-at
2727
import testutilStyles from '../../test-classes/styles.css.js';
2828
import styles from './styles.css.js';
2929

30+
type AppLayoutState = ReturnType<typeof useAppLayout>;
31+
type SkeletonSlotsAttributes = ReturnType<typeof useSkeletonSlotsAttributes>;
32+
3033
export interface SkeletonLayoutProps {
3134
appLayoutProps: AppLayoutInternalProps;
3235
appLayoutState:
33-
| (ReturnType<typeof useAppLayout> &
36+
| (Partial<Omit<AppLayoutState, 'appLayoutInternals'>> & { appLayoutInternals: Partial<AppLayoutInternals> } &
37+
// these props are excluded from the runtime app layout, because they are critical for the initial rendering
38+
// to prevent layout shifts
3439
Partial<ReturnType<typeof useMultiAppLayout>> &
3540
Partial<{
3641
hasToolbar: boolean;
@@ -40,7 +45,7 @@ export interface SkeletonLayoutProps {
4045
}
4146

4247
export interface RootSkeletonLayoutProps extends SkeletonLayoutProps {
43-
skeletonSlotsAttributes: ReturnType<typeof useSkeletonSlotsAttributes> | null;
48+
skeletonSlotsAttributes: SkeletonSlotsAttributes | null;
4449
}
4550

4651
const componentAnalyticsMetadata: GeneratedAnalyticsMetadataAppLayoutToolbarComponent = {
@@ -87,7 +92,7 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
8792
function (open: boolean) {
8893
fireNonCancelableEvent(onNavigationChange, { open });
8994
},
90-
navigationFocusRef: appLayoutState?.appLayoutInternals?.navigationFocusControl.refs.toggle,
95+
navigationFocusRef: appLayoutState?.appLayoutInternals?.navigationFocusControl?.refs.toggle,
9196
breadcrumbs,
9297
activeDrawerId: appLayoutState?.activeDrawer?.id ?? null,
9398
// only pass it down if there are non-empty drawers or tools
@@ -99,15 +104,15 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
99104
activeGlobalDrawersIds: appLayoutState?.activeGlobalDrawersIds,
100105
onActiveGlobalDrawersChange: appLayoutState?.appLayoutInternals?.onActiveGlobalDrawersChange,
101106
onActiveDrawerChange: appLayoutState?.appLayoutInternals?.onActiveDrawerChange,
102-
drawersFocusRef: appLayoutState?.appLayoutInternals?.drawersFocusControl.refs.toggle,
107+
drawersFocusRef: appLayoutState?.appLayoutInternals?.drawersFocusControl?.refs.toggle,
103108
splitPanel,
104109
splitPanelToggleProps: {
105110
...appLayoutState?.appLayoutInternals?.splitPanelToggleConfig,
106111
active: Boolean(appLayoutState?.splitPanelOpen),
107112
controlId: appLayoutState?.appLayoutInternals?.splitPanelControlId,
108113
position: appLayoutState?.splitPanelPosition ?? 'side',
109114
},
110-
splitPanelFocusRef: appLayoutState?.appLayoutInternals?.splitPanelFocusControl.refs.toggle,
115+
splitPanelFocusRef: appLayoutState?.appLayoutInternals?.splitPanelFocusControl?.refs.toggle,
111116
onSplitPanelToggle: appLayoutState?.appLayoutInternals?.onSplitPanelToggle ?? function () {},
112117
expandedDrawerId: appLayoutState?.expandedDrawerId,
113118
setExpandedDrawerId: appLayoutState?.setExpandedDrawerId ?? function () {},
@@ -123,7 +128,8 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
123128
toolbarHeight: appLayoutState?.toolbarHeight ?? 0,
124129
stickyNotifications: Boolean(appLayoutState?.appLayoutInternals?.stickyNotifications),
125130
});
126-
const combinedProps = {
131+
// here we merge runtime and built-time props
132+
const mergedProps = {
127133
...props,
128134
appLayoutState: {
129135
...appLayoutState,
@@ -139,7 +145,7 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
139145
ariaLabels: appLayoutState?.appLayoutInternals?.ariaLabels ?? ariaLabels,
140146
},
141147
toolbarProps,
142-
registered,
148+
registered: !!registered,
143149
hasToolbar,
144150
verticalOffsets,
145151
resolvedNavigation: appLayoutState?.resolvedNavigation ?? resolvedNavigation,
@@ -172,9 +178,9 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
172178
ref={ref}
173179
{...getAnalyticsMetadataAttribute({ component: componentAnalyticsMetadata })}
174180
>
175-
<AppLayoutSkeletonTopSlot {...(combinedProps as any)} />
181+
<AppLayoutSkeletonTopSlot {...mergedProps} />
176182
<main {...mainElAttributes} className={mainElAttributes?.className ?? styles['main-landmark']}>
177-
<AppLayoutSkeletonTopContentSlot {...(combinedProps as any)} />
183+
<AppLayoutSkeletonTopContentSlot {...mergedProps} />
178184
<div
179185
{...contentWrapperElAttributes}
180186
className={
@@ -188,9 +194,9 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
188194
{registered ? content : null}
189195
</div>
190196
</div>
191-
<AppLayoutSkeletonBottomContentSlot {...(combinedProps as any)} />
197+
<AppLayoutSkeletonBottomContentSlot {...mergedProps} />
192198
</main>
193-
<AppLayoutSkeletonSideSlot {...(combinedProps as any)} />
199+
<AppLayoutSkeletonSideSlot {...mergedProps} />
194200
</div>
195201
</VisualContext>
196202
</>

src/app-layout/visual-refresh-toolbar/skeleton/widget-slots/side-page-slot.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
AppLayoutDrawerImplementation as AppLayoutDrawer,
1010
AppLayoutGlobalDrawersImplementation as AppLayoutGlobalDrawers,
1111
} from '../../drawer';
12+
import { AppLayoutInternals } from '../../interfaces';
1213
import { AppLayoutSplitPanelDrawerSideImplementation as AppLayoutSplitPanelSide } from '../../split-panel';
1314
import { SkeletonLayoutProps } from '../index';
1415

@@ -58,11 +59,15 @@ const SidePageSlot = (props: SkeletonLayoutProps) => {
5859
drawerExpandedMode && styles.hidden
5960
)}
6061
>
61-
{drawers && drawers.length > 0 && <AppLayoutDrawer appLayoutInternals={appLayoutInternals!} />}
62+
{drawers && drawers.length > 0 && (
63+
// type casting is safe here since 'drawers' only exists at runtime after appLayoutInternals
64+
// has been initialized
65+
<AppLayoutDrawer appLayoutInternals={appLayoutInternals as AppLayoutInternals} />
66+
)}
6267
</div>
6368
<div className={clsx(styles['global-tools'], !globalToolsOpen && styles['panel-hidden'])}>
6469
<ActiveDrawersContext.Provider value={activeGlobalDrawersIds ?? []}>
65-
<AppLayoutGlobalDrawers appLayoutInternals={appLayoutInternals!} />
70+
<AppLayoutGlobalDrawers appLayoutInternals={appLayoutInternals as AppLayoutInternals} />
6671
</ActiveDrawersContext.Provider>
6772
</div>
6873
</>

src/app-layout/visual-refresh-toolbar/split-panel/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AppLayoutInternals } from '../interfaces';
1010
import styles from './styles.css.js';
1111

1212
interface AppLayoutSplitPanelDrawerSideImplementationProps {
13-
appLayoutInternals: AppLayoutInternals;
13+
appLayoutInternals: Partial<AppLayoutInternals>;
1414
splitPanelInternals: SplitPanelProviderProps;
1515
children: React.ReactNode;
1616
}
@@ -21,7 +21,7 @@ export function AppLayoutSplitPanelDrawerSideImplementation({
2121
splitPanelInternals,
2222
}: AppLayoutSplitPanelDrawerSideImplementationProps) {
2323
const { splitPanelControlId, placement, verticalOffsets, isMobile, splitPanelAnimationDisabled } = appLayoutInternals;
24-
const { drawerTopOffset, drawerHeight } = getDrawerStyles(verticalOffsets, isMobile, placement);
24+
const { drawerTopOffset, drawerHeight } = getDrawerStyles(verticalOffsets!, isMobile!, placement!);
2525

2626
return (
2727
<SplitPanelProvider {...splitPanelInternals} animationDisabled={splitPanelAnimationDisabled}>
@@ -40,7 +40,7 @@ export function AppLayoutSplitPanelDrawerSideImplementation({
4040
}
4141

4242
interface AppLayoutSplitPanelDrawerBottomImplementationProps {
43-
appLayoutInternals: AppLayoutInternals;
43+
appLayoutInternals: Partial<AppLayoutInternals>;
4444
splitPanelInternals: SplitPanelProviderProps;
4545
children: React.ReactNode;
4646
}

0 commit comments

Comments
 (0)