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

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

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

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

16
// material ui
17
import { FileCopyOutlined as CopyToClipboardIcon } from '@mui/icons-material';
18
import { Tooltip } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import copy from 'copy-to-clipboard';
22

23
const useStyles = makeStyles()(theme => ({
183✔
24
  root: {
25
    ['.key > b']: {
26
      backgroundColor: theme.palette.grey[400],
27
      color: theme.palette.getContrastText(theme.palette.grey[400])
28
    }
29
  }
30
}));
31

32
const cutoffLength = 100;
183✔
33
const ValueColumn = ({ value = '', setSnackbar }) => {
183!
34
  const [tooltipVisible, setTooltipVisible] = useState(false);
233✔
35
  const isComponent = React.isValidElement(value);
233✔
36
  const onClick = () => {
233✔
37
    if (setSnackbar) {
×
38
      let copyable = value;
×
39
      if (isComponent) {
×
40
        copyable = value.props.value;
×
41
      }
42
      copy(copyable);
×
43
      setSnackbar('Value copied to clipboard');
×
44
    }
45
  };
46
  let shownValue = value;
233✔
47
  if (!isComponent) {
233✔
48
    shownValue = <div title={value}>{value.length > cutoffLength ? `${value.substring(0, cutoffLength - 3)}...` : value}</div>;
184!
49
  }
50
  return (
233✔
51
    <div
52
      className={`flexbox ${setSnackbar ? 'clickable' : ''}`}
233✔
53
      onClick={onClick}
54
      onMouseEnter={() => setTooltipVisible(true)}
×
55
      onMouseLeave={() => setTooltipVisible(false)}
×
56
    >
57
      {shownValue}
58
      {setSnackbar && (
267✔
59
        <Tooltip title={'Copy to clipboard'} placement="top" open={tooltipVisible}>
60
          <CopyToClipboardIcon color="primary" className={`margin-left-small ${tooltipVisible ? 'fadeIn' : 'fadeOut'}`} fontSize="small"></CopyToClipboardIcon>
34!
61
        </Tooltip>
62
      )}
63
    </div>
64
  );
65
};
66

67
const KeyColumn = ({ value, chipLikeKey }) => (
183✔
68
  <div className={`align-right ${chipLikeKey ? 'key' : ''} muted`}>
246✔
69
    <b>{value}</b>
70
  </div>
71
);
72

73
export const TwoColumns = ({
183✔
74
  className = '',
10✔
75
  children,
76
  chipLikeKey = true,
77✔
77
  compact,
78
  items = {},
×
79
  KeyComponent = KeyColumn,
122✔
80
  KeyProps = {},
122✔
81
  setSnackbar,
82
  style = {},
84✔
83
  ValueComponent = ValueColumn,
109✔
84
  ValueProps = {}
119✔
85
}) => {
86
  const { classes } = useStyles();
122✔
87
  return (
122✔
88
    <div className={`break-all two-columns ${classes.root} ${compact ? 'compact' : ''} ${className}`} style={style}>
122✔
89
      {children
122!
90
        ? children
91
        : Object.entries(items).map(([key, value]) => (
92
            <Fragment key={key}>
246✔
93
              <KeyComponent chipLikeKey={chipLikeKey} value={key} {...KeyProps} />
94
              <ValueComponent setSnackbar={setSnackbar} value={value} {...ValueProps} />
95
            </Fragment>
96
          ))}
97
    </div>
98
  );
99
};
100

101
export const TwoColumnData = ({ className = '', config, ...props }) => <TwoColumns className={`column-data ${className}`} items={config} {...props} />;
183✔
102

103
export const TwoColumnDataMultiple = ({ className = '', config, style, ...props }) => (
183✔
104
  <div className={`two-columns-multiple ${className}`} style={{ ...style }}>
2✔
105
    {Object.entries(config).map(([key, value]) => (
106
      <TwoColumnData className="multiple" config={{ [key]: value }} key={key} compact {...props} />
3✔
107
    ))}
108
  </div>
109
);
110

111
export const ConfigurationObject = ({ config, ...props }) => {
183✔
112
  const content = Object.entries(config).reduce((accu, [key, value]) => {
3✔
113
    accu[key] = `${value}`;
10✔
114
    return accu;
10✔
115
  }, {});
116
  return <TwoColumnData {...props} config={content} />;
3✔
117
};
118

119
export default ConfigurationObject;
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