Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 13049d3

Browse files
authored
bring back visited nodes for private registry (#424)
1 parent fd54c57 commit 13049d3

3 files changed

Lines changed: 169 additions & 1 deletion

File tree

src/components/sidebar/space/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ReplicatedNodes from "./replicatedNodes"
88
import SpacePanelIframe from "./spacePanelIframe"
99
import SignInPrompt from "./prompts/signIn"
1010
import OfflinePrompt from "./prompts/offline"
11+
import VisitedNodes from "./visitedNodes"
1112

1213
const replicatedNodesSelector = createSelector(
1314
state => state.global.chartsMetadata.data || {},
@@ -62,7 +63,7 @@ const Space = ({ isOpen, toggle }) => {
6263
)}
6364
{!!visitedNodes.length && (
6465
<Text strong color="border">
65-
VisitedNodes
66+
<VisitedNodes machinesArray={visitedNodes} />
6667
</Text>
6768
)}
6869
</>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { useCallback, useState } from "react"
2+
import { CollapsibleList, SimpleListItem } from "@rmwc/list"
3+
import "@material/list/dist/mdc.list.css"
4+
import "@rmwc/list/collapsible-list.css"
5+
import "@rmwc/icon/icon.css"
6+
import { Box, Flex, Text } from "@netdata/netdata-ui"
7+
8+
import truncateMiddle from "utils/truncateMiddle"
9+
import { naturalSortCompare } from "domains/dashboard/utils/sorting"
10+
import { MASKED_DATA } from "domains/global/constants"
11+
import { MenuList } from "components/menus"
12+
13+
import { NodesContainer, ListItem, StyledIcon, NodeUrl, NodeName, TrashIcon } from "./styled"
14+
15+
const Node = ({ name, alternateUrls, machineGuid }) => (
16+
<CollapsibleList
17+
handle={
18+
<SimpleListItem
19+
text={
20+
<>
21+
<StyledIcon name="node" />
22+
<NodeName
23+
color="bright"
24+
href=""
25+
onClick={event => {
26+
event.preventDefault() // prevent navigating to url
27+
event.stopPropagation()
28+
window.gotoServerModalHandler(machineGuid)
29+
}}
30+
>
31+
{name}
32+
</NodeName>
33+
</>
34+
}
35+
metaIcon={alternateUrls.length && "chevron_right"}
36+
/>
37+
}
38+
>
39+
<Box margin={[2, 0, 0]}>
40+
{alternateUrls.map(url => (
41+
<ListItem key={url}>
42+
<NodeUrl href={url}>{truncateMiddle(url, 50)}</NodeUrl>
43+
<TrashIcon
44+
name="trashcan"
45+
size="small"
46+
onClick={() => {
47+
window.deleteRegistryModalHandler(machineGuid, name, url)
48+
}}
49+
/>
50+
</ListItem>
51+
))}
52+
</Box>
53+
</CollapsibleList>
54+
)
55+
56+
export const VisitedNodes = ({ machinesArray }) => {
57+
const sortedMachines = machinesArray
58+
.sort((a, b) => naturalSortCompare(a.name, b.name))
59+
.filter(({ url }) => url !== MASKED_DATA)
60+
61+
const [listOpen, setListOpen] = useState(true)
62+
const toggleListOpen = useCallback(() => setListOpen(o => !o), [])
63+
64+
return (
65+
<MenuList
66+
isOpen={listOpen}
67+
toggleOpen={toggleListOpen}
68+
label={
69+
<Flex alignItems="center" justifyContent="between">
70+
<Text strong color="border">
71+
Visited Nodes
72+
</Text>
73+
<StyledIcon right={!listOpen} name="chevron_down" size="small" color="text" />
74+
</Flex>
75+
}
76+
>
77+
<NodesContainer column gap={2}>
78+
{sortedMachines.map(({ name, alternateUrls, guid, url }) => (
79+
<Node
80+
alternateUrls={alternateUrls}
81+
key={`${name}-${guid}`}
82+
machineGuid={guid}
83+
name={name}
84+
url={url}
85+
/>
86+
))}
87+
</NodesContainer>
88+
</MenuList>
89+
)
90+
}
91+
92+
export default VisitedNodes
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import styled from "styled-components"
2+
import { getSizeBy, getColor, Icon, TextNano, Text } from "@netdata/netdata-ui"
3+
4+
export const NodesContainer = styled.div`
5+
.mdc-list-item {
6+
padding: 0 0;
7+
padding-left: 0;
8+
}
9+
.rmwc-collapsible-list__children {
10+
.mdc-list-item {
11+
padding: 0 0;
12+
padding-left: 0;
13+
height: ${getSizeBy(4)};
14+
}
15+
}
16+
.rmwc-collapsible-list__handle {
17+
.mdc-list-item {
18+
padding: 0 ${getSizeBy(2)};
19+
}
20+
}
21+
.mdc-list-item__meta {
22+
color: ${getColor("bright")};
23+
}
24+
.mdc-list-item:before {
25+
background: none;
26+
}
27+
`
28+
29+
export const ListItem = styled.div`
30+
width: 100%;
31+
min-height: ${getSizeBy(3)};
32+
display: flex;
33+
flex-flow: row nowrap;
34+
align-items: center;
35+
cursor: pointer;
36+
justify-content: space-between;
37+
`
38+
39+
export const TrashIcon = styled(Icon)`
40+
fill: #35414a;
41+
margin-right: ${getSizeBy(2)};
42+
transition: opacity 0.4s ease-in;
43+
&:hover {
44+
opacity: 0.6;
45+
}
46+
`
47+
48+
export const StyledIcon = styled(Icon)`
49+
flex-shrink: 0;
50+
flex-grow: 0;
51+
margin-right: ${getSizeBy(2)};
52+
fill: ${getColor(["gray", "arsenic"])};
53+
`
54+
55+
// @ts-ignore todo extend interface in dashboard due to lack of types in netdata-ui
56+
export const NodeUrl = styled(TextNano.withComponent("a"))`
57+
text-decoration: none;
58+
margin-left: ${getSizeBy(5)};
59+
color: #aeb3b7;
60+
max-width: 145px;
61+
word-wrap: break-word;
62+
&:hover {
63+
color: inherit; // overwrite bootstrap
64+
text-decoration: none;
65+
}
66+
`
67+
68+
// @ts-ignore todo
69+
export const NodeName = styled(Text.withComponent("a"))`
70+
flex: 1;
71+
overflow: hidden;
72+
text-overflow: ellipsis;
73+
min-width: 0;
74+
white-space: nowrap;
75+
`

0 commit comments

Comments
 (0)