Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 101 additions & 98 deletions src/components/SMI-Table/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useId, useState } from "react";
import { useTable } from "react-table";
import { IoMdHelpCircle } from "@react-icons/all-files/io/IoMdHelpCircle";
import { IconContext } from "@react-icons/all-files";
Expand All @@ -12,12 +12,105 @@ import passingMark from "../../assets/images/landscape/passing.svg";
import failingMark from "../../assets/images/landscape/failing.svg";
import ServiceMeshIcon from "../../assets/images/service-mesh-icons/service-mesh.svg";

const getRowId = (row) => `${row.original.mesh_name}-${row.original.mesh_version}`;

// const halfMark = "../../assets/images/landscape/half.svg";
// const passingMark = "../../assets/images/landscape/passing.svg";
// const failingMark = "../../assets/images/landscape/failing.svg";
// const ServiceMeshIcon = "../../assets/images/service-mesh-icons/service-mesh.svg";

const TableRow = React.memo(({ row, tooltipId }) => {
const [isCollapsed, setIsCollapsed] = useState(false);
const meshMatch = non_functional.find((ele) => ele.name.includes(row.original.mesh_name));
const rowId = getRowId(row);

return (
<React.Fragment key={rowId}>
<tr
id={`row-${rowId}`}
className="primaryRow"
{...row.getRowProps()}
onClick={() => setIsCollapsed((prevState) => !prevState)}
>
<td>
{
meshMatch ?
<img data-tooltip-id={tooltipId} data-tooltip-content={row.original.mesh_name} className="smiMark" src={meshMatch.icon} alt="Mesh Icon" />
: <img data-tooltip-id={tooltipId} data-tooltip-content={"Service Mesh"} className="smiMark" src={ServiceMeshIcon} alt="Service Mesh" />
}
</td>
<td>{row.original.mesh_version}</td>
{row.original.more_details.map((spec, index) => {
if (spec["capability"] === "FULL") {
return <td key={`spec${index}`}>
<div className="tooltip-div" data-tooltip-id={tooltipId} data-tooltip-content={`${spec["result"]}`}>
<img className="smiMark" src={passingMark} alt="Pass Mark" />
</div>
</td>;
} else if (spec["capability"] === "HALF") {
return <td key={`spec${index}`}>
<div className="tooltip-div" data-tooltip-id={tooltipId} data-tooltip-content={`${spec["reason"]}<br>${spec["result"]}`}>
<img className="smiMark" src={halfMark} alt="Half Mark" />
</div>
</td>;
} else if (spec["capability"] === "NONE") {
return <td key={`spec${index}`}>
<div className="tooltip-div" data-tooltip-id={tooltipId} data-tooltip-content={`${spec["reason"]}<br>${spec["result"]}`}>
<img className="smiMark" src={failingMark} alt="Fail Mark" />
</div>
</td>;
} else {
return <td key={`spec${index}`}>
<IconContext.Provider value={{ color: "gray", size: "20px" }}>
<IoMdHelpCircle />
</IconContext.Provider>
</td>;
}
})
}
<td>{row.original.passing_percentage}</td>
</tr>

{
row.original.previous_versions && row.original.previous_versions.map((prevResult, index) => {
return (
<tr key={`collapse-row-${rowId}-${prevResult.mesh_version}-${index}`} className={isCollapsed ? "secondaryRow" : "secondaryRow-hidden"} >
<td></td>
<td>{prevResult.mesh_version}</td>
{prevResult.more_details.map((spec, prevIndex) => {
if (spec["capability"] === "Full") {
return <td key={`spec${prevIndex}`}>
<img className="smiMark" src={passingMark} alt="Passing Mark" />
</td>;
} else if (spec["capability"] === "None") {
return <td key={`spec${prevIndex}`}>
<img className="smiMark" src={failingMark} alt="Fail Mark" />
</td>;
} else if (spec["capability"] === "Half") {
return <td key={`spec${prevIndex}`}>
<img className="smiMark" src={halfMark} alt="Half Mark" />
</td>;
} else {
return <td key={`spec${prevIndex}`}>
<IconContext.Provider value={{ color: "gray", size: "20px" }}>
<IoMdHelpCircle />
</IconContext.Provider>
</td>;
}
})}
<td>{prevResult.passing_percentage}</td>
</tr>
);
})
}
</React.Fragment>
);
});

