-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter-tree: Use a table layout in filter tree
This allows to display many columns in the tree. Columns are sortable. Signed-off-by: Lea <lea.carlier@polymtl.ca> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
- Loading branch information
Showing
15 changed files
with
477 additions
and
138 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
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
12 changes: 9 additions & 3 deletions
12
viewer-prototype/src/browser/trace-viewer/components/utils/filtrer-tree/icons.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 |
---|---|---|
@@ -1,21 +1,27 @@ | ||
import * as React from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faChevronDown, faChevronRight, faCheckSquare, faSquare, faMinusSquare } from '@fortawesome/free-solid-svg-icons'; | ||
import { faChevronDown, faChevronRight, faCheckSquare, faSquare, faMinusSquare, faSort, faSortDown, faSortUp } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
interface iconsShape { | ||
expand: React.ReactNode, | ||
collapse: React.ReactNode, | ||
unchecked: React.ReactNode, | ||
checked: React.ReactNode, | ||
halfChecked: React.ReactNode | ||
halfChecked: React.ReactNode, | ||
sort: React.ReactNode, | ||
sortDown: React.ReactNode, | ||
sortUp: React.ReactNode | ||
} | ||
|
||
const icons: iconsShape = { | ||
expand: <FontAwesomeIcon icon={faChevronRight}/>, | ||
collapse: <FontAwesomeIcon icon={faChevronDown}/>, | ||
unchecked: <FontAwesomeIcon icon={faSquare}/>, | ||
checked: <FontAwesomeIcon icon={faCheckSquare}/>, | ||
halfChecked: <FontAwesomeIcon icon={faMinusSquare}/> | ||
halfChecked: <FontAwesomeIcon icon={faMinusSquare}/>, | ||
sort: <FontAwesomeIcon icon={faSort}/>, | ||
sortDown: <FontAwesomeIcon icon={faSortDown}/>, | ||
sortUp: <FontAwesomeIcon icon={faSortUp}/> | ||
}; | ||
|
||
export default icons; |
70 changes: 70 additions & 0 deletions
70
viewer-prototype/src/browser/trace-viewer/components/utils/filtrer-tree/sort.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,70 @@ | ||
import icons from './icons'; | ||
import { TreeNode } from './tree-node'; | ||
|
||
interface SortState { | ||
asc: React.ReactNode, | ||
desc: React.ReactNode, | ||
default: React.ReactNode; | ||
} | ||
|
||
export const sortState: SortState = { | ||
asc: icons.sortUp, | ||
desc: icons.sortDown, | ||
default: icons.sort | ||
}; | ||
|
||
export interface SortConfig { | ||
column: string; | ||
sortState: React.ReactNode; | ||
} | ||
|
||
export const nextSortState = (currentState: React.ReactNode): React.ReactNode => { | ||
if (currentState === sortState.default || currentState === sortState.asc) { | ||
return sortState.desc; | ||
} else if (currentState === sortState.desc) { | ||
return sortState.asc; | ||
} else { | ||
return sortState.default; | ||
} | ||
}; | ||
|
||
export const sortNodes = (nodes: TreeNode[], sortConfig: SortConfig[]): TreeNode[] => { | ||
const sortedNodes = [...nodes]; | ||
const orderToSort = sortConfig.find((config: SortConfig) => config.sortState !== sortState.default); | ||
if (orderToSort) { | ||
sortedNodes.sort((node1: TreeNode, node2: TreeNode) => { | ||
const key = orderToSort.column; | ||
const order = (orderToSort.sortState === sortState.asc) ? 'asc' : 'desc'; | ||
const value1 = node1[key as keyof TreeNode]; | ||
const value2 = node2[key as keyof TreeNode]; | ||
let result = 0; | ||
if (!value1 && value2) { | ||
result = -1; | ||
} else if (value1 && !value2) { | ||
result = 1; | ||
} else if (!value1 && !value2) { | ||
result = 0; | ||
} else { | ||
if (typeof value1 === 'string' && typeof value2 === 'string') { | ||
const comp = value1.localeCompare(value2); | ||
result = (order === 'asc') ? -comp : comp; | ||
} else { | ||
if (value1 < value2) { | ||
result = (order === 'asc') ? -1 : 1; | ||
} else if (value1 > value2) { | ||
result = (order === 'asc') ? 1 : -1; | ||
} else { | ||
result = 0; | ||
} | ||
} | ||
} | ||
return result; | ||
}); | ||
sortedNodes.forEach((node: TreeNode) => { | ||
if (node.children.length) { | ||
node.children = sortNodes(node.children, sortConfig); | ||
} | ||
}); | ||
} | ||
return sortedNodes; | ||
}; |
39 changes: 39 additions & 0 deletions
39
viewer-prototype/src/browser/trace-viewer/components/utils/filtrer-tree/table-body.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,39 @@ | ||
import * as React from 'react'; | ||
import { TreeNode } from './tree-node'; | ||
import { TableRow } from './table-row'; | ||
|
||
interface TableBodyProps { | ||
nodes: TreeNode[]; | ||
keys: string[]; | ||
collapsedNodes: number[]; | ||
isCheckable: boolean; | ||
getCheckedStatus: (id: number) => number; | ||
onToggleCollapse: (id: number) => void; | ||
onToggleCheck: (id: number) => void; | ||
} | ||
|
||
export class TableBody extends React.Component<TableBodyProps> { | ||
constructor(props: TableBodyProps) { | ||
super(props); | ||
} | ||
|
||
createRow = (node: TreeNode): React.ReactNode => | ||
<TableRow | ||
{...this.props} | ||
key={'row-'+node.id} | ||
node={node} | ||
level={0} | ||
/>; | ||
|
||
renderRows = (): React.ReactNode => this.props.nodes.map((node: TreeNode) => this.createRow(node)); | ||
|
||
render(): React.ReactNode | undefined { | ||
if (!this.props.nodes) {return undefined;} | ||
|
||
return ( | ||
<tbody> | ||
{this.renderRows()} | ||
</tbody> | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
viewer-prototype/src/browser/trace-viewer/components/utils/filtrer-tree/table-cell.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,25 @@ | ||
import * as React from 'react'; | ||
import { TreeNode } from './tree-node'; | ||
|
||
interface TableCellProps { | ||
nodeKey: string; | ||
node: TreeNode; | ||
} | ||
|
||
export class TableCell extends React.Component<TableCellProps> { | ||
constructor(props: TableCellProps) { | ||
super(props); | ||
} | ||
|
||
render(): React.ReactNode { | ||
const content: React.ReactNode = (this.props.nodeKey !== 'Legend') | ||
? this.props.node[this.props.nodeKey as keyof TreeNode] | ||
: undefined; | ||
return ( | ||
<td key={this.props.nodeKey+'-'+this.props.node.id}> | ||
{this.props.children} | ||
{content} | ||
</td> | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
viewer-prototype/src/browser/trace-viewer/components/utils/filtrer-tree/table-header.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,46 @@ | ||
import * as React from 'react'; | ||
import { SortConfig } from './sort'; | ||
|
||
interface TableHeaderProps { | ||
columns: string[]; | ||
sortableColumns: string[]; | ||
sortConfig: SortConfig[]; | ||
onSort: (sortColumn: string) => void; | ||
} | ||
|
||
export class TableHeader extends React.Component<TableHeaderProps> { | ||
constructor(props: TableHeaderProps) { | ||
super(props); | ||
} | ||
|
||
handleSortChange = (sortColumn: string): void => { | ||
this.props.onSort(sortColumn); | ||
}; | ||
|
||
toCapitalCase = (name: string): string => (name.charAt(0).toUpperCase() + name.slice(1)); | ||
|
||
renderSortIcon = (column: string): React.ReactNode | undefined => { | ||
if (this.props.sortableColumns.includes(column)) { | ||
const state = this.props.sortConfig.find((config: SortConfig) => config.column === column); | ||
return state | ||
? <span style={{float: 'right'}}>{state.sortState}</span> | ||
: undefined; | ||
} | ||
return undefined; | ||
}; | ||
|
||
renderHeader = (): React.ReactNode => this.props.columns.map((column: string, index) => | ||
<th key={'th-'+index} onClick={() => this.handleSortChange(column)}> | ||
{this.toCapitalCase(column)} | ||
{this.renderSortIcon(column)} | ||
</th> | ||
); | ||
|
||
render(): React.ReactNode { | ||
return <thead> | ||
<tr> | ||
{this.renderHeader()} | ||
</tr> | ||
</thead>; | ||
} | ||
} |
Oops, something went wrong.