From 77ddf3c96d8383e9fc66d0caf3056485992e741e Mon Sep 17 00:00:00 2001 From: ramongduraes Date: Fri, 21 Sep 2018 19:29:48 -0300 Subject: [PATCH 1/2] unlocking create job button when theres no job in progress --- src/components/job.js | 26 +++++++++++++++++++------- src/components/services.js | 19 +++++++++++++++---- src/index.js | 20 +++++++++++++++++--- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/components/job.js b/src/components/job.js index a9e55dd..d49d5ec 100644 --- a/src/components/job.js +++ b/src/components/job.js @@ -2,7 +2,7 @@ import React from 'react'; import agentAbi from 'singularitynet-platform-contracts/abi/Agent.json'; import jobAbi from 'singularitynet-platform-contracts/abi/Job.json'; import Eth from 'ethjs'; -import {Layout, Divider, Card, Icon, Spin, Alert, Row, Col, Button, Tag, message, Table, Collapse, Steps, Modal, Upload} from 'antd'; +import {Layout, Divider, Card, Icon, Spin, Alert, Row, Col, Button, Tag, message, Table, Collapse, Steps, Modal, Upload, Popconfirm} from 'antd'; import { NETWORKS, ERROR_UTILS, AGENT_STATE, AGI } from '../util'; import {JsonRpcClient} from "../jsonrpc"; import abiDecoder from 'abi-decoder'; @@ -96,6 +96,7 @@ class Job extends React.Component { })); this.nextJobStep(); + this.props.sendJobInProgress(true); } }); }).catch(this.handleReject); @@ -204,7 +205,7 @@ class Job extends React.Component { return receipt; } - + render() { let modal = type => @@ -359,13 +360,24 @@ class Job extends React.Component { // Display service specific form submission or results display for the last two steps (this.state.jobStep >= (steps.length - 2)) && -
- Service Call - -
+
+ Service Call + +
+
+ } + { + // Display a button that allows the user to end the job, clear the data and possibly choose another job + (this.state.jobStep >= (steps.length - 1)) && + +
+ + this.props.sendJobInProgress(false)} okText="Yes" cancelText="No"> + + +
} - ); diff --git a/src/components/services.js b/src/components/services.js index fe4271c..4c8f3ad 100644 --- a/src/components/services.js +++ b/src/components/services.js @@ -11,7 +11,6 @@ class Services extends React.Component { this.state = { agents : [], - selectedAgent: undefined, }; this.servicesTableKeys = [ @@ -46,8 +45,13 @@ class Services extends React.Component { title: '', dataIndex: 'state', render: (state, agent, index) => - } ].map(column => Object.assign({}, { width: 150 }, column)); @@ -55,9 +59,16 @@ class Services extends React.Component { this.watchRegistriesTimer = undefined; } + isSelectedAgent(agent){ + if (this.props.selectedAgent !== undefined) { + return this.props.selectedAgent.key === agent.key; + } + return false; + } + getAgentButtonText(state, agent) { if (this.props.account) { - if (typeof this.state.selectedAgent === 'undefined' || this.state.selectedAgent.key !== agent.key) { + if (typeof this.props.selectedAgent === 'undefined' || this.props.selectedAgent.key !== agent.key) { return state == AGENT_STATE.ENABLED ? 'Create Job' : 'Agent Disabled'; } else { return 'Selected'; diff --git a/src/index.js b/src/index.js index f7d2125..bb81071 100644 --- a/src/index.js +++ b/src/index.js @@ -36,6 +36,7 @@ class App extends React.Component { selectedAgent: undefined, agentCallComponent: undefined, usingDefaultCallComponent: false, + jobInProgress: false, }; this.serviceNameToComponent = { @@ -44,7 +45,7 @@ class App extends React.Component { 'face_landmarks': FaceLandmarksService, 'face_alignment': FaceAlignmentService, 'face_recognition': FaceRecognitionService, - 'Exchange AGI for BTC': ExchangeService + 'Exchange AGI for BTC': ExchangeService, }; this.serviceDefaultComponent = DefaultService; @@ -148,6 +149,19 @@ class App extends React.Component { }); } + updateJobInProgress(jobInProgress) { + if (jobInProgress){ + console.log("There is a job in progress"); + this.setState({jobInProgress: true,}) + } else { + console.log("No job in progress"); + this.setState({selectedAgent: undefined, + agentCallComponent: undefined, + usingDefaultCallComponent: false, + jobInProgress: false,}) + } + } + render() { return ( @@ -161,14 +175,14 @@ class App extends React.Component { - this.hireAgent(agent)} /> + this.hireAgent(agent)} jobInProgress={this.state.jobInProgress} selectedAgent={this.state.selectedAgent} /> { this.state.usingDefaultCallComponent && } { this.state.selectedAgent && this.state.chainId && this.state.account && - + this.updateJobInProgress(jobInProgress)} /> } From 91fd50bb4211af33491e8e8b8dfe87fa57a98a17 Mon Sep 17 00:00:00 2001 From: ramongduraes Date: Mon, 24 Sep 2018 13:57:13 -0300 Subject: [PATCH 2/2] added search functionality for agents --- src/components/services.js | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/components/services.js b/src/components/services.js index 4c8f3ad..0492c41 100644 --- a/src/components/services.js +++ b/src/components/services.js @@ -1,6 +1,6 @@ import React from 'react'; import Eth from 'ethjs'; -import {Layout, Divider, Card, Icon, Spin, Alert, Row, Col, Button, Tag, message, Table} from 'antd'; +import {Input, Divider, Card, Icon, Button, Tag, Table} from 'antd'; import {NETWORKS, AGENT_STATE, AGI, FORMAT_UTILS, STRINGS} from '../util'; @@ -18,6 +18,27 @@ class Services extends React.Component { title: 'Agent', dataIndex: 'name', width: 200, + filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => this.renderFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters }), + filterIcon: filtered => , + onFilter: (value, record) => record.name.toLowerCase().includes(value.toLowerCase()), + onFilterDropdownVisibleChange: (visible) => { + if (visible) { + setTimeout(() => { + this.searchInput.focus(); + }); + } + }, + render: (text) => { + const { searchText } = this.state; + return searchText ? ( + + {text.split(new RegExp(`(?<=${searchText})|(?=${searchText})`, 'i')).map((fragment, i) => ( + fragment.toLowerCase() === searchText.toLowerCase() + ? {fragment} : fragment // eslint-disable-line + ))} + + ) : text; + }, }, { title: 'Contract Address', @@ -208,6 +229,33 @@ class Services extends React.Component { } } + handleSearch(selectedKeys, confirm) { + this.setState({ searchText: selectedKeys[0] }) + return confirm() + } + + handleReset(clearFilters){ + this.setState({ searchText: '' }); + return clearFilters() + } + + renderFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters }){ + return ( +
+ this.searchInput = ele} + placeholder="Search name" + value={selectedKeys[0]} + onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])} + onPressEnter={() => this.handleSearch(selectedKeys, confirm)} + /> + + +
+ ) + } + render() { let servicesTable = (columns, dataSource, featured) =>