From ce177a88bd1b01ae5ca156f33a0d3a95c2f66a2d Mon Sep 17 00:00:00 2001 From: Maximiliano Osorio Date: Thu, 16 May 2024 08:31:37 -0400 Subject: [PATCH 1/5] add: share/unshare working --- src/tapis-api/apps/share.ts | 18 +++++ .../Toolbar/ShareModal/ShareModal.tsx | 77 +++++++++++++++---- src/tapis-hooks/apps/useList.ts | 3 +- src/tapis-hooks/apps/useShare.ts | 60 +++++++++++++++ .../AppListing/CookbookListing.module.scss | 54 ++++++++----- .../apps/AppListing/CookbookListing.tsx | 13 +++- 6 files changed, 185 insertions(+), 40 deletions(-) create mode 100644 src/tapis-api/apps/share.ts create mode 100644 src/tapis-hooks/apps/useShare.ts diff --git a/src/tapis-api/apps/share.ts b/src/tapis-api/apps/share.ts new file mode 100644 index 0000000..c96e64c --- /dev/null +++ b/src/tapis-api/apps/share.ts @@ -0,0 +1,18 @@ +import { Apps } from '@tapis/tapis-typescript'; +import { apiGenerator, errorDecoder } from 'tapis-api/utils'; + +const shareApp = ( + request: Apps.ShareAppRequest, + basePath: string, + jwt: string +) => { + const api: Apps.SharingApi = apiGenerator( + Apps, + Apps.SharingApi, + basePath, + jwt + ); + return errorDecoder(() => api.shareApp(request)); +}; + +export default shareApp; diff --git a/src/tapis-app/Apps/_components/Toolbar/ShareModal/ShareModal.tsx b/src/tapis-app/Apps/_components/Toolbar/ShareModal/ShareModal.tsx index fb9c56d..e803858 100644 --- a/src/tapis-app/Apps/_components/Toolbar/ShareModal/ShareModal.tsx +++ b/src/tapis-app/Apps/_components/Toolbar/ShareModal/ShareModal.tsx @@ -2,7 +2,6 @@ import { useEffect, useCallback, useState } from 'react'; import { Button } from 'reactstrap'; import { DropdownSelector, GenericModal } from 'tapis-ui/_common'; import { SubmitWrapper } from 'tapis-ui/_wrappers'; -import { FileListingTable } from 'tapis-ui/components/files/FileListing/FileListing'; import { ToolbarModalProps } from '../Toolbar'; import { focusManager } from 'react-query'; import { Column } from 'react-table'; @@ -16,13 +15,16 @@ import useSharePublic, { } from 'tapis-hooks/apps/useSharePublic'; import { AppListingTable } from 'tapis-ui/components/apps/AppListing'; import useUnsharePublic from 'tapis-hooks/apps/useUnsharePublic'; +import useShare, { ShareUserHookParams } from 'tapis-hooks/apps/useShare'; const ShareModel: React.FC = ({ toggle }) => { const { selectedApps, unselect } = useAppsSelect(); const { shareAppPublicAsync, reset } = useSharePublic(); const { unShareAppPublicAsync, reset: resetUnshare } = useUnsharePublic(); + const { shareAppAsync, reset: resetShare } = useShare(); const [isPublishedApp, setIsPublishedApp] = useState(false); + const [users, setUsers] = useState>(['wmobley']); useEffect(() => { reset(); }, [reset]); @@ -31,16 +33,23 @@ const ShareModel: React.FC = ({ toggle }) => { resetUnshare(); }, [resetUnshare]); + useEffect(() => { + resetShare(); + }, [resetShare]); + const onComplete = useCallback(() => { // Calling the focus manager triggers react-query's // automatic refetch on window focus focusManager.setFocused(true); }, []); - const { run, state, isLoading, isSuccess, error } = useAppsOperations< - ShareHookParams, - Apps.RespChangeCount - >({ + const { + run: runSharePublic, + state: stateSharePublic, + isLoading: isLoadingSharePublic, + isSuccess: isSuccessSharePublic, + error: errorSharePublic, + } = useAppsOperations({ fn: shareAppPublicAsync, onComplete, }); @@ -56,17 +65,37 @@ const ShareModel: React.FC = ({ toggle }) => { onComplete, }); + const { + run: runShare, + state: stateShare, + isLoading: isLoadingShare, + isSuccess: isSuccessShare, + error: errorShare, + } = useAppsOperations({ + fn: shareAppAsync, + onComplete, + }); + const onSubmit = useCallback(() => { const operations: Array = selectedApps.map((app) => ({ id: app.id!, })); if (isPublishedApp) { - run(operations); + runSharePublic(operations); } if (!isPublishedApp) { runUnshare(operations); } - }, [selectedApps, run, runUnshare]); + const userOperations: Array = selectedApps.map( + (app) => ({ + id: app.id!, + reqShareUpdate: { + users, + }, + }) + ); + runShare(userOperations); + }, [selectedApps, runSharePublic, runUnshare]); const removeApps = useCallback( (file: Apps.TapisApp) => { @@ -84,7 +113,7 @@ const ShareModel: React.FC = ({ toggle }) => { id: 'deleteStatus', Cell: (el) => { const file = selectedApps[el.row.index]; - if (!state[file.id!]) { + if (!stateSharePublic[file.id!]) { return ( = ({ toggle }) => { ); } - return ; + return ( + + ); }, }, ]; @@ -119,11 +150,13 @@ const ShareModel: React.FC = ({ toggle }) => { />

General access

- { const value = e.target.value; + reset(); + resetUnshare(); + resetShare(); if (value === 'public') { setIsPublishedApp(true); } @@ -140,22 +173,36 @@ const ShareModel: React.FC = ({ toggle }) => { footer={ - {!isSuccess && ( + {!isSuccessSharePublic && (