Code coverage report for js/sidebar/ChildActions.tsx

# All files / js/sidebar ChildActions.tsx

42.86% Statements 6/14
0% Branches 0/2
0% Functions 0/2
60% Lines 6/10

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
    54
    55
    56
    57
    581x
    1x
    1x

    1x

    1x
    1x

     import React from "react";
    import { trans, trans_obj } from "../i18n";
    import {
      getUrlRecordPath,
      RecordPathDetails,
    } from "../components/RecordComponent";
    import Link from "../components/Link";
    import { RecordChild } from "../components/types";
    import ChildPagination from "./ChildPagination";
    import { CHILDREN_PER_PAGE } from "./constants";

    export default function ChildActions({
      target,
      allChildren,
      record,
      page,
      setPage,
    }: {
      target: "preview" | "edit";
      allChildren: RecordChild[];
      record: RecordPathDetails;
      page: number;
      setPage: (n: number) => void;
    }): JSX.Element {
      const shownChildren = allChildren.slice(
        (page - 1) * CHILDREN_PER_PAGE,
        page * CHILDREN_PER_PAGE
      );

      return (
        <div key="children" className="section">
          <h3>{trans("CHILD_PAGES")}</h3>
          <ul className="nav record-children">
            <ChildPagination
              numberOfChildren={allChildren.length}
              page={page}
              setPage={setPage}
            />
            {shownChildren.length > 0 ? (
              shownChildren.map((child) => (
                <li key={child.id}>
                  <Link
                    to={`${getUrlRecordPath(child.path, record.alt)}/${target}`}
                  >
                    {trans_obj(child.label_i18n)}
                  </Link>
                </li>
              ))
            ) : (
              <li key="_missing">
                <em>{trans("NO_CHILD_PAGES")}</em>
              </li>
            )}
          </ul>
        </div>
      );
    }