Skip to content

Commit

Permalink
hide carrot dropdown for empty response
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-n committed Jul 24, 2023
1 parent 219959a commit 9896f19
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/components/dagshub/data-engine/file-tree/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const FileList = ({
}
if (!children?.length) {
if (emptyMessage) {
return <Box ml={2} p={1}>{emptyMessage}</Box>;
return (
<Box ml={2} p={1}>
{emptyMessage}
</Box>
);
}
// fallback
return <Box p={1}>This directory is empty</Box>;
Expand All @@ -47,7 +51,7 @@ export const FileList = ({
<Box>
{children?.map((child: FileListItemType) => (
<FileTreeItem
emptyMessage={emptyMessage}
emptyMessage={emptyMessage}
href={child?.href}
setSelected={setSelected}
getFilesCb={getFilesCb}
Expand Down
31 changes: 19 additions & 12 deletions src/components/dagshub/data-engine/file-tree/FileTreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export function FileTreeItem({
setSelected,
type,
href,
emptyMessage,
emptyMessage
}: FileItemInterface) {
const [open, setOpen] = useState(false);
const [isEmpty, setIsEmpty] = useState(false);
const [children, setChildren] = useState<FileListItemType[] | null>(null);
const [loading, setLoading] = useState(false);
const [cache, setCache] = useState<any>({});
Expand All @@ -43,6 +44,9 @@ export function FileTreeItem({
setLoading(true);
const res = await getFilesCb(id);
setChildren(res);
if (!res?.length) {
setIsEmpty(true);
}
const newCache = { ...cache };
newCache[id] = res;
setCache(newCache);
Expand Down Expand Up @@ -98,6 +102,7 @@ export function FileTreeItem({
onClick={openFileHandler}
disableRipple
sx={{
visibility: isEmpty ? 'hidden' : 'unset',
transition: '.1s ease-in-out',
transform: open ? 'rotate(90deg)' : 'unset',
'&:hover': {
Expand Down Expand Up @@ -135,18 +140,20 @@ export function FileTreeItem({
)}
</Box>

<Collapse sx={{ ml: 2 }} in={open}>
<Stack>
<FileList
{!isEmpty && (
<Collapse sx={{ ml: 2 }} in={open}>
<Stack>
<FileList
emptyMessage={emptyMessage}
children={children}
loading={loading}
setSelected={setSelected}
getFilesCb={getFilesCb}
selected={selected}
/>
</Stack>
</Collapse>
children={children}
loading={loading}
setSelected={setSelected}
getFilesCb={getFilesCb}
selected={selected}
/>
</Stack>
</Collapse>
)}
</Box>
);
}

0 comments on commit 9896f19

Please sign in to comment.