Skip to content

Commit af9f254

Browse files
committed
chore: Wrapping up (type adjustments, snapshot upd)
1 parent 84e08ba commit af9f254

File tree

11 files changed

+47
-32
lines changed

11 files changed

+47
-32
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
@@ -11,7 +11,7 @@ import { fireNonCancelableEvent } from '../../../internal/events';
1111
import customCssProps from '../../../internal/generated/custom-css-properties';
1212
import { useGetGlobalBreadcrumbs } from '../../../internal/plugins/helpers/use-global-breadcrumbs';
1313
import { computeVerticalLayout } from '../compute-layout';
14-
import { AppLayoutInternalProps } from '../interfaces';
14+
import { AppLayoutInternalProps, AppLayoutInternals } from '../interfaces';
1515
import {
1616
AppLayoutSkeletonBottomContentSlot,
1717
AppLayoutSkeletonSideSlot,
@@ -25,10 +25,15 @@ import { useSkeletonSlotsAttributes } from './widget-slots/use-skeleton-slots-at
2525
import testutilStyles from '../../test-classes/styles.css.js';
2626
import styles from './styles.css.js';
2727

28+
type AppLayoutState = ReturnType<typeof useAppLayout>;
29+
type SkeletonSlotsAttributes = ReturnType<typeof useSkeletonSlotsAttributes>;
30+
2831
export interface SkeletonLayoutProps {
2932
appLayoutProps: AppLayoutInternalProps;
3033
appLayoutState:
31-
| (ReturnType<typeof useAppLayout> &
34+
| (Partial<Omit<AppLayoutState, 'appLayoutInternals'>> & { appLayoutInternals: Partial<AppLayoutInternals> } &
35+
// these props are excluded from the runtime app layout, because they are critical for the initial rendering
36+
// to prevent layout shifts
3237
Partial<ReturnType<typeof useMultiAppLayout>> &
3338
Partial<{
3439
hasToolbar: boolean;
@@ -38,7 +43,7 @@ export interface SkeletonLayoutProps {
3843
}
3944

4045
export interface RootSkeletonLayoutProps extends SkeletonLayoutProps {
41-
skeletonSlotsAttributes: ReturnType<typeof useSkeletonSlotsAttributes> | null;
46+
skeletonSlotsAttributes: SkeletonSlotsAttributes | null;
4247
}
4348

4449
export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
@@ -77,7 +82,7 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
7782
function (open: boolean) {
7883
fireNonCancelableEvent(onNavigationChange, { open });
7984
},
80-
navigationFocusRef: appLayoutState?.appLayoutInternals?.navigationFocusControl.refs.toggle,
85+
navigationFocusRef: appLayoutState?.appLayoutInternals?.navigationFocusControl?.refs.toggle,
8186
breadcrumbs,
8287
activeDrawerId: appLayoutState?.activeDrawer?.id ?? null,
8388
// only pass it down if there are non-empty drawers or tools
@@ -89,15 +94,15 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
8994
activeGlobalDrawersIds: appLayoutState?.activeGlobalDrawersIds,
9095
onActiveGlobalDrawersChange: appLayoutState?.appLayoutInternals?.onActiveGlobalDrawersChange,
9196
onActiveDrawerChange: appLayoutState?.appLayoutInternals?.onActiveDrawerChange,
92-
drawersFocusRef: appLayoutState?.appLayoutInternals?.drawersFocusControl.refs.toggle,
97+
drawersFocusRef: appLayoutState?.appLayoutInternals?.drawersFocusControl?.refs.toggle,
9398
splitPanel,
9499
splitPanelToggleProps: {
95100
...appLayoutState?.appLayoutInternals?.splitPanelToggleConfig,
96101
active: Boolean(appLayoutState?.splitPanelOpen),
97102
controlId: appLayoutState?.appLayoutInternals?.splitPanelControlId,
98103
position: appLayoutState?.splitPanelPosition ?? 'side',
99104
},
100-
splitPanelFocusRef: appLayoutState?.appLayoutInternals?.splitPanelFocusControl.refs.toggle,
105+
splitPanelFocusRef: appLayoutState?.appLayoutInternals?.splitPanelFocusControl?.refs.toggle,
101106
onSplitPanelToggle: appLayoutState?.appLayoutInternals?.onSplitPanelToggle ?? function () {},
102107
expandedDrawerId: appLayoutState?.expandedDrawerId,
103108
setExpandedDrawerId: appLayoutState?.setExpandedDrawerId ?? function () {},
@@ -113,7 +118,8 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
113118
toolbarHeight: appLayoutState?.toolbarHeight ?? 0,
114119
stickyNotifications: Boolean(appLayoutState?.appLayoutInternals?.stickyNotifications),
115120
});
116-
const combinedProps = {
121+
// here we merge runtime and built-time props
122+
const mergedProps = {
117123
...props,
118124
appLayoutState: {
119125
...appLayoutState,
@@ -129,7 +135,7 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
129135
ariaLabels: appLayoutState?.appLayoutInternals?.ariaLabels ?? ariaLabels,
130136
},
131137
toolbarProps,
132-
registered,
138+
registered: !!registered,
133139
hasToolbar,
134140
verticalOffsets,
135141
resolvedNavigation: appLayoutState?.resolvedNavigation ?? resolvedNavigation,
@@ -161,9 +167,9 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
161167
}
162168
ref={ref}
163169
>
164-
<AppLayoutSkeletonTopSlot {...(combinedProps as any)} />
170+
<AppLayoutSkeletonTopSlot {...mergedProps} />
165171
<main {...mainElAttributes} className={mainElAttributes?.className ?? styles['main-landmark']}>
166-
<AppLayoutSkeletonTopContentSlot {...(combinedProps as any)} />
172+
<AppLayoutSkeletonTopContentSlot {...mergedProps} />
167173
<div
168174
{...contentWrapperElAttributes}
169175
className={
@@ -177,9 +183,9 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
177183
{registered ? content : null}
178184
</div>
179185
</div>
180-
<AppLayoutSkeletonBottomContentSlot {...(combinedProps as any)} />
186+
<AppLayoutSkeletonBottomContentSlot {...mergedProps} />
181187
</main>
182-
<AppLayoutSkeletonSideSlot {...(combinedProps as any)} />
188+
<AppLayoutSkeletonSideSlot {...mergedProps} />
183189
</div>
184190
</VisualContext>
185191
</>

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)