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

mendersoftware / gui / 1081664682

22 Nov 2023 02:11PM UTC coverage: 82.798% (-17.2%) from 99.964%
1081664682

Pull #4214

gitlab-ci

tranchitella
fix: Fixed the infinite page redirects when the back button is pressed

Remove the location and navigate from the useLocationParams.setValue callback
dependencies as they change the set function that is presented in other
useEffect dependencies. This happens when the back button is clicked, which
leads to the location changing infinitely.

Changelog: Title
Ticket: MEN-6847
Ticket: MEN-6796

Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
Pull Request #4214: fix: Fixed the infinite page redirects when the back button is pressed

4319 of 6292 branches covered (0.0%)

8332 of 10063 relevant lines covered (82.8%)

191.0 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);
266✔
35
  const isComponent = React.isValidElement(value);
266✔
36
  const onClick = () => {
266✔
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;
266✔
47
  if (!isComponent) {
266✔
48
    shownValue = <div title={value}>{value.length > cutoffLength ? `${value.substring(0, cutoffLength - 3)}...` : value}</div>;
199!
49
  }
50
  return (
266✔
51
    <div
52
      className={`flexbox ${setSnackbar ? 'clickable' : ''}`}
266✔
53
      onClick={onClick}
54
      onMouseEnter={() => setTooltipVisible(true)}
×
55
      onMouseLeave={() => setTooltipVisible(false)}
×
56
    >
57
      {shownValue}
58
      {setSnackbar && (
300✔
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`}>
285✔
69
    <b>{value}</b>
70
  </div>
71
);
72

73
export const TwoColumns = ({
183✔
74
  className = '',
16✔
75
  children,
76
  chipLikeKey = true,
77✔
77
  compact,
78
  items = {},
×
79
  KeyComponent = KeyColumn,
146✔
80
  KeyProps = {},
146✔
81
  setSnackbar,
82
  style = {},
90✔
83
  ValueComponent = ValueColumn,
127✔
84
  ValueProps = {}
143✔
85
}) => {
86
  const { classes } = useStyles();
146✔
87
  return (
146✔
88
    <div className={`break-all two-columns ${classes.root} ${compact ? 'compact' : ''} ${className}`} style={style}>
146✔
89
      {children
146!
90
        ? children
91
        : Object.entries(items).map(([key, value]) => (
92
            <Fragment key={key}>
285✔
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