Skip to content

Commit

Permalink
Merge pull request #115 from Patrik-Stas/feature/ui-value-copy
Browse files Browse the repository at this point in the history
Add copy value button to UI
  • Loading branch information
Patrik-Stas authored Aug 2, 2021
2 parents 90b2bf5 + 4a6d0cf commit 6660a98
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 46 deletions.
2 changes: 1 addition & 1 deletion indypool-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-daemon",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "Application scanning Hyperledger Indy blockchain for fetching and processing transactions.",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-api-client",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "IndyScan HTTP API client.",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-api",
"version": "4.3.1",
"version": "4.4.0",
"description": "Web application to browse Hyperledger Indy blockchain transactions.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion indyscan-daemon-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-daemon-api-client",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "IndyScan Daemon HTTP API client.",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-daemon-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-daemon-ui",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "UI to view and manage the state of indyscan-daemon.",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-daemon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-daemon",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "Application scanning Hyperledger Indy blockchain for fetching and processing transactions.",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-storage",
"version": "4.3.1",
"version": "4.4.0",
"author": "Patrik Staš",
"license": "ISC",
"description": "",
Expand Down
2 changes: 1 addition & 1 deletion indyscan-txtype/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-txtype",
"version": "4.3.1",
"version": "4.4.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState } from 'react'
import './BadgedValueDisplay.scss'
import { Icon, Label, List } from 'semantic-ui-react'
import ReactTooltip from 'react-tooltip'
import { renderValuesAsBadges } from '../Common'

export function BadgedValueDisplay (props) {

const [copied, setCopied] = useState(false)

function renderKeyValuePair (key, value, keyValueId, color = 'red') {
return (
<List.Item key={keyValueId} style={{ marginTop: 5 }}>
<Label color={color} horizontal>
<div className="tooltip">
{ copied === key &&
< span className="tooltiptext">Copied</span>
}
<Icon data-tip data-for="registerTip"
name='copy outline icon'
style={{ cursor: 'pointer', marginRight: '1em' }}
onClick={() => {
navigator.clipboard.writeText(value)
setCopied(key)
setTimeout(() => setCopied(null), 400)
}}
>
</Icon>
</div>
{key}
</Label>

{Array.isArray(value) ? renderValuesAsBadges(key, value) : <Label>{value.toString().trim()}</Label>}
</List.Item>
)
}

function renderKeyValues (obj, groupId, color) {
let items = []
let i = 0
for (let [key, value] of Object.entries(obj)) {
if (value) {
if (Array.isArray(value) && value.length > 0) {
items.push(renderKeyValuePair(key, value, `${groupId}-${i}`, color))
} else {
let stringified = value.toString().trim()
if (stringified) {
items.push(renderKeyValuePair(key, value, `${groupId}-${i}`, color))
} else {
continue
}
}
i++
}
}
return items
}

return <div>
{renderKeyValues(props.obj, props.groupId, props.color)}
</div>
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
}

/* Tooltip text */
.tooltip .tooltiptext {
visibility: visible;
width: 60px;
background-color: black;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;

/* Position the tooltip text - see examples below! */
position: absolute;
left: -50px;
bottom: 0.3em;
z-index: 1;
}

///* Show the tooltip text when you mouse over the tooltip container */
//.tooltip:hover .tooltiptext {
// visibility: visible;
//}
40 changes: 5 additions & 35 deletions indyscan-webapp/components/TxDisplay/TxDisplay.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,21 @@
import React from 'react'
import './TxDisplay.scss'
import {
GridRow,
Button,
GridRow, Icon,
Item,
ItemContent,
ItemDescription,
ItemGroup,
ItemHeader,
ItemMeta,
Label,
List
} from 'semantic-ui-react'
import { renderValuesAsBadges } from '../Common'
import { converTxDataBasicToHumanReadable, extractTxDataBasic, extractTxDataDetailsHumanReadable, } from '../../txtools'
import TimeAgoText from '../TimeAgoText/TimeAgoText'
import { BadgedValueDisplay } from '../BadgedValueDisplay/BadgedValueDisplay'

function renderKeyValuePair (key, value, keyValueId, color = 'red') {
return (
<List.Item key={keyValueId}>
<Label color={color} horizontal>
{key}
</Label>
{Array.isArray(value) ? renderValuesAsBadges(key, value) : <Label>{value.toString().trim()}</Label>}
</List.Item>
)
}

function renderKeyValues (obj, groupId, color) {
let items = []
let i = 0
for (let [key, value] of Object.entries(obj)) {
if (value) {
if (Array.isArray(value) && value.length > 0) {
items.push(renderKeyValuePair(key, value, `${groupId}-${i}`, color))
} else {
let stringified = value.toString().trim()
if (stringified) {
items.push(renderKeyValuePair(key, value, `${groupId}-${i}`, color))
} else {
continue
}
}
i++
}
}
return items
}

const TxDisplay = ({ txIndyscan, txLedger }) => {
const keyValTxDetailsHumanReadable = extractTxDataDetailsHumanReadable(txIndyscan)
Expand All @@ -61,8 +31,8 @@ const TxDisplay = ({ txIndyscan, txLedger }) => {
<ItemMeta><TimeAgoText sinceEpoch={new Date(txnTimeIso8601)} className='txdisplay-graytext'/></ItemMeta>
<ItemDescription>
<List divided>
{renderKeyValues(keyValBasicHumanReadable, 'txbasic', 'blue')}
{renderKeyValues(keyValTxDetailsHumanReadable, 'txdetails', 'green')}
<BadgedValueDisplay obj={keyValBasicHumanReadable} groupId='txbasic' color='blue'/>
<BadgedValueDisplay obj={keyValTxDetailsHumanReadable} groupId='txdetails' color='green'/>
</List>
</ItemDescription>
</ItemContent>
Expand Down
2 changes: 1 addition & 1 deletion indyscan-webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indyscan-webapp",
"version": "4.3.1",
"version": "4.4.0",
"description": "Web application to browse Hyperledger Indy blockchain transactions.",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"major": 4,
"minor": 3,
"patch": 1
"minor": 4,
"patch": 0
}

0 comments on commit 6660a98

Please sign in to comment.