Skip to content

Commit

Permalink
Merge pull request #186 from Lyt99/feature/sort-history
Browse files Browse the repository at this point in the history
feature(webui): sort diagnosis & packet capturing histories
  • Loading branch information
BSWANG committed Feb 6, 2024
2 parents 5b2a84d + ea73199 commit e85b954
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/service/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *controller) DiagnoseList(_ context.Context) ([]DiagnoseTaskResult, erro
}

slices.SortFunc(taskSlice, func(a, b DiagnoseTaskResult) bool {
return a.TaskID < b.TaskID
return a.TaskID > b.TaskID
})
return taskSlice, nil
}
Expand Down
35 changes: 18 additions & 17 deletions webui/src/pages/capture/components/captureResult/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {Table} from '@alifd/next';
import {CaptureResult} from "@/services/capture";
import {requestConfig} from "@/app";
import { Table } from '@alifd/next';
import { CaptureResult } from "@/services/capture";
import { requestConfig } from "@/app";


const convertToTable = (res)=> {
const convertToTable = (res) => {
return res.map((i: CaptureResult[]) => {
return {
capture_id: i[0].task_id,
capture_names: i.map((capture) => capture.spec.task_type+": "+capture.spec.name).join(", "),
capture_results: i
}
})
return {
capture_id: i[0].task_id,
capture_names: i.map((capture) => capture.spec.task_type + ": " + capture.spec.name).join(", "),
capture_results: i
}
})
}

interface CaptureTableProps {
Expand All @@ -19,19 +19,20 @@ interface CaptureTableProps {

const CaptureHistory: React.FunctionComponent<CaptureTableProps> = (props: CaptureTableProps) => {
const render = (value, index, record) => {
if (record.capture_results.reduce((prev, item)=> {
return prev && item.status==="success"},true)) {
return <a href={requestConfig.baseURL+"/controller/capture/"+record.capture_id+"/download"} target="_blank">Download</a>;
} else if (record.capture_results.reduce((prev, item)=>{return prev || item.status==="running"}, false)) {
return <span style={{color: "green"}}>Running</span>;
if (record.capture_results.reduce((prev, item) => {
return prev && item.status === "success"
}, true)) {
return <a href={requestConfig.baseURL + "/controller/capture/" + record.capture_id + "/download"} target="_blank">Download</a>;
} else if (record.capture_results.reduce((prev, item) => { return prev || item.status === "running" }, false)) {
return <span style={{ color: "green" }}>Running</span>;
} else {
return <div style={{color: "red"}}>Failed {record.capture_results.map(item => item.message).join(",")}</div>
return <div style={{ color: "red" }}>Failed {record.capture_results.map(item => item.message).join(",")}</div>
}
};
return (
<div>
<Table
dataSource={convertToTable(props.captureResult.filter((i)=>i!=null))}
dataSource={convertToTable(props.captureResult.filter((i) => i != null))}
>
<Table.Column title="Id" dataIndex="capture_id" sortable />
<Table.Column title="CaptureObjects" dataIndex="capture_names" />
Expand Down
6 changes: 3 additions & 3 deletions webui/src/pages/capture/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const submitCapture = (props, callback) => {
}

export default function Capture() {
const [captureList, setCaptureList] = useState([])
const [captureList, setCaptureList] = useState<any[]>([])
const [abortController, setAbortController] = useState<AbortController | null>(null);
const [refreshCount, setRefreshCount] = useState(0);
const refreshCaptureList = () => {
Expand All @@ -40,9 +40,9 @@ export default function Capture() {
captureService.listCaptures(signal)
.then(res => {
if (res == null) {
res = []
res = {}
}
setCaptureList(Object.values(res))
setCaptureList(Object.values(res).toSorted((a, b) => b[0]?.task_id - a[0]?.task_id))
})
.catch(err => {
Message.error(`Error when fetching diagnosis: ${getErrorMessage(err)}`)
Expand Down
6 changes: 5 additions & 1 deletion webui/src/services/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface CaptureResult {
message: string
}

export interface Captures {
[key: number]: CaptureResult[]
}

export default {
async createCapture(task: CaptureTask): Promise<string> {
return await request({
Expand All @@ -22,7 +26,7 @@ export default {
data: task,
});
},
async listCaptures(signal?: AbortSignal): Promise<string> {
async listCaptures(signal?: AbortSignal): Promise<Captures> {
return await request({
url: '/controller/captures',
method: 'GET',
Expand Down

0 comments on commit e85b954

Please sign in to comment.