@egym/mwa-logger
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -86,2 +86,7 @@ 'use strict'; | ||
}; | ||
let ciConfig = null; | ||
const getCIConfig = () => ciConfig; | ||
const setCIConfig = (config) => { | ||
ciConfig = config; | ||
}; | ||
@@ -91,3 +96,3 @@ class ErrorBoundary extends React.Component { | ||
super(props); | ||
this.state = { hasError: false }; | ||
this.state = { hasError: false, error: null, errorInfo: null }; | ||
} | ||
@@ -100,6 +105,11 @@ static getDerivedStateFromError(error) { | ||
logWSOD({ error, errorInfo }); | ||
this.setState({ error, errorInfo }); | ||
} | ||
render() { | ||
if (this.state.hasError) { | ||
return this.props.fallback; | ||
const ciConfig = getCIConfig(); | ||
return React.cloneElement(this.props.fallback, { | ||
error: this.state.error, | ||
ciConfig, | ||
}); | ||
} | ||
@@ -564,2 +574,6 @@ return this.props.children; | ||
}, [position]); | ||
React.useEffect(() => { | ||
if (ciConfig) | ||
setCIConfig(ciConfig); | ||
}, [ciConfig]); | ||
const contentWidth = React.useMemo(() => { | ||
@@ -566,0 +580,0 @@ if (!positionStyles) |
@@ -1,7 +0,13 @@ | ||
import React, { ErrorInfo, PropsWithChildren, ReactElement } from 'react'; | ||
import React, { ErrorInfo, PropsWithChildren, ReactElement } from "react"; | ||
import { CIConfig } from '../types'; | ||
export type ErrorBoundaryProps = { | ||
fallback: ReactElement; | ||
fallback: ReactElement<{ | ||
error?: Error | null; | ||
ciConfig: CIConfig | null; | ||
}>; | ||
}; | ||
export declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, { | ||
hasError: boolean; | ||
error: Error | null; | ||
errorInfo: ErrorInfo | null; | ||
}> { | ||
@@ -13,3 +19,3 @@ constructor(props: any); | ||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void; | ||
render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined; | ||
render(): React.ReactNode; | ||
} |
export { logHttpRequest, logHttpResponse, logDebug, logPortalsRequest, logPortalsResponse, logWebWitals } from './messages'; | ||
export { ErrorBoundary } from './ErrorBoundary'; | ||
export { default as EgymMwaDevtools } from './EgymMwaDevtools'; | ||
export { CIConfig } from './types'; |
import { Metric as WebVitalsMetric } from 'web-vitals'; | ||
import { CIConfig } from '../types'; | ||
type BaseMessage = { | ||
@@ -40,2 +41,4 @@ id: string; | ||
export declare const getSnapshot: () => Message[]; | ||
export declare const getCIConfig: () => CIConfig | null; | ||
export declare const setCIConfig: (config: CIConfig) => void; | ||
export {}; |
@@ -84,2 +84,7 @@ import React, { useState, useCallback, useMemo, useSyncExternalStore, useEffect } from 'react'; | ||
}; | ||
let ciConfig = null; | ||
const getCIConfig = () => ciConfig; | ||
const setCIConfig = (config) => { | ||
ciConfig = config; | ||
}; | ||
@@ -89,3 +94,3 @@ class ErrorBoundary extends React.Component { | ||
super(props); | ||
this.state = { hasError: false }; | ||
this.state = { hasError: false, error: null, errorInfo: null }; | ||
} | ||
@@ -98,6 +103,11 @@ static getDerivedStateFromError(error) { | ||
logWSOD({ error, errorInfo }); | ||
this.setState({ error, errorInfo }); | ||
} | ||
render() { | ||
if (this.state.hasError) { | ||
return this.props.fallback; | ||
const ciConfig = getCIConfig(); | ||
return React.cloneElement(this.props.fallback, { | ||
error: this.state.error, | ||
ciConfig, | ||
}); | ||
} | ||
@@ -562,2 +572,6 @@ return this.props.children; | ||
}, [position]); | ||
useEffect(() => { | ||
if (ciConfig) | ||
setCIConfig(ciConfig); | ||
}, [ciConfig]); | ||
const contentWidth = useMemo(() => { | ||
@@ -564,0 +578,0 @@ if (!positionStyles) |
@@ -1,7 +0,13 @@ | ||
import React, { ErrorInfo, PropsWithChildren, ReactElement } from 'react'; | ||
import React, { ErrorInfo, PropsWithChildren, ReactElement } from "react"; | ||
import { CIConfig } from '../types'; | ||
export type ErrorBoundaryProps = { | ||
fallback: ReactElement; | ||
fallback: ReactElement<{ | ||
error?: Error | null; | ||
ciConfig: CIConfig | null; | ||
}>; | ||
}; | ||
export declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, { | ||
hasError: boolean; | ||
error: Error | null; | ||
errorInfo: ErrorInfo | null; | ||
}> { | ||
@@ -13,3 +19,3 @@ constructor(props: any); | ||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void; | ||
render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined; | ||
render(): React.ReactNode; | ||
} |
export { logHttpRequest, logHttpResponse, logDebug, logPortalsRequest, logPortalsResponse, logWebWitals } from './messages'; | ||
export { ErrorBoundary } from './ErrorBoundary'; | ||
export { default as EgymMwaDevtools } from './EgymMwaDevtools'; | ||
export { CIConfig } from './types'; |
import { Metric as WebVitalsMetric } from 'web-vitals'; | ||
import { CIConfig } from '../types'; | ||
type BaseMessage = { | ||
@@ -40,2 +41,4 @@ id: string; | ||
export declare const getSnapshot: () => Message[]; | ||
export declare const getCIConfig: () => CIConfig | null; | ||
export declare const setCIConfig: (config: CIConfig) => void; | ||
export {}; |
import { Metric } from 'web-vitals'; | ||
import React, { PropsWithChildren, ErrorInfo, ReactElement, FC, CSSProperties } from 'react'; | ||
type CIConfigItem = { | ||
value: string; | ||
description: string; | ||
}; | ||
type CIConfig = { | ||
appId: CIConfigItem; | ||
appName: CIConfigItem; | ||
gitCommitSha: CIConfigItem; | ||
gitCommitMsg?: CIConfigItem; | ||
gitRef?: CIConfigItem; | ||
gitRefType?: CIConfigItem; | ||
isAutomatedBuild: CIConfigItem; | ||
automationId: CIConfigItem; | ||
automationName: CIConfigItem; | ||
buildId: CIConfigItem; | ||
buildNumber: CIConfigItem; | ||
platform: CIConfigItem; | ||
}; | ||
type BaseMessage = { | ||
@@ -36,6 +55,11 @@ id: string; | ||
type ErrorBoundaryProps = { | ||
fallback: ReactElement; | ||
fallback: ReactElement<{ | ||
error?: Error | null; | ||
ciConfig: CIConfig | null; | ||
}>; | ||
}; | ||
declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, { | ||
hasError: boolean; | ||
error: Error | null; | ||
errorInfo: ErrorInfo | null; | ||
}> { | ||
@@ -47,24 +71,5 @@ constructor(props: any); | ||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void; | ||
render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined; | ||
render(): React.ReactNode; | ||
} | ||
type CIConfigItem = { | ||
value: string; | ||
description: string; | ||
}; | ||
type CIConfig = { | ||
appId: CIConfigItem; | ||
appName: CIConfigItem; | ||
gitCommitSha: CIConfigItem; | ||
gitCommitMsg?: CIConfigItem; | ||
gitRef?: CIConfigItem; | ||
gitRefType?: CIConfigItem; | ||
isAutomatedBuild: CIConfigItem; | ||
automationId: CIConfigItem; | ||
automationName: CIConfigItem; | ||
buildId: CIConfigItem; | ||
buildNumber: CIConfigItem; | ||
platform: CIConfigItem; | ||
}; | ||
type Props = { | ||
@@ -78,2 +83,2 @@ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; | ||
export { EgymMwaDevtools, ErrorBoundary, logDebug, logHttpRequest, logHttpResponse, logPortalsRequest, logPortalsResponse, logWebWitals }; | ||
export { CIConfig, EgymMwaDevtools, ErrorBoundary, logDebug, logHttpRequest, logHttpResponse, logPortalsRequest, logPortalsResponse, logWebWitals }; |
{ | ||
"name": "@egym/mwa-logger", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "EGYM", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
223039
1908