Skip to content

Commit

Permalink
send action now takes selected and validated items
Browse files Browse the repository at this point in the history
  • Loading branch information
craigrbarnes committed Dec 6, 2024
1 parent 317816d commit dcc9920
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/frontend/src/features/DataLibrary/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const SelectedItemsModal: React.FC<SelectedItemsModelProps> = (props) => {
onClick={async () => {
setIsRunning(true);
await actionFunction.action(
validatedLibrarySelections,
actionFunction.parameters,
onDone,
onError,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { sendPFBToURL } from './exportActions';
import { sendExistingPFBToURL } from './exportActions';
import { HTTPError } from '@gen3/core';
import { ValidatedSelectedItem } from '../types';

export type DataActionFunction<T = void> = (
validatedSelections: ReadonlyArray<ValidatedSelectedItem>,
params?: Record<string, any>, // function options from the config
done?: (arg0?: string) => void,
onError?: (error: HTTPError | Error) => void,
Expand Down Expand Up @@ -48,7 +50,7 @@ export const findAction = (

export const registerDefaultDataLibraryActions = () => {
registerAction('export-pfb-to-url', {
action: sendPFBToURL,
action: sendExistingPFBToURL,
});
};

Expand Down

0 comments on commit dcc9920

Please sign in to comment.