diff --git a/package.json b/package.json index 3f4379d..66a67b5 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@types/react-dom": "^15.5.0", "@types/react-router-dom": "^4.0.4", "@types/react-tap-event-plugin": "^0.0.30", + "@types/lodash": "^4.14.69", "awesome-typescript-loader": "^3.1.3", "css-loader": "^0.28.2", "copy-webpack-plugin": "^4.0.1", @@ -34,6 +35,7 @@ "react-dom": "15.5.4", "react-router-dom": "^4.1.1", "react-tap-event-plugin": "^2.0.1", - "semantic-ui-react": "^0.70.0" + "semantic-ui-react": "^0.70.0", + "lodash": "^4.17.4" } } diff --git a/src/ts/Routes.tsx b/src/ts/Routes.tsx index 08d6d0a..6a772a7 100644 --- a/src/ts/Routes.tsx +++ b/src/ts/Routes.tsx @@ -12,6 +12,7 @@ import { Components } from './containers/test/Components'; import { Sensors } from './containers/test/Sensors'; // import { Layout } from './containers/test/layout/Layout' import { Tree } from './containers/test/commons/Tree'; +import { TableExampleSortable } from './containers/test/TableExampleSortable' export class Blank extends React.Component { render() { @@ -52,6 +53,7 @@ export class Routes extends React.Component { + diff --git a/src/ts/containers/test/Probes.tsx b/src/ts/containers/test/Probes.tsx index 702c322..018b820 100644 --- a/src/ts/containers/test/Probes.tsx +++ b/src/ts/containers/test/Probes.tsx @@ -26,7 +26,7 @@ export class Probes extends React.Component { "domain": { "name": "asus" }, - "probeKey": "AGBLKDFJ2452ASDGFL2KWJLKSDJ", + "probeKey": "1AGBLKDFJ2452ASDGFL2KWJLKSDJ", "description": "description1111111111", }, { @@ -37,7 +37,7 @@ export class Probes extends React.Component { "domain": { "name": "ottugi" }, - "probeKey": "AGBLKDFJ2452ASDGFL2KWJLKSDJ", + "probeKey": "2AGBLKDFJ2452ASDGFL2KWJLKSDJ", "description": "description22222222", }, { @@ -48,7 +48,7 @@ export class Probes extends React.Component { "domain": { "name": "lg" }, - "probeKey": "AGBLKDFJ2452ASDGFL2KWJLKSDJ", + "probeKey": "3AGBLKDFJ2452ASDGFL2KWJLKSDJ", "description": "description33333", }, { @@ -59,7 +59,7 @@ export class Probes extends React.Component { "domain": { "name": "apple" }, - "probeKey": "AGBLKDFJ2452ASDGFL2KWJLKSDJ", + "probeKey": "4AGBLKDFJ2452ASDGFL2KWJLKSDJ", "description": "description4444", }, ]; @@ -82,17 +82,9 @@ export class Probes extends React.Component { }); } - handleSearch(searchWord: string) { - let founds = new Array(); - for (let probe of this.data) { - if (probe.domain.name.toLowerCase().indexOf(searchWord) !== -1 - || probe.description.toLowerCase().indexOf(searchWord) !== -1 - || probe.metaProbeStatus.name.toLowerCase().indexOf(searchWord) !== -1) { - founds.push(probe); - } - } + handleSearch(result: object[]) { this.setState({ - list: founds, + list: result, }); } @@ -115,7 +107,7 @@ export class Probes extends React.Component { } renderRows() { - if(this.state.list.length === 0) { + if (this.state.list.length === 0) { return No results found. ; @@ -131,6 +123,7 @@ export class Probes extends React.Component { )); } + render() { if (this.state.isDetail) { return this.setState({ isDetail: false })} />; @@ -157,8 +150,9 @@ export class Probes extends React.Component { return ( } + data={this.data} onSearch={this.handleSearch.bind(this)} + filter={} /> ); } diff --git a/src/ts/containers/test/TableExampleSortable.tsx b/src/ts/containers/test/TableExampleSortable.tsx new file mode 100644 index 0000000..d20a7e3 --- /dev/null +++ b/src/ts/containers/test/TableExampleSortable.tsx @@ -0,0 +1,74 @@ +import * as _ from 'lodash'; +import * as React from 'react'; +import { Table } from 'semantic-ui-react'; + +const tableData = [ + { name: 'John', age: 15, gender: 'Male' }, + { name: 'Amber', age: 40, gender: 'Female' }, + { name: 'Leslie', age: 25, gender: 'Female' }, + { name: 'Ben', age: 70, gender: 'Male' }, +]; + +export class TableExampleSortable extends React.Component { + + constructor(props: any, context: any) { + super(props, context); + + this.state = { + column: null, + data: tableData, + direction: null, + }; + } + + + handleSort = (clickedColumn:any) => () => { + const { column, data, direction } = this.state + + if (column !== clickedColumn) { + this.setState({ + column: clickedColumn, + data: _.sortBy(data, [clickedColumn]), + direction: 'ascending', + }); + + return + } + + this.setState({ + data: data.reverse(), + direction: direction === 'ascending' ? 'descending' : 'ascending', + }) + }; + + render() { + const { column, data, direction } = this.state; + + return ( + + + + + Name + + + Age + + + Gender + + + + + {_.map(data, ({ age, gender, name }) => ( + + {name} + {age} + {gender} + + ))} + +
+ ) + } +} \ No newline at end of file diff --git a/src/ts/containers/test/commons/ListContainer.tsx b/src/ts/containers/test/commons/ListContainer.tsx index 155475d..37a9d88 100644 --- a/src/ts/containers/test/commons/ListContainer.tsx +++ b/src/ts/containers/test/commons/ListContainer.tsx @@ -1,26 +1,67 @@ import * as React from 'react'; -import { Grid, Input, Form, Checkbox, Divider, Button } from 'semantic-ui-react'; +import { Grid, Input, Form, Checkbox, Divider } from 'semantic-ui-react'; export class ListContainer extends React.Component { - private data: any = null; + private found: boolean = false; constructor(props: any, context: any) { super(props, context); this.state = { }; + } handleSearch(e: any, data: any) { - this.props.onSearch(data.value.toLowerCase()); + let searchWord = data.value; + let items: object[]; + items = this.props.data; + let item: any; + + let result = new Array(); + for (item of items) { + this.search(item, searchWord); + if (this.found) { + result.push(item); + } + this.found = false; + } + + this.props.onSearch(result); } - + + handleSearchInput(e: any, data: any) { + this.setState({ + searchWord: data.value, + }); + } + + search(item: any, searchWord: string) { + let key: any; + for (key in item) { + if (this.isString(item[key])) { + if (item[key].toLowerCase().indexOf(searchWord.toLowerCase()) !== -1) { + this.found = true; + } + } else { + this.search(item[key], searchWord); + } + } + } + + isString(val: any): boolean { + if (typeof val === 'string') { + return true; + } + return false; + } + render() { return ( - - {/*filter */} + {this.props.filter} diff --git a/src/ts/containers/test/layout/Header.tsx b/src/ts/containers/test/layout/Header.tsx index 930e903..2adb7d4 100644 --- a/src/ts/containers/test/layout/Header.tsx +++ b/src/ts/containers/test/layout/Header.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Container } from 'semantic-ui-react'; +import { Container, Divider } from 'semantic-ui-react'; import { TopBar } from '../TopBar'; import { LogoBar } from './LogoBar'; import { TitleBar } from './TitleBar'; @@ -16,7 +16,9 @@ export class Header extends React.Component { return ( + + // ); diff --git a/src/ts/containers/test/layout/Layout.tsx b/src/ts/containers/test/layout/Layout.tsx index f2daa8b..decd14d 100644 --- a/src/ts/containers/test/layout/Layout.tsx +++ b/src/ts/containers/test/layout/Layout.tsx @@ -28,7 +28,7 @@ export class Layout extends React.Component { - + diff --git a/src/ts/containers/test/layout/LeftMenu.tsx b/src/ts/containers/test/layout/LeftMenu.tsx index 49e0b47..694ac23 100644 --- a/src/ts/containers/test/layout/LeftMenu.tsx +++ b/src/ts/containers/test/layout/LeftMenu.tsx @@ -24,15 +24,17 @@ export class LeftMenu extends React.Component { - + - + Home - + + Monitoring + {/* Monitoring @@ -40,43 +42,45 @@ export class LeftMenu extends React.Component { Sensors + */} - + + Infrastructure + {/* - - Infrastructure Maps Targets + */} - + Dashboard - + Metrics - + Alerts - + History - + @@ -88,10 +92,11 @@ export class LeftMenu extends React.Component { Insanity DiscoveryDetails Tree + TableExampleSortable - + Settings diff --git a/src/ts/containers/test/layout/LogoBar.tsx b/src/ts/containers/test/layout/LogoBar.tsx index f1a5665..8b59a93 100644 --- a/src/ts/containers/test/layout/LogoBar.tsx +++ b/src/ts/containers/test/layout/LogoBar.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Menu, Header } from 'semantic-ui-react'; +import { Menu, Header, Container } from 'semantic-ui-react'; export class LogoBar extends React.Component { @@ -19,7 +19,7 @@ export class LogoBar extends React.Component { render() { return ( -
+ { -
+ ); } } diff --git a/src/ts/containers/test/layout/TitleBar.tsx b/src/ts/containers/test/layout/TitleBar.tsx index 6b20f1e..c4f5b60 100644 --- a/src/ts/containers/test/layout/TitleBar.tsx +++ b/src/ts/containers/test/layout/TitleBar.tsx @@ -28,15 +28,16 @@ export class TitleBar extends React.Component { -
Page Title - - Home - - Monitoring - - Probes - - +
Page Title + + + Home + + Monitoring + + Probes + +