From c4c1bd525a660118ecf3b53811cd112a992fdc81 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 9 May 2023 11:25:08 -0400 Subject: [PATCH] 20452: don't set path if currentItemUuid is not a collection Also fixes bug when clicking "refresh" on collection. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../collection-panel-files.tsx | 211 +++++++++--------- 1 file changed, 107 insertions(+), 104 deletions(-) diff --git a/src/components/collection-panel-files/collection-panel-files.tsx b/src/components/collection-panel-files/collection-panel-files.tsx index fb36ebce..b75f3018 100644 --- a/src/components/collection-panel-files/collection-panel-files.tsx +++ b/src/components/collection-panel-files/collection-panel-files.tsx @@ -39,6 +39,7 @@ import { setCollectionFiles } from 'store/collection-panel/collection-panel-file import { sortBy } from 'lodash'; import { formatFileSize } from 'common/formatters'; import { getInlineFileUrl, sanitizeToken } from 'views-components/context-menu/actions/helpers'; +import { extractUuidObjectType, ResourceObjectType } from 'models/resource'; export interface CollectionPanelFilesProps { isWritable: boolean; @@ -260,7 +261,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const rightData = pathData[rightKey]; React.useEffect(() => { - if (props.currentItemUuid) { + if (props.currentItemUuid && extractUuidObjectType(props.currentItemUuid) == ResourceObjectType.COLLECTION) { setPathData({}); setPath([props.currentItemUuid]); } @@ -288,33 +289,33 @@ 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 }; - }, {}); - setPathData((state) => ({ ...state, ...newState })); - }) - .finally(() => { - setIsLoading(false); - keyArray.forEach(key => delete pathPromise[key]); - }); + .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 }; + }, {}); + setPathData((state) => ({ ...state, ...newState })); + }) + .finally(() => { + setIsLoading(false); + keyArray.forEach(key => delete pathPromise[key]); + }); }; React.useEffect(() => { @@ -323,7 +324,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState setLeftSearch(''); setRightSearch(''); } - }, [rightKey]); // eslint-disable-line react-hooks/exhaustive-deps + }, [rightKey, rightData]); // eslint-disable-line react-hooks/exhaustive-deps const currentPDH = (collectionPanel.item || {}).portableDataHash; React.useEffect(() => { @@ -420,7 +421,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState } if (elem.dataset.id && type === 'file') { - const item = rightData.find(({id}) => id === elem.dataset.id) || leftData.find(({ id }) => id === elem.dataset.id); + const item = rightData.find(({ id }) => id === elem.dataset.id) || leftData.find(({ id }) => id === elem.dataset.id); const enhancedItem = servicesProvider.getServices().collectionService.extendFileURL(item); const fileUrl = sanitizeToken(getInlineFileUrl(enhancedItem.url, config.keepWebServiceUrl, config.keepWebInlineServiceUrl), true); window.open(fileUrl, '_blank'); @@ -483,12 +484,12 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState return
- { path.map( (p: string, index: number) => - - {index === 0 ? 'Home' : p} /  - ) - } + {path.map((p: string, index: number) => + + {index === 0 ? 'Home' : p} /  + ) + }
1 ? classes.leftPanelVisible : classes.leftPanelHidden)} data-cy="collection-files-left-panel"> 1 ? classes.backButton : classes.backButtonHidden}> - setPath((state) => ([...state.slice(0, state.length -1)]))}> + setPath((state) => ([...state.slice(0, state.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
+
{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 && - } -
{ rightData && !isLoading + {isWritable && + } +
{rightData && !isLoading ? {({ 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} + ? {({ index, style }) => { + const { id, type, name, size } = filtered[index]; + + return
+   + {getItemIcon(type, null)} +
+ {name} +
+ + {formatFileSize(size)} + + + + + +
- - { formatFileSize(size) } - - - - - - -
- } } - :
This collection is empty
+ }} + :
This collection is empty
}} :
-
} +
}
-
})); +
+})); -- 2.30.2