Skip to content

Commit 803803f

Browse files
authored
Merge pull request #865 from amitamrutiya/fix-download
make download patters, filters from the server side
2 parents e103b21 + 8b474a1 commit 803803f

File tree

7 files changed

+41
-33
lines changed

7 files changed

+41
-33
lines changed

src/custom/CatalogDesignTable/DesignTableColumnConfig.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PLAYGROUND_MODES } from '../../constants/constants';
33
import { ChainIcon, CopyIcon, KanvasIcon, PublishIcon } from '../../icons';
44
import Download from '../../icons/Download/Download';
55
import { CHARCOAL } from '../../theme';
6-
import { downloadYaml, slugify } from '../CatalogDetail/helper';
6+
import { downloadPattern, slugify } from '../CatalogDetail/helper';
77
import { RESOURCE_TYPES } from '../CatalogDetail/types';
88
import { Pattern } from '../CustomCatalog/CustomCard';
99
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
@@ -25,6 +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: (id: string) => string;
2829
isDownloadAllowed: boolean;
2930
isCopyLinkAllowed: boolean;
3031
isDeleteAllowed: boolean;
@@ -53,6 +54,7 @@ export const createDesignsColumnsConfig = ({
5354
handleCopyUrl,
5455
handleClone,
5556
handleShowDetails,
57+
getDownloadUrl,
5658
isUnpublishAllowed,
5759
isCopyLinkAllowed,
5860
isDeleteAllowed,
@@ -167,15 +169,15 @@ export const createDesignsColumnsConfig = ({
167169
const actionsList = [
168170
{
169171
title: 'Download',
170-
onClick: () => downloadYaml(rowData?.pattern_file, rowData?.name),
172+
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
171173
disabled: !isDownloadAllowed,
172174
icon: <Download width={24} height={24} fill={CHARCOAL} />
173175
},
174176
{
175177
title: 'Copy Link',
176178
disabled: rowData.visibility === 'private' || !isCopyLinkAllowed,
177179
onClick: () => {
178-
handleCopyUrl(RESOURCE_TYPES.DESIGNS, rowData?.name, rowData?.id);
180+
handleCopyUrl(RESOURCE_TYPES.DESIGN, rowData?.name, rowData?.id);
179181
},
180182
icon: <ChainIcon width={'24'} height={'24'} fill={CHARCOAL} />
181183
},
@@ -185,9 +187,7 @@ export const createDesignsColumnsConfig = ({
185187
window.open(
186188
`https://playground.meshery.io/extension/meshmap?mode=${
187189
PLAYGROUND_MODES.DESIGNER
188-
}&type=${RESOURCE_TYPES.DESIGNS}&id=${rowData?.id}&name=${slugify(
189-
rowData?.name
190-
)}`,
190+
}&type=${RESOURCE_TYPES.DESIGN}&id=${rowData?.id}&name=${slugify(rowData?.name)}`,
191191
'_blank'
192192
);
193193
},

src/custom/CatalogDesignTable/columnConfig.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
PublishIcon,
1414
TwitterIcon
1515
} from '../../icons';
16-
import { downloadFilter, downloadYaml } from '../CatalogDetail/helper';
17-
import { RESOURCE_TYPES } from '../CatalogDetail/types';
16+
import { downloadPattern } from '../CatalogDetail/helper';
1817
import { Pattern } from '../CustomCatalog/CustomCard';
1918
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
2019
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
@@ -48,13 +47,13 @@ interface ColumnConfigProps {
4847
handleUnpublish?: (design: Pattern) => void;
4948
maxWidth?: boolean;
5049
getCatalogUrl: (type: string, name: string) => string;
51-
type?: string;
5250
theme?: any;
5351
showUnpublish?: boolean;
5452
showOpenPlayground?: boolean;
5553
currentUserId?: string;
5654
isCloneDisabled?: boolean;
5755
isUnpublishDisabled?: boolean;
56+
getDownloadUrl: (id: string) => string;
5857
}
5958

6059
interface ActionItem {
@@ -74,15 +73,14 @@ export const createDesignColumns = ({
7473
handleUnpublish = () => {},
7574
maxWidth = true,
7675
getCatalogUrl,
77-
type,
76+
getDownloadUrl,
7877
theme,
7978
showUnpublish,
8079
currentUserId,
8180
isCloneDisabled,
8281
isUnpublishDisabled,
8382
showOpenPlayground
8483
}: ColumnConfigProps): MUIDataTableColumn[] => {
85-
const cleanedType = type?.replace('my-', '').replace(/s$/, '');
8684
return [
8785
{
8886
name: 'id',
@@ -260,11 +258,7 @@ export const createDesignColumns = ({
260258
},
261259
{
262260
title: 'Download',
263-
onClick: () => {
264-
cleanedType === RESOURCE_TYPES.FILTERS
265-
? downloadFilter(rowData.id, rowData.name)
266-
: downloadYaml(rowData.pattern_file, rowData.name);
267-
},
261+
onClick: () => downloadPattern(rowData.id, rowData.name, getDownloadUrl),
268262
icon: <DownloadIcon width={24} height={24} fill={theme.palette.text.primary} />
269263
},
270264
{

src/custom/CatalogDetail/ActionButton.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +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 { downloadFilter, downloadYaml } 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: (id: string) => string;
1617
handleClone: (name: string, id: string) => void;
1718
handleUnpublish: () => void;
1819
isCloneDisabled: boolean;
@@ -34,6 +35,7 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
3435
isCloneDisabled,
3536
showUnpublishAction,
3637
handleUnpublish,
38+
getDownloadUrl,
3739
showOpenPlaygroundAction,
3840
onOpenPlaygroundClick,
3941
showInfoAction,
@@ -83,16 +85,16 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
8385
color: theme.palette.text.default
8486
}}
8587
onClick={() =>
86-
cleanedType === RESOURCE_TYPES.FILTERS
87-
? downloadFilter(details.id, details.name)
88-
: downloadYaml(details.pattern_file, details.name)
88+
cleanedType === VIEWS
89+
? downloadYaml(details.pattern_file, details.name)
90+
: downloadPattern(details.id, details.name, getDownloadUrl)
8991
}
9092
>
9193
<Download width={24} height={24} fill={theme.palette.icon.default} />
9294
Download
9395
</ActionButton>
9496

95-
{cleanedType !== RESOURCE_TYPES.FILTERS && (
97+
{cleanedType !== FILTERS && (
9698
<ActionButton
9799
sx={{
98100
borderRadius: '0.2rem',

src/custom/CatalogDetail/LeftPanel.tsx

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

3233
const LeftPanel: React.FC<LeftPanelProps> = ({
@@ -48,7 +49,8 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
4849
showInfoAction = false,
4950
handleInfoClick,
5051
showDeleteAction = false,
51-
handleDelete
52+
handleDelete,
53+
getDownloadUrl
5254
}) => {
5355
const theme = useTheme();
5456

@@ -95,6 +97,7 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
9597
handleInfoClick={handleInfoClick}
9698
showDeleteAction={showDeleteAction}
9799
handleDelete={handleDelete}
100+
getDownloadUrl={getDownloadUrl}
98101
/>
99102
{showTechnologies && (
100103
<TechnologySection

src/custom/CatalogDetail/helper.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ export function slugify(str: string): string {
3434
return str;
3535
}
3636

37-
export const downloadFilter = (id: string, name: string): void => {
38-
const dataUri = `${process.env.API_ENDPOINT_PREFIX}/api/content/filters/download/${id}`;
39-
40-
// Add the .wasm extension to the filename
41-
const fileNameWithExtension = name + '.wasm';
42-
37+
export const downloadPattern = (
38+
id: string,
39+
name: string,
40+
getDownloadUrl: (id: string) => string
41+
): void => {
42+
const downloadUrl = getDownloadUrl(id);
43+
44+
const fileNameWithExtension = `${name}.yaml`;
4345
const linkElement = document.createElement('a');
44-
linkElement.setAttribute('href', dataUri);
46+
linkElement.setAttribute('href', downloadUrl);
4547
linkElement.setAttribute('download', fileNameWithExtension);
4648
linkElement.click();
4749
linkElement.remove();

src/custom/CatalogDetail/types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ 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

40+
export const PATTERNS = 'patterns';
41+
export const FILTERS = 'filters';
42+
export const VIEWS = 'views';
43+
4044
export type ContentClassType = {
4145
community: {
4246
icon: React.ComponentType;

src/custom/Workspaces/DesignTable.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface DesignTableProps {
3939
workspaceName: string,
4040
workspaceId: string
4141
) => void;
42+
getDownloadUrl: (id: string) => string;
4243
handlePublish: (publishModal: PublishModalState, data: any) => void;
4344
publishModalHandler: any;
4445
handleUnpublishModal: (design: Pattern, modalRef: React.RefObject<any>) => void;
@@ -83,6 +84,7 @@ const DesignTable: React.FC<DesignTableProps> = ({
8384
handleShowDetails,
8485
handleUnpublishModal,
8586
handleWorkspaceDesignDeleteModal,
87+
getDownloadUrl,
8688
publishModalHandler,
8789
isCopyLinkAllowed,
8890
isDeleteAllowed,
@@ -122,6 +124,7 @@ const DesignTable: React.FC<DesignTableProps> = ({
122124
handleCopyUrl,
123125
handleClone,
124126
handleShowDetails,
127+
getDownloadUrl,
125128
isCopyLinkAllowed,
126129
isDeleteAllowed,
127130
isDownloadAllowed,

0 commit comments

Comments
 (0)