UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

59 lines 2.7 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { useEffect, useLayoutEffect, useState } from 'react'; import { metrics } from '../../../internal/metrics'; import { awsuiPluginsInternal } from '../../../internal/plugins/api'; import { useAppLayoutFlagEnabled } from '../../utils/feature-flags'; export function useMultiAppLayout(forceDeduplicationType, isEnabled, props, mergeProps) { const [registration, setRegistration] = useState(null); const isToolbar = useAppLayoutFlagEnabled(); useLayoutEffect(() => { if (!isEnabled || forceDeduplicationType === 'suspended' || !isToolbar) { return; } if (forceDeduplicationType === 'off') { setRegistration({ type: 'primary', discoveredProps: [] }); return; } const unregister = awsuiPluginsInternal.appLayoutWidget.register(forceDeduplicationType, props => setRegistration(props)); return () => { unregister(); setRegistration({ type: 'suspended' }); }; }, [forceDeduplicationType, isEnabled, isToolbar]); useLayoutEffect(() => { if ((registration === null || registration === void 0 ? void 0 : registration.type) === 'secondary') { registration.update(props); } }); useEffect(() => { if (registration) { reportMultiLayoutMetric(registration); } }, [registration]); if (!isToolbar) { return { registered: true, // mergeProps is needed here because the toolbar's behavior depends on reconciliation logic // in this function. For example, navigation trigger visibility toolbarProps: mergeProps(props, []), }; } return { registered: !!(registration === null || registration === void 0 ? void 0 : registration.type), toolbarProps: (registration === null || registration === void 0 ? void 0 : registration.type) === 'primary' ? mergeProps(props, registration.discoveredProps) : null, }; } function reportMultiLayoutMetric(registration) { if (registration.type === 'primary' && registration.discoveredProps.length > 0) { metrics.sendOpsMetricObject('awsui-multi-layout-usage-primary', { // temporary workaround for missing typings // https://github.com/cloudscape-design/component-toolkit/pull/153 instancesCount: registration.discoveredProps.length, }); } else if (registration.type === 'suspended') { metrics.sendOpsMetricObject('awsui-multi-layout-usage-suspended', {}); } } //# sourceMappingURL=multi-layout.js.map