|
| 1 | +import _ from 'lodash'; |
| 2 | +import React from 'react'; |
| 3 | +import { CircularProgress } from '../../base'; |
| 4 | +import { CopyIcon, KanvasIcon } from '../../icons'; |
| 5 | +import Download from '../../icons/Download/Download'; |
| 6 | +import { charcoal } from '../../theme'; |
| 7 | +import { Pattern } from '../CustomCatalog/CustomCard'; |
| 8 | +import { downloadFilter, downloadYaml, slugify } from './helper'; |
| 9 | +import { ActionButton, LinkUrl, StyledActionWrapper } from './style'; |
| 10 | +import { RESOURCE_TYPES } from './types'; |
| 11 | + |
| 12 | +interface ActionButtonsProps { |
| 13 | + actionItems: boolean; |
| 14 | + details: Pattern; |
| 15 | + type: string; |
| 16 | + cardId: string; |
| 17 | + isCloneLoading: boolean; |
| 18 | + handleClone: (name: string, id: string) => void; |
| 19 | + mode: string; |
| 20 | + isCloneDisabled: boolean; |
| 21 | +} |
| 22 | + |
| 23 | +const ActionButtons: React.FC<ActionButtonsProps> = ({ |
| 24 | + actionItems, |
| 25 | + details, |
| 26 | + type, |
| 27 | + cardId, |
| 28 | + isCloneLoading, |
| 29 | + handleClone, |
| 30 | + mode, |
| 31 | + isCloneDisabled |
| 32 | +}) => { |
| 33 | + const cleanedType = type.replace('my-', '').replace(/s$/, ''); |
| 34 | + const resourcePlaygroundType = Object.values({ |
| 35 | + ..._.omit(RESOURCE_TYPES, ['FILTERS']), |
| 36 | + CATALOG: 'catalog' |
| 37 | + }).includes(cleanedType) |
| 38 | + ? cleanedType |
| 39 | + : 'design'; |
| 40 | + return ( |
| 41 | + <StyledActionWrapper> |
| 42 | + {actionItems && ( |
| 43 | + <div |
| 44 | + style={{ |
| 45 | + display: 'flex', |
| 46 | + flexDirection: 'row', |
| 47 | + gap: '0.75rem', |
| 48 | + width: '100%' |
| 49 | + }} |
| 50 | + > |
| 51 | + <ActionButton |
| 52 | + sx={{ |
| 53 | + borderRadius: '0.2rem', |
| 54 | + backgroundColor: 'background.inverse', |
| 55 | + gap: '10px', |
| 56 | + color: charcoal[100] |
| 57 | + }} |
| 58 | + onClick={() => |
| 59 | + cleanedType === RESOURCE_TYPES.FILTERS |
| 60 | + ? downloadFilter(details.id, details.name) |
| 61 | + : downloadYaml(details.pattern_file, details.name) |
| 62 | + } |
| 63 | + > |
| 64 | + <Download width={24} height={24} fill={charcoal[100]} /> |
| 65 | + Download |
| 66 | + </ActionButton> |
| 67 | + |
| 68 | + {cleanedType !== RESOURCE_TYPES.FILTERS && ( |
| 69 | + <ActionButton |
| 70 | + sx={{ |
| 71 | + borderRadius: '0.2rem', |
| 72 | + gap: '10px', |
| 73 | + color: charcoal[100] |
| 74 | + }} |
| 75 | + onClick={() => handleClone(details?.name, details?.id)} |
| 76 | + disabled={isCloneDisabled} |
| 77 | + > |
| 78 | + {isCloneLoading ? ( |
| 79 | + <CircularProgress size={24} color={'inherit'} /> |
| 80 | + ) : ( |
| 81 | + <> |
| 82 | + <CopyIcon width={24} height={24} fill={charcoal[100]} /> |
| 83 | + Clone |
| 84 | + </> |
| 85 | + )} |
| 86 | + </ActionButton> |
| 87 | + )} |
| 88 | + </div> |
| 89 | + )} |
| 90 | + <LinkUrl |
| 91 | + style={{ width: '100%' }} |
| 92 | + href={`https://playground.meshery.io/extension/meshmap?mode=${mode}&type=${resourcePlaygroundType}&id=${cardId}&name=${slugify( |
| 93 | + details.name |
| 94 | + )}`} |
| 95 | + target="_blank" |
| 96 | + rel="noreferrer" |
| 97 | + > |
| 98 | + <ActionButton |
| 99 | + sx={{ |
| 100 | + borderRadius: '0.2rem', |
| 101 | + backgroundColor: 'background.cta.default', |
| 102 | + color: charcoal[10], |
| 103 | + gap: '10px', |
| 104 | + width: '100%' |
| 105 | + }} |
| 106 | + > |
| 107 | + <KanvasIcon width={24} height={24} primaryFill={charcoal[10]} fill={charcoal[10]} /> |
| 108 | + Open in Playground |
| 109 | + </ActionButton> |
| 110 | + </LinkUrl> |
| 111 | + </StyledActionWrapper> |
| 112 | + ); |
| 113 | +}; |
| 114 | + |
| 115 | +export default ActionButtons; |
0 commit comments