From c3880cd5a77c64c4b0e34c35f07b414e1f37c35b Mon Sep 17 00:00:00 2001 From: Bianca Procopio Date: Wed, 31 Jan 2024 19:11:00 -0700 Subject: [PATCH] update `downloadCSV` and `downloadRundown` to accept a file name and add two new options to `ProjectListItem` --- apps/client/src/common/api/ontimeApi.ts | 12 ++++++++---- .../panel/project-panel/ProjectListItem.tsx | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/client/src/common/api/ontimeApi.ts b/apps/client/src/common/api/ontimeApi.ts index 8a6319b25..f7d8c06e6 100644 --- a/apps/client/src/common/api/ontimeApi.ts +++ b/apps/client/src/common/api/ontimeApi.ts @@ -143,15 +143,19 @@ export async function postOscSubscriptions(data: OscSubscription) { /** * @description HTTP request to download db in CSV format */ -export const downloadCSV = () => { - return fileDownload(ontimeURL, { name: 'rundown', type: 'csv' }, { type: 'text/csv;charset=utf-8;' }); +export const downloadCSV = (fileName?: string) => { + return fileDownload(ontimeURL, { name: fileName ?? 'rundown', type: 'csv' }, { type: 'text/csv;charset=utf-8;' }); }; /** * @description HTTP request to download db in JSON format */ -export const downloadRundown = () => { - return fileDownload(ontimeURL, { name: 'rundown', type: 'json' }, { type: 'application/json;charset=utf-8;' }); +export const downloadRundown = (fileName?: string) => { + return fileDownload( + ontimeURL, + { name: fileName ?? 'rundown', type: 'json' }, + { type: 'application/json;charset=utf-8;' }, + ); }; // TODO: should this be extracted to shared code? diff --git a/apps/client/src/features/app-settings/panel/project-panel/ProjectListItem.tsx b/apps/client/src/features/app-settings/panel/project-panel/ProjectListItem.tsx index ca7d0b7d6..b378b4c24 100644 --- a/apps/client/src/features/app-settings/panel/project-panel/ProjectListItem.tsx +++ b/apps/client/src/features/app-settings/panel/project-panel/ProjectListItem.tsx @@ -3,7 +3,14 @@ import { IconButton, Menu, MenuButton, MenuItem, MenuList } from '@chakra-ui/rea import { IoEllipsisHorizontal } from '@react-icons/all-files/io5/IoEllipsisHorizontal'; import { invalidateAllCaches, maybeAxiosError } from '../../../../common/api/apiUtils'; -import { deleteProject, duplicateProject, loadProject, renameProject } from '../../../../common/api/ontimeApi'; +import { + deleteProject, + downloadCSV, + downloadRundown, + duplicateProject, + loadProject, + renameProject, +} from '../../../../common/api/ontimeApi'; import ProjectForm, { ProjectFormValues } from './ProjectForm'; @@ -139,6 +146,14 @@ function ActionMenu({ await onRefetch(); }; + const handleDownload = async () => { + await downloadRundown(filename); + }; + + const handleExportCSV = async () => { + await downloadCSV(filename); + }; + return ( Rename Duplicate + Download + {current && Export CSV Rundown} Delete