X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/43551086cc04bb37a2b1dc6c8ec24af44f2acf8d..614e5664c62ac01307744e29072ca1804cb7e676:/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 1ef6b5c94c..b077d91778 100644 --- a/src/components/collection-panel-files/collection-panel-files.tsx +++ b/src/components/collection-panel-files/collection-panel-files.tsx @@ -27,8 +27,7 @@ export interface CollectionPanelFilesProps { items: any; isWritable: boolean; isLoading: boolean; - tooManyFiles: boolean; - onUploadDataClick: () => void; + onUploadDataClick: (targetLocation?: string) => void; onSearchChange: (searchValue: string) => void; onItemMenuOpen: (event: React.MouseEvent, item: TreeItem, isWritable: boolean) => void; onOptionsMenuOpen: (event: React.MouseEvent, isWritable: boolean) => void; @@ -201,7 +200,6 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const [path, setPath]: any = React.useState([]); const [pathData, setPathData]: any = React.useState({}); const [isLoading, setIsLoading] = React.useState(false); - const [collectionAutofetchEnabled, setCollectionAutofetchEnabled] = React.useState(false); const [leftSearch, setLeftSearch] = React.useState(''); const [rightSearch, setRightSearch] = React.useState(''); @@ -212,6 +210,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const rightData = pathData[rightKey]; React.useEffect(() => { + console.log(' --> useEffect current UUID: ', props.currentItemUuid); if (props.currentItemUuid) { setPathData({}); setPath([props.currentItemUuid]); @@ -219,9 +218,10 @@ 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 + Promise.all(keyArray.filter(key => !!key) .map((key) => { const dataExists = !!pathData[key]; const runningRequest = pathPromise[key]; @@ -233,6 +233,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState pathPromise[key] = true; + console.log('>>> fetching data for key', key); return webdavClient.propfind(`c=${key}`, webDAVRequestConfig); } @@ -240,37 +241,39 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState }) .filter((promise) => !!promise) ) - .then((requests) => { - const newState = requests.map((request, index) => { - if (request && request.responseXML != null) { - const key = keyArray[index]; - const result: any = extractFilesData(request.responseXML); - const sortedResult = sortBy(result, (n) => n.name).sort((n1, n2) => { - if (n1.type === 'directory' && n2.type !== 'directory') { - return -1; - } - if (n1.type !== 'directory' && n2.type === 'directory') { - return 1; - } - return 0; - }); - - return { [key]: sortedResult }; - } - return {}; - }).reduce((prev, next) => { - return { ...next, ...prev }; - }, {}); + .then((requests) => { + const newState = requests.map((request, index) => { + if (request && request.responseXML != null) { + console.log(">>> got data for key", keyArray[index]); + const key = keyArray[index]; + const result: any = extractFilesData(request.responseXML); + const sortedResult = sortBy(result, (n) => n.name).sort((n1, n2) => { + if (n1.type === 'directory' && n2.type !== 'directory') { + return -1; + } + if (n1.type !== 'directory' && n2.type === 'directory') { + return 1; + } + return 0; + }); - setPathData({ ...pathData, ...newState }); - }) - .finally(() => { - setIsLoading(false); - keyArray.forEach(key => delete pathPromise[key]); - }); + return { [key]: sortedResult }; + } + return {}; + }).reduce((prev, next) => { + return { ...next, ...prev }; + }, {}); + + setPathData({ ...pathData, ...newState }); + }) + .finally(() => { + setIsLoading(false); + keyArray.forEach(key => delete pathPromise[key]); + }); }; React.useEffect(() => { + console.log('---> useEffect rightKey', rightKey); if (rightKey) { fetchData(rightKey); setLeftSearch(''); @@ -278,15 +281,16 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState } }, [rightKey]); // eslint-disable-line react-hooks/exhaustive-deps + const currentPDH = (collectionPanel.item || {}).portableDataHash; React.useEffect(() => { - const hash = (collectionPanel.item || {}).portableDataHash; - - if (hash && collectionAutofetchEnabled) { + console.log('---> useEffect PDH change:', currentPDH); + if (currentPDH) { fetchData([leftKey, rightKey], true); } - }, [(collectionPanel.item || {}).portableDataHash]); // eslint-disable-line react-hooks/exhaustive-deps + }, [currentPDH]); // eslint-disable-line react-hooks/exhaustive-deps React.useEffect(() => { + console.log('---> useEffect rightData:', rightData, dispatch, rightSearch); if (rightData) { const filtered = rightData.filter(({ name }) => name.indexOf(rightSearch) > -1); setCollectionFiles(filtered, false)(dispatch); @@ -315,16 +319,13 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState if (id) { onItemMenuOpen(event, item, isWritable); - - if (!collectionAutofetchEnabled) { - setCollectionAutofetchEnabled(true); - } } }, [onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps ); React.useEffect(() => { + console.log('---> useEffect parentRef:', parentRef, handleRightClick); let node = null; if (parentRef && parentRef.current) { @@ -425,37 +426,39 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState [props.onOptionsMenuOpen] // eslint-disable-line react-hooks/exhaustive-deps ); - return ( -
-
-
- { - path - .map((p: string, index: number) => - {index === 0 ? 'Home' : p} /  - ) - } -
- - { - if (!collectionAutofetchEnabled) { - setCollectionAutofetchEnabled(true); - } - onOptionsMenuOpen(ev, isWritable); - }}> - + console.log('---> render CollectionPanel <------'); + return
+
+
+ { path.map((p: string, index: number) => + {index === 0 ? 'Home' : p} /  + ) } +
+ + { + onOptionsMenuOpen(ev, isWritable); + }}> + + + +
+
+
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)}> +
1 ? classes.leftPanelVisible : classes.leftPanelHidden)} data-cy="collection-files-left-panel"> 1 ? classes.backButton : classes.backButtonHidden}> setPath([...path.slice(0, path.length -1)])}> @@ -507,7 +510,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
-
+
@@ -517,10 +520,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState className={classes.uploadButton} data-cy='upload-button' onClick={() => { - if (!collectionAutofetchEnabled) { - setCollectionAutofetchEnabled(true); - } - onUploadDataClick(); + onUploadDataClick(rightKey === leftKey ? undefined : rightKey); }} variant='contained' color='primary' @@ -536,44 +536,81 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState {({ height, width }) => { const filtered = rightData.filter(({ name }) => name.indexOf(rightSearch) > -1); - return !!filtered.length ? - { - ({ index, style }) => { - const { id, type, name, size } = filtered[index]; - - return
-   - {getItemIcon(type, null)}
- {name} -
- - {formatFileSize(size)} - -
- } - } -
:
No data available
- }} - :
- } -
+ 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
+ } } + :
+ +
} +
+
+
+
+ +
+ { isWritable && + } +
{ rightData && !isLoading + ? {({ height, width }) => { + const filtered = rightData.filter(({ name }) => name.indexOf(rightSearch) > -1); + console.log("Right Data: ", filtered); + + return !!filtered.length + ? { ({ index, style }) => { + console.log("Right Data ROW: ", filtered[index]); + const { id, type, name, size } = filtered[index]; + + return
+   + {getItemIcon(type, null)} +
+ {name} +
+ + { formatFileSize(size) } + +
+ } }
+ :
This collection is empty
+ }}
+ :
+ +
}
- ); -})); +
}));