Skip to content

Commit

Permalink
chore: Expose private API to disable breadcrumbs globalization (#2892)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Oct 18, 2024
1 parent 11df6c3 commit b7c90b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/app-layout/__tests__/global-breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ describeEachAppLayout({ themes: ['refresh-toolbar'], sizes: ['desktop'] }, () =>
expect(findRootBreadcrumb().getElement()).toHaveTextContent('Static');
});
});

test('allows opt-out from this behavior', async () => {
render(
<AppLayout
breadcrumbs={<BreadcrumbGroup items={defaultBreadcrumbs} />}
content={<BreadcrumbGroup items={[{ text: 'Local', href: '' }]} {...{ __disableGlobalization: true }} />}
/>
);
await waitFor(() =>
expect(wrapper.findAppLayout()!.find('[data-awsui-discovered-breadcrumbs="true"]')).toBeTruthy()
);
expect(findAllBreadcrumbsInstances()).toHaveLength(2);
});
});

describe('without feature flag', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/internal/plugins/helpers/use-global-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import { BreadcrumbGroupProps } from '../../../breadcrumb-group/interfaces';
import { awsuiPluginsInternal } from '../api';
import { BreadcrumbsGlobalRegistration } from '../controllers/breadcrumbs';

function useSetGlobalBreadcrumbsImplementation(props: BreadcrumbGroupProps<any>) {
function useSetGlobalBreadcrumbsImplementation({
__disableGlobalization,
...props
}: BreadcrumbGroupProps<any> & { __disableGlobalization?: boolean }) {
const registrationRef = useRef<BreadcrumbsGlobalRegistration<BreadcrumbGroupProps> | null>();
const [registered, setRegistered] = useState(false);

useEffect(() => {
if (__disableGlobalization) {
return;
}
const registration = awsuiPluginsInternal.breadcrumbs.registerBreadcrumbs(props, () => setRegistered(true));
registrationRef.current = registration;

Expand All @@ -20,7 +26,7 @@ function useSetGlobalBreadcrumbsImplementation(props: BreadcrumbGroupProps<any>)
};
// subsequent prop changes are handled by another effect
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [__disableGlobalization]);

useLayoutEffect(() => {
registrationRef.current?.update(props);
Expand Down

0 comments on commit b7c90b6

Please sign in to comment.