expose Rule Count column in table

This commit is contained in:
Collin M. Barrett 2018-09-28 05:41:04 -05:00
parent bc8ced6be9
commit 1db169a2d2
4 changed files with 33 additions and 3 deletions

View file

@ -3,11 +3,12 @@ import { IColumnVisibility, ILanguage, IList, IMaintainer, ISoftware, ITag } fro
import { ListsTable, Oneliner } from "./components";
const columnVisibilityDefaults: IColumnVisibility[] = [
{ column: "Maintainers", visible: false },
{ column: "Software", visible: true },
{ column: "Tags", visible: true },
{ column: "Languages", visible: true },
{ column: "Maintainers", visible: false },
{ column: "Updated Date", visible: true }
{ column: "Updated Date", visible: true },
{ column: "Rule Count", visible: true }
];
interface IProps {

View file

@ -4,7 +4,7 @@ import "../../../../utils/loader.css";
import ReactTable from "react-table";
import "react-table/react-table.css";
import "./listsTable.css";
import { DetailsButton, Languages, Maintainers, Name, Software, Tags, UpdatedDate } from "./columns";
import { DetailsButton, Languages, Maintainers, Name, RuleCount, Software, Tags, UpdatedDate } from "./columns";
import { IListDetails } from "../../components/detailsExpander";
import { DetailsExpander } from "../../components";
@ -31,6 +31,7 @@ export const ListsTable = (props: IProps) =>
Tags(props.columnVisibility, props.tags),
Languages(props.columnVisibility, props.languages),
UpdatedDate(props.columnVisibility),
RuleCount(props.columnVisibility),
DetailsButton
]}
defaultSorted={[{ id: "name" }]}

View file

@ -0,0 +1,26 @@
import * as React from "react";
import { Column } from "react-table";
import { IColumnVisibility } from "../../../interfaces";
export const RuleCount = (columnVisibility: IColumnVisibility[]) =>
({
Header: "Rules",
accessor: "ruleCount",
sortMethod: (a: string, b: string) => sortMethod(a, b),
Cell: (c: any) => Cell(c.value),
style: { whiteSpace: "inherit" },
width: 80,
headerClassName: "d-none d-md-block",
className: "d-none d-md-block",
show: columnVisibility.filter((c: IColumnVisibility) => c.column === "Rule Count")[0].visible
} as Column);
const sortMethod = (a: string, b: string) =>
a > b
? 1
: -1;
const Cell = (ruleCount: number) =>
ruleCount
? <span>{ruleCount.toLocaleString() }</span>
: null;

View file

@ -2,6 +2,7 @@
import { Languages } from "./Languages";
import { Maintainers } from "./Maintainers";
import { Name } from "./Name";
import { RuleCount } from "./RuleCount";
import { Software } from "./Software";
import { Tags } from "./Tags";
import { UpdatedDate } from "./UpdatedDate";
@ -11,6 +12,7 @@ export {
Languages,
Maintainers,
Name,
RuleCount,
Software,
Tags,
UpdatedDate