All files / src/components/pages/filesytem FilesBreadcrumb.tsx

66.67% Statements 4/6
100% Branches 0/0
60% Functions 3/5
66.67% Lines 4/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                      2x 2x                     6x   3x                                                      
import React, { ReactElement } from "react";
import { Breadcrumb } from "react-bootstrap";
import { Link } from "react-router-dom";
import { filesBaseUrl } from "./Filesystem";
 
type Props = {
  path: string;
  setPath: Function;
};
 
export function FilesBreadcrumb(props: Props): ReactElement {
  console.log("[FilesBreadcrumb]: " + props.path);
  return (
    <Breadcrumb>
      <Link
        className={"breadcrumb-item active"}
        to={filesBaseUrl}
        onClick={() => props.setPath("/")}
      >
        Home{" "}
      </Link>
      {props.path
        .split("/")
        .filter((s: string) => s)
        .map((folder: string, i: number) => {
          return (
            <Link
              className={"breadcrumb-item active"}
              to={
                filesBaseUrl +
                props.path
                  .split("/")
                  .slice(0, i + 2)
                  .join("/")
              }
              onClick={() =>
                props.setPath(
                  props.path
                    .split("/")
                    .slice(0, i + 2)
                    .join("/")
                )
              }
              key={i}
            >
              {folder}{" "}
            </Link>
          );
        })}
    </Breadcrumb>
  );
}