From 208e8e4837e3cdba5647dcde633fce034aaa8aa1 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 10:47:30 -0600 Subject: [PATCH 1/7] codegen against the master branch --- package.json | 2 +- src/openapi/v2/index.ts | 7 ++++--- ..._file_api_v2_datasets__dataset_id__files_post.ts | 4 ++-- .../Body_update_file_api_v2_files__file_id__put.ts | 4 ++-- src/openapi/v2/models/FileIn.ts | 8 ++++++++ .../v2/models/{ClowderFile.ts => FileOut.ts} | 10 ++++++---- src/openapi/v2/models/FolderOut.ts | 4 +++- src/openapi/v2/models/UserDB.ts | 3 ++- src/openapi/v2/models/UserIn.ts | 3 ++- src/openapi/v2/models/UserOut.ts | 3 ++- src/openapi/v2/services/DatasetsService.ts | 13 ++++++------- src/openapi/v2/services/FilesService.ts | 8 ++++---- 12 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 src/openapi/v2/models/FileIn.ts rename src/openapi/v2/models/{ClowderFile.ts => FileOut.ts} (73%) diff --git a/package.json b/package.json index 30a3ddd..4864691 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lint": "eslint src", "lint:fix": "npm run lint -- --fix", "codegen:v1": "./node_modules/.bin/openapi -i https://clowder.ncsa.illinois.edu/clowder/swagger -o src/openapi/v1", - "codegen:v2": "./node_modules/.bin/openapi -i ${CLOWDER_REMOTE_HOSTNAME}/api/v2/openapi.json -o src/openapi/v2", + "codegen:v2": "export CLOWDER_REMOTE_HOSTNAME=http://localhost:8000 && ./node_modules/.bin/openapi -i ${CLOWDER_REMOTE_HOSTNAME}/api/v2/openapi.json -o src/openapi/v2", "codegen": "npm run codegen:v1 && npm run codegen:v2", "docs": "typedoc" }, diff --git a/src/openapi/v2/index.ts b/src/openapi/v2/index.ts index 9c5c21c..4be8d8c 100644 --- a/src/openapi/v2/index.ts +++ b/src/openapi/v2/index.ts @@ -7,13 +7,14 @@ export { OpenAPI } from './core/OpenAPI'; export type { Body_save_file_api_v2_datasets__dataset_id__files_post } from './models/Body_save_file_api_v2_datasets__dataset_id__files_post'; export type { Body_update_file_api_v2_files__file_id__put } from './models/Body_update_file_api_v2_files__file_id__put'; -export type { ClowderFile } from './models/ClowderFile'; export type { Collection } from './models/Collection'; -export type { FolderIn } from './models/FolderIn'; -export type { FolderOut } from './models/FolderOut'; export type { DatasetBase } from './models/DatasetBase'; export type { DatasetIn } from './models/DatasetIn'; export type { DatasetOut } from './models/DatasetOut'; +export type { FileIn } from './models/FileIn'; +export type { FileOut } from './models/FileOut'; +export type { FolderIn } from './models/FolderIn'; +export type { FolderOut } from './models/FolderOut'; export type { HTTPValidationError } from './models/HTTPValidationError'; export type { UserDB } from './models/UserDB'; export type { UserIn } from './models/UserIn'; diff --git a/src/openapi/v2/models/Body_save_file_api_v2_datasets__dataset_id__files_post.ts b/src/openapi/v2/models/Body_save_file_api_v2_datasets__dataset_id__files_post.ts index c5e9611..52eb75b 100644 --- a/src/openapi/v2/models/Body_save_file_api_v2_datasets__dataset_id__files_post.ts +++ b/src/openapi/v2/models/Body_save_file_api_v2_datasets__dataset_id__files_post.ts @@ -2,10 +2,10 @@ /* tslint:disable */ /* eslint-disable */ -import type { ClowderFile } from './ClowderFile'; +import type { FileIn } from './FileIn'; export type Body_save_file_api_v2_datasets__dataset_id__files_post = { folder_id?: string; file: Blob; - file_info?: ClowderFile; + file_info?: FileIn; } diff --git a/src/openapi/v2/models/Body_update_file_api_v2_files__file_id__put.ts b/src/openapi/v2/models/Body_update_file_api_v2_files__file_id__put.ts index 5cbbb54..6f9917f 100644 --- a/src/openapi/v2/models/Body_update_file_api_v2_files__file_id__put.ts +++ b/src/openapi/v2/models/Body_update_file_api_v2_files__file_id__put.ts @@ -2,9 +2,9 @@ /* tslint:disable */ /* eslint-disable */ -import type { ClowderFile } from './ClowderFile'; +import type { FileIn } from './FileIn'; export type Body_update_file_api_v2_files__file_id__put = { file: Blob; - file_info?: ClowderFile; + file_info?: FileIn; } diff --git a/src/openapi/v2/models/FileIn.ts b/src/openapi/v2/models/FileIn.ts new file mode 100644 index 0000000..81f6d85 --- /dev/null +++ b/src/openapi/v2/models/FileIn.ts @@ -0,0 +1,8 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type FileIn = { + id?: string; + name?: string; +} diff --git a/src/openapi/v2/models/ClowderFile.ts b/src/openapi/v2/models/FileOut.ts similarity index 73% rename from src/openapi/v2/models/ClowderFile.ts rename to src/openapi/v2/models/FileOut.ts index 9829589..71ff05f 100644 --- a/src/openapi/v2/models/ClowderFile.ts +++ b/src/openapi/v2/models/FileOut.ts @@ -2,14 +2,16 @@ /* tslint:disable */ /* eslint-disable */ -export type ClowderFile = { +import type { UserOut } from './UserOut'; + +export type FileOut = { id?: string; name?: string; - creator?: string; + creator: UserOut; created?: string; version?: string; - views?: number; - downloads?: number; dataset_id: string; folder_id?: string; + views?: number; + downloads?: number; } diff --git a/src/openapi/v2/models/FolderOut.ts b/src/openapi/v2/models/FolderOut.ts index 8021428..003adee 100644 --- a/src/openapi/v2/models/FolderOut.ts +++ b/src/openapi/v2/models/FolderOut.ts @@ -2,12 +2,14 @@ /* tslint:disable */ /* eslint-disable */ +import type { UserOut } from './UserOut'; + export type FolderOut = { id?: string; name?: string; dataset_id: string; parent_folder?: string; - author?: string; + author: UserOut; created?: string; modified?: string; } diff --git a/src/openapi/v2/models/UserDB.ts b/src/openapi/v2/models/UserDB.ts index bd53eac..85c67fc 100644 --- a/src/openapi/v2/models/UserDB.ts +++ b/src/openapi/v2/models/UserDB.ts @@ -5,6 +5,7 @@ export type UserDB = { id?: string; email: string; - full_name?: string; + first_name?: string; + last_name?: string; hashed_password: string; } diff --git a/src/openapi/v2/models/UserIn.ts b/src/openapi/v2/models/UserIn.ts index 3da5cb8..ec238f7 100644 --- a/src/openapi/v2/models/UserIn.ts +++ b/src/openapi/v2/models/UserIn.ts @@ -5,6 +5,7 @@ export type UserIn = { id?: string; email: string; - full_name?: string; + first_name?: string; + last_name?: string; password: string; } diff --git a/src/openapi/v2/models/UserOut.ts b/src/openapi/v2/models/UserOut.ts index e8da94f..37da7a2 100644 --- a/src/openapi/v2/models/UserOut.ts +++ b/src/openapi/v2/models/UserOut.ts @@ -5,5 +5,6 @@ export type UserOut = { id?: string; email: string; - full_name?: string; + first_name?: string; + last_name?: string; } diff --git a/src/openapi/v2/services/DatasetsService.ts b/src/openapi/v2/services/DatasetsService.ts index 6db2c80..279d0c7 100644 --- a/src/openapi/v2/services/DatasetsService.ts +++ b/src/openapi/v2/services/DatasetsService.ts @@ -2,13 +2,12 @@ /* tslint:disable */ /* eslint-disable */ import type { Body_save_file_api_v2_datasets__dataset_id__files_post } from '../models/Body_save_file_api_v2_datasets__dataset_id__files_post'; -import type { ClowderFile } from '../models/ClowderFile'; -import type { Dataset } from '../models/Dataset'; -import type { FolderIn } from '../models/FolderIn'; -import type { FolderOut } from '../models/FolderOut'; import type { DatasetBase } from '../models/DatasetBase'; import type { DatasetIn } from '../models/DatasetIn'; import type { DatasetOut } from '../models/DatasetOut'; +import type { FileOut } from '../models/FileOut'; +import type { FolderIn } from '../models/FolderIn'; +import type { FolderOut } from '../models/FolderOut'; import type { CancelablePromise } from '../core/CancelablePromise'; import { request as __request } from '../core/request'; @@ -146,13 +145,13 @@ export class DatasetsService { * Save File * @param datasetId * @param formData - * @returns ClowderFile Successful Response + * @returns FileOut Successful Response * @throws ApiError */ public static saveFileApiV2DatasetsDatasetIdFilesPost( datasetId: string, formData: Body_save_file_api_v2_datasets__dataset_id__files_post, - ): CancelablePromise { + ): CancelablePromise { return __request({ method: 'POST', path: `/api/v2/datasets/${datasetId}/files`, @@ -229,4 +228,4 @@ export class DatasetsService { }); } -} +} \ No newline at end of file diff --git a/src/openapi/v2/services/FilesService.ts b/src/openapi/v2/services/FilesService.ts index 81ea603..680f88f 100644 --- a/src/openapi/v2/services/FilesService.ts +++ b/src/openapi/v2/services/FilesService.ts @@ -2,7 +2,7 @@ /* tslint:disable */ /* eslint-disable */ import type { Body_update_file_api_v2_files__file_id__put } from '../models/Body_update_file_api_v2_files__file_id__put'; -import type { ClowderFile } from '../models/ClowderFile'; +import type { FileOut } from '../models/FileOut'; import type { CancelablePromise } from '../core/CancelablePromise'; import { request as __request } from '../core/request'; @@ -30,13 +30,13 @@ export class FilesService { * Update File * @param fileId * @param formData - * @returns ClowderFile Successful Response + * @returns FileOut Successful Response * @throws ApiError */ public static updateFileApiV2FilesFileIdPut( fileId: string, formData: Body_update_file_api_v2_files__file_id__put, - ): CancelablePromise { + ): CancelablePromise { return __request({ method: 'PUT', path: `/api/v2/files/${fileId}`, @@ -110,4 +110,4 @@ export class FilesService { }); } -} +} \ No newline at end of file From ae52924de9f9920855cac80f99ba0dbc1448571a Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 10:48:20 -0600 Subject: [PATCH 2/7] revert unmerged fastapi change --- src/openapi/v2/models/UserDB.ts | 3 +-- src/openapi/v2/models/UserIn.ts | 3 +-- src/openapi/v2/models/UserOut.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/openapi/v2/models/UserDB.ts b/src/openapi/v2/models/UserDB.ts index 85c67fc..bd53eac 100644 --- a/src/openapi/v2/models/UserDB.ts +++ b/src/openapi/v2/models/UserDB.ts @@ -5,7 +5,6 @@ export type UserDB = { id?: string; email: string; - first_name?: string; - last_name?: string; + full_name?: string; hashed_password: string; } diff --git a/src/openapi/v2/models/UserIn.ts b/src/openapi/v2/models/UserIn.ts index ec238f7..3da5cb8 100644 --- a/src/openapi/v2/models/UserIn.ts +++ b/src/openapi/v2/models/UserIn.ts @@ -5,7 +5,6 @@ export type UserIn = { id?: string; email: string; - first_name?: string; - last_name?: string; + full_name?: string; password: string; } diff --git a/src/openapi/v2/models/UserOut.ts b/src/openapi/v2/models/UserOut.ts index 37da7a2..e8da94f 100644 --- a/src/openapi/v2/models/UserOut.ts +++ b/src/openapi/v2/models/UserOut.ts @@ -5,6 +5,5 @@ export type UserOut = { id?: string; email: string; - first_name?: string; - last_name?: string; + full_name?: string; } From b22f750d6eeb7aa328968430958fec0f8e5b400e Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 10:59:40 -0600 Subject: [PATCH 3/7] gradually replacing types with models from openapi --- src/components/files/FileMenu.tsx | 2 +- src/reducers/dataset.ts | 3 ++- src/types/action.ts | 12 ++++++++++++ src/types/{data.ts => data.ts.ignore} | 0 4 files changed, 15 insertions(+), 2 deletions(-) rename src/types/{data.ts => data.ts.ignore} (100%) diff --git a/src/components/files/FileMenu.tsx b/src/components/files/FileMenu.tsx index f5dbc49..03e1978 100644 --- a/src/components/files/FileMenu.tsx +++ b/src/components/files/FileMenu.tsx @@ -4,7 +4,7 @@ import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import MenuIcon from '@mui/icons-material/Menu'; import { downloadFile } from '../../utils/file'; -import {File} from "../../types/data"; +import {FileOut as File} from "../../openapi/v2/models/FileOut"; import {useState} from "react"; import {fileDeleted} from "../../actions/file"; import {useDispatch} from "react-redux"; diff --git a/src/reducers/dataset.ts b/src/reducers/dataset.ts index 963776c..5da29c6 100644 --- a/src/reducers/dataset.ts +++ b/src/reducers/dataset.ts @@ -9,7 +9,8 @@ import { } from "../actions/dataset"; import {CREATE_FILE, UPDATE_FILE, DELETE_FILE} from "../actions/file"; import {DataAction} from "../types/action"; -import {Dataset, DatasetState} from "../types/data"; +import {DatasetState} from "../types/data"; +import {DatasetOut as Dataset} from "../openapi/v2/models/DatasetOut"; const defaultState: DatasetState = { files: [], diff --git a/src/types/action.ts b/src/types/action.ts index ee45e35..83eafbd 100644 --- a/src/types/action.ts +++ b/src/types/action.ts @@ -1,10 +1,21 @@ import {About, Dataset, ExtractedMetadata, File, MetadataJsonld, FilePreview, FileMetadata, FileVersion, Folder} from "./data"; +import {UPDATE_FILE} from "../actions/file"; interface RECEIVE_FILES_IN_DATASET { type: "RECEIVE_FILES_IN_DATASET"; files: File[]; } +interface RECEIVE_FOLDERS_IN_DATASET { + type: "RECEIVE_FOLDERS_IN_DATASET"; + folders: Folder[]; +} + +interface UPDATE_FILE { + type: "UPDATE_FILE"; + file: File[]; +} + interface DELETE_FILE { type: "DELETE_FILE"; file: File; @@ -123,6 +134,7 @@ export type DataAction = | REGISTER_USER | CREATE_DATASET | CREATE_FILE + | UPDATE_FILE | FAILED | RESET_FAILED | RESET_LOGOUT diff --git a/src/types/data.ts b/src/types/data.ts.ignore similarity index 100% rename from src/types/data.ts rename to src/types/data.ts.ignore From ac9cafdd6b31d3a6f3b1cdcc1000d7e32afd6a04 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 13:49:33 -0600 Subject: [PATCH 4/7] replacing more types --- src/components/Dashbard.tsx | 39 +++++---------- src/components/datasets/Dataset.tsx | 9 ++-- src/components/files/FileMenu.tsx | 2 +- src/components/folders/CreateFolder.tsx | 4 +- .../versions/FileVersionHistory.tsx | 1 - src/reducers/dataset.ts | 4 +- src/types/action.ts | 20 ++++++-- src/types/{data.ts.ignore => data.ts} | 49 +------------------ 8 files changed, 38 insertions(+), 90 deletions(-) rename src/types/{data.ts.ignore => data.ts} (72%) diff --git a/src/components/Dashbard.tsx b/src/components/Dashbard.tsx index 057158e..4f29bc4 100644 --- a/src/components/Dashbard.tsx +++ b/src/components/Dashbard.tsx @@ -3,11 +3,11 @@ import {Box, Button, Dialog, DialogTitle, Grid, Link, Tab, Tabs, Typography} fro import {CreateDataset} from "./datasets/CreateDataset"; -import {Dataset, RootState} from "../types/data"; +import {RootState} from "../types/data"; +import {DatasetOut as Dataset} from "../openapi/v2"; import {useDispatch, useSelector} from "react-redux"; import {datasetDeleted, fetchDatasets,} from "../actions/dataset"; import {resetFailedReason, resetLogout} from "../actions/common"; -import {downloadThumbnail} from "../utils/thumbnail"; import TopBar from "./navigation/TopBar"; import {a11yProps, TabPanel} from "./tabs/TabComponent"; @@ -32,7 +32,7 @@ export const Dashboard = (): JSX.Element => { // Redux connect equivalent const dispatch = useDispatch(); - const deleteDataset = (datasetId: string) => dispatch(datasetDeleted(datasetId)); + const deleteDataset = (datasetId: string | undefined) => dispatch(datasetDeleted(datasetId)); const listDatasets = (skip: number | undefined, limit: number | undefined, mine: boolean | undefined) => dispatch(fetchDatasets(skip, limit, mine)); const dismissError = () => dispatch(resetFailedReason()); const dismissLogout = () => dispatch(resetLogout()); @@ -41,7 +41,6 @@ export const Dashboard = (): JSX.Element => { const stack = useSelector((state: RootState) => state.error.stack); const loggedOut = useSelector((state: RootState) => state.error.loggedOut); - const [datasetThumbnailList, setDatasetThumbnailList] = useState([]); // TODO add option to determine limit number; default show 5 datasets each time const [currPageNum, setCurrPageNum] = useState(0); const [limit,] = useState(20); @@ -93,24 +92,8 @@ export const Dashboard = (): JSX.Element => { } }, [loggedOut]); - // fetch thumbnails from each individual dataset/id calls + // check prev/next button valid or not useEffect(() => { - (async () => { - if (datasets !== undefined && datasets.length > 0) { - - // TODO change the type any to something else - const datasetThumbnailListTemp: any = []; - await Promise.all(datasets.map(async (dataset) => { - // add thumbnails - if (dataset["thumbnail"] !== null && dataset["thumbnail"] !== undefined) { - const thumbnailURL = await downloadThumbnail(dataset["thumbnail"]); - datasetThumbnailListTemp.push({"id": dataset["id"], "thumbnail": thumbnailURL}); - } - })); - setDatasetThumbnailList(datasetThumbnailListTemp); - } - })(); - // disable flipping if reaches the last page if (datasets.length < limit) setNextDisabled(true); else setNextDisabled(false); @@ -182,19 +165,19 @@ export const Dashboard = (): JSX.Element => { { - datasets !== undefined && datasetThumbnailList !== undefined ? - datasets.map((dataset) => { - return ( + datasets.map((dataset) => { + return ( + dataset !== undefined ? - ); - }) - : - <> + : + <> + ); + }) } diff --git a/src/components/datasets/Dataset.tsx b/src/components/datasets/Dataset.tsx index b79a2b9..d0b1322 100644 --- a/src/components/datasets/Dataset.tsx +++ b/src/components/datasets/Dataset.tsx @@ -49,7 +49,7 @@ export const Dataset = (): JSX.Element => { const { datasetId } = useParams<{datasetId?: string}>(); // search parameters - let [searchParams, setSearchParams] = useSearchParams(); + let [searchParams, _] = useSearchParams(); const folder = searchParams.get("folder"); useEffect(() => { const currentParams = Object.fromEntries([...searchParams]); @@ -62,10 +62,9 @@ export const Dataset = (): JSX.Element => { // Redux connect equivalent const dispatch = useDispatch(); const deleteDataset = (datasetId:string|undefined) => dispatch(datasetDeleted(datasetId)); - const addFolder = (datasetId:string|undefined, folderName:string, parentFolder:string|null) => dispatch(folderAdded(datasetId, folderName, parentFolder)); - const getFolderPath= (folderId:string|undefined) => dispatch(fetchFolderPath(folderId)); - const listFilesInDataset = (datasetId:string|undefined, folderId:string|undefined) => dispatch(fetchFilesInDataset(datasetId, folderId)); - const listFoldersInDataset = (datasetId:string|undefined, parentFolder:string|undefined) => dispatch(fetchFoldersInDataset(datasetId, parentFolder)); + const getFolderPath= (folderId: string | null) => dispatch(fetchFolderPath(folderId)); + const listFilesInDataset = (datasetId: string | undefined, folderId: string | null) => dispatch(fetchFilesInDataset(datasetId, folderId)); + const listFoldersInDataset = (datasetId: string | undefined, parentFolder: string | null) => dispatch(fetchFoldersInDataset(datasetId, parentFolder)); const listDatasetAbout= (datasetId:string|undefined) => dispatch(fetchDatasetAbout(datasetId)); const dismissError = () => dispatch(resetFailedReason()); const dismissLogout = () => dispatch(resetLogout()); diff --git a/src/components/files/FileMenu.tsx b/src/components/files/FileMenu.tsx index 03e1978..cdb8894 100644 --- a/src/components/files/FileMenu.tsx +++ b/src/components/files/FileMenu.tsx @@ -4,7 +4,7 @@ import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import MenuIcon from '@mui/icons-material/Menu'; import { downloadFile } from '../../utils/file'; -import {FileOut as File} from "../../openapi/v2/models/FileOut"; +import {FileOut as File} from "../../openapi/v2"; import {useState} from "react"; import {fileDeleted} from "../../actions/file"; import {useDispatch} from "react-redux"; diff --git a/src/components/folders/CreateFolder.tsx b/src/components/folders/CreateFolder.tsx index 5f3bd1e..524ea76 100644 --- a/src/components/folders/CreateFolder.tsx +++ b/src/components/folders/CreateFolder.tsx @@ -15,8 +15,8 @@ import {folderAdded} from "../../actions/dataset"; type CreateFolderProps = { - datasetId: string, - parentFolder: string, + datasetId: string | undefined, + parentFolder: string | null, handleClose:(open:boolean) => void, open: boolean; } diff --git a/src/components/versions/FileVersionHistory.tsx b/src/components/versions/FileVersionHistory.tsx index 5854eac..0aceffd 100644 --- a/src/components/versions/FileVersionHistory.tsx +++ b/src/components/versions/FileVersionHistory.tsx @@ -1,7 +1,6 @@ import React from "react"; import {Box, Button, List, ListItem, ListItemAvatar, ListItemText} from "@mui/material"; import {FileVersion} from "../../types/data"; -import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; import {VersionChip} from "./VersionChip"; import {parseDate} from "../../utils/common"; diff --git a/src/reducers/dataset.ts b/src/reducers/dataset.ts index 5da29c6..0ae358b 100644 --- a/src/reducers/dataset.ts +++ b/src/reducers/dataset.ts @@ -10,11 +10,11 @@ import { import {CREATE_FILE, UPDATE_FILE, DELETE_FILE} from "../actions/file"; import {DataAction} from "../types/action"; import {DatasetState} from "../types/data"; -import {DatasetOut as Dataset} from "../openapi/v2/models/DatasetOut"; +import {DatasetOut as Dataset} from "../openapi/v2"; const defaultState: DatasetState = { files: [], - about: {name: "", id: "", authorId: "", description: "", created: "", thumbnail: ""}, + about: {}, datasets: [], newDataset: {}, folders: [], diff --git a/src/types/action.ts b/src/types/action.ts index 83eafbd..2e7968d 100644 --- a/src/types/action.ts +++ b/src/types/action.ts @@ -1,5 +1,6 @@ -import {About, Dataset, ExtractedMetadata, File, MetadataJsonld, FilePreview, FileMetadata, FileVersion, Folder} from "./data"; -import {UPDATE_FILE} from "../actions/file"; +import {ExtractedMetadata, MetadataJsonld, FilePreview, FileMetadata, FileVersion} from "./data"; +import {DatasetOut as Dataset, FileOut as File, FolderOut as Folder} from "../openapi/v2"; +import {GET_FOLDER_PATH} from "../actions/dataset"; interface RECEIVE_FILES_IN_DATASET { type: "RECEIVE_FILES_IN_DATASET"; @@ -13,7 +14,7 @@ interface RECEIVE_FOLDERS_IN_DATASET { interface UPDATE_FILE { type: "UPDATE_FILE"; - file: File[]; + file: File; } interface DELETE_FILE { @@ -23,7 +24,7 @@ interface DELETE_FILE { interface RECEIVE_DATASET_ABOUT{ type: "RECEIVE_DATASET_ABOUT"; - about: About; + about: Dataset; } interface RECEIVE_DATASETS{ @@ -115,6 +116,15 @@ interface FOLDER_ADDED{ folder: Folder } +interface GET_FOLDER_PATH{ + type: "GET_FOLDER_PATH", + folderPath: string +} + +interface RESET_CREATE_DATASET{ + type: "RESET_CREATE_DATASET", + newDataset: Dataset +} export type DataAction = | RECEIVE_FILES_IN_DATASET | RECEIVE_FOLDERS_IN_DATASET @@ -139,4 +149,6 @@ export type DataAction = | RESET_FAILED | RESET_LOGOUT | FOLDER_ADDED + | GET_FOLDER_PATH + | RESET_CREATE_DATASET ; diff --git a/src/types/data.ts.ignore b/src/types/data.ts similarity index 72% rename from src/types/data.ts.ignore rename to src/types/data.ts index 6cef1aa..38baf8b 100644 --- a/src/types/data.ts.ignore +++ b/src/types/data.ts @@ -1,49 +1,4 @@ -export interface Dataset { - name: string; - description: string; - id:string; - author: Author; - created: string | Date; - modified: string | Date; - files: string[]; - folders: string[]; - status: string; - views: string; - downloads: string; - thumbnail: string; -} - -export interface Author { - id: string; - email: string; - "full_name": string|null; -} - -export interface File { - version: string; - creator: string; - created: string | Date; - id: string; - name: string; - size: number; - "date-created": string; - contentType:string; -} - -export interface Folder { - id: string; - name: string; - "parent_folder": string|null; -} - -export interface About { - name: string; - id: string; - authorId: string; - description: string; - created: string | Date; - thumbnail: string; -} +import {FileOut as File, DatasetOut as Dataset, FolderOut as Folder} from "../openapi/v2"; export interface FileMetadata { id: string; @@ -139,7 +94,7 @@ export interface DatasetState{ files: File[]; datasets: Dataset[]; newDataset: Dataset; - about: About; + about: Dataset; folders: Folder[]; folderPath: string[]; } From af295f33877f91b02a0fff896b2f3fd85b3b43fc Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 13:52:27 -0600 Subject: [PATCH 5/7] fix eslint --- src/actions/dataset.js | 2 +- src/components/Dashbard.tsx | 10 ++--- src/components/auth/Login.tsx | 2 +- src/components/auth/Logout.tsx | 4 +- src/components/auth/Register.tsx | 4 +- src/components/datasets/Dataset.tsx | 45 ++++++++++---------- src/components/datasets/DatasetCard.tsx | 10 ++--- src/components/dialog/ActionModal.tsx | 26 ++++++------ src/components/files/File.tsx | 26 ++++++------ src/components/files/FileMenu.tsx | 26 ++++++------ src/components/files/FilesTable.tsx | 54 ++++++++++++------------ src/components/folders/CreateFolder.tsx | 16 +++---- src/components/navigation/BreadCrumb.tsx | 26 ++++++------ src/index.tsx | 6 +-- src/reducers/dataset.ts | 2 +- src/reducers/error.ts | 20 ++++----- src/routes.tsx | 2 +- src/theme.ts | 2 +- 18 files changed, 141 insertions(+), 142 deletions(-) diff --git a/src/actions/dataset.js b/src/actions/dataset.js index 71b0bae..f86c850 100644 --- a/src/actions/dataset.js +++ b/src/actions/dataset.js @@ -120,7 +120,7 @@ export function datasetDeleted(datasetId){ export const FOLDER_ADDED = "FOLDER_ADDED"; export function folderAdded(datasetId, folderName, parentFolder = null){ return (dispatch) => { - const folder = {"name": folderName, "parent_folder": parentFolder} + const folder = {"name": folderName, "parent_folder": parentFolder}; return V2.DatasetsService.addFolderApiV2DatasetsDatasetIdFoldersPost(datasetId, folder) .then(json => { dispatch({ diff --git a/src/components/Dashbard.tsx b/src/components/Dashbard.tsx index 4f29bc4..27d1ade 100644 --- a/src/components/Dashbard.tsx +++ b/src/components/Dashbard.tsx @@ -60,7 +60,7 @@ export const Dashboard = (): JSX.Element => { deleteDataset(selectedDataset["id"]); } setConfirmationOpen(false); - } + }; // component did mount useEffect(() => { @@ -73,15 +73,15 @@ export const Dashboard = (): JSX.Element => { if (reason !== "" && reason !== null && reason !== undefined) { setErrorOpen(true); } - }, [reason]) + }, [reason]); const handleErrorCancel = () => { // reset error message and close the error window dismissError(); setErrorOpen(false); - } + }; const handleErrorReport = () => { window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + }; // log user out if token expired/unauthorized useEffect(() => { @@ -153,7 +153,7 @@ export const Dashboard = (): JSX.Element => {
- + diff --git a/src/components/auth/Login.tsx b/src/components/auth/Login.tsx index f2f6bf4..bcf3f1a 100644 --- a/src/components/auth/Login.tsx +++ b/src/components/auth/Login.tsx @@ -26,7 +26,7 @@ export const Login = (): JSX.Element => { // component did mount useEffect(() => { if (isAuthorized()) { history("/");} - }, []); + }, []); const handleKeyPressed= async (event: React.KeyboardEvent<{}>) => { if (event.key === "Enter") { await handleLoginButtonClick();} diff --git a/src/components/auth/Logout.tsx b/src/components/auth/Logout.tsx index da4fa61..27526d8 100644 --- a/src/components/auth/Logout.tsx +++ b/src/components/auth/Logout.tsx @@ -11,5 +11,5 @@ export const Logout = (): JSX.Element => { return ( - ) -} + ); +}; diff --git a/src/components/auth/Register.tsx b/src/components/auth/Register.tsx index dd3eb5e..650e78d 100644 --- a/src/components/auth/Register.tsx +++ b/src/components/auth/Register.tsx @@ -29,7 +29,7 @@ const textField = { borderColor: "#212529", }, }, -} +}; export const Register = (): JSX.Element => { @@ -51,7 +51,7 @@ export const Register = (): JSX.Element => { useEffect(()=>{ if (registerSucceeded) history("/login"); - }, [registerSucceeded]) + }, [registerSucceeded]); const changeUsername = (event: React.ChangeEvent) => { setEmail(event.target.value); diff --git a/src/components/datasets/Dataset.tsx b/src/components/datasets/Dataset.tsx index d0b1322..3cff419 100644 --- a/src/components/datasets/Dataset.tsx +++ b/src/components/datasets/Dataset.tsx @@ -12,9 +12,8 @@ import { fetchDatasetAbout, fetchFilesInDataset, fetchFolderPath, fetchFoldersInDataset, - folderAdded } from "../../actions/dataset"; -import {resetFailedReason, resetLogout} from "../../actions/common" +import {resetFailedReason, resetLogout} from "../../actions/common"; import {a11yProps, TabPanel} from "../tabs/TabComponent"; import TopBar from "../navigation/TopBar"; @@ -41,7 +40,7 @@ const optionMenuItem = { fontSize: "14px", color: "#212529", marginTop:"8px", -} +}; export const Dataset = (): JSX.Element => { @@ -49,7 +48,7 @@ export const Dataset = (): JSX.Element => { const { datasetId } = useParams<{datasetId?: string}>(); // search parameters - let [searchParams, _] = useSearchParams(); + const [searchParams, _] = useSearchParams(); const folder = searchParams.get("folder"); useEffect(() => { const currentParams = Object.fromEntries([...searchParams]); @@ -97,15 +96,15 @@ export const Dataset = (): JSX.Element => { if (reason !== "" && reason !== null && reason !== undefined){ setErrorOpen(true); } - }, [reason]) + }, [reason]); const handleErrorCancel = () => { // reset error message and close the error window dismissError(); setErrorOpen(false); - } + }; const handleErrorReport = (reason:string) => { window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + }; // log user out if token expired/unauthorized useEffect(() => { @@ -120,7 +119,7 @@ export const Dataset = (): JSX.Element => { const [newFolder, setNewFolder] = React.useState(false); const handleCloseNewFolder = () => { setNewFolder(false); - } + }; const handleTabChange = (_event:React.ChangeEvent<{}>, newTabIndex:number) => { setSelectedTabIndex(newTabIndex); @@ -152,10 +151,10 @@ export const Dataset = (): JSX.Element => { paths.push({ "name": folderBread["folder_name"], "url": `/datasets/${datasetId}?folder=${folderBread["folder_id"]}` - }) + }); } } else { - paths.slice(0, 1) + paths.slice(0, 1); } return ( @@ -170,7 +169,7 @@ export const Dataset = (): JSX.Element => {
- + @@ -191,17 +190,17 @@ export const Dataset = (): JSX.Element => { {/*option menus*/} { // Go to Explore page history("/"); } - }>Delete Dataset + }>Delete Dataset Follow Collaborators Extraction diff --git a/src/components/datasets/DatasetCard.tsx b/src/components/datasets/DatasetCard.tsx index 46c0999..73c0fce 100644 --- a/src/components/datasets/DatasetCard.tsx +++ b/src/components/datasets/DatasetCard.tsx @@ -1,9 +1,9 @@ import React from "react"; -import Card from '@mui/material/Card'; -import CardActions from '@mui/material/CardActions'; -import CardContent from '@mui/material/CardContent'; -import Button from '@mui/material/Button'; -import Typography from '@mui/material/Typography'; +import Card from "@mui/material/Card"; +import CardActions from "@mui/material/CardActions"; +import CardContent from "@mui/material/CardContent"; +import Button from "@mui/material/Button"; +import Typography from "@mui/material/Typography"; import {useNavigate} from "react-router-dom"; import {parseDate} from "../../utils/common"; diff --git a/src/components/dialog/ActionModal.tsx b/src/components/dialog/ActionModal.tsx index a113457..d89f671 100644 --- a/src/components/dialog/ActionModal.tsx +++ b/src/components/dialog/ActionModal.tsx @@ -23,17 +23,17 @@ export const ActionModal:React.FC = (props: ActionModalProps) return ( {actionTitle} - - - {actionText} - - - - {/*handleActionBtnClick This could be used to report error/ confirm deletion and so on*/} - - - - + + + {actionText} + + + + {/*handleActionBtnClick This could be used to report error/ confirm deletion and so on*/} + + + + ); -} +}; diff --git a/src/components/files/File.tsx b/src/components/files/File.tsx index 1d686dd..ff6e064 100644 --- a/src/components/files/File.tsx +++ b/src/components/files/File.tsx @@ -8,7 +8,7 @@ import Thumbnail from "../previewers/Thumbnail"; import {PreviewConfiguration, RootState} from "../../types/data"; import {useParams, useLocation, useNavigate} from "react-router-dom"; import {useDispatch, useSelector} from "react-redux"; -import {resetFailedReason, resetLogout} from "../../actions/common" +import {resetFailedReason, resetLogout} from "../../actions/common"; import {TabPanel} from "../tabs/TabComponent"; import {a11yProps} from "../tabs/TabComponent"; @@ -23,11 +23,11 @@ import {FileVersionHistory} from "../versions/FileVersionHistory"; const tab = { fontStyle: "normal", - fontWeight: "normal", - fontSize: "16px", - color: "#495057", - textTransform: "capitalize", -} + fontWeight: "normal", + fontSize: "16px", + color: "#495057", + textTransform: "capitalize", +}; export const File = (): JSX.Element => { // use history hook to redirect/navigate between routes @@ -76,15 +76,15 @@ export const File = (): JSX.Element => { if (reason !== "" && reason !== null && reason !== undefined){ setErrorOpen(true); } - }, [reason]) + }, [reason]); const handleErrorCancel = () => { // reset error message and close the error window dismissError(); setErrorOpen(false); - } + }; const handleErrorReport = (reason:string) => { window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + }; // log user out if token expired/unauthorized useEffect(() => { @@ -149,17 +149,17 @@ export const File = (): JSX.Element => { paths.push({ "name": folderBread["folder_name"], "url": `/datasets/${datasetId}?folder=${folderBread["folder_id"]}` - }) + }); } } else { - paths.slice(0, 1) + paths.slice(0, 1); } // add file link to breadcrumbs paths.push({ "name":fileMetadata["name"], "url":`/files/${fileId}` - }) + }); return ( @@ -174,7 +174,7 @@ export const File = (): JSX.Element => {
- + diff --git a/src/components/files/FileMenu.tsx b/src/components/files/FileMenu.tsx index cdb8894..4e5fa47 100644 --- a/src/components/files/FileMenu.tsx +++ b/src/components/files/FileMenu.tsx @@ -1,17 +1,17 @@ -import * as React from 'react'; -import Button from '@mui/material/Button'; -import Menu from '@mui/material/Menu'; -import MenuItem from '@mui/material/MenuItem'; -import MenuIcon from '@mui/icons-material/Menu'; -import { downloadFile } from '../../utils/file'; +import * as React from "react"; +import Button from "@mui/material/Button"; +import Menu from "@mui/material/Menu"; +import MenuItem from "@mui/material/MenuItem"; +import MenuIcon from "@mui/icons-material/Menu"; +import { downloadFile } from "../../utils/file"; import {FileOut as File} from "../../openapi/v2"; import {useState} from "react"; import {fileDeleted} from "../../actions/file"; import {useDispatch} from "react-redux"; import {ActionModal} from "../dialog/ActionModal"; -import DownloadIcon from '@mui/icons-material/Download'; -import DeleteIcon from '@mui/icons-material/Delete'; -import UploadIcon from '@mui/icons-material/Upload'; +import DownloadIcon from "@mui/icons-material/Download"; +import DeleteIcon from "@mui/icons-material/Delete"; +import UploadIcon from "@mui/icons-material/Upload"; import {Dialog, DialogTitle, ListItemIcon, ListItemText} from "@mui/material"; import {UpdateFile} from "./UpdateFile"; @@ -40,7 +40,7 @@ export default function FileMenu(props: FileMenuProps) { deleteFile(file.id); } setConfirmationOpen(false); - } + }; return (
@@ -56,9 +56,9 @@ export default function FileMenu(props: FileMenuProps) { id="basic-button" // variant="outlined" size="small" - aria-controls={open ? 'basic-menu' : undefined} + aria-controls={open ? "basic-menu" : undefined} aria-haspopup="true" - aria-expanded={open ? 'true' : undefined} + aria-expanded={open ? "true" : undefined} onClick={handleClick} > @@ -69,7 +69,7 @@ export default function FileMenu(props: FileMenuProps) { open={open} onClose={handleClose} MenuListProps={{ - 'aria-labelledby': 'basic-button', + "aria-labelledby": "basic-button", }} > { diff --git a/src/components/files/FilesTable.tsx b/src/components/files/FilesTable.tsx index 5ba8b99..cb27227 100644 --- a/src/components/files/FilesTable.tsx +++ b/src/components/files/FilesTable.tsx @@ -1,18 +1,18 @@ -import * as React from 'react'; -import Table from '@mui/material/Table'; -import TableBody from '@mui/material/TableBody'; -import TableCell from '@mui/material/TableCell'; -import TableContainer from '@mui/material/TableContainer'; -import TableHead from '@mui/material/TableHead'; -import TableRow from '@mui/material/TableRow'; -import Paper from '@mui/material/Paper'; +import * as React from "react"; +import Table from "@mui/material/Table"; +import TableBody from "@mui/material/TableBody"; +import TableCell from "@mui/material/TableCell"; +import TableContainer from "@mui/material/TableContainer"; +import TableHead from "@mui/material/TableHead"; +import TableRow from "@mui/material/TableRow"; +import Paper from "@mui/material/Paper"; import {useSelector} from "react-redux"; import {RootState} from "../../types/data"; import {useNavigate} from "react-router-dom"; import {Button} from "@mui/material"; import FileMenu from "./FileMenu"; -import FolderIcon from '@mui/icons-material/Folder'; -import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile'; +import FolderIcon from "@mui/icons-material/Folder"; +import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile"; import {parseDate} from "../../utils/common"; import {VersionChip} from "../versions/VersionChip"; @@ -44,7 +44,7 @@ export default function FilesTable(props: FilesTableProps) { Updated Size Type - + @@ -52,7 +52,7 @@ export default function FilesTable(props: FilesTableProps) { foldersInDataset.map((folder) => ( @@ -65,21 +65,21 @@ export default function FilesTable(props: FilesTableProps) { } { filesInDataset.map((file) => ( - - - - - {/*TODO this should be version number; for now put version ID instead*/} - - - {parseDate(file.created)} by {file.creator} - {file.size} - {file.contentType} - - )) + + + + + {/*TODO this should be version number; for now put version ID instead*/} + + + {parseDate(file.created)} by {file.creator} + {file.size} + {file.contentType} + + )) } diff --git a/src/components/folders/CreateFolder.tsx b/src/components/folders/CreateFolder.tsx index 524ea76..cb3d2f2 100644 --- a/src/components/folders/CreateFolder.tsx +++ b/src/components/folders/CreateFolder.tsx @@ -51,14 +51,14 @@ export const CreateFolder: React.FC = (props: CreateFolderPro Create New Folder - + diff --git a/src/components/navigation/BreadCrumb.tsx b/src/components/navigation/BreadCrumb.tsx index b784927..6fdafda 100644 --- a/src/components/navigation/BreadCrumb.tsx +++ b/src/components/navigation/BreadCrumb.tsx @@ -12,18 +12,18 @@ export const MainBreadcrumbs: React.FC = (props:BreadCrumbProps const history = useNavigate(); return ( - - { - paths.map((path:any, index:number) => { - if (index !== paths.length -1){ - return (); - } - else{ - return (); - } - }) - } - + + { + paths.map((path:any, index:number) => { + if (index !== paths.length -1){ + return (); + } + else{ + return (); + } + }) + } + ); }; diff --git a/src/index.tsx b/src/index.tsx index 349fe1b..70847bc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,10 +6,10 @@ import { render } from "react-dom"; import { Provider } from "react-redux"; import AppRoutes from "./routes"; import configureStore from "./store/configureStore"; -import {ThemeProvider} from '@mui/material/styles'; -import CssBaseline from '@mui/material/CssBaseline'; +import {ThemeProvider} from "@mui/material/styles"; +import CssBaseline from "@mui/material/CssBaseline"; const store = configureStore(); -import theme from './theme'; +import theme from "./theme"; render( diff --git a/src/reducers/dataset.ts b/src/reducers/dataset.ts index 0ae358b..046c462 100644 --- a/src/reducers/dataset.ts +++ b/src/reducers/dataset.ts @@ -47,7 +47,7 @@ const dataset = (state = defaultState, action: DataAction) => { case CREATE_DATASET: return Object.assign({}, state, {newDataset: action.dataset}); case RESET_CREATE_DATASET: - return Object.assign({}, state, {newDataset: {}}); + return Object.assign({}, state, {newDataset: {}}); case DELETE_DATASET: return Object.assign({}, state, { datasets: state.datasets.filter(dataset => dataset.id !== action.dataset.id), diff --git a/src/reducers/error.ts b/src/reducers/error.ts index 878838c..89d792a 100644 --- a/src/reducers/error.ts +++ b/src/reducers/error.ts @@ -8,16 +8,16 @@ const defaultState = { const error = (state = defaultState, action: DataAction) => { switch (action.type) { - case "FAILED": - return Object.assign({}, state, {reason: action.reason, stack: action.stack}); - case "RESET_FAILED": - return Object.assign({}, state, {reason: "", stack: ""}); - case "LOGOUT": - return Object.assign({}, state, {loggedOut: true}); - case "RESET_LOGOUT": - return Object.assign({}, state, {loggedOut: false}); - default: - return state; + case "FAILED": + return Object.assign({}, state, {reason: action.reason, stack: action.stack}); + case "RESET_FAILED": + return Object.assign({}, state, {reason: "", stack: ""}); + case "LOGOUT": + return Object.assign({}, state, {loggedOut: true}); + case "RESET_LOGOUT": + return Object.assign({}, state, {loggedOut: false}); + default: + return state; } }; diff --git a/src/routes.tsx b/src/routes.tsx index a5b802b..250220a 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -13,7 +13,7 @@ import {isAuthorized} from "./utils/common"; // https://dev.to/iamandrewluca/private-route-in-react-router-v6-lg5 class PrivateRoute extends React.Component<{ children: JSX.Element }> { render() { - let {children} = this.props; + const {children} = this.props; return isAuthorized() ? children : ; } } diff --git a/src/theme.ts b/src/theme.ts index 8cd47e3..57be1ce 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -1,4 +1,4 @@ -import { createTheme } from '@mui/material/styles'; +import { createTheme } from "@mui/material/styles"; // A custom theme for this app const theme = createTheme({ From e342f38fbeabb8621fc99740f9700fe66030dc00 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 16:11:42 -0600 Subject: [PATCH 6/7] include fileversion model --- src/components/Dashbard.tsx | 17 +++++++---------- src/components/auth/Logout.tsx | 1 + src/components/datasets/Dataset.tsx | 19 +++++++++---------- src/components/datasets/DatasetCard.tsx | 13 +++++++------ src/components/files/FileAbout.tsx | 3 ++- src/components/files/FileSearch.tsx | 3 ++- src/components/files/FilesTable.tsx | 15 ++++++++------- src/components/files/UploadFile.tsx | 8 ++++---- src/components/navigation/BreadCrumb.tsx | 1 - src/components/previewers/Audio.tsx | 1 + src/components/previewers/Thumbnail.tsx | 1 + src/components/previewers/Video.tsx | 1 + ...reInputLabel.jsx => ClowderInputLabel.jsx} | 2 +- .../{IncoreSelect.jsx => ClowderSelect.jsx} | 0 src/components/tabs/TabComponent.tsx | 1 + .../versions/FileVersionHistory.tsx | 8 ++++++-- src/components/versions/VersionChip.tsx | 1 + src/openapi/v2/index.ts | 1 + src/openapi/v2/models/FileVersion.ts | 13 +++++++++++++ src/openapi/v2/services/FilesService.ts | 5 +++-- src/types/action.ts | 6 +++--- src/types/data.ts | 17 +++++++---------- 22 files changed, 79 insertions(+), 58 deletions(-) rename src/components/styledComponents/{IncoreInputLabel.jsx => ClowderInputLabel.jsx} (80%) rename src/components/styledComponents/{IncoreSelect.jsx => ClowderSelect.jsx} (100%) create mode 100644 src/openapi/v2/models/FileVersion.ts diff --git a/src/components/Dashbard.tsx b/src/components/Dashbard.tsx index 27d1ade..59e314e 100644 --- a/src/components/Dashbard.tsx +++ b/src/components/Dashbard.tsx @@ -167,16 +167,13 @@ export const Dashboard = (): JSX.Element => { { datasets.map((dataset) => { return ( - dataset !== undefined ? - - - - : - <> - ); + + + + ) }) } diff --git a/src/components/auth/Logout.tsx b/src/components/auth/Logout.tsx index 27526d8..f18f490 100644 --- a/src/components/auth/Logout.tsx +++ b/src/components/auth/Logout.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import React, {useEffect} from "react"; import {useDispatch} from "react-redux"; import {logout as logoutAction} from "../../actions/user"; diff --git a/src/components/datasets/Dataset.tsx b/src/components/datasets/Dataset.tsx index 3cff419..72965fa 100644 --- a/src/components/datasets/Dataset.tsx +++ b/src/components/datasets/Dataset.tsx @@ -19,7 +19,6 @@ import {a11yProps, TabPanel} from "../tabs/TabComponent"; import TopBar from "../navigation/TopBar"; import {MainBreadcrumbs} from "../navigation/BreadCrumb"; import {UploadFile} from "../files/UploadFile"; -import {V2} from "../../openapi"; import {ActionModal} from "../dialog/ActionModal"; import FilesTable from "../files/FilesTable"; import {CreateFolder} from "../folders/CreateFolder"; @@ -60,11 +59,11 @@ export const Dataset = (): JSX.Element => { // Redux connect equivalent const dispatch = useDispatch(); - const deleteDataset = (datasetId:string|undefined) => dispatch(datasetDeleted(datasetId)); + const deleteDataset = (datasetId:string | undefined) => dispatch(datasetDeleted(datasetId)); const getFolderPath= (folderId: string | null) => dispatch(fetchFolderPath(folderId)); const listFilesInDataset = (datasetId: string | undefined, folderId: string | null) => dispatch(fetchFilesInDataset(datasetId, folderId)); const listFoldersInDataset = (datasetId: string | undefined, parentFolder: string | null) => dispatch(fetchFoldersInDataset(datasetId, parentFolder)); - const listDatasetAbout= (datasetId:string|undefined) => dispatch(fetchDatasetAbout(datasetId)); + const listDatasetAbout= (datasetId?:string) => dispatch(fetchDatasetAbout(datasetId)); const dismissError = () => dispatch(resetFailedReason()); const dismissLogout = () => dispatch(resetLogout()); @@ -257,11 +256,11 @@ export const Dataset = (): JSX.Element => { setNewDatasetName(value); }} defaultValue={about["name"]}/> : @@ -270,11 +269,11 @@ export const Dataset = (): JSX.Element => { } Dataset ID: {about["id"]} - Owner: {about["authorId"]} + {/*Owner: {about["author"]["full_name"]}*/} Description: {about["description"]} Created on: {parseDate(about["created"])} {/*/!*TODO use this to get thumbnail*!/*/} - Thumbnail: {about["thumbnail"]} + {/*Thumbnail: {about["thumbnail"]}*/} {/*Belongs to spaces: {about["authorId"]}*/} {/*/!*TODO not sure how to use this info*!/*/} {/*Resource type: {about["resource_type"]}*/} diff --git a/src/components/datasets/DatasetCard.tsx b/src/components/datasets/DatasetCard.tsx index 73c0fce..8ba0d00 100644 --- a/src/components/datasets/DatasetCard.tsx +++ b/src/components/datasets/DatasetCard.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import React from "react"; import Card from "@mui/material/Card"; import CardActions from "@mui/material/CardActions"; @@ -8,11 +9,11 @@ import {useNavigate} from "react-router-dom"; import {parseDate} from "../../utils/common"; type DatasetCardProps = { - id: string, - name: string, - author: string, - created: string | Date, - description: string + id?: string, + name?: string, + author?: string, + created?: string | Date, + description?: string } export default function DatasetCard(props: DatasetCardProps) { @@ -20,7 +21,7 @@ export default function DatasetCard(props: DatasetCardProps) { const formattedCreated = parseDate(created); // use history hook to redirect/navigate between routes const history = useNavigate(); - const selectDataset = (selectedDatasetId: string) => { + const selectDataset = (selectedDatasetId: string | undefined) => { // Redirect to dataset route with dataset Id history(`/datasets/${selectedDatasetId}`); }; diff --git a/src/components/files/FileAbout.tsx b/src/components/files/FileAbout.tsx index 40e5925..2c89aad 100644 --- a/src/components/files/FileAbout.tsx +++ b/src/components/files/FileAbout.tsx @@ -1,7 +1,8 @@ -import {Box, Typography} from "@mui/material"; +// @ts-ignore import React from "react"; import {FileMetadata} from "../../types/data"; import {parseDate} from "../../utils/common"; +import {Box, Typography} from "@mui/material"; type FileAboutProps = { diff --git a/src/components/files/FileSearch.tsx b/src/components/files/FileSearch.tsx index a3dcb62..c671bd2 100644 --- a/src/components/files/FileSearch.tsx +++ b/src/components/files/FileSearch.tsx @@ -1,7 +1,8 @@ -import {Box, Grid, Typography} from "@mui/material"; +// @ts-ignore import React from "react"; import {ClowderInput} from "../styledComponents/ClowderInput"; import {ClowderButton} from "../styledComponents/ClowderButton"; +import {Box, Grid, Typography} from "@mui/material"; export function FileSearch() { diff --git a/src/components/files/FilesTable.tsx b/src/components/files/FilesTable.tsx index cb27227..f367cfb 100644 --- a/src/components/files/FilesTable.tsx +++ b/src/components/files/FilesTable.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import * as React from "react"; import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; @@ -17,8 +18,8 @@ import {parseDate} from "../../utils/common"; import {VersionChip} from "../versions/VersionChip"; type FilesTableProps = { - datasetId: string | undefined, - datasetName: string + datasetId?: string, + datasetName?: string } export default function FilesTable(props: FilesTableProps) { @@ -27,11 +28,11 @@ export default function FilesTable(props: FilesTableProps) { const foldersInDataset = useSelector((state:RootState) => state.dataset.folders); // use history hook to redirect/navigate between routes const history = useNavigate(); - const selectFile = (selectedFileId: string) => { + const selectFile = (selectedFileId?:string) => { // Redirect to file route with file Id and dataset id history(`/files/${selectedFileId}?dataset=${props.datasetId}&name=${props.datasetName}`); }; - const selectFolder = (selectedFolderId: string) => { + const selectFolder = (selectedFolderId?:string) => { // Redirect to file route with file Id and dataset id history(`/datasets/${props.datasetId}?folder=${selectedFolderId}`); }; @@ -73,11 +74,11 @@ export default function FilesTable(props: FilesTableProps) { {/*TODO this should be version number; for now put version ID instead*/} - + { + file.version ? : <> + } {parseDate(file.created)} by {file.creator} - {file.size} - {file.contentType} )) } diff --git a/src/components/files/UploadFile.tsx b/src/components/files/UploadFile.tsx index 6933e55..421bd4d 100644 --- a/src/components/files/UploadFile.tsx +++ b/src/components/files/UploadFile.tsx @@ -13,20 +13,20 @@ import {fileCreated} from "../../actions/file"; type UploadFileProps ={ - selectedDatasetId: string|undefined, - folderId: string|undefined, + selectedDatasetId?: string, + folderId: string | null, setOpen:(open:boolean) => void, } export const UploadFile: React.FC = (props: UploadFileProps) => { const dispatch = useDispatch(); - const uploadFile = (formData: FormData, selectedDatasetId: string|undefined) => dispatch(fileCreated(formData, selectedDatasetId)); + const uploadFile = (formData: any, selectedDatasetId?: string) => dispatch(fileCreated(formData, selectedDatasetId)); const {selectedDatasetId, folderId, setOpen,} = props; const [loading, setLoading] = useState(false); - const onSave = async (formData:FormData) => { + const onSave = async (formData:any) => { setLoading(true); formData["folder_id"] = folderId; uploadFile(formData, selectedDatasetId); diff --git a/src/components/navigation/BreadCrumb.tsx b/src/components/navigation/BreadCrumb.tsx index 6fdafda..58b1b47 100644 --- a/src/components/navigation/BreadCrumb.tsx +++ b/src/components/navigation/BreadCrumb.tsx @@ -1,5 +1,4 @@ import React from "react"; -import Typography from "@mui/material/Typography"; import Breadcrumbs from "@mui/material/Breadcrumbs"; import {Button} from "@mui/material"; import {useNavigate} from "react-router-dom"; diff --git a/src/components/previewers/Audio.tsx b/src/components/previewers/Audio.tsx index 3d340ca..8f43823 100644 --- a/src/components/previewers/Audio.tsx +++ b/src/components/previewers/Audio.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import React from "react"; type AudioProps = { diff --git a/src/components/previewers/Thumbnail.tsx b/src/components/previewers/Thumbnail.tsx index cc017a0..b58dfe8 100644 --- a/src/components/previewers/Thumbnail.tsx +++ b/src/components/previewers/Thumbnail.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import React from "react"; import { Typography } from "@mui/material"; diff --git a/src/components/previewers/Video.tsx b/src/components/previewers/Video.tsx index 6022657..659dcce 100644 --- a/src/components/previewers/Video.tsx +++ b/src/components/previewers/Video.tsx @@ -1,3 +1,4 @@ +// @ts-ignore import React from "react"; type VideoProps = { diff --git a/src/components/styledComponents/IncoreInputLabel.jsx b/src/components/styledComponents/ClowderInputLabel.jsx similarity index 80% rename from src/components/styledComponents/IncoreInputLabel.jsx rename to src/components/styledComponents/ClowderInputLabel.jsx index 4f97b6f..eb1befc 100644 --- a/src/components/styledComponents/IncoreInputLabel.jsx +++ b/src/components/styledComponents/ClowderInputLabel.jsx @@ -1,7 +1,7 @@ import {styled} from "@mui/styles"; import {InputLabel} from "@mui/material"; -export const IncoreInputLabel = styled(InputLabel)({ +export const ClowderInputLabel = styled(InputLabel)({ color: "#2E384D", fontSize: "16px", fontWeight: 500, diff --git a/src/components/styledComponents/IncoreSelect.jsx b/src/components/styledComponents/ClowderSelect.jsx similarity index 100% rename from src/components/styledComponents/IncoreSelect.jsx rename to src/components/styledComponents/ClowderSelect.jsx diff --git a/src/components/tabs/TabComponent.tsx b/src/components/tabs/TabComponent.tsx index d85b095..c31e5ae 100644 --- a/src/components/tabs/TabComponent.tsx +++ b/src/components/tabs/TabComponent.tsx @@ -1,4 +1,5 @@ import {Box, Typography} from "@mui/material"; +// @ts-ignore import React from "react"; export function TabPanel(props:any) { diff --git a/src/components/versions/FileVersionHistory.tsx b/src/components/versions/FileVersionHistory.tsx index 0aceffd..bd89a02 100644 --- a/src/components/versions/FileVersionHistory.tsx +++ b/src/components/versions/FileVersionHistory.tsx @@ -1,6 +1,7 @@ +// @ts-ignore import React from "react"; import {Box, Button, List, ListItem, ListItemAvatar, ListItemText} from "@mui/material"; -import {FileVersion} from "../../types/data"; +import {FileVersion} from "../../openapi/v2"; import {VersionChip} from "./VersionChip"; import {parseDate} from "../../utils/common"; @@ -22,7 +23,10 @@ export function FileVersionHistory(props: FileVersionHistoryProps) { {/*TODO replace with pretty version name*/} - + {fileVersion["version_id"] ? + + : <> + } { + ): CancelablePromise> { return __request({ method: 'GET', path: `/api/v2/files/${fileId}/versions`, diff --git a/src/types/action.ts b/src/types/action.ts index 2e7968d..bd97c40 100644 --- a/src/types/action.ts +++ b/src/types/action.ts @@ -1,5 +1,5 @@ -import {ExtractedMetadata, MetadataJsonld, FilePreview, FileMetadata, FileVersion} from "./data"; -import {DatasetOut as Dataset, FileOut as File, FolderOut as Folder} from "../openapi/v2"; +import {ExtractedMetadata, MetadataJsonld, FilePreview, FileMetadata, FolderPath} from "./data"; +import {DatasetOut as Dataset, FileOut as File, FolderOut as Folder, FileVersion} from "../openapi/v2"; import {GET_FOLDER_PATH} from "../actions/dataset"; interface RECEIVE_FILES_IN_DATASET { @@ -118,7 +118,7 @@ interface FOLDER_ADDED{ interface GET_FOLDER_PATH{ type: "GET_FOLDER_PATH", - folderPath: string + folderPath: FolderPath[], } interface RESET_CREATE_DATASET{ diff --git a/src/types/data.ts b/src/types/data.ts index 38baf8b..9e3c2f7 100644 --- a/src/types/data.ts +++ b/src/types/data.ts @@ -1,4 +1,4 @@ -import {FileOut as File, DatasetOut as Dataset, FolderOut as Folder} from "../openapi/v2"; +import {FileOut as File, DatasetOut as Dataset, FolderOut as Folder, FileVersion} from "../openapi/v2"; export interface FileMetadata { id: string; @@ -15,14 +15,6 @@ export interface FileMetadata { version: string; } -export interface FileVersion { - id: string; - "version_id": string; - "file_id": string; - "creator": string; - "created": string | Date; -} - export interface FileMetadataList{ id: string; metadata: FileMetadata; @@ -90,13 +82,18 @@ export interface Thumbnail{ thumbnail: string; } +export interface FolderPath{ + "folder_name": string; + "folder_id": string; +} + export interface DatasetState{ files: File[]; datasets: Dataset[]; newDataset: Dataset; about: Dataset; folders: Folder[]; - folderPath: string[]; + folderPath: FolderPath[]; } export interface FileState{ From 1082f1f28e20058c6594cb85a23573d7c1128711 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 8 Mar 2022 16:59:19 -0600 Subject: [PATCH 7/7] fix most type related issues --- src/components/Dashbard.tsx | 2 +- src/components/datasets/Dataset.tsx | 6 +----- src/components/files/FilesTable.tsx | 4 ++-- src/reducers/dataset.ts | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/Dashbard.tsx b/src/components/Dashbard.tsx index 59e314e..2da511b 100644 --- a/src/components/Dashbard.tsx +++ b/src/components/Dashbard.tsx @@ -169,7 +169,7 @@ export const Dashboard = (): JSX.Element => { return ( diff --git a/src/components/datasets/Dataset.tsx b/src/components/datasets/Dataset.tsx index 72965fa..7a2afd8 100644 --- a/src/components/datasets/Dataset.tsx +++ b/src/components/datasets/Dataset.tsx @@ -49,10 +49,6 @@ export const Dataset = (): JSX.Element => { // search parameters const [searchParams, _] = useSearchParams(); const folder = searchParams.get("folder"); - useEffect(() => { - const currentParams = Object.fromEntries([...searchParams]); - console.log(currentParams); // get new values onchange - }, [searchParams]); // use history hook to redirect/navigate between routes const history = useNavigate(); @@ -269,7 +265,7 @@ export const Dataset = (): JSX.Element => { } Dataset ID: {about["id"]} - {/*Owner: {about["author"]["full_name"]}*/} + Owner: {about["author"]["full_name"]} Description: {about["description"]} Created on: {parseDate(about["created"])} {/*/!*TODO use this to get thumbnail*!/*/} diff --git a/src/components/files/FilesTable.tsx b/src/components/files/FilesTable.tsx index f367cfb..3d6f05b 100644 --- a/src/components/files/FilesTable.tsx +++ b/src/components/files/FilesTable.tsx @@ -58,7 +58,7 @@ export default function FilesTable(props: FilesTableProps) { - {folder.author} + {folder.author.full_name} - - - @@ -78,7 +78,7 @@ export default function FilesTable(props: FilesTableProps) { file.version ? : <> } - {parseDate(file.created)} by {file.creator} + {parseDate(file.created)} by {file.creator.full_name} )) } diff --git a/src/reducers/dataset.ts b/src/reducers/dataset.ts index 046c462..e26e304 100644 --- a/src/reducers/dataset.ts +++ b/src/reducers/dataset.ts @@ -10,11 +10,11 @@ import { import {CREATE_FILE, UPDATE_FILE, DELETE_FILE} from "../actions/file"; import {DataAction} from "../types/action"; import {DatasetState} from "../types/data"; -import {DatasetOut as Dataset} from "../openapi/v2"; +import {DatasetOut as Dataset, UserOut as Author} from "../openapi/v2"; const defaultState: DatasetState = { files: [], - about: {}, + about: {"author":{}}, datasets: [], newDataset: {}, folders: [],