diff --git a/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx b/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx new file mode 100644 index 0000000..9a05af7 --- /dev/null +++ b/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx @@ -0,0 +1,69 @@ + +import * as React from 'react'; +import { + Table, +} from 'semantic-ui-react'; + + +export interface Props { + columnList?: string[]; + onHeaderColumnClick?(col:string, direction: string): void; +} + +export interface State { + column: string; + direction: 'ascending' | 'descending'; +} + + +export class SortTableHeaderRow extends React.Component { + + constructor(props: Props, context: State) { + super(props, context); + this.state = { + column: null, + direction: null, + }; + } + + public render(): JSX.Element { + return ( + + {this.renderCell()} + + ); + } + + private renderCell = (): (JSX.Element | JSX.Element[]) => { + let arr = []; + let idx:number = 0; + + for (let colValue of this.props.columnList) { + + arr.push( + {colValue}); + } + + return arr; + } + + private handleColumnSort = (col:string) => ():void => { + if (this.state.column !== col) { + this.setState({ + column: col, + direction: 'ascending', + }); + } else { + this.setState({ + direction: this.state.direction === 'ascending' ? 'descending' : 'ascending', + }); + } + + this.props.onHeaderColumnClick(this.state.column, this.state.direction); + + } + +} + diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index 9934597..de60d26 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -7,7 +7,7 @@ import History from '@overflow/history/api/model/History'; import Page from '@overflow/commons/api/model/Page'; import MetaHistoryType from '@overflow/meta/api/model/MetaHistoryType'; import { Pager } from '@overflow/commons/react/component/Pager'; - +import { SortTableHeaderRow } from '@overflow/commons/react/component/SortTableHeaderRow'; export interface StateProps { probes: Probe[]; @@ -117,19 +117,25 @@ export class HistoryList extends React.Component { } } + private handleSort = (col:string, direction:string):void => { + console.log(col + 'direction:' + direction); + } + public render(): JSX.Element { + let cols:string[] = ['No.', 'Probe', 'Type', 'Message', 'Created At', 'Created By']; let historyList: JSX.Element = ( - - No. - Probe - Type - Message - Created At - Created By - + + {/**/} + {/*No.*/} + {/*Probe*/} + {/*Type*/} + {/*Message*/} + {/*Created At*/} + {/*Created By*/} + {/**/}