Skip to content

Commit

Permalink
Merge branch 'main' into feat/Tapis-v3-redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina authored Apr 23, 2024
2 parents 76e796b + 2605554 commit 7689964
Show file tree
Hide file tree
Showing 94 changed files with 4,247 additions and 289 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useMutation } from '@tanstack/react-query';
import apiClient from '../../apiClient';

export type TPipelineValidationResult = {
errorType: string;
name: string;
title: string;
missing: string[];
};

async function validateEntitySelection(
projectId: string,
entityUuids: string[]
) {
const res = await apiClient.post<{ result: TPipelineValidationResult[] }>(
`/api/projects/v2/${projectId}/entities/validate/`,
{ entityUuids }
);
return res.data;
}

export function useValidateEntitySelection() {
return useMutation({
mutationFn: ({
projectId,
entityUuids,
}: {
projectId: string;
entityUuids: string[];
}) => validateEntitySelection(projectId, entityUuids),
});
}
4 changes: 4 additions & 0 deletions client/modules/_hooks/src/datafiles/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export { useRemoveEntityFromTree } from './useRemoveEntityFromTree';
export { useAddFileAssociation } from './useAddFileAssociation';
export { useRemoveFileAssociation } from './useRemoveFileAssociation';
export { useSetFileTags } from './useSetFileTags';
export { usePatchEntityMetadata } from './usePatchEntityMetadata';
export { usePatchProjectMetadata } from './usePatchProjectMetadata';
export { useValidateEntitySelection } from './UseValidateEntitySelection';
export type { TPipelineValidationResult } from './UseValidateEntitySelection';
22 changes: 21 additions & 1 deletion client/modules/_hooks/src/datafiles/projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ export type TBaseProjectValue = {
dois: string[];
fileObjs: TFileObj[];
fileTags: TFileTag[];

license?: string;
};

type TEntityValue = {
export type TEntityValue = {
title: string;
description?: string;
projectId?: string;
authors?: TProjectUser[];
fileObjs?: TFileObj[];
fileTags: TFileTag[];
Expand All @@ -116,3 +119,20 @@ export type TBaseProject = TProjectMeta & {
export type TEntityMeta = TProjectMeta & {
value: TEntityValue;
};

export type TPreviewTreeData = {
name: string;
id: string;
uuid: string;
value: TEntityValue;
order: number;
children: TPreviewTreeData[];
};

export type TTreeData = {
name: string;
id: string;
uuid: string;
order: number;
children: TTreeData[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import apiClient from '../../apiClient';

async function patchEntityMetadata(
entityUuid: string,
patchMetadata: Record<string, unknown>
) {
// Replace undefined with null so that deleted values are unset instead of ignored.
Object.keys(patchMetadata).forEach((k) => {
if (patchMetadata[k] === undefined) {
patchMetadata[k] = null;
}
});
const res = await apiClient.patch(
`/api/projects/v2/entities/${entityUuid}/`,
{ patchMetadata }
);
return res.data;
}

export function usePatchEntityMetadata() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
entityUuid,
patchMetadata,
}: {
patchMetadata: Record<string, unknown>;
entityUuid: string;
}) => patchEntityMetadata(entityUuid, patchMetadata),
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ['datafiles', 'projects', 'detail'],
}),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import apiClient from '../../apiClient';

async function patchProjectMetadata(
projectId: string,
patchMetadata: Record<string, unknown>
) {
// Replace undefined with null so that deleted values are unset instead of ignored.
Object.keys(patchMetadata).forEach((k) => {
if (patchMetadata[k] === undefined) {
patchMetadata[k] = null;
}
});
const res = await apiClient.patch(`/api/projects/v2/${projectId}/`, {
patchMetadata,
});
return res.data;
}

export function usePatchProjectMetadata(projectId: string) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
patchMetadata,
}: {
patchMetadata: Record<string, unknown>;
}) => patchProjectMetadata(projectId, patchMetadata),
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ['datafiles', 'projects', 'detail', projectId],
}),
});
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import apiClient from '../../apiClient';
import { TBaseProject, TEntityMeta, TFileTag } from './types';
import { TBaseProject, TEntityMeta, TFileTag, TTreeData } from './types';
import { useMemo } from 'react';

