• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 10423

11 Nov 2025 04:53PM UTC coverage: 74.435% (-0.1%) from 74.562%
10423

push

gitlab-ci

web-flow
Merge pull request #1071 from mendersoftware/dependabot/npm_and_yarn/frontend/main/development-dependencies-92732187be

3868 of 5393 branches covered (71.72%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

176 existing lines in 95 files now uncovered.

64605 of 86597 relevant lines covered (74.6%)

7.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.8
/frontend/src/js/common-ui/ExpandableAttribute.tsx
1
// Copyright 2019 Northern.tech AS
2✔
2
//
2✔
3
//    Licensed under the Apache License, Version 2.0 (the "License");
2✔
4
//    you may not use this file except in compliance with the License.
2✔
5
//    You may obtain a copy of the License at
2✔
6
//
2✔
7
//        http://www.apache.org/licenses/LICENSE-2.0
2✔
8
//
2✔
9
//    Unless required by applicable law or agreed to in writing, software
2✔
10
//    distributed under the License is distributed on an "AS IS" BASIS,
2✔
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2✔
12
//    See the License for the specific language governing permissions and
2✔
13
//    limitations under the License.
2✔
14
import { useCallback, useEffect, useRef, useState } from 'react';
2✔
15

2✔
16
// material ui
2✔
17
import { FileCopyOutlined as CopyToClipboardIcon } from '@mui/icons-material';
2✔
18
import { ListItem, ListItemText, Tooltip } from '@mui/material';
2✔
19

2✔
20
import { toggle } from '@northern.tech/utils/helpers';
2✔
21
import copy from 'copy-to-clipboard';
2✔
22

2✔
23
const defaultClasses = { root: 'attributes' };
16✔
24

2✔
25
export const ExpandableAttribute = ({
16✔
26
  className = '',
2✔
27
  copyToClipboard,
2✔
28
  dividerDisabled,
2✔
29
  onExpansion,
2✔
30
  primary,
2✔
31
  secondary,
2✔
32
  secondaryTypographyProps = {},
2✔
33
  setSnackbar,
2✔
34
  style,
2✔
35
  textClasses,
2✔
36
  ...remainder
2✔
37
}) => {
2✔
38
  const textContent = useRef(null);
135✔
39
  const [expanded, setExpanded] = useState(false);
135✔
40
  const [overflowActive, setOverflowActive] = useState(false);
135✔
41
  const [tooltipVisible, setTooltipVisible] = useState(false);
135✔
42

2✔
43
  useEffect(() => {
135✔
44
    if (textContent.current) {
36!
45
      const overflowActiveCurrently =
2✔
46
        textContent.current.scrollWidth > textContent.current.clientWidth || textContent.current.scrollHeight > textContent.current.clientHeight;
36✔
47
      if (overflowActive !== overflowActiveCurrently && !expanded) {
36!
48
        setOverflowActive(overflowActiveCurrently);
2✔
49
      }
2✔
50
    }
2✔
51
  }, [expanded, overflowActive, textContent]);
2✔
52

2✔
53
  const onClick = useCallback(() => {
135✔
54
    if (copyToClipboard) {
2!
55
      // Date/Time components
2✔
56
      copy(secondary);
2✔
57
      setSnackbar('Value copied to clipboard');
2✔
58
    }
2✔
59
    if (!expanded && !!onExpansion) {
2!
60
      onExpansion();
2✔
61
    }
2✔
62
    setExpanded(toggle);
2✔
63
  }, [copyToClipboard, expanded, onExpansion, secondary, setSnackbar]);
2✔
64

2✔
65
  const currentTextClasses = `${textClasses ? textClasses.secondary : 'inventory-text'}${expanded && overflowActive ? ' expanded-attribute' : ''}`;
135!
66
  const secondaryText = (
2✔
67
    <>
135✔
68
      <span className={currentTextClasses} ref={textContent}>
2✔
69
        {secondary}
2✔
70
      </span>{' '}
2✔
71
      {overflowActive ? <a>show {expanded ? 'less' : 'more'}</a> : null}
2!
72
    </>
2✔
73
  );
2✔
74

2✔
75
  const cssClasses = { ...defaultClasses, root: `${defaultClasses.root} ${copyToClipboard ? 'copy-to-clipboard' : ''}`.trim() };
135✔
76

2✔
77
  return (
135✔
UNCOV
78
    <div className={className} onClick={onClick} onMouseEnter={() => setTooltipVisible(true)} onMouseLeave={() => setTooltipVisible(false)} style={style}>
2✔
79
      <ListItem classes={cssClasses} divider={!dividerDisabled} {...remainder}>
2✔
80
        <ListItemText
2✔
81
          primary={primary}
2✔
82
          secondary={secondaryText}
2✔
83
          secondaryTypographyProps={{ title: secondary, component: 'div', ...secondaryTypographyProps }}
2✔
84
        />
2✔
85
        {copyToClipboard ? (
2✔
86
          <Tooltip title={'Copy to clipboard'} placement="top" open={tooltipVisible}>
2✔
87
            <CopyToClipboardIcon fontSize="small" />
2✔
88
          </Tooltip>
2✔
89
        ) : null}
2✔
90
      </ListItem>
2✔
91
    </div>
2✔
92
  );
2✔
93
};
2✔
94

2✔
95
export default ExpandableAttribute;
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc