diff --git a/packages/frontend/src/features/DataLibrary/TODO.md b/packages/frontend/src/features/DataLibrary/TODO.md index 0b753a4d..b522668b 100644 --- a/packages/frontend/src/features/DataLibrary/TODO.md +++ b/packages/frontend/src/features/DataLibrary/TODO.md @@ -18,10 +18,10 @@ * ~~export to terra~~, * ~~export to 7 bridges~~, * ~~fix action button disable state~~ +* actions are passed selections * add cancel action button? -* download pfb -* rename with API -* remove member with API +* ~~rename with API~~ +* ~~remove member with API~~ * ~~add id as column~~ * remove id from FileItem * ~~hide add new list~~ diff --git a/packages/frontend/src/features/DataLibrary/modals/SelectedItemsModal.tsx b/packages/frontend/src/features/DataLibrary/modals/SelectedItemsModal.tsx index 0b8724ab..ebc94e9c 100644 --- a/packages/frontend/src/features/DataLibrary/modals/SelectedItemsModal.tsx +++ b/packages/frontend/src/features/DataLibrary/modals/SelectedItemsModal.tsx @@ -215,6 +215,7 @@ const SelectedItemsModal: React.FC = (props) => { onClick={async () => { setIsRunning(true); await actionFunction.action( + validatedLibrarySelections, actionFunction.parameters, onDone, onError, diff --git a/packages/frontend/src/features/DataLibrary/selection/exportActions.ts b/packages/frontend/src/features/DataLibrary/selection/exportActions.ts index 01f3b342..2f1f3e36 100644 --- a/packages/frontend/src/features/DataLibrary/selection/exportActions.ts +++ b/packages/frontend/src/features/DataLibrary/selection/exportActions.ts @@ -1,14 +1,15 @@ import { DataActionFunction } from './registeredActions'; -import { fetchFencePresignedURL } from '@gen3/core'; +import { fetchFencePresignedURL, FileItem, isFileItem } from '@gen3/core'; +import { notifications } from '@mantine/notifications'; const PRESIGNED_URL_TEMPLATE_VARIABLE = '{{PRESIGNED_URL}}'; -interface SendPFBToURLParameters { +interface SendExistingPFBToURLParameters { targetURLTemplate: string; } -const isSendPFBToURLParameters = ( +const isSendExistingPFBToURLParameters = ( value: unknown, -): value is SendPFBToURLParameters => { +): value is SendExistingPFBToURLParameters => { if (!value || typeof value !== 'object') { return false; } @@ -19,23 +20,42 @@ const isSendPFBToURLParameters = ( ); }; -export const sendPFBToURL: DataActionFunction = async ( +export const sendExistingPFBToURL: DataActionFunction = async ( + validatedSelections, params, done = () => null, error = () => null, onAbort = () => null, signal = undefined, ) => { - if (!isSendPFBToURLParameters(params)) { + if (!isSendExistingPFBToURLParameters(params)) { console.error('Invalid parameters for sendPFBToURL action:', params); return; } - const { targetURLTemplate } = params as SendPFBToURLParameters; + const { targetURLTemplate } = params; + // get the selection + + if (validatedSelections.length !== 1 || !isFileItem(validatedSelections[0])) { + notifications.show({ + id: 'data-library-send-existing-pfb-to-url-validate-length', + position: 'bottom-center', + withCloseButton: true, + autoClose: 5000, + title: 'Action Error', + message: 'Invalid data passed to send PFB to URL', + color: 'red', + loading: false, + }); + return; + } + + const { guid } = validatedSelections[0] as FileItem; + console.log('Sending existing PFB to URL:', targetURLTemplate, guid); // get the presigned URL for the selected PFB try { const presignedURL = await fetchFencePresignedURL({ - guid: 'dg.4503/d470e2bc-d4f8-4088-815a-4333780d2bf0', + guid: guid, onAbort: onAbort, signal: signal, }); diff --git a/packages/frontend/src/features/DataLibrary/selection/registeredActions.ts b/packages/frontend/src/features/DataLibrary/selection/registeredActions.ts index 06259828..7d9f55f6 100644 --- a/packages/frontend/src/features/DataLibrary/selection/registeredActions.ts +++ b/packages/frontend/src/features/DataLibrary/selection/registeredActions.ts @@ -1,7 +1,9 @@ -import { sendPFBToURL } from './exportActions'; +import { sendExistingPFBToURL } from './exportActions'; import { HTTPError } from '@gen3/core'; +import { ValidatedSelectedItem } from '../types'; export type DataActionFunction = ( + validatedSelections: ReadonlyArray, params?: Record, // function options from the config done?: (arg0?: string) => void, onError?: (error: HTTPError | Error) => void, @@ -48,7 +50,7 @@ export const findAction = ( export const registerDefaultDataLibraryActions = () => { registerAction('export-pfb-to-url', { - action: sendPFBToURL, + action: sendExistingPFBToURL, }); };