Skip to content

Commit 5ba18c0

Browse files
authored
Merge branch 'master' into component-filter
2 parents 15bf9d8 + 7a83103 commit 5ba18c0

File tree

4 files changed

+99
-8
lines changed

4 files changed

+99
-8
lines changed

src/custom/CatalogDetail/ActionButton.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import _ from 'lodash';
22
import React from 'react';
33
import { CircularProgress } from '../../base';
4-
import { CopyIcon, KanvasIcon } from '../../icons';
4+
import { CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
55
import Download from '../../icons/Download/Download';
66
import { charcoal } from '../../theme';
77
import { Pattern } from '../CustomCatalog/CustomCard';
88
import { downloadFilter, downloadYaml, slugify } from './helper';
9-
import { ActionButton, LinkUrl, StyledActionWrapper } from './style';
9+
import { ActionButton, LinkUrl, StyledActionWrapper, UnpublishAction } from './style';
1010
import { RESOURCE_TYPES } from './types';
1111

1212
interface ActionButtonsProps {
@@ -17,8 +17,10 @@ interface ActionButtonsProps {
1717
isCloneLoading: boolean;
1818
handleClone: (name: string, id: string) => void;
1919
mode: string;
20+
handleUnpublish: () => void;
2021
isCloneDisabled: boolean;
2122
showOpenPlaygroundButton: boolean;
23+
showUnpublishAction: boolean;
2224
}
2325

2426
const ActionButtons: React.FC<ActionButtonsProps> = ({
@@ -30,7 +32,9 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
3032
handleClone,
3133
mode,
3234
isCloneDisabled,
33-
showOpenPlaygroundButton
35+
showOpenPlaygroundButton,
36+
showUnpublishAction,
37+
handleUnpublish
3438
}) => {
3539
const cleanedType = type.replace('my-', '').replace(/s$/, '');
3640
const resourcePlaygroundType = Object.values({
@@ -112,6 +116,19 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
112116
</ActionButton>
113117
</LinkUrl>
114118
)}
119+
{showUnpublishAction && (
120+
<UnpublishAction
121+
sx={{
122+
borderRadius: '0.2rem',
123+
gap: '10px',
124+
width: '100%'
125+
}}
126+
onClick={handleUnpublish}
127+
>
128+
<PublishIcon width={24} height={24} fill={charcoal[10]} />
129+
Unpublish
130+
</UnpublishAction>
131+
)}
115132
</StyledActionWrapper>
116133
);
117134
};

src/custom/CatalogDetail/LeftPanel.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ interface LeftPanelProps {
2222
technologySVGSubpath: string;
2323
fontFamily?: string;
2424
showOpenPlaygroundButton?: boolean;
25+
handleUnpublish: () => void;
26+
showUnpublishAction?: boolean;
2527
}
2628

2729
const LeftPanel: React.FC<LeftPanelProps> = ({
@@ -31,13 +33,15 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
3133
actionItems = true,
3234
isCloneLoading,
3335
handleClone,
36+
handleUnpublish,
3437
showTechnologies = true,
3538
mode,
3639
filteredAcademyData,
3740
isCloneDisabled,
3841
technologySVGPath,
3942
technologySVGSubpath,
4043
fontFamily,
44+
showUnpublishAction = false,
4145
showOpenPlaygroundButton = true
4246
}) => {
4347
const theme = useTheme();
@@ -77,6 +81,8 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
7781
cardId={cardId}
7882
isCloneLoading={isCloneLoading}
7983
handleClone={handleClone}
84+
showUnpublishAction={showUnpublishAction}
85+
handleUnpublish={handleUnpublish}
8086
mode={mode}
8187
isCloneDisabled={isCloneDisabled}
8288
showOpenPlaygroundButton={showOpenPlaygroundButton}

src/custom/CatalogDetail/style.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ export const ActionButton = styled('div')<ActionButtonProps>(({ disabled = false
3939
flex: '1'
4040
}));
4141

42+
export const UnpublishAction = styled('div')<ActionButtonProps>(({ disabled = false, theme }) => ({
43+
cursor: disabled ? 'not-allowed' : 'pointer',
44+
opacity: disabled ? '0.5' : '1',
45+
textAlign: 'center',
46+
display: 'flex',
47+
justifyContent: 'center',
48+
alignItems: 'center',
49+
borderRadius: '0.5rem',
50+
backgroundColor: 'transparent',
51+
border: `1px solid ${theme.palette.border.normal}`,
52+
padding: '0.5rem',
53+
color: theme.palette.text.default,
54+
gap: '0.625rem',
55+
flex: '1'
56+
}));
57+
4258
export const ContentDetailsText = styled(Typography)(({ theme }) => ({
4359
fontFamily: 'inherit',
4460
fontSize: '1rem',

src/custom/ErrorBoundary/ErrorBoundary.tsx

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const StyledLink = styled(Link)(({ theme }) => ({
2020
}));
2121

2222
const CodeMessage = styled('div')(({ theme }) => ({
23+
display: 'flex',
24+
flexDirection: 'column',
2325
backgroundColor: theme.palette.background.code,
2426
color: theme.palette.text.tertiary,
2527
padding: '.85rem',
@@ -30,14 +32,32 @@ const CodeMessage = styled('div')(({ theme }) => ({
3032
interface FallbackComponentProps extends FallbackProps {
3133
resetErrorBoundary: () => void;
3234
children?: React.ReactNode;
35+
pageUrl?: string;
36+
timestamp?: string;
37+
showPackageInfo?: boolean;
38+
version?: string;
3339
}
3440

35-
export function Fallback({ error, children }: FallbackComponentProps): JSX.Element {
41+
export function Fallback({
42+
error,
43+
children,
44+
showPackageInfo,
45+
version
46+
}: FallbackComponentProps): JSX.Element {
3647
return (
3748
<div role="alert">
3849
<h2>Uh-oh!😔 Please pardon the mesh.</h2>
3950
<CodeMessage>
40-
<code>{(error as Error).message}</code>
51+
<code>
52+
<strong>Error: </strong>
53+
{(error as Error).message}
54+
</code>
55+
<br />
56+
{showPackageInfo && (
57+
<>
58+
<strong>Version:</strong> {version}
59+
</>
60+
)}
4161
</CodeMessage>
4262
<ErrorMessage>
4363
We apologize for the inconvenience. The issue may be on our end. If troubleshooting doesn't
@@ -56,18 +76,50 @@ export function Fallback({ error, children }: FallbackComponentProps): JSX.Eleme
5676
}
5777

5878
const reportError = (error: Error, info: React.ErrorInfo): void => {
79+
const pageUrl = window.location.href;
80+
const timestamp = new Date().toLocaleString();
5981
// This is where you'd send the error to Sentry, etc
60-
console.log('Error Caught Inside Boundary --reportError', error, 'Info', info);
82+
console.log(
83+
'Error Caught Inside Boundary --reportError',
84+
error,
85+
'Info',
86+
info,
87+
'Page URL:',
88+
pageUrl,
89+
'Timestamp:',
90+
timestamp
91+
);
6192
};
6293

6394
interface ErrorBoundaryProps {
6495
customFallback?: React.ComponentType<FallbackProps>;
6596
children: React.ReactNode;
97+
onErrorCaught?: (error: string) => void;
6698
}
6799

68-
export const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ customFallback, children }) => {
100+
export const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({
101+
customFallback,
102+
children,
103+
onErrorCaught
104+
}) => {
105+
const pageUrl = window.location.href;
106+
const timestamp = new Date().toLocaleString();
107+
108+
const handleError = (error: Error, info: React.ErrorInfo) => {
109+
// Pass error message to onErrorCaught
110+
onErrorCaught?.(error.message);
111+
reportError(error, info);
112+
};
113+
69114
return (
70-
<ReactErrorBoundary FallbackComponent={customFallback ?? Fallback} onError={reportError}>
115+
<ReactErrorBoundary
116+
FallbackComponent={
117+
customFallback
118+
? customFallback
119+
: (props) => <Fallback {...props} pageUrl={pageUrl} timestamp={timestamp} />
120+
}
121+
onError={handleError}
122+
>
71123
{children}
72124
</ReactErrorBoundary>
73125
);

0 commit comments

Comments
 (0)