-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohamed Abokammer <mahmednabil109@gmail.com>
- Loading branch information
1 parent
8e681c5
commit ac21969
Showing
11 changed files
with
4,033 additions
and
3,778 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
const ( | ||
INT = "int" | ||
UINT = "uint" | ||
STRING = "string" | ||
TIME = "time" | ||
ENUM = "enum" | ||
) | ||
|
||
type FieldMetaData struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Values []string `json:"values"` | ||
} | ||
|
||
type Description []FieldMetaData | ||
|
||
/* | ||
DescribeEntity returns a Description for some entity fields | ||
to help frontend renders appropiate filters and tables. | ||
it depends on the tags assigned to the entity fields to create the needed metadata. | ||
it expects tags: filter, values | ||
*/ | ||
func DescribeEntity(entity interface{}) (Description, error) { | ||
var describtion Description | ||
t := reflect.TypeOf(entity) | ||
|
||
for i := 0; i < t.NumField(); i++ { | ||
sf := t.Field(i) | ||
if sf.Anonymous { | ||
return nil, fmt.Errorf("Error Anonymous Field") | ||
} | ||
|
||
name := sf.Tag.Get("json") | ||
tagValue := sf.Tag.Get("filter") | ||
var values []string | ||
if tagValue == ENUM { | ||
values = strings.Split(sf.Tag.Get("values"), ",") | ||
} | ||
describtion = append(describtion, FieldMetaData{ | ||
Name: name, | ||
Type: tagValue, | ||
Values: values, | ||
}) | ||
} | ||
|
||
return describtion, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
import superagent from 'superagent'; | ||
|
||
// TODO: remove the hardcoded levels | ||
// logLevels is the possible levels for logs | ||
export const Levels = ['panic', 'fatal', 'error', 'warning', 'info', 'debug']; | ||
|
||
// Log defines the expected log entry returned from the api | ||
export interface Log { | ||
job_id: number; | ||
log_data: string; | ||
log_level: string; | ||
date: string; | ||
} | ||
|
||
// Query defines all the possible filters to form a query | ||
export interface Query { | ||
job_id?: number; | ||
text?: string; | ||
log_level?: string; | ||
start_date?: string; | ||
end_date?: string; | ||
page: number; | ||
page_size: number; | ||
} | ||
|
||
// Result defines the structure of the api response to a query | ||
export interface Result { | ||
logs: Log[] | null; | ||
logs: any; | ||
count: number; | ||
page: number; | ||
page_size: number; | ||
} | ||
|
||
// getLogs returns Result that contains logs fetched according to the Query | ||
export async function getLogs(query: Query): Promise<Result> { | ||
export async function getLogs(query: any): Promise<Result> { | ||
let result: superagent.Response = await superagent.get('/log').query(query); | ||
|
||
return result.body; | ||
} | ||
|
||
export enum FieldType { | ||
INT = 'int', | ||
UINT = 'uint', | ||
STRING = 'string', | ||
TIME = 'time', | ||
ENUM = 'enum', | ||
} | ||
|
||
export interface FieldMetaData { | ||
name: string; | ||
type: string; | ||
values: string[]; | ||
} | ||
|
||
export async function getLogDescription(): Promise<FieldMetaData[]> { | ||
let result: superagent.Response = await superagent.get('/log-description'); | ||
|
||
return result.body; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
cmds/admin_server/ui/src/search_logs/log_table/render_columns.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { FieldMetaData, FieldType } from '../../api/logs'; | ||
import { Column, Cell, HeaderCell } from 'rsuite-table'; | ||
import DateCell from './date_cell/date_cell'; | ||
|
||
export function renderColumn(field: FieldMetaData, key: any) { | ||
switch (field.type) { | ||
case FieldType.INT: | ||
case FieldType.UINT: | ||
case FieldType.ENUM: | ||
return ( | ||
<Column width={80} align="center" fixed key={key}> | ||
<HeaderCell>{field.name}</HeaderCell> | ||
<Cell className="log-table__cell" dataKey={field.name} /> | ||
</Column> | ||
); | ||
case FieldType.STRING: | ||
return ( | ||
<Column width={600} align="left" flexGrow={1} key={key}> | ||
<HeaderCell>{field.name}</HeaderCell> | ||
<Cell className="log-table__cell" dataKey={field.name} /> | ||
</Column> | ||
); | ||
case FieldType.TIME: | ||
return ( | ||
<Column width={250} align="center" fixed key={key}> | ||
<HeaderCell>{field.name}</HeaderCell> | ||
<DateCell | ||
className="log-table__cell" | ||
dataKey={field.name} | ||
/> | ||
</Column> | ||
); | ||
} | ||
} |
Oops, something went wrong.