From ad7a53d72884ce1a76b4fc2c6745d7425dae5deb Mon Sep 17 00:00:00 2001 From: julia-zielke Date: Tue, 9 Jan 2024 12:19:55 +0100 Subject: [PATCH] Version 2 - only two cases: emptyDirectory or pathNotFound Signed-off-by: julia-zielke --- public/locales/en/translation.json | 3 - src/componentsNext/FilePicker/index.tsx | 259 ++++++++++-------------- src/design/Filepicker/index.tsx | 20 +- 3 files changed, 113 insertions(+), 169 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 74a1921b4..a69f34e0d 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -1241,9 +1241,6 @@ "filepicker": { "buttonText": "Browse Files", "placeholder": "No File selected", - "emptyNamespace": { - "title": "The namespace \"{{namespace}}\" is empty." - }, "emptyDirectory": { "title": "The directory \"{{path}}\" is empty." }, diff --git a/src/componentsNext/FilePicker/index.tsx b/src/componentsNext/FilePicker/index.tsx index 0525884ca..60b97c3d8 100644 --- a/src/componentsNext/FilePicker/index.tsx +++ b/src/componentsNext/FilePicker/index.tsx @@ -41,171 +41,134 @@ const FilePicker = ({ path, namespace, }); - //const isError = true; const { t } = useTranslation(); const { parent, isRoot, segments } = analyzePath(path); const results = data?.children?.results ?? []; - const noResults = data?.children?.results.length ? false : true; - const scrollableLength = - data?.children == undefined || data.children.results.length < 8 - ? false - : true; - - namespace = namespace || data?.namespace; - - const emptyNamespace = isRoot && noResults; - const emptyDirectory = !isRoot && !isError && noResults; - - console.log("data " + data); - console.log("isRoot " + isRoot); + const emptyDirectory = !isError && noResults; + const pathNotFound = isError; + const folderUpButton = !isRoot && data && !isError; return ( - {emptyNamespace ? ( - { - setPath(convertFileToPath(inputValue)); - }} - className="w-44" - > - -
- {t("components.filepicker.emptyNamespace.title", { namespace })} + { + setPath(convertFileToPath(inputValue)); + }} + className="w-44" + > + + + { + setPath("/"); + }} + className="h-5 hover:underline" + > + + + {segments.map((file) => { + const isEmpty = file.absolute === ""; + + if (isEmpty) return null; + return ( + { + setPath(file.absolute); + }} + className="h-5 hover:underline" + > + {file.relative} + + ); + })} + + + + {folderUpButton && ( + <> +
{ + parent ? setPath(parent.absolute) : null; + }} + className="h-auto w-full cursor-pointer p-0 font-normal text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" + > + ..
- -
- ) : ( - { - setPath(convertFileToPath(inputValue)); - }} - className="w-44" - > - - - { - setPath("/"); - }} - className="h-5 hover:underline" - > - - - {segments.map((file) => { - const isEmpty = file.absolute === ""; - - if (isEmpty) return null; - return ( - + + )} + {emptyDirectory && ( + + {t("components.filepicker.emptyDirectory.title", { path })} + + )} + {pathNotFound && ( + <> +
{ + setPath("/"); + }} + className="h-auto w-full cursor-pointer p-0 font-normal text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" + > + + {t("components.filepicker.error.linkText")} + +
+ + + {t("components.filepicker.error.title", { path })} + + + )} + + {results.map((file) => { + const isSelectable = selectable?.(file) ?? true; + return ( + + {file.type === "directory" ? ( +
{ - setPath(file.absolute); + setPath(file.path); }} - className="h-5 hover:underline" + className="h-auto w-full cursor-pointer text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" > - {file.relative} - - ); - })} - - - - -
- {!isRoot && data && ( - <> -
{ - parent ? setPath(parent.absolute) : null; - }} - className="h-auto w-full cursor-pointer p-0 font-normal text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" - > - .. -
- - - )} - {isError ? ( - <> -
{ - setPath("/"); - }} - className="h-auto w-full cursor-pointer p-0 font-normal text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" - > - - {t("components.filepicker.error.linkText")} - -
- - {t("components.filepicker.error.title", { path })} - - - ) : ( -
- {emptyDirectory ? ( - - {t("components.filepicker.emptyDirectory.title", { path })} - + + {file.name} + +
) : ( - - {results.map((file) => { - const isSelectable = selectable?.(file) ?? true; - return ( - - {file.type === "directory" ? ( -
{ - setPath(file.path); - }} - className="h-auto w-full cursor-pointer text-gray-11 hover:underline focus:bg-transparent focus:ring-0 focus:ring-transparent focus:ring-offset-0 dark:text-gray-dark-11 dark:focus:bg-transparent" - > - - {file.name} - -
- ) : ( - { - setPath(file.parent); - setInputValue(file.path); - onChange?.(file.path); - }} - > - - {file.name} - - - )} - - -
- ); - })} -
+ { + setPath(file.parent); + setInputValue(file.path); + onChange?.(file.path); + }} + > + + {file.name} + + )} -
- )} -
-
- )} + + + + ); + })} + + = ({ children }) => (
); -const Content: FC = ({ children }) => ( -
{children}
-); - -const ScrollableContent: FC = ({ children }) => ( -
+const FilepickerList: FC = ({ children }) => ( +
{children}
); -export type FilepickerListProps = PropsWithChildren & { - scrollableLength: boolean; -}; - -const FilepickerList: FC = ({ - children, - scrollableLength, -}) => { - const Comp = scrollableLength ? ScrollableContent : Content; - return {children}; -}; - // asChild only works with exactly one child, so when asChild is true, we can not have a loading property type AsChildOrLoading = | {