Skip to content

Commit 8fe79d2

Browse files
committed
added copy to clipboard functionality to Tree, in Actions and State tab, updates permissions, copy to clipboard, chrome, edge, firefox
1 parent 3b7bca2 commit 8fe79d2

File tree

8 files changed

+84
-8
lines changed

8 files changed

+84
-8
lines changed

extension/chrome/manifest.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
"storage",
6262
"file:///*",
6363
"http://*/*",
64-
"https://*/*"
64+
"https://*/*",
65+
"clipboardWrite",
66+
"clipboardRead"
6567
],
6668
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;",
6769
"update_url": "https://clients2.google.com/service/update2/crx",

extension/edge/manifest.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
"storage",
6262
"file:///*",
6363
"http://*/*",
64-
"https://*/*"
64+
"https://*/*",
65+
"clipboardWrite",
66+
"clipboardRead"
6567
],
6668
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;"
6769
}

extension/firefox/manifest.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
"storage",
5858
"file:///*",
5959
"http://*/*",
60-
"https://*/*"
60+
"https://*/*",
61+
"clipboardWrite",
62+
"clipboardRead"
6163
],
6264
"content_security_policy": "script-src 'self'; object-src 'self'; img-src 'self' data:;"
6365
}

packages/redux-devtools-inspector-monitor/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"immutable": "^4.3.5",
4848
"javascript-stringify": "^2.1.0",
4949
"jsondiffpatch": "^0.6.0",
50+
"lodash.clonedeep": "^4.5.0",
5051
"lodash.debounce": "^4.0.8",
5152
"react-base16-styling": "^0.9.1",
5253
"react-json-tree": "^0.18.0",
@@ -66,6 +67,7 @@
6667
"@types/dateformat": "^5.0.2",
6768
"@types/hex-rgba": "^1.0.3",
6869
"@types/history": "^4.7.11",
70+
"@types/lodash.clonedeep": "^4.5.9",
6971
"@types/lodash.debounce": "^4.0.9",
7072
"@types/react": "^18.2.58",
7173
"@typescript-eslint/eslint-plugin": "^6.21.0",

packages/redux-devtools-inspector-monitor/src/ActionPreview.tsx

+34-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import ActionPreviewHeader from './ActionPreviewHeader';
1010
import DiffTab from './tabs/DiffTab';
1111
import StateTab from './tabs/StateTab';
1212
import ActionTab from './tabs/ActionTab';
13+
import { getValueByPath } from './utils/getValueByPath';
14+
import { copyToClipboard } from './utils/copyToClipboard';
1315

1416
export interface TabComponentProps<S, A extends Action<string>> {
1517
labelRenderer: LabelRenderer;
@@ -184,7 +186,7 @@ class ActionPreview<S, A extends Action<string>> extends Component<
184186

185187
labelRenderer: LabelRenderer = ([key, ...rest], nodeType, expanded) => {
186188
const { onInspectPath, inspectedPath } = this.props;
187-
189+
const reversedPath = [key, ...rest].reverse();
188190
return (
189191
<span>
190192
<span>{key}</span>
@@ -202,14 +204,41 @@ class ActionPreview<S, A extends Action<string>> extends Component<
202204
onClick={() =>
203205
onInspectPath([
204206
...inspectedPath.slice(0, inspectedPath.length - 1),
205-
...[key, ...rest].reverse(),
207+
...reversedPath,
206208
])
207209
}
208210
>
209-
{'(pin)'}
210-
</span>
211-
{!expanded && ': '}
211+
{'(pin)'}
212212
</span>
213+
<span
214+
css={(theme) => ({
215+
fontSize: '0.7em',
216+
paddingLeft: '5px',
217+
cursor: 'pointer',
218+
'&:hover': {
219+
textDecoration: 'underline',
220+
},
221+
color: theme.PIN_COLOR,
222+
})}
223+
onClick={event => {
224+
event.stopPropagation();
225+
let objectForCopying;
226+
if (this.props.tabName === 'Action') {
227+
objectForCopying = getValueByPath(this.props.action, reversedPath);
228+
} else if (this.props.tabName === 'State') {
229+
objectForCopying = getValueByPath(this.props.nextState, reversedPath);
230+
}
231+
if (objectForCopying !== undefined) {
232+
copyToClipboard(objectForCopying);
233+
} else {
234+
console.error('Unable to find the object to copy');
235+
}
236+
}}
237+
>
238+
{'(copy)'}
239+
</span>
240+
{!expanded && ': '}
241+
</span>
213242
);
214243
};
215244
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import cloneDeep from 'lodash.clonedeep';
2+
3+
export function copyToClipboard(object: any){
4+
try {
5+
const deepCopiedObject = cloneDeep(object);
6+
const jsonString = JSON.stringify(deepCopiedObject, null, 2);
7+
void navigator.clipboard.writeText(jsonString);
8+
} catch (err) {
9+
console.error('Error during copy: ', err);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function getValueByPath(obj: any, path: (string | number)[]){
2+
let current: any = obj;
3+
for (let i = 0; i < path.length; i++) {
4+
const key = path[i];
5+
const adjustedKey = typeof key === 'string' && !isNaN(Number(key)) ? parseInt(key, 10) : key;
6+
if (current[adjustedKey] === undefined) {
7+
return undefined;
8+
}
9+
current = current[adjustedKey];
10+
}
11+
return current;
12+
}

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)