type TProjectDetailResponse = {
baseProject: TBaseProject;
entities: TEntityMeta[];
tree: unknown;
tree: TTreeData;
};

async function getProjectDetail({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import apiClient from '../../apiClient';
import { TBaseProject, TEntityMeta } from './types';
import { TBaseProject, TEntityMeta, TPreviewTreeData } from './types';

type TProjectPreviewResponse = {
baseProject: TBaseProject;
entities: TEntityMeta[];
tree: unknown;
tree: TPreviewTreeData;
};

async function getProjectPreview({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import apiClient from '../../apiClient';
import { TBaseProjectValue } from '../projects';
import { TBaseProjectValue, TEntityValue } from '../projects';

export type TPublicationTree<T> = {
name: string;
uuid: string;
id: string;
basePath: string;
value: T;
publicationDate: string;
status: string;
order: number;
version?: number;
children: TPublicationTree<TEntityValue>[];
};

export type TPublicationDetailResponse = {
tree: unknown;
tree: TPublicationTree<TBaseProjectValue | undefined>;
baseProject: TBaseProjectValue;
};

Expand Down
3 changes: 3 additions & 0 deletions client/modules/_hooks/src/datafiles/useFileListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TFileListingHookArgs = {
path: string;
scheme: string;
pageSize: number;
disabled?: boolean;
};

type TFileListingPageParam = {
Expand All @@ -58,6 +59,7 @@ function useFileListing({
path,
scheme = 'private',
pageSize = 100,
disabled = false,
}: TFileListingHookArgs) {
return useInfiniteQuery<
FileListingResponse,
Expand All @@ -78,6 +80,7 @@ function useFileListing({
signal,
}
),
enabled: !disabled,
getNextPageParam: (lastPage, allpages): TFileListingPageParam | null => {
return lastPage.listing.length >= pageSize
? { page: allpages.length, nextPageToken: lastPage.nextPageToken }
Expand Down
2 changes: 1 addition & 1 deletion client/modules/_hooks/src/datafiles/usePathDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function _getPathDisplayName(
return 'My Data';
}
if (system === 'designsafe.storage.frontera.work' && path === usernamePath) {
return 'My Data (Work)';
return 'HPC Work';
}

return decodeURIComponent(path).split('/').slice(-1)[0] || 'Data Files';
Expand Down
36 changes: 30 additions & 6 deletions client/modules/_hooks/src/datafiles/useSelectedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,48 @@ export function useSelectedFiles(

const queryClient = useQueryClient();
const setSelectedFiles = useCallback(
(selection: TFileListing[]) =>
queryClient.setQueryData(queryKey, selection),
(selection: TFileListing[]) => {
queryClient.setQueryData(queryKey, selection);
queryClient.invalidateQueries({ queryKey: ['rows-for-system'] });
},
[queryKey, queryClient]
);

return { selectedFiles: selectedRowsQuery.data, setSelectedFiles };
const unsetSelections = useCallback(() => {
queryClient.setQueriesData({ queryKey: ['selected-rows'] }, () => []);
queryClient.invalidateQueries({ queryKey: ['rows-for-system'] });
}, [queryClient]);

return {
selectedFiles: selectedRowsQuery.data,
setSelectedFiles,
unsetSelections,
};
}

export function useSelectedFilesForSystem(api: string, system: string) {
// Get all selected files matching a given system.
// Used when multiple listings can be present in a single page, e.g. publications.
const queryKey = ['selected-rows', api, system];

const queryClient = useQueryClient();
const selections = queryClient.getQueriesData<TFileListing[]>({ queryKey });
/*
const selections = useMemo(() => {
const queryKey = ['selected-rows', api, system];
return queryClient.getQueriesData<TFileListing[]>({ queryKey });
}, [api, system, queryClient]);
*/

const { data: selections } = useQuery({
queryKey: ['rows-for-system', api, system],
queryFn: () => {
const queryKey = ['selected-rows', api, system];
return queryClient.getQueriesData<TFileListing[]>({ queryKey });
},
});

const reducedSelections = useMemo(() => {
const allSelections: TFileListing[] = [];
selections.forEach((s) => s[1] && allSelections.push(...s[1]));
(selections ?? []).forEach((s) => s[1] && allSelections.push(...s[1]));
return allSelections;
}, [selections]);
return reducedSelections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ a.navLink:not(:global(.active)):hover > div {
}

.customUl {
border: 1px solid #e3e3e3;
list-style-type: none;
padding-left: 0;
}
Expand Down
31 changes: 16 additions & 15 deletions client/modules/datafiles/src/AddFileFolder/AddFileFolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,23 @@ export const AddFileFolder: React.FC = () => {
)}
</DatafilesModal.UploadFolder>
</li>
<li
onClick={(e) => {
e.preventDefault();
window.location.href =
'https://www.designsafe-ci.org/rw/user-guides/data-transfer-guide/';
}}
>
<Button
type="text"
className={`${styles.active} ${styles.fullWidthButton}`}
<li>
<a
href="https://www.designsafe-ci.org/rw/user-guides/data-transfer-guide/"
target="_blank"
rel="noopener noreferrer"
style={{ padding: '0px' }}
>
<span className="fa-stack fa-lg">
<i className="fa fa-hdd-o fa-stack-2x" role="none"></i>
</span>
<span>Bulk Data Transfer</span>
</Button>
<Button
type="text"
className={`${styles.active} ${styles.fullWidthButton}`}
>
<span className="fa-stack fa-lg">
<i className="fa fa-hdd-o fa-stack-2x" role="none"></i>
</span>
<span>Bulk Data Transfer</span>
</Button>
</a>
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ export const DatafilesBreadcrumb: React.FC<
baseRoute: string;
systemRoot: string;
systemRootAlias?: string;
skipBreadcrumbs?: number; // Number of path elements to skip when generating breadcrumbs
} & BreadcrumbProps
> = ({
initialBreadcrumbs,
path,
baseRoute,
systemRoot,
systemRootAlias,
skipBreadcrumbs,
...props
}) => {
const breadcrumbItems = [
...initialBreadcrumbs,
...getPathRoutes(baseRoute, path, systemRoot, systemRootAlias),
...getPathRoutes(baseRoute, path, systemRoot, systemRootAlias).slice(
skipBreadcrumbs ?? 0
),
];

return (
Expand All @@ -67,19 +71,32 @@ function isUserHomeSystem(system: string) {
}

export const BaseFileListingBreadcrumb: React.FC<
{ api: string; system: string; path: string } & BreadcrumbProps
> = ({ api, system, path, ...props }) => {
{
api: string;
system: string;
path: string;
systemRootAlias?: string;
initialBreadcrumbs?: { title: string; path: string }[];
} & BreadcrumbProps
> = ({
api,
system,
path,
systemRootAlias,
initialBreadcrumbs = [],
...props
}) => {
const { user } = useAuthenticatedUser();

return (
<DatafilesBreadcrumb
initialBreadcrumbs={[]}
initialBreadcrumbs={initialBreadcrumbs ?? []}
path={path}
baseRoute={`/${api}/${system}`}
systemRoot={
isUserHomeSystem(system) ? encodeURIComponent('/' + user?.username) : ''
}
systemRootAlias={getSystemRootDisplayName(api, system)}
systemRootAlias={systemRootAlias || getSystemRootDisplayName(api, system)}
{...props}
/>
);
Expand Down
Loading

0 comments on commit 7689964

Please sign in to comment.