Skip to content

Commit

Permalink
Added set pod permission
Browse files Browse the repository at this point in the history
  • Loading branch information
NotChristianGarcia committed Sep 18, 2024
1 parent 15cec40 commit fbdd478
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/tapisui-hooks/src/pods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as useGetVolume } from './useGetVolume';
export { default as useListVolumeFiles } from './useListVolumeFiles';
export { default as useUpdateTemplate } from './useUpdateTemplate';
export { default as useDeletePodPermission } from './useDeletePodPermission';
export { default as useSetPodPermission } from './useSetPodPermission';
export { default as useGetPodLogs } from './useGetPodLogs';
export { default as useListImages } from './useListImages';
export { default as useListVolumes } from './useListVolumes';
Expand Down
52 changes: 52 additions & 0 deletions packages/tapisui-hooks/src/pods/useSetPodPermission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect } from 'react';
import { useMutation, MutateOptions } from 'react-query';
import { Pods } from '@tapis/tapis-typescript';
import { Pods as API } from '@tapis/tapisui-api';
import { useTapisConfig } from '../context';
import QueryKeys from './queryKeys';

type SetPodPermissionHookParams = Pods.SetPodPermissionRequest;

const useSetPodPermission = (podId: string) => {
const { basePath, accessToken } = useTapisConfig();
const jwt = accessToken?.access_token || '';

// The useMutation react-query hook is used to call operations that make server-side changes
// (Other hooks would be used for data retrieval)
//
// In this case, mkdir helper is called to perform the operation
const { mutate, isLoading, isError, isSuccess, data, error, reset } =
useMutation<
Pods.PodPermissionsResponse,
Error,
Pods.SetPodPermissionRequest
>([QueryKeys.setPodPermission, podId, basePath, jwt], (params) =>
API.setPodPermission(params, basePath, jwt)
);

useEffect(() => reset(), [reset, podId]);

// Return hook object with loading states and login function
return {
isLoading,
isError,
isSuccess,
data,
error,
reset,
setPodPermission: (
params: SetPodPermissionHookParams,
// react-query options to allow callbacks such as onSuccess
options?: MutateOptions<
Pods.PodPermissionsResponse,
Error,
SetPodPermissionHookParams
>
) => {
// Call mutate to trigger a single post-like API operation
return mutate(params, options);
},
};
};

export default useSetPodPermission;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/app/Pods/_components/Modals/PodPermissionModal/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/app/Pods/_components/Modals/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/app/Pods/_components/PagePods/PagePods.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbdd478

Please sign in to comment.