Skip to content

Commit 7ae7463

Browse files
committed
feat: Custom feature flag appLayoutDelayedWidget to test async widget behavior
1 parent b0e6186 commit 7ae7463

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pages/app/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ interface GlobalFlags {
2222
appLayoutWidget?: boolean;
2323
appLayoutToolbar?: boolean;
2424
}
25+
// used for local dev / testing
26+
interface CustomFlags {
27+
appLayoutDelayedWidget?: boolean;
28+
}
2529
const awsuiVisualRefreshFlag = Symbol.for('awsui-visual-refresh-flag');
2630
const awsuiGlobalFlagsSymbol = Symbol.for('awsui-global-flags');
31+
const awsuiCustomFlagsSymbol = Symbol.for('awsui-custom-flags');
2732

2833
interface ExtendedWindow extends Window {
2934
[awsuiVisualRefreshFlag]?: () => boolean;
3035
[awsuiGlobalFlagsSymbol]?: GlobalFlags;
36+
[awsuiCustomFlagsSymbol]?: CustomFlags;
3137
}
3238
declare const window: ExtendedWindow;
3339

@@ -86,15 +92,21 @@ function App() {
8692
}
8793

8894
const history = createHashHistory();
89-
const { direction, visualRefresh, appLayoutWidget, appLayoutToolbar } = parseQuery(history.location.search);
95+
const { direction, visualRefresh, appLayoutWidget, appLayoutToolbar, appLayoutDelayedWidget } = parseQuery(
96+
history.location.search
97+
);
9098

9199
// The VR class needs to be set before any React rendering occurs.
92100
window[awsuiVisualRefreshFlag] = () => visualRefresh;
93101
if (!window[awsuiGlobalFlagsSymbol]) {
94102
window[awsuiGlobalFlagsSymbol] = {};
95103
}
104+
if (!window[awsuiCustomFlagsSymbol]) {
105+
window[awsuiCustomFlagsSymbol] = {};
106+
}
96107
window[awsuiGlobalFlagsSymbol].appLayoutWidget = appLayoutWidget;
97108
window[awsuiGlobalFlagsSymbol].appLayoutToolbar = appLayoutToolbar;
109+
window[awsuiCustomFlagsSymbol].appLayoutDelayedWidget = appLayoutDelayedWidget;
98110

99111
// Apply the direction value to the HTML element dir attribute
100112
document.documentElement.setAttribute('dir', direction);

src/app-layout/utils/feature-flags.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import { getGlobalFlag } from '@cloudscape-design/component-toolkit/internal';
77
import { useVisualRefresh } from '../../internal/hooks/use-visual-mode';
88
import { AppLayoutToolbarPublicContext } from '../visual-refresh-toolbar/contexts';
99

10+
const getCutomFlag = (flagName: string) => {
11+
const isBrowser = typeof window !== 'undefined';
12+
if (!isBrowser) {
13+
return {};
14+
}
15+
const awsuiCustomFlagsSymbol = Symbol.for('awsui-custom-flags');
16+
return window?.[awsuiCustomFlagsSymbol as any]?.[flagName as any];
17+
};
18+
1019
// useAppLayoutFlagEnabled is set to true only in consoles. It controls if AppLayout theme is toolbar
1120
export const useAppLayoutFlagEnabled = () => {
1221
const isRefresh = useVisualRefresh();
@@ -23,3 +32,7 @@ export const useAppLayoutToolbarDesignEnabled = () => {
2332

2433
return isToolbarPublic || isToolbarPrivate;
2534
};
35+
36+
export const isAppLayoutDelayedWidget = () => {
37+
return !!getCutomFlag('appLayoutDelayedWidget');
38+
};

src/app-layout/visual-refresh-toolbar/internal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import React, { useEffect, useRef, useState } from 'react';
44

5+
import { isAppLayoutDelayedWidget } from '../utils/feature-flags';
56
import { AppLayoutState as AppLayoutStateImplementation, createWidgetizedAppLayoutState } from './app-layout-state';
67
import { createWidgetizedAppLayoutDrawer, createWidgetizedAppLayoutGlobalDrawers } from './drawer';
78
import { createWidgetizedAppLayoutNavigation } from './navigation';
@@ -33,7 +34,7 @@ export const AppLayoutWidgetizedState = createWidgetizedAppLayoutState(
3334
createAppLayoutPart({ Component: AppLayoutStateImplementation })
3435
);
3536

36-
const enableDelayedComponents = false;
37+
const enableDelayedComponents = isAppLayoutDelayedWidget();
3738

3839
export function createAppLayoutPart({ Component }: { Component: React.JSXElementConstructor<any> }) {
3940
const AppLayoutPartLoader = ({ Skeleton, ...props }: any) => {

0 commit comments

Comments
 (0)