-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (78 loc) · 2.82 KB
/
Copy pathindex.js
File metadata and controls
83 lines (78 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, { Fragment, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import { useParams, useHistory } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCaretLeft } from '@fortawesome/free-solid-svg-icons';
import NodeList from '../NodeList';
import styles from './index.module.scss';
import AdvancedDetails from './AdvancedDetails';
import { getConfig } from '../../services/read-config';
import { readNodeDetails } from '../../actions/nodes';
import { addFilter } from '../../actions/filters';
import Button, { ButtonLink } from '../Button';
export default function NodeDetails(props) {
const dispatch = useDispatch();
const history = useHistory();
const { nodes, details } = props;
const { selectedNodeId } = useParams();
const selectedNode = nodes[selectedNodeId];
useEffect(() => {
const detailsUrl = getConfig('detailsUrl');
if (detailsUrl) {
dispatch(readNodeDetails(selectedNodeId));
}
}, [dispatch, selectedNodeId]);
return (
<Fragment>
<div className={styles.panelControls}>
<Button type="button" onClick={history.goBack} title="go back to previously selected node">
<FontAwesomeIcon icon={faCaretLeft} /> Back
</Button>
<ButtonLink type="button" to="/" title={`deselect ${selectedNode.id}`}>
Clear
</ButtonLink>
</div>
<h2>{selectedNode.id}</h2>
{Boolean(Object.keys(selectedNode.tags).length) && (
<div className={styles.tagsBlock}>
{Object.keys(selectedNode.tags).map((tagName) => {
return (
<p key={tagName}>
<span className={styles.tagName}>{tagName}</span>{' '}
{selectedNode.tags[tagName].map((tag) => {
return (
<button
className={styles.tagButton}
onClick={() => dispatch(addFilter(tagName, tag))}
key={tag}
title={`add "${tag}" to the "${tagName}" filter `}
>
{tag}
</button>
);
})}
</p>
);
})}
</div>
)}
{details && <AdvancedDetails details={details} />}
<div>
<NodeList
title="Dependencies"
nodes={selectedNode.dependencies.map((n) => ({ ...n, status: nodes[n.id].status }))}
/>
<NodeList
title="Dependents"
nodes={selectedNode.dependents.map((n) => ({ ...n, status: nodes[n.id].status }))}
/>
</div>
</Fragment>
);
}
NodeDetails.propTypes = {
nodes: PropTypes.instanceOf(Object).isRequired,
actions: PropTypes.instanceOf(Object).isRequired,
details: PropTypes.instanceOf(Object),
};