X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d6a28995f22dc04688444c0098b185717f7d4ed4..f0f1a84dcd35f11214f0c534f8490f6a4f648b48:/src/components/collection-panel-files/collection-panel-files.tsx diff --git a/src/components/collection-panel-files/collection-panel-files.tsx b/src/components/collection-panel-files/collection-panel-files.tsx index 3c064973..42408270 100644 --- a/src/components/collection-panel-files/collection-panel-files.tsx +++ b/src/components/collection-panel-files/collection-panel-files.tsx @@ -10,24 +10,38 @@ import AutoSizer from "react-virtualized-auto-sizer"; import servicesProvider from 'common/service-provider'; import { CustomizeTableIcon, DownloadIcon } from 'components/icon/icon'; import { SearchInput } from 'components/search-input/search-input'; -import { ListItemIcon, StyleRulesCallback, Theme, WithStyles, withStyles, Tooltip, IconButton, Checkbox, CircularProgress, Button } from '@material-ui/core'; +import { + ListItemIcon, + StyleRulesCallback, + Theme, + WithStyles, + withStyles, + Tooltip, + IconButton, + Checkbox, + CircularProgress, + Button, +} from '@material-ui/core'; import { FileTreeData } from '../file-tree/file-tree-data'; import { TreeItem, TreeItemStatus } from '../tree/tree'; import { RootState } from 'store/store'; import { WebDAV, WebDAVRequestConfig } from 'common/webdav'; import { AuthState } from 'store/auth/auth-reducer'; import { extractFilesData } from 'services/collection-service/collection-service-files-response'; -import { DefaultIcon, DirectoryIcon, FileIcon, BackIcon, SidePanelRightArrowIcon } from 'components/icon/icon'; +import { + DefaultIcon, + DirectoryIcon, + FileIcon, + BackIcon, + SidePanelRightArrowIcon +} from 'components/icon/icon'; import { setCollectionFiles } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions'; import { sortBy } from 'lodash'; import { formatFileSize } from 'common/formatters'; import { getInlineFileUrl, sanitizeToken } from 'views-components/context-menu/actions/helpers'; export interface CollectionPanelFilesProps { - items: any; isWritable: boolean; - isLoading: boolean; - tooManyFiles: boolean; onUploadDataClick: (targetLocation?: string) => void; onSearchChange: (searchValue: string) => void; onItemMenuOpen: (event: React.MouseEvent, item: TreeItem, isWritable: boolean) => void; @@ -35,14 +49,35 @@ export interface CollectionPanelFilesProps { onSelectionToggle: (event: React.MouseEvent, item: TreeItem) => void; onCollapseToggle: (id: string, status: TreeItemStatus) => void; onFileClick: (id: string) => void; - loadFilesFunc: () => void; currentItemUuid: any; dispatch: Function; collectionPanelFiles: any; collectionPanel: any; } -type CssRules = "backButton" | "backButtonHidden" | "pathPanelPathWrapper" | "uploadButton" | "uploadIcon" | "loader" | "wrapper" | "dataWrapper" | "row" | "rowEmpty" | "leftPanel" | "rightPanel" | "pathPanel" | "pathPanelItem" | "rowName" | "listItemIcon" | "rowActive" | "pathPanelMenu" | "rowSelection" | "leftPanelHidden" | "leftPanelVisible" | "searchWrapper" | "searchWrapperHidden"; +type CssRules = "backButton" + | "backButtonHidden" + | "pathPanelPathWrapper" + | "uploadButton" + | "uploadIcon" + | "loader" + | "wrapper" + | "dataWrapper" + | "row" + | "rowEmpty" + | "leftPanel" + | "rightPanel" + | "pathPanel" + | "pathPanelItem" + | "rowName" + | "listItemIcon" + | "rowActive" + | "pathPanelMenu" + | "rowSelection" + | "leftPanelHidden" + | "leftPanelVisible" + | "searchWrapper" + | "searchWrapperHidden"; const styles: StyleRulesCallback = (theme: Theme) => ({ wrapper: { @@ -198,8 +233,8 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState }; const parentRef = React.useRef(null); - const [path, setPath]: any = React.useState([]); - const [pathData, setPathData]: any = React.useState({}); + const [path, setPath] = React.useState([]); + const [pathData, setPathData] = React.useState({}); const [isLoading, setIsLoading] = React.useState(false); const [leftSearch, setLeftSearch] = React.useState(''); const [rightSearch, setRightSearch] = React.useState(''); @@ -218,7 +253,6 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState }, [props.currentItemUuid]); const fetchData = (keys, ignoreCache = false) => { - console.log('---> fetchData', keys); const keyArray = Array.isArray(keys) ? keys : [keys]; Promise.all(keyArray.filter(key => !!key) @@ -226,14 +260,13 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const dataExists = !!pathData[key]; const runningRequest = pathPromise[key]; - if ((!dataExists || ignoreCache) && (!runningRequest || ignoreCache)) { + if (ignoreCache || (!dataExists && !runningRequest)) { if (!isLoading) { setIsLoading(true); } pathPromise[key] = true; - console.log('>>> fetching data for key', key); return webdavClient.propfind(`c=${key}`, webDAVRequestConfig); } @@ -282,7 +315,12 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const currentPDH = (collectionPanel.item || {}).portableDataHash; React.useEffect(() => { if (currentPDH) { - fetchData([leftKey, rightKey], true); + // Avoid fetching the same content level twice + if (leftKey !== rightKey) { + fetchData([leftKey, rightKey], true); + } else { + fetchData(rightKey, true); + } } }, [currentPDH]); // eslint-disable-line react-hooks/exhaustive-deps @@ -317,13 +355,12 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState onItemMenuOpen(event, item, isWritable); } }, - [onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps - ); + [onItemMenuOpen, isWritable, rightData]); React.useEffect(() => { let node = null; - if (parentRef && parentRef.current) { + if (parentRef?.current) { node = parentRef.current; (node as any).addEventListener('contextmenu', handleRightClick); } @@ -424,18 +461,15 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState return
- { path.map((p: string, index: number) => + { path.map( (p: string, index: number) => + {index === 0 ? 'Home' : p} /  - ) } + ) + }
- { onOptionsMenuOpen(ev, isWritable); }}> @@ -444,128 +478,51 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
-
1 ? classes.leftPanelVisible : classes.leftPanelHidden)} data-cy="collection-files-left-panel"> +
1 ? classes.leftPanelVisible : classes.leftPanelHidden)} data-cy="collection-files-left-panel"> 1 ? classes.backButton : classes.backButtonHidden}> setPath([...path.slice(0, path.length -1)])}> -
-
-
1 ? classes.leftPanelVisible : classes.leftPanelHidden)} data-cy="collection-files-left-panel"> - 1 ? classes.backButton : classes.backButtonHidden}> - setPath([...path.slice(0, path.length -1)])}> - - - -
1 ? classes.searchWrapper : classes.searchWrapperHidden}> - -
-
- { - leftData ? - - {({ height, width }) => { - const filtered = leftData.filter(({ name }) => name.indexOf(leftSearch) > -1); - - return !!filtered.length ? - { - ({ index, style }) => { - const { id, type, name } = filtered[index]; - - return
- {getItemIcon(type, getActiveClass(name))} -
- {name} -
- { - getActiveClass(name) ? : null - } -
; - } - } -
:
No directories available
- }} -
:
- } - -
+
1 ? classes.searchWrapper : classes.searchWrapperHidden}> +
-
-
- -
- { - isWritable && - - } -
- { - rightData && !isLoading ? - - {({ height, width }) => { - const filtered = rightData.filter(({ name }) => name.indexOf(rightSearch) > -1); - - return !!filtered.length - ? { ({ index, style }) => { - console.log("Left Data ROW: ", filtered[index]); - const { id, type, name } = filtered[index]; - - return
- { getItemIcon(type, getActiveClass(name)) } -
- {name} -
- { getActiveClass(name) - ? - : null } -
; - } }
- :
No directories available
- } }
- :
- -
} +
{ leftData + ? {({ height, width }) => { + const filtered = leftData.filter(({ name }) => name.indexOf(leftSearch) > -1); + return !!filtered.length + ? { ({ index, style }) => { + const { id, type, name } = filtered[index]; + return
+ { getItemIcon(type, getActiveClass(name)) } +
+ {name} +
+ { getActiveClass(name) + ? + : null + } +
; + }}
+ :
No directories available
+ }} +
+ :
}
-
+
{ isWritable &&