@codecademy/brand 3.21.0-alpha.c60fb49007.0 → 3.22.0-alpha.c6b0e83449.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { useMemo, useRef } from 'react';
2
+ import { useContext, useMemo, useRef } from 'react';
3
+ import { LogErrorContext } from '..';
3
4
  import { HeaderHeightArea } from '../HeaderHeightArea';
4
5
  import { NotificationsDropdown } from '../Notifications/NotificationsDropdown';
5
6
  import { useHeaderNotifications } from '../Notifications/useHeaderNotifications';
@@ -41,8 +42,24 @@ export const AppHeader = ({
41
42
  }
42
43
  return [...defaultItems, ...items.right];
43
44
  }, [searchButton, notificationsBell, hideRightButtonDefaults, items, isTeams]);
45
+ const {
46
+ logError
47
+ } = useContext(LogErrorContext);
44
48
  const mapItemsToElement = (items, side) => {
45
- return items.map((item, index) => {
49
+ // logging error to help with debugging
50
+ if (items && items.some(item => !item)) {
51
+ try {
52
+ const itemTypesString = items.map(item => item.type).join(', ');
53
+ logError?.(`Error: Found an undefined app header item on the ${side} side of the header.`, {
54
+ message: `The current array of items includes the following header item types: ${itemTypesString}`
55
+ });
56
+ } catch (e) {
57
+ logError?.(`Error while logging undefined header items: ${e}`);
58
+ }
59
+ }
60
+ return items
61
+ // preventative measure to handle a possibly undefined item from being rendered
62
+ .filter(item => !!item).map((item, index) => {
46
63
  const margin = appHeaderSpacing[type];
47
64
  return /*#__PURE__*/_jsx(AppHeaderListItem, {
48
65
  mr: margin,
@@ -3,6 +3,14 @@ import * as React from 'react';
3
3
  import { EnhancedBannerProps } from '../Banner/EnhancedBanner';
4
4
  import { GlobalFooterProps } from '../GlobalFooter';
5
5
  import { GlobalHeaderProps } from '../GlobalHeader';
6
+ type ErrorContext = {
7
+ message?: string;
8
+ [k: string]: any;
9
+ };
10
+ type LogErrorContextType = {
11
+ logError?: (error: unknown, context?: ErrorContext | string) => void;
12
+ };
13
+ export declare const LogErrorContext: React.Context<LogErrorContextType>;
6
14
  export type GlobalPageBackgroundColor = 'beige' | 'background' | 'background-contrast' | 'navy' | 'paleBlue' | 'paleGreen' | 'palePink' | 'paleYellow' | 'white';
7
15
  export interface GlobalPageProps extends WithChildrenProp {
8
16
  backgroundColor?: GlobalPageBackgroundColor;
@@ -30,5 +38,11 @@ export interface GlobalPageProps extends WithChildrenProp {
30
38
  * Custom element ID to link to by the SkipToContent control, if not a default one at the beginning of the page.
31
39
  */
32
40
  skipToContentId?: string;
41
+ /**
42
+ * Temporary function called with error and context when an error occurs to
43
+ * help with debugging.
44
+ */
45
+ onError?: (error: unknown, context?: ErrorContext | string) => void;
33
46
  }
34
47
  export declare const GlobalPage: React.FC<GlobalPageProps>;
48
+ export {};
@@ -6,6 +6,7 @@ import { EnhancedBanner } from '../Banner/EnhancedBanner';
6
6
  import { GlobalFooter } from '../GlobalFooter';
7
7
  import { GlobalHeader } from '../GlobalHeader';
8
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ export const LogErrorContext = /*#__PURE__*/React.createContext({});
9
10
  const defaultSkipToContentId = 'page-skip-to-content-target';
10
11
  const RestrictedBackground = /*#__PURE__*/forwardRef(({
11
12
  children,
@@ -28,7 +29,8 @@ export const GlobalPage = ({
28
29
  footer,
29
30
  header,
30
31
  modal,
31
- skipToContentId
32
+ skipToContentId,
33
+ onError
32
34
  }) => {
33
35
  return /*#__PURE__*/_jsxs(GlobalPageWrapper, {
34
36
  bg: backgroundColor,
@@ -37,8 +39,13 @@ export const GlobalPage = ({
37
39
  contentId: skipToContentId || defaultSkipToContentId
38
40
  }), banner && /*#__PURE__*/_jsx(EnhancedBanner, {
39
41
  ...banner
40
- }), !header.hideEnterpriseHeader && /*#__PURE__*/_jsx(GlobalHeader, {
41
- ...header
42
+ }), /*#__PURE__*/_jsx(LogErrorContext.Provider, {
43
+ value: {
44
+ logError: onError
45
+ },
46
+ children: !header.hideEnterpriseHeader && /*#__PURE__*/_jsx(GlobalHeader, {
47
+ ...header
48
+ })
42
49
  }), !skipToContentId && /*#__PURE__*/_jsx(SkipToContentTarget, {
43
50
  id: defaultSkipToContentId
44
51
  }), /*#__PURE__*/_jsx(AppWrapper, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/brand",
3
3
  "description": "Brand component library for Codecademy",
4
- "version": "3.21.0-alpha.c60fb49007.0",
4
+ "version": "3.22.0-alpha.c6b0e83449.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "dependencies": {
7
7
  "@emotion/is-prop-valid": "^1.2.1",