Skip to content

Commit

Permalink
feat: remove the soruce content logic with the id only
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Amrutiya <[email protected]>
  • Loading branch information
amitamrutiya committed Jan 2, 2025
1 parent 5478ebd commit 4d4bebf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 38 deletions.
12 changes: 5 additions & 7 deletions src/custom/CatalogDesignTable/DesignTableColumnConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChainIcon, CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
import Download from '../../icons/Download/Download';
import { CHARCOAL } from '../../theme';
import { downloadPattern, slugify } from '../CatalogDetail/helper';
import { PATTERNS, RESOURCE_TYPES } from '../CatalogDetail/types';
import { RESOURCE_TYPES } from '../CatalogDetail/types';
import { Pattern } from '../CustomCatalog/CustomCard';
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx';
Expand All @@ -25,7 +25,7 @@ interface ColumnConfigProps {
handleCopyUrl: (type: string, name: string, id: string) => void;
handleClone: (name: string, id: string) => void;
handleShowDetails: (designId: string, designName: string) => void;
getDownloadUrl: (sorceType: string, id: string) => string;
getDownloadUrl: (id: string) => string;
isDownloadAllowed: boolean;
isCopyLinkAllowed: boolean;
isDeleteAllowed: boolean;
Expand Down Expand Up @@ -169,15 +169,15 @@ export const createDesignsColumnsConfig = ({
const actionsList = [
{
title: 'Download',
onClick: () => downloadPattern(rowData.id, rowData.name, PATTERNS, getDownloadUrl),
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
disabled: !isDownloadAllowed,
icon: <Download width={24} height={24} fill={CHARCOAL} />
},
{
title: 'Copy Link',
disabled: rowData.visibility === 'private' || !isCopyLinkAllowed,
onClick: () => {
handleCopyUrl(RESOURCE_TYPES.DESIGNS, rowData?.name, rowData?.id);
handleCopyUrl(RESOURCE_TYPES.DESIGN, rowData?.name, rowData?.id);
},
icon: <ChainIcon width={'24'} height={'24'} fill={CHARCOAL} />
},
Expand All @@ -187,9 +187,7 @@ export const createDesignsColumnsConfig = ({
window.open(
`https://playground.meshery.io/extension/meshmap?mode=${
PLAYGROUND_MODES.DESIGNER
}&type=${RESOURCE_TYPES.DESIGNS}&id=${rowData?.id}&name=${slugify(
rowData?.name
)}`,
}&type=${RESOURCE_TYPES.DESIGN}&id=${rowData?.id}&name=${slugify(rowData?.name)}`,
'_blank'
);
},
Expand Down
5 changes: 2 additions & 3 deletions src/custom/CatalogDesignTable/columnConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
TwitterIcon
} from '../../icons';
import { downloadPattern } from '../CatalogDetail/helper';
import { PATTERNS } from '../CatalogDetail/types';
import { Pattern } from '../CustomCatalog/CustomCard';
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
Expand Down Expand Up @@ -54,7 +53,7 @@ interface ColumnConfigProps {
currentUserId?: string;
isCloneDisabled?: boolean;
isUnpublishDisabled?: boolean;
getDownloadUrl: (sorceType: string, id: string) => string;
getDownloadUrl: (id: string) => string;
}

interface ActionItem {
Expand Down Expand Up @@ -259,7 +258,7 @@ export const createDesignColumns = ({
},
{
title: 'Download',
onClick: () => downloadPattern(rowData.id, rowData.name, PATTERNS, getDownloadUrl),
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
icon: <DownloadIcon width={24} height={24} fill={theme.palette.text.primary} />
},
{
Expand Down
13 changes: 6 additions & 7 deletions src/custom/CatalogDetail/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { CopyIcon, DeleteIcon, EditIcon, KanvasIcon, PublishIcon } from '../../i
import Download from '../../icons/Download/Download';
import { charcoal, useTheme } from '../../theme';
import { Pattern } from '../CustomCatalog/CustomCard';
import { downloadPattern, downloadYaml, getValidSorceType } from './helper';
import { downloadPattern, downloadYaml } from './helper';
import { ActionButton, StyledActionWrapper, UnpublishAction } from './style';
import { RESOURCE_TYPES } from './types';
import { FILTERS, VIEWS } from './types';

interface ActionButtonsProps {
actionItems: boolean;
details: Pattern;
type: string;
isCloneLoading: boolean;
getDownloadUrl: (sorceType: string, id: string) => string;
getDownloadUrl: (id: string) => string;
handleClone: (name: string, id: string) => void;
handleUnpublish: () => void;
isCloneDisabled: boolean;
Expand Down Expand Up @@ -44,7 +44,6 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
handleDelete
}) => {
const cleanedType = type.replace('my-', '').replace(/s$/, '');
const sorceType = getValidSorceType(type);
const theme = useTheme();
return (
<StyledActionWrapper>
Expand Down Expand Up @@ -86,16 +85,16 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
color: theme.palette.text.default
}}
onClick={() =>
cleanedType === RESOURCE_TYPES.VIEWS
cleanedType === VIEWS
? downloadYaml(details.pattern_file, details.name)
: downloadPattern(details.id, details.name, sorceType, getDownloadUrl)
: downloadPattern(details.id, details.name, getDownloadUrl)
}
>
<Download width={24} height={24} fill={theme.palette.icon.default} />
Download
</ActionButton>

{cleanedType !== RESOURCE_TYPES.FILTERS && (
{cleanedType !== FILTERS && (
<ActionButton
sx={{
borderRadius: '0.2rem',
Expand Down
2 changes: 1 addition & 1 deletion src/custom/CatalogDetail/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface LeftPanelProps {
handleInfoClick?: () => void;
showDeleteAction?: boolean;
handleDelete: () => void;
getDownloadUrl: (sorceType: string, id: string) => string;
getDownloadUrl: (id: string) => string;
}

const LeftPanel: React.FC<LeftPanelProps> = ({
Expand Down
18 changes: 2 additions & 16 deletions src/custom/CatalogDetail/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ export function slugify(str: string): string {
export const downloadPattern = (
id: string,
name: string,
sorceType: string,
getDownloadUrl: (sorceType: string, id: string) => string
getDownloadUrl: (id: string) => string
): void => {
const downloadUrl = getDownloadUrl(sorceType, id);
const downloadUrl = getDownloadUrl(id);

const fileNameWithExtension = `${name}.yaml`;
const linkElement = document.createElement('a');
Expand All @@ -62,16 +61,3 @@ export const formatDate = (date: Date) => {
const formattedDate = new Date(date).toLocaleDateString('en-US', options);
return formattedDate;
};

export const getValidSorceType = (type: string): string => {
if (type === 'my-designs' || type === 'catalog') {
return 'patterns';
}
if (type === 'my-filters') {
return 'filters';
}
if (type === 'my-views') {
return 'views';
}
return '';
};
8 changes: 5 additions & 3 deletions src/custom/CatalogDetail/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ export interface Theme {
}

export const RESOURCE_TYPES = {
DESIGNS: 'design',
FILTERS: 'filter',
VIEWS: 'view'
DESIGN: 'design',
FILTER: 'filter',
VIEW: 'view'
};

export const PATTERNS = 'patterns';
export const FILTERS = 'filters';
export const VIEWS = 'views';

export type ContentClassType = {
community: {
Expand Down
2 changes: 1 addition & 1 deletion src/custom/Workspaces/DesignTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface DesignTableProps {
workspaceName: string,
workspaceId: string
) => void;
getDownloadUrl: (sorceType: string, id: string) => string;
getDownloadUrl: (id: string) => string;
handlePublish: (publishModal: PublishModalState, data: any) => void;
publishModalHandler: any;
handleUnpublishModal: (design: Pattern, modalRef: React.RefObject<any>) => void;
Expand Down

0 comments on commit 4d4bebf

Please sign in to comment.