Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add open in playground button for cloud and extension #800

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 20 additions & 39 deletions src/custom/CatalogDetail/ActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
import _ from 'lodash';
import React from 'react';
import { CircularProgress } from '../../base';
import { CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
import Download from '../../icons/Download/Download';
import { charcoal } from '../../theme';
import { Pattern } from '../CustomCatalog/CustomCard';
import { downloadFilter, downloadYaml, slugify } from './helper';
import { ActionButton, LinkUrl, StyledActionWrapper, UnpublishAction } from './style';
import { downloadFilter, downloadYaml } from './helper';
import { ActionButton, StyledActionWrapper, UnpublishAction } from './style';
import { RESOURCE_TYPES } from './types';

interface ActionButtonsProps {
actionItems: boolean;
details: Pattern;
type: string;
cardId: string;
isCloneLoading: boolean;
handleClone: (name: string, id: string) => void;
mode: string;
handleUnpublish: () => void;
isCloneDisabled: boolean;
showOpenPlaygroundButton: boolean;
showUnpublishAction: boolean;
onOpenPlaygroundClick: (designId: string, name: string) => void;
}

const ActionButtons: React.FC<ActionButtonsProps> = ({
actionItems,
details,
type,
cardId,
isCloneLoading,
handleClone,
mode,
isCloneDisabled,
showOpenPlaygroundButton,
showUnpublishAction,
handleUnpublish
handleUnpublish,
onOpenPlaygroundClick
}) => {
const cleanedType = type.replace('my-', '').replace(/s$/, '');
const resourcePlaygroundType = Object.values({
..._.omit(RESOURCE_TYPES, ['FILTERS']),
CATALOG: 'catalog'
}).includes(cleanedType)
? cleanedType
: 'design';
return (
<StyledActionWrapper>
{actionItems && (
Expand Down Expand Up @@ -93,29 +82,21 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
)}
</div>
)}
{showOpenPlaygroundButton && (
<LinkUrl
style={{ width: '100%' }}
href={`https://playground.meshery.io/extension/meshmap?mode=${mode}&type=${resourcePlaygroundType}&id=${cardId}&name=${slugify(
details.name
)}`}
target="_blank"
rel="noreferrer"
>
<ActionButton
sx={{
borderRadius: '0.2rem',
backgroundColor: 'background.cta.default',
color: charcoal[10],
gap: '10px',
width: '100%'
}}
>
<KanvasIcon width={24} height={24} primaryFill={charcoal[10]} fill={charcoal[10]} />
Open in Playground
</ActionButton>
</LinkUrl>
)}

<ActionButton
sx={{
borderRadius: '0.2rem',
backgroundColor: 'background.cta.default',
color: charcoal[10],
gap: '10px',
width: '100%'
}}
onClick={() => onOpenPlaygroundClick(details.id, details.name)}
>
<KanvasIcon width={24} height={24} primaryFill={charcoal[10]} fill={charcoal[10]} />
Open in Playground
</ActionButton>

{showUnpublishAction && (
<UnpublishAction
sx={{
Expand Down
12 changes: 3 additions & 9 deletions src/custom/CatalogDetail/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@ import { FilteredAcademyData } from './types';
interface LeftPanelProps {
details: Pattern;
type: string;
cardId?: string;
actionItems?: boolean;
isCloneLoading: boolean;
handleClone: (name: string, id: string) => void;
showTechnologies?: boolean;
mode: string;
filteredAcademyData: FilteredAcademyData;
isCloneDisabled: boolean;
technologySVGPath: string;
technologySVGSubpath: string;
fontFamily?: string;
showOpenPlaygroundButton?: boolean;
handleUnpublish: () => void;
showUnpublishAction?: boolean;
onOpenPlaygroundClick: (designId: string, name: string) => void;
}

const LeftPanel: React.FC<LeftPanelProps> = ({
details,
type,
cardId = details.id,
actionItems = true,
isCloneLoading,
handleClone,
handleUnpublish,
showTechnologies = true,
mode,
filteredAcademyData,
isCloneDisabled,
technologySVGPath,
technologySVGSubpath,
fontFamily,
showUnpublishAction = false,
showOpenPlaygroundButton = true
onOpenPlaygroundClick
}) => {
const theme = useTheme();

Expand Down Expand Up @@ -78,14 +74,12 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
actionItems={actionItems}
details={details}
type={type}
cardId={cardId}
isCloneLoading={isCloneLoading}
handleClone={handleClone}
showUnpublishAction={showUnpublishAction}
handleUnpublish={handleUnpublish}
mode={mode}
isCloneDisabled={isCloneDisabled}
showOpenPlaygroundButton={showOpenPlaygroundButton}
onOpenPlaygroundClick={onOpenPlaygroundClick}
/>
{showTechnologies && (
<TechnologySection
Expand Down
4 changes: 0 additions & 4 deletions src/custom/CatalogDetail/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export const StyledActionWrapper = styled(Paper)(() => ({
alignItems: 'center'
}));

export const LinkUrl = styled('a')(() => ({
textDecoration: 'none'
}));

interface ActionButtonProps {
disabled?: boolean;
theme?: Theme;
Expand Down
Loading