Skip to content

Commit 4d4bebf

Browse files
committed
feat: remove the soruce content logic with the id only
Signed-off-by: Amit Amrutiya <[email protected]>
1 parent 5478ebd commit 4d4bebf

File tree

7 files changed

+22
-38
lines changed

7 files changed

+22
-38
lines changed

src/custom/CatalogDesignTable/DesignTableColumnConfig.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChainIcon, CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
44
import Download from '../../icons/Download/Download';
55
import { CHARCOAL } from '../../theme';
66
import { downloadPattern, slugify } from '../CatalogDetail/helper';
7-
import { PATTERNS, RESOURCE_TYPES } from '../CatalogDetail/types';
7+
import { RESOURCE_TYPES } from '../CatalogDetail/types';
88
import { Pattern } from '../CustomCatalog/CustomCard';
99
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
1010
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx';
@@ -25,7 +25,7 @@ interface ColumnConfigProps {
2525
handleCopyUrl: (type: string, name: string, id: string) => void;
2626
handleClone: (name: string, id: string) => void;
2727
handleShowDetails: (designId: string, designName: string) => void;
28-
getDownloadUrl: (sorceType: string, id: string) => string;
28+
getDownloadUrl: (id: string) => string;
2929
isDownloadAllowed: boolean;
3030
isCopyLinkAllowed: boolean;
3131
isDeleteAllowed: boolean;
@@ -169,15 +169,15 @@ export const createDesignsColumnsConfig = ({
169169
const actionsList = [
170170
{
171171
title: 'Download',
172-
onClick: () => downloadPattern(rowData.id, rowData.name, PATTERNS, getDownloadUrl),
172+
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
173173
disabled: !isDownloadAllowed,
174174
icon: <Download width={24} height={24} fill={CHARCOAL} />
175175
},
176176
{
177177
title: 'Copy Link',
178178
disabled: rowData.visibility === 'private' || !isCopyLinkAllowed,
179179
onClick: () => {
180-
handleCopyUrl(RESOURCE_TYPES.DESIGNS, rowData?.name, rowData?.id);
180+
handleCopyUrl(RESOURCE_TYPES.DESIGN, rowData?.name, rowData?.id);
181181
},
182182
icon: <ChainIcon width={'24'} height={'24'} fill={CHARCOAL} />
183183
},
@@ -187,9 +187,7 @@ export const createDesignsColumnsConfig = ({
187187
window.open(
188188
`https://playground.meshery.io/extension/meshmap?mode=${
189189
PLAYGROUND_MODES.DESIGNER
190-
}&type=${RESOURCE_TYPES.DESIGNS}&id=${rowData?.id}&name=${slugify(
191-
rowData?.name
192-
)}`,
190+
}&type=${RESOURCE_TYPES.DESIGN}&id=${rowData?.id}&name=${slugify(rowData?.name)}`,
193191
'_blank'
194192
);
195193
},

src/custom/CatalogDesignTable/columnConfig.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
TwitterIcon
1515
} from '../../icons';
1616
import { downloadPattern } from '../CatalogDetail/helper';
17-
import { PATTERNS } from '../CatalogDetail/types';
1817
import { Pattern } from '../CustomCatalog/CustomCard';
1918
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
2019
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
@@ -54,7 +53,7 @@ interface ColumnConfigProps {
5453
currentUserId?: string;
5554
isCloneDisabled?: boolean;
5655
isUnpublishDisabled?: boolean;
57-
getDownloadUrl: (sorceType: string, id: string) => string;
56+
getDownloadUrl: (id: string) => string;
5857
}
5958

6059
interface ActionItem {
@@ -259,7 +258,7 @@ export const createDesignColumns = ({
259258
},
260259
{
261260
title: 'Download',
262-
onClick: () => downloadPattern(rowData.id, rowData.name, PATTERNS, getDownloadUrl),
261+
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
263262
icon: <DownloadIcon width={24} height={24} fill={theme.palette.text.primary} />
264263
},
265264
{

src/custom/CatalogDetail/ActionButton.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { CopyIcon, DeleteIcon, EditIcon, KanvasIcon, PublishIcon } from '../../i
44
import Download from '../../icons/Download/Download';
55
import { charcoal, useTheme } from '../../theme';
66
import { Pattern } from '../CustomCatalog/CustomCard';
7-
import { downloadPattern, downloadYaml, getValidSorceType } from './helper';
7+
import { downloadPattern, downloadYaml } from './helper';
88
import { ActionButton, StyledActionWrapper, UnpublishAction } from './style';
9-
import { RESOURCE_TYPES } from './types';
9+
import { FILTERS, VIEWS } from './types';
1010

1111
interface ActionButtonsProps {
1212
actionItems: boolean;
1313
details: Pattern;
1414
type: string;
1515
isCloneLoading: boolean;
16-
getDownloadUrl: (sorceType: string, id: string) => string;
16+
getDownloadUrl: (id: string) => string;
1717
handleClone: (name: string, id: string) => void;
1818
handleUnpublish: () => void;
1919
isCloneDisabled: boolean;
@@ -44,7 +44,6 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
4444
handleDelete
4545
}) => {
4646
const cleanedType = type.replace('my-', '').replace(/s$/, '');
47-
const sorceType = getValidSorceType(type);
4847
const theme = useTheme();
4948
return (
5049
<StyledActionWrapper>
@@ -86,16 +85,16 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
8685
color: theme.palette.text.default
8786
}}
8887
onClick={() =>
89-
cleanedType === RESOURCE_TYPES.VIEWS
88+
cleanedType === VIEWS
9089
? downloadYaml(details.pattern_file, details.name)
91-
: downloadPattern(details.id, details.name, sorceType, getDownloadUrl)
90+
: downloadPattern(details.id, details.name, getDownloadUrl)
9291
}
9392
>
9493
<Download width={24} height={24} fill={theme.palette.icon.default} />
9594
Download
9695
</ActionButton>
9796

98-
{cleanedType !== RESOURCE_TYPES.FILTERS && (
97+
{cleanedType !== FILTERS && (
9998
<ActionButton
10099
sx={{
101100
borderRadius: '0.2rem',

src/custom/CatalogDetail/LeftPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface LeftPanelProps {
2727
handleInfoClick?: () => void;
2828
showDeleteAction?: boolean;
2929
handleDelete: () => void;
30-
getDownloadUrl: (sorceType: string, id: string) => string;
30+
getDownloadUrl: (id: string) => string;
3131
}
3232

3333
const LeftPanel: React.FC<LeftPanelProps> = ({

src/custom/CatalogDetail/helper.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ export function slugify(str: string): string {
3737
export const downloadPattern = (
3838
id: string,
3939
name: string,
40-
sorceType: string,
41-
getDownloadUrl: (sorceType: string, id: string) => string
40+
getDownloadUrl: (id: string) => string
4241
): void => {
43-
const downloadUrl = getDownloadUrl(sorceType, id);
42+
const downloadUrl = getDownloadUrl(id);
4443

4544
const fileNameWithExtension = `${name}.yaml`;
4645
const linkElement = document.createElement('a');
@@ -62,16 +61,3 @@ export const formatDate = (date: Date) => {
6261
const formattedDate = new Date(date).toLocaleDateString('en-US', options);
6362
return formattedDate;
6463
};
65-
66-
export const getValidSorceType = (type: string): string => {
67-
if (type === 'my-designs' || type === 'catalog') {
68-
return 'patterns';
69-
}
70-
if (type === 'my-filters') {
71-
return 'filters';
72-
}
73-
if (type === 'my-views') {
74-
return 'views';
75-
}
76-
return '';
77-
};

src/custom/CatalogDetail/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ export interface Theme {
3232
}
3333

3434
export const RESOURCE_TYPES = {
35-
DESIGNS: 'design',
36-
FILTERS: 'filter',
37-
VIEWS: 'view'
35+
DESIGN: 'design',
36+
FILTER: 'filter',
37+
VIEW: 'view'
3838
};
3939

4040
export const PATTERNS = 'patterns';
41+
export const FILTERS = 'filters';
42+
export const VIEWS = 'views';
4143

4244
export type ContentClassType = {
4345
community: {

src/custom/Workspaces/DesignTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface DesignTableProps {
3939
workspaceName: string,
4040
workspaceId: string
4141
) => void;
42-
getDownloadUrl: (sorceType: string, id: string) => string;
42+
getDownloadUrl: (id: string) => string;
4343
handlePublish: (publishModal: PublishModalState, data: any) => void;
4444
publishModalHandler: any;
4545
handleUnpublishModal: (design: Pattern, modalRef: React.RefObject<any>) => void;

0 commit comments

Comments
 (0)