Skip to content

Commit bb5c9a3

Browse files
Manoj-KesanaCopilotmerill
authored
Sorting order Fix (#1089)
* Sorting * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Feedback Addressed * Feedback addressed * Update ReportTemplate.html --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: merill <merill@users.noreply.github.com>
1 parent 236ce09 commit bb5c9a3

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/powershell/assets/ReportTemplate.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/powershell/private/core/Get-ZtAssessmentResults.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ function Get-ZtAssessmentResults {
8181

8282
$mgContext = Get-MgContext
8383
$org = Get-Organization
84-
# Sort by risk then by status
85-
$tests = $script:__ZtSession.TestResultDetail.Value.values | Sort-Object -Property @{Expression = { $_.TestRisk } }, @{Expression = { $_.TestStatus } }
84+
$tests = $script:__ZtSession.TestResultDetail.Value.values
8685

8786
$ztTestResults = [PSCustomObject][ordered]@{
8887
ExecutedAt = Get-Date

src/report/src/components/test-table/columns.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Button } from "../ui/button"
55
import { impacts } from "./data-icons"
66
import { StatusIcon } from "../status-icon"
77

8+
const RISK_ORDER: Record<string, number> = { High: 0, Medium: 1, Low: 2 }
9+
const STATUS_ORDER: Record<string, number> = { Failed: 0, Passed: 1, Skipped: 2, Planned: 3 }
10+
811
export const columns: ColumnDef<Test>[] = [
912
{
1013
accessorKey: "TestId",
@@ -190,6 +193,11 @@ export const columns: ColumnDef<Test>[] = [
190193
{
191194
accessorKey: "TestRisk",
192195
meta: { label: "Risk" },
196+
sortingFn: (rowA, rowB, columnId) => {
197+
const a = RISK_ORDER[rowA.getValue(columnId) as string] ?? 3
198+
const b = RISK_ORDER[rowB.getValue(columnId) as string] ?? 3
199+
return a - b
200+
},
193201
header: ({ column }) => {
194202
return (
195203
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}>
@@ -220,6 +228,11 @@ export const columns: ColumnDef<Test>[] = [
220228
{
221229
accessorKey: "TestStatus",
222230
meta: { label: "Status" },
231+
sortingFn: (rowA, rowB, columnId) => {
232+
const a = STATUS_ORDER[rowA.getValue(columnId) as string] ?? 3
233+
const b = STATUS_ORDER[rowB.getValue(columnId) as string] ?? 3
234+
return a - b
235+
},
223236
header: ({ column }) => {
224237
return (
225238
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}>

src/report/src/components/test-table/data-table.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,10 @@ export function DataTable<TData extends Test, TValue>({
5555
data,
5656
pillar,
5757
}: DataTableProps<TData, TValue>) {
58-
const [sorting, setSorting] = React.useState<SortingState>(
59-
pillar === "Devices"
60-
? [
61-
{ id: "TestCategory", desc: false },
62-
{ id: "TestStatus", desc: false },
63-
{ id: "TestTitle", desc: false }
64-
]
65-
: []
66-
)
58+
const [sorting, setSorting] = React.useState<SortingState>([
59+
{ id: "TestRisk", desc: false },
60+
{ id: "TestStatus", desc: false },
61+
])
6762
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
6863
const [globalFilter, setGlobalFilter] = React.useState("");
6964
const [selectedSfiPillars, setSelectedSfiPillars] = React.useState<string[]>([]);

0 commit comments

Comments
 (0)