All files / js/sidebar Alternatives.tsx

20% Statements 4/20
0% Branches 0/8
0% Functions 0/2
20% Lines 4/20

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 531x 1x         1x   1x                                                                                        
import React, { PureComponent } from "react";
import {
  getUrlRecordPath,
  pathToAdminPage,
  RecordProps,
} from "../components/RecordComponent";
import Link from "../components/Link";
import { Alternative } from "../components/types";
import { trans, trans_obj } from "../i18n";
 
type Props = Pick<RecordProps, "record" | "page"> & {
  recordAlts: Alternative[];
};
 
export default class Alternatives extends PureComponent<Props, unknown> {
  render() {
    const { recordAlts } = this.props;
    if (recordAlts.length < 2) {
      return null;
    }
 
    const items = recordAlts.map((item) => {
      let title = trans_obj(item.name_i18n);
      let className = "alt";
      if (item.is_primary) {
        title += " (" + trans("PRIMARY_ALT") + ")";
      } else if (item.primary_overlay) {
        title += " (" + trans("PRIMARY_OVERLAY") + ")";
      }
      if (!item.exists) {
        className += " alt-missing";
      }
 
      const path = pathToAdminPage(
        this.props.page,
        getUrlRecordPath(this.props.record.path, item.alt)
      );
      return (
        <li key={item.alt} className={className}>
          <Link to={path}>{title}</Link>
        </li>
      );
    });
 
    return (
      <div className="section">
        <h3>{trans("ALTS")}</h3>
        <ul className="nav">{items}</ul>
      </div>
    );
  }
}