Skip to content

Commit a32ee32

Browse files
authored
Merge pull request #800 from amitamrutiya/open-playground
feat: add open in playground button for cloud and extension
2 parents 42e0295 + 4446993 commit a32ee32

3 files changed

Lines changed: 23 additions & 52 deletions

File tree

src/custom/CatalogDetail/ActionButton.tsx

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
1-
import _ from 'lodash';
21
import React from 'react';
32
import { CircularProgress } from '../../base';
43
import { CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
54
import Download from '../../icons/Download/Download';
65
import { charcoal } from '../../theme';
76
import { Pattern } from '../CustomCatalog/CustomCard';
8-
import { downloadFilter, downloadYaml, slugify } from './helper';
9-
import { ActionButton, LinkUrl, StyledActionWrapper, UnpublishAction } from './style';
7+
import { downloadFilter, downloadYaml } from './helper';
8+
import { ActionButton, StyledActionWrapper, UnpublishAction } from './style';
109
import { RESOURCE_TYPES } from './types';
1110

1211
interface ActionButtonsProps {
1312
actionItems: boolean;
1413
details: Pattern;
1514
type: string;
16-
cardId: string;
1715
isCloneLoading: boolean;
1816
handleClone: (name: string, id: string) => void;
19-
mode: string;
2017
handleUnpublish: () => void;
2118
isCloneDisabled: boolean;
22-
showOpenPlaygroundButton: boolean;
2319
showUnpublishAction: boolean;
20+
onOpenPlaygroundClick: (designId: string, name: string) => void;
2421
}
2522

2623
const ActionButtons: React.FC<ActionButtonsProps> = ({
2724
actionItems,
2825
details,
2926
type,
30-
cardId,
3127
isCloneLoading,
3228
handleClone,
33-
mode,
3429
isCloneDisabled,
35-
showOpenPlaygroundButton,
3630
showUnpublishAction,
37-
handleUnpublish
31+
handleUnpublish,
32+
onOpenPlaygroundClick
3833
}) => {
3934
const cleanedType = type.replace('my-', '').replace(/s$/, '');
40-
const resourcePlaygroundType = Object.values({
41-
..._.omit(RESOURCE_TYPES, ['FILTERS']),
42-
CATALOG: 'catalog'
43-
}).includes(cleanedType)
44-
? cleanedType
45-
: 'design';
4635
return (
4736
<StyledActionWrapper>
4837
{actionItems && (
@@ -93,29 +82,21 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
9382
)}
9483
</div>
9584
)}
96-
{showOpenPlaygroundButton && (
97-
<LinkUrl
98-
style={{ width: '100%' }}
99-
href={`https://playground.meshery.io/extension/meshmap?mode=${mode}&type=${resourcePlaygroundType}&id=${cardId}&name=${slugify(
100-
details.name
101-
)}`}
102-
target="_blank"
103-
rel="noreferrer"
104-
>
105-
<ActionButton
106-
sx={{
107-
borderRadius: '0.2rem',
108-
backgroundColor: 'background.cta.default',
109-
color: charcoal[10],
110-
gap: '10px',
111-
width: '100%'
112-
}}
113-
>
114-
<KanvasIcon width={24} height={24} primaryFill={charcoal[10]} fill={charcoal[10]} />
115-
Open in Playground
116-
</ActionButton>
117-
</LinkUrl>
118-
)}
85+
86+
<ActionButton
87+
sx={{
88+
borderRadius: '0.2rem',
89+
backgroundColor: 'background.cta.default',
90+
color: charcoal[10],
91+
gap: '10px',
92+
width: '100%'
93+
}}
94+
onClick={() => onOpenPlaygroundClick(details.id, details.name)}
95+
>
96+
<KanvasIcon width={24} height={24} primaryFill={charcoal[10]} fill={charcoal[10]} />
97+
Open in Playground
98+
</ActionButton>
99+
119100
{showUnpublishAction && (
120101
<UnpublishAction
121102
sx={{

src/custom/CatalogDetail/LeftPanel.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,35 @@ import { FilteredAcademyData } from './types';
1010
interface LeftPanelProps {
1111
details: Pattern;
1212
type: string;
13-
cardId?: string;
1413
actionItems?: boolean;
1514
isCloneLoading: boolean;
1615
handleClone: (name: string, id: string) => void;
1716
showTechnologies?: boolean;
18-
mode: string;
1917
filteredAcademyData: FilteredAcademyData;
2018
isCloneDisabled: boolean;
2119
technologySVGPath: string;
2220
technologySVGSubpath: string;
2321
fontFamily?: string;
24-
showOpenPlaygroundButton?: boolean;
2522
handleUnpublish: () => void;
2623
showUnpublishAction?: boolean;
24+
onOpenPlaygroundClick: (designId: string, name: string) => void;
2725
}
2826

2927
const LeftPanel: React.FC<LeftPanelProps> = ({
3028
details,
3129
type,
32-
cardId = details.id,
3330
actionItems = true,
3431
isCloneLoading,
3532
handleClone,
3633
handleUnpublish,
3734
showTechnologies = true,
38-
mode,
3935
filteredAcademyData,
4036
isCloneDisabled,
4137
technologySVGPath,
4238
technologySVGSubpath,
4339
fontFamily,
4440
showUnpublishAction = false,
45-
showOpenPlaygroundButton = true
41+
onOpenPlaygroundClick
4642
}) => {
4743
const theme = useTheme();
4844

@@ -78,14 +74,12 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
7874
actionItems={actionItems}
7975
details={details}
8076
type={type}
81-
cardId={cardId}
8277
isCloneLoading={isCloneLoading}
8378
handleClone={handleClone}
8479
showUnpublishAction={showUnpublishAction}
8580
handleUnpublish={handleUnpublish}
86-
mode={mode}
8781
isCloneDisabled={isCloneDisabled}
88-
showOpenPlaygroundButton={showOpenPlaygroundButton}
82+
onOpenPlaygroundClick={onOpenPlaygroundClick}
8983
/>
9084
{showTechnologies && (
9185
<TechnologySection

src/custom/CatalogDetail/style.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export const StyledActionWrapper = styled(Paper)(() => ({
1515
alignItems: 'center'
1616
}));
1717

18-
export const LinkUrl = styled('a')(() => ({
19-
textDecoration: 'none'
20-
}));
21-
2218
interface ActionButtonProps {
2319
disabled?: boolean;
2420
theme?: Theme;

0 commit comments

Comments
 (0)