/* * Copyright 2020 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React, { useCallback, useEffect, useMemo, useRef, } from "react"; import { Icons, Stub, Table, TableElements, Cells, useQueryParams, } from "@drill4j/ui-kit"; import { Link } from "react-router-dom"; import { FilterList } from "@drill4j/types-admin/dist"; import { keyframes, css } from "styled-components"; import { useExpanded, useTable } from "react-table"; import { styled } from "twin.macro"; import { ClassCoverage } from "types/class-coverage"; import { useFilteredData } from "hooks"; import { Package } from "types/package"; import { getModalPath } from "common"; import { NameCell } from "./name-cell"; interface Props { topic: string; classesTopicPrefix: string; } export const MethodsTable = ({ classesTopicPrefix, topic, }: Props) => { const { methodOwnerClass = "", methodName = "", methodDesc = "" } = useQueryParams<{ methodOwnerClass?: string; methodName?: string; methodDesc?: string; }>(); const ownerClassPath = methodOwnerClass.slice(0, methodOwnerClass.lastIndexOf("/")); const { items: coverageByPackages = [], } = useFilteredData>(topic, { output: "LIST" }) || {}; const columns = [ { Header: () => null, id: "expander", Cell: ({ row }: any) => ( {row.isExpanded ? : } ), SubCell: ({ row }: any) => (row.canExpand ? ( {row.isExpanded ? ( ) : ( )} ) : null), notSortable: true, width: "32px", }, { Header: "Name", accessor: "name", filterable: true, isCustomCell: true, Cell: ({ value = "", state }: any) => ( } value={ filter.value)} />} testContext="package" title={value} /> ), SubCell: ({ value = "", row }: any) => { const ref = useRef(null); useEffect(() => { if (value === methodName) { ref?.current?.scrollIntoView({ behavior: "smooth", block: "end", }); } }, []); return (row.canExpand ? (
} value={value} testContext="package" />
) : (
} />
)); }, textAlign: "left", width: "50%", }, { Header: "Coverage, %", accessor: "coverage", Cell: ({ value = 0 }: { value: number }) => , width: "175px", sortType: "number", textAlign: "left", }, { Header: "Methods total", accessor: "totalMethodsCount", width: "175px", sortType: "number", }, { Header: "Methods covered", accessor: "coveredMethodsCount", width: "175px", sortType: "number", }, { Header: "Associated tests", accessor: "assocTestsCount", Cell: ({ value = "", row }: any) => ( {value ? ( {value} ) : ( "n/a" )} ), width: "175px", sortType: "number", }, ]; const ExpandedClasses = ({ parentRow }: any) => { const { classes = [] } = useFilteredData( `/${classesTopicPrefix}/coverage/packages/${parentRow.values.name}`, ) || {}; const defaultExpandedClass = classes.find(({ methods = [] }) => methods .find(({ name, desc }) => name === methodName && desc === methodDesc)); const strngifiedClasses = JSON.stringify(classes); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const { rows, prepareRow, toggleRowExpanded } = useTable( { columns: useMemo(() => columns as any, []), data: useMemo(() => classes, [strngifiedClasses]), getSubRows: (row) => row.methods || [], }, useExpanded, ); const defaultExpandedRow = rows.find((row) => row.original.id === defaultExpandedClass?.id); useEffect(() => { defaultExpandedRow?.id && toggleRowExpanded(defaultExpandedRow.id); }, [strngifiedClasses]); return ( <> {rows.map((row: any) => { prepareRow(row); const rowProps = row.getRowProps(); return ( {row.cells.map((cell: any) => ( {cell.render(cell.column.SubCell ? "SubCell" : "Cell")} ))} ); })} ); }; const renderRowSubComponent = useCallback( ({ row }) => , [], ); return (
original?.name === ownerClassPath} stub={( } title="No results found" message="Try adjusting your search or filter to find what you are looking for." /> )} renderHeader={({ currentCount, totalCount }: { currentCount: number, totalCount: number }) => (
Application Packages
{`Displaying ${currentCount} of ${totalCount} packages`}
)} /> ); }; const disappear = keyframes` 0%{ background-color: #fffbe5; } 75% { background-color: #fffbe5; } 100% { background-color: #ffffff; } `; const TableRow = styled(TableElements.TR)` ${({ isHighlighted }: {isHighlighted: boolean}) => isHighlighted && css`animation: ${disappear} 4s ease-in`}; `;