const Table = ({ columns, data, spec }) => {
const reactId = useId();
const tooltipId = `smi-table-tooltip-${reactId.replace(/:/g, "")}`;

// Use the state and functions returned from useTable to build the UI
const {
getTableProps,
Expand All @@ -31,7 +124,6 @@ const Table = ({ columns, data, spec }) => {
});

// Render the UI for the table
const [isCollapsed, setCollapse] = useState(new Array(rows.length).fill(false));
return (
<TableWrapper>
<table {...getTableProps()}>
Expand All @@ -52,105 +144,16 @@ const Table = ({ columns, data, spec }) => {
<tbody {...getTableBodyProps()}>
{rows.map((row, i) => {
prepareRow(row);
return (
<React.Fragment key={`row${i}`}>
<tr key={`row${i}`} id={`row${i}`} className="primaryRow" {...row.getRowProps()} onClick={() => {
let e = isCollapsed; e[i] = !isCollapsed[i]; setCollapse([...e]);
}}
>
<td>
{
(non_functional.find(ele => ele.name.includes(row.original.mesh_name))) ?
<>
<img data-tooltip-id="react-tooltip" data-tooltip-content={row.original.mesh_name} className="smiMark" src={non_functional.find(ele => ele.name.includes(row.original.mesh_name)).icon} alt="Mesh Icon" />
<Tooltip
id="react-tooltip"
place="bottom"
style={{ backgroundColor: "rgb(60,73,79)" }}
className="smi-tooltip"
/>
</>
: <>
<img data-tooltip-id="react-tooltip" data-tooltip-content={"Service Mesh"} className="smiMark" src={ServiceMeshIcon} alt="Service Mesh" />
<Tooltip
id="react-tooltip"
place="bottom"
style={{ backgroundColor: "rgb(60,73,79)" }}
className="smi-tooltip"
/>
</>
}
</td>
<td>{row.original.mesh_version}</td>
{row.original.more_details.map((spec,i) => {
if (spec["capability"] === "FULL"){
return <td key={`spec${i}`}>
<div className="tooltip-div" data-tooltip-id="react-tooltip" data-tooltip-content={`${spec["result"]}`}>
<img className="smiMark" src={passingMark} alt="Pass Mark" />
</div>
</td>;
} else if (spec["capability"] === "HALF"){
return <td key={`spec${i}`}>
<div className="tooltip-div" data-tooltip-id="react-tooltip" data-tooltip-content={`${spec["reason"]}<br>${spec["result"]}`}>
<img className="smiMark" src={halfMark} alt="Half Mark" />
</div>
</td>;
} else if (spec["capability"] === "NONE") {
return <td key={`spec${i}`}>
<div className="tooltip-div" data-tooltip-id="react-tooltip" data-tooltip-content={`${spec["reason"]}<br>${spec["result"]}`}>
<img className="smiMark" src={failingMark} alt="Fail Mark" />
</div>
</td>;
} else {
return <td key={`spec${i}`}>
<IconContext.Provider value={{ color: "gray", size: "20px" }}>
<IoMdHelpCircle />
</IconContext.Provider>
</td>;
}
})
}
<td>{row.original.passing_percentage}</td>
</tr>

{
row.original.previous_versions && row.original.previous_versions.map(prevResult => {
return (
<tr key={`collapse-row${i}`} className={isCollapsed[i] ? "secondaryRow" : "secondaryRow-hidden"} >
<td></td>
<td>{prevResult.mesh_version}</td>
{prevResult.more_details.map((spec,i) => {
if (spec["capability"] === "Full"){
return <td key={`spec${i}`}>
<img className="smiMark" src={passingMark} alt="Passing Mark" />
</td>;
} else if (spec["capability"] === "None"){
return <td key={`spec${i}`}>
<img className="smiMark" src={failingMark} alt="Fail Mark" />
</td>;
} else if (spec["capability"] === "Half"){
return <td key={`spec${i}`}>
<img className="smiMark" src={halfMark} alt="Half Mark" />
</td>;
} else {
return <td key={`spec${i}`}>
<IconContext.Provider value={{ color: "gray", size: "20px" }}>
<IoMdHelpCircle />
</IconContext.Provider>
</td>;
}
})}
<td>{prevResult.passing_percentage}</td>
</tr>
);
})
}

</React.Fragment>
);
return <TableRow key={getRowId(row)} row={row} tooltipId={tooltipId} />;
})}
</tbody>
</table>
<Tooltip
id={tooltipId}
place="bottom"
style={{ backgroundColor: "rgb(60,73,79)" }}
className="smi-tooltip"
/>
Comment thread
Manishnemade12 marked this conversation as resolved.
</TableWrapper>
);
};
Expand Down
Loading