Skip to content

Commit

Permalink
Merge pull request #367 from fflaten/report-tag-filter
Browse files Browse the repository at this point in the history
Add tag filter to HTML report
  • Loading branch information
f-bader authored Jul 21, 2024
2 parents 10097b2 + 9c28919 commit bfc8018
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
38 changes: 32 additions & 6 deletions powershell/assets/ReportTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -58000,22 +58000,33 @@
function TestResultsTable(props) {
const [selectedStatus, setSelectedStatus] = reactExports.useState(["Passed", "Failed", "Skipped"]);
const [selectedBlock, setSelectedBlock] = reactExports.useState([]);
const [selectedTag, setSelectedTag] = reactExports.useState([]);
const testResults2 = props.TestResults;
const isStatusSelected = (item) => {
return (selectedStatus.includes(item.Result) || selectedStatus.length === 0) && (selectedBlock.includes(item.Block) || selectedBlock.length === 0);
return (selectedStatus.length === 0 || selectedStatus.includes(item.Result)) && (selectedBlock.length === 0 || selectedBlock.includes(item.Block)) && (selectedTag.length === 0 || item.Tag.some((tag) => selectedTag.includes(tag)));
};
const status = ["Passed", "Failed", "NotRun", "Skipped"];
const uniqueTags = [...new Set(testResults2.Tests.flatMap((t3) => t3.Tag))];
return /* @__PURE__ */ jsxRuntimeExports$1.jsxs(c$6, { children: [
/* @__PURE__ */ jsxRuntimeExports$1.jsxs(a$m, { justifyContent: "start", children: [
/* @__PURE__ */ jsxRuntimeExports$1.jsxs(a$m, { justifyContent: "start", className: "flex-wrap gap-2", children: [
/* @__PURE__ */ jsxRuntimeExports$1.jsx(
h$2,
{
onValueChange: setSelectedBlock,
placeholder: "Select category...",
className: "max-w-lg mr-6",
className: "max-w-lg",
children: testResults2.Blocks.sort((a4, b3) => a4.Name > b3.Name ? 1 : -1).map((item) => /* @__PURE__ */ jsxRuntimeExports$1.jsx(i$d, { value: item.Name, children: item.Name }, item.Name))
}
),
/* @__PURE__ */ jsxRuntimeExports$1.jsx(
h$2,
{
onValueChange: setSelectedTag,
placeholder: "Select tag...",
className: "max-w-fit",
children: uniqueTags.sort((a4, b3) => a4 > b3 ? 1 : -1).map((tag) => /* @__PURE__ */ jsxRuntimeExports$1.jsx(i$d, { value: tag, children: tag }, tag))
}
),
/* @__PURE__ */ jsxRuntimeExports$1.jsx(
h$2,
{
Expand Down Expand Up @@ -58807,6 +58818,21 @@
"ErrorRecord": [],
"Block": "App Management Policies",
"ResultDetail": null
},
{
"Name": "MT.1003: App management restrictions on applications and service principals is configured and enabled.",
"HelpUrl": "https://maester.dev/docs/tests/MT.1002",
"Tag": [
"App",
"Security",
"Some"
],
"Result": "Passed",
"ScriptBlock": '\n Test-MtAppManagementPolicyEnabled | Should -Be $true -Because "an app policy for workload identities should be defined to enforce strong credentials instead of passwords and a maximum expiry period (e.g. credential should be renewed every six months)"\n ',
"ScriptBlockFile": "/Users/merill/GitHub/maester/tests/Maester/Entra/Test-AppManagementPolicies.Tests.ps1",
"ErrorRecord": [],
"Block": "App Management Policies",
"ResultDetail": null
}
],
"Blocks": [
Expand Down Expand Up @@ -59995,9 +60021,6 @@
.mr-5 {
margin-right: 1.25rem;
}
.mr-6 {
margin-right: 1.5rem;
}
.mr-8 {
margin-right: 2rem;
}
Expand Down Expand Up @@ -60382,6 +60405,9 @@
.gap-12 {
gap: 3rem;
}
.gap-2 {
gap: 0.5rem;
}
.gap-3 {
gap: 0.75rem;
}
Expand Down
23 changes: 20 additions & 3 deletions report/src/components/TestResultsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ import StatusLabel from "./StatusLabel";
export default function TestResultsTable(props) {
const [selectedStatus, setSelectedStatus] = useState(['Passed', 'Failed', 'Skipped']);
const [selectedBlock, setSelectedBlock] = useState([]);
const [selectedTag, setSelectedTag] = useState([]);
const testResults = props.TestResults;

const isStatusSelected = (item) => {
return (selectedStatus.includes(item.Result) || selectedStatus.length === 0) && (selectedBlock.includes(item.Block) || selectedBlock.length === 0);
return (selectedStatus.length === 0 || selectedStatus.includes(item.Result)) &&
(selectedBlock.length === 0 || selectedBlock.includes(item.Block)) &&
(selectedTag.length === 0 || item.Tag.some(tag => selectedTag.includes(tag)));
}

const status = ['Passed', 'Failed', 'NotRun', 'Skipped'];
const uniqueTags = [...new Set(testResults.Tests.flatMap((t) => t.Tag))];

return (
<Card>
<Flex justifyContent="start">
<Flex justifyContent="start" className="flex-wrap gap-2">
<MultiSelect
onValueChange={setSelectedBlock}
placeholder="Select category..."
className="max-w-lg mr-6"
className="max-w-lg"
>
{testResults.Blocks
.sort((a, b) => a.Name > b.Name ? 1 : -1)
Expand All @@ -31,6 +35,19 @@ export default function TestResultsTable(props) {
</MultiSelectItem>
))}
</MultiSelect>
<MultiSelect
onValueChange={setSelectedTag}
placeholder="Select tag..."
className="max-w-fit"
>
{uniqueTags
.sort((a, b) => a > b ? 1 : -1)
.map((tag) => (
<MultiSelectItem key={tag} value={tag}>
{tag}
</MultiSelectItem>
))}
</MultiSelect>
<MultiSelect
defaultValue={['Passed', 'Failed', 'Skipped']}
onValueChange={setSelectedStatus}
Expand Down

0 comments on commit bfc8018

Please sign in to comment.