-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from Patrik-Stas/feature/ui-value-copy
Add copy value button to UI
- Loading branch information
Showing
13 changed files
with
106 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
indyscan-webapp/components/BadgedValueDisplay/BadgedValueDisplay.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
indyscan-webapp/components/BadgedValueDisplay/BadgedValueDisplay.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"major": 4, | ||
"minor": 3, | ||
"patch": 1 | ||
"minor": 4, | ||
"patch": 0 | ||
} |