From ec0c4edab85e617770b9bef7b0f3d6da51a97cba Mon Sep 17 00:00:00 2001 From: viktor Date: Tue, 26 Dec 2017 15:12:37 +0300 Subject: [PATCH] Search logic; relates to #18 --- README.md | 2 +- src/App.js | 4 ++-- src/components/BallotKeysCard.jsx | 18 ++++++++++++++---- src/components/BallotMinThresholdCard.jsx | 16 +++++++++++++++- src/components/BallotProxyCard.jsx | 17 ++++++++++++++++- src/contracts/addresses.js | 14 +++++++------- src/stores/CommonStore.js | 4 ++-- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 69e6adc..748d492 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## MetaMask plugin setup -* Connect to POA Network in MetaMask plugin (See [Connect to Oracles network via MetaMask](https://github.com/poanetwork/wiki/blob/master/MetaMask-connect.md#connect-to-poa-network-via-metamask)) +* Connect to POA Network in MetaMask plugin (See [Connect to POA Network via MetaMask](https://github.com/poanetwork/wiki/blob/master/MetaMask-connect.md#connect-to-poa-network-via-metamask)) * Import your voting key to MetaMask Plugin (See [Governance section from wiki](https://github.com/poanetwork/wiki/blob/master/governance.md)). diff --git a/src/App.js b/src/App.js index 9a5a06f..c9c5e63 100644 --- a/src/App.js +++ b/src/App.js @@ -11,13 +11,13 @@ import { inject, observer } from 'mobx-react'; class App extends Component { onBallotsRender = () => { const { commonStore } = this.props; - commonStore.filtered = false; + commonStore.isActiveFilter = false; return ; } onActiveBallotsRender = () => { const { commonStore } = this.props; - commonStore.filtered = true; + commonStore.isActiveFilter = true; return ; } diff --git a/src/components/BallotKeysCard.jsx b/src/components/BallotKeysCard.jsx index 27ab2d2..281ca4b 100644 --- a/src/components/BallotKeysCard.jsx +++ b/src/components/BallotKeysCard.jsx @@ -264,15 +264,25 @@ export class BallotKeysCard extends React.Component { this.getIsFinalized(); } - checkFilter = () => { + hideCard = () => { let { commonStore } = this.props; - let filtered = commonStore.filtered && this.isFinalized; - return filtered; + let hideCard = commonStore.isActiveFilter && this.isFinalized; + if (commonStore.searchTerm) { + if (commonStore.searchTerm.length == 0) return hideCard; + if (String(this.affectedKey).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.affectedKeyTypeDisplayName).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.ballotTypeDisplayName).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.creator).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + } else { + return hideCard; + } + + return true; } render () { let { contractsStore } = this.props; - let ballotClass = this.checkFilter() ? "ballots-i display-none" : "ballots-i"; + let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; return (
diff --git a/src/components/BallotMinThresholdCard.jsx b/src/components/BallotMinThresholdCard.jsx index a716cf0..70232a2 100644 --- a/src/components/BallotMinThresholdCard.jsx +++ b/src/components/BallotMinThresholdCard.jsx @@ -200,9 +200,23 @@ export class BallotMinThresholdCard extends React.Component { this.getIsFinalized(this.props.id); } + hideCard = () => { + let { commonStore } = this.props; + let hideCard = commonStore.isActiveFilter && this.isFinalized; + if (commonStore.searchTerm) { + if (commonStore.searchTerm.length == 0) return hideCard; + if (String(this.proposedValue).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.creator).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + } else { + return hideCard; + } + + return true; + } + render () { let { commonStore, contractsStore } = this.props; - let ballotClass = (commonStore.filtered && this.isFinalized) ? "ballots-i display-none" : "ballots-i"; + let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; return (
diff --git a/src/components/BallotProxyCard.jsx b/src/components/BallotProxyCard.jsx index 1d76098..43e3191 100644 --- a/src/components/BallotProxyCard.jsx +++ b/src/components/BallotProxyCard.jsx @@ -209,9 +209,24 @@ export class BallotProxyCard extends React.Component { this.getIsFinalized(); } + hideCard = () => { + let { commonStore } = this.props; + let hideCard = commonStore.isActiveFilter && this.isFinalized; + if (commonStore.searchTerm) { + if (commonStore.searchTerm.length == 0) return hideCard; + if (String(this.proposedAddress).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.contractType).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + if (String(this.creator).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); + } else { + return hideCard; + } + + return true; + } + render () { const { commonStore, contractsStore, ballotStore } = this.props; - let ballotClass = (commonStore.filtered && this.isFinalized) ? "ballots-i display-none" : "ballots-i"; + let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; return (
diff --git a/src/contracts/addresses.js b/src/contracts/addresses.js index a0a18a6..195af0c 100644 --- a/src/contracts/addresses.js +++ b/src/contracts/addresses.js @@ -1,9 +1,9 @@ module.exports = { - KEYS_MANAGER_ADDRESS: '0xfc90125492e58dbfe80c0bfb6a2a759c4f703ca8', - VOTING_TO_CHANGE_KEYS_ADDRESS: '0x49df4ec19243263e5db22da5865b4f482b8323a0', - VOTING_TO_CHANGE_MIN_THRESHOLD: '0x8829ebe113535826e8af17ed51f83755f675789a', - VOTING_TO_CHANGE_PROXY: '0x6b728399b41a38d4109f7af2213d4cc31ca87812', - METADATA_ADDRESS: '0xcBB2912666c7e8023B7ec78B6842702eB26336aC', - POA_ADDRESS: '0x8bf38d4764929064f2d4d3a56520a76ab3df415b', - BALLOTS_STORAGE_ADDRESS: '0x0d7590c7aedf1e7e85fc9a1ee88f6f17d3ba762f' + KEYS_MANAGER_ADDRESS: '0x0e4a78ba651fcf2058e1326e16fc9160553ca467', + VOTING_TO_CHANGE_KEYS_ADDRESS: '0x534165101c5eec16c4a18102b98b8a903644e513', + VOTING_TO_CHANGE_MIN_THRESHOLD: '0xf7ee04d7e85ecf98ad62f96b0a40ab82de1eb0e3', + VOTING_TO_CHANGE_PROXY: '0x13d3c35d9947d77c677a648b9916998c4393622f', + METADATA_ADDRESS: '0x1ada723e24f414a72bac6a127f4b2a8d91dfec38', + POA_ADDRESS: '0xf472e0e43570b9afaab67089615080cf7c20018d', + BALLOTS_STORAGE_ADDRESS: '0x886cc61ef0ec40300378104eb547c2e86117b819' } \ No newline at end of file diff --git a/src/stores/CommonStore.js b/src/stores/CommonStore.js index 816959f..e8929b1 100644 --- a/src/stores/CommonStore.js +++ b/src/stores/CommonStore.js @@ -3,12 +3,12 @@ import { observable, action } from 'mobx'; class CommonStore { @observable loading; @observable rootPath; - @observable filtered; + @observable isActiveFilter; @observable searchTerm; constructor() { this.loading = false; - this.filtered = false; + this.isActiveFilter = false; this.rootPath = '/poa-dapps-voting' }