• 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

97.37
/src/js/components/deployments/deploymentitem.js
1
// Copyright 2019 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, { useState } from 'react';
15

16
// material ui
17
import { CancelOutlined as CancelOutlinedIcon } from '@mui/icons-material';
18
import { Button, IconButton, Tooltip } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import { DEPLOYMENT_STATES, DEPLOYMENT_TYPES } from '../../constants/deploymentConstants';
22
import { FileSize, getDeploymentState } from '../../helpers';
23
import { useDeploymentDevice } from '../../utils/deploymentdevicehook';
24
import Confirm from '../common/confirm';
25
import { RelativeTime } from '../common/time';
26
import { PhaseProgressDisplay } from './deployment-report/phaseprogress';
27
import { getDeploymentTargetText } from './deployment-wizard/softwaredevices';
28
import DeploymentStats from './deploymentstatus';
29
import ProgressDisplay, { DeploymentStatusNotification } from './progressChart';
30

31
export const deploymentTypeClasses = {
11✔
32
  [DEPLOYMENT_STATES.finished]: 'past-item',
33
  [DEPLOYMENT_STATES.pending]: 'pending-item',
34
  [DEPLOYMENT_STATES.inprogress]: 'progress-item',
35
  [DEPLOYMENT_STATES.scheduled]: 'scheduled-item'
36
};
37

38
export const DeploymentDeviceCount = ({ className, deployment }) => (
11✔
39
  <div className={className} key="DeploymentDeviceCount">
1,110✔
40
    {Math.max(deployment.device_count || 0, deployment.max_devices || 0)}
3,337✔
41
  </div>
42
);
43
export const DeploymentDeviceGroup = ({ deployment, devicesById, idAttribute, wrappingClass }) => {
11✔
44
  const deploymentName = getDeploymentTargetText({ deployment, devicesById, idAttribute });
3,519✔
45
  return (
3,519✔
46
    <div className={wrappingClass} key="DeploymentDeviceGroup" title={deploymentName}>
47
      {deploymentName}
48
    </div>
49
  );
50
};
51
export const DeploymentEndTime = ({ deployment }) => <RelativeTime key="DeploymentEndTime" updateTime={deployment.finished} shouldCount="none" />;
1,110✔
52
export const DeploymentPhases = ({ deployment }) => <div key="DeploymentPhases">{deployment.phases ? deployment.phases.length : '-'}</div>;
11!
53
export const DeploymentProgress = ({ deployment, minimal = false }) => {
11✔
54
  const { phases = [], update_control_map } = deployment;
1,835✔
55
  const status = getDeploymentState(deployment);
1,835✔
56
  if (status === 'queued') {
1,835✔
57
    return <DeploymentStatusNotification status={status} />;
913✔
58
  } else if (phases.length > 1 || !update_control_map) {
922!
59
    return <ProgressDisplay key="DeploymentProgress" deployment={deployment} status={status} minimal={minimal} />;
922✔
60
  }
61
  return <PhaseProgressDisplay key="DeploymentProgress" deployment={deployment} status={status} minimal={minimal} />;
×
62
};
63
export const DeploymentRelease = ({ deployment: { artifact_name, type = DEPLOYMENT_TYPES.software }, wrappingClass }) => {
11✔
64
  const deploymentRelease = type === DEPLOYMENT_TYPES.configuration ? type : artifact_name;
1,110!
65
  return (
1,110✔
66
    <div className={wrappingClass} key="DeploymentRelease" title={deploymentRelease}>
67
      {deploymentRelease}
68
    </div>
69
  );
70
};
71
export const DeploymentStartTime = ({ direction = 'both', started }) => <RelativeTime key="DeploymentStartTime" updateTime={started} shouldCount={direction} />;
1,110✔
72

73
export const DeploymentStatus = ({ deployment }) => <DeploymentStats key="DeploymentStatus" deployment={deployment} />;
76✔
74

75
export const DeploymentSize = ({ deployment: { total_size } }) => <div className="align-right">{total_size ? <FileSize fileSize={total_size} /> : '-'}</div>;
76!
76

77
const useStyles = makeStyles()(theme => ({
34✔
78
  detailsButton: {
79
    backgroundColor: 'transparent',
80
    color: theme.palette.text.primary,
81
    justifySelf: 'center',
82
    textTransform: 'none',
83
    [`&:hover`]: {
84
      backgroundColor: 'transparent',
85
      color: theme.palette.text.primary
86
    }
87
  },
88
  textWrapping: { whiteSpace: 'initial' }
89
}));
90

91
export const DeploymentItem = ({
11✔
92
  abort: abortDeployment,
93
  canConfigure,
94
  canDeploy,
95
  columnHeaders,
96
  deployment,
97
  devices,
98
  idAttribute,
99
  isEnterprise,
100
  openReport,
101
  type
102
}) => {
103
  const [abort, setAbort] = useState(null);
1,110✔
104
  useDeploymentDevice(deployment.name);
1,110✔
105

106
  const { classes } = useStyles();
1,110✔
107

108
  const toggleConfirm = id => setTimeout(() => setAbort(abort ? null : id), 150);
1,110✔
109

110
  const { created, id, phases } = deployment;
1,110✔
111

112
  let confirmation;
113
  if (abort === id) {
1,110✔
114
    confirmation = <Confirm classes="flexbox centered confirmation-overlay" cancel={() => toggleConfirm(id)} action={() => abortDeployment(id)} type="abort" />;
7✔
115
  }
116
  const started = isEnterprise && phases?.length >= 1 ? phases[0].start_ts || created : created;
1,110✔
117
  const wrappingClass = `text-overflow ${type === DEPLOYMENT_STATES.inprogress ? classes.textWrapping : ''}`;
1,110✔
118
  return (
1,110✔
119
    <div className={`deployment-item ${deploymentTypeClasses[type]}`}>
120
      {!!confirmation && confirmation}
1,117✔
121
      {columnHeaders.map((column, i) => {
122
        const ColumnComponent = column.renderer;
6,736✔
123
        return (
6,736✔
124
          <div className={column.class} key={`deploy-item-${i}`}>
125
            {column.title && <span className="deployment-item-title muted">{column.title}</span>}
13,472✔
126
            <ColumnComponent
127
              className={column.class || ''}
12,362✔
128
              idAttribute={idAttribute}
129
              deployment={deployment}
130
              devicesById={devices}
131
              started={started}
132
              wrappingClass={wrappingClass}
133
              {...column.props}
134
            />
135
          </div>
136
        );
137
      })}
138
      <Button className={classes.detailsButton} variant="contained" onClick={() => openReport(type, deployment.id)}>
1✔
139
        View details
140
      </Button>
141
      {(canDeploy || (canConfigure && deployment.type === DEPLOYMENT_TYPES.configuration)) && type !== DEPLOYMENT_STATES.finished && (
3,251!
142
        <Tooltip className="columnHeader" title="Abort" placement="top-start">
143
          <IconButton onClick={() => toggleConfirm(id)} size="large">
1✔
144
            <CancelOutlinedIcon className="cancelButton muted" />
145
          </IconButton>
146
        </Tooltip>
147
      )}
148
    </div>
149
  );
150
};
151

152
export default DeploymentItem;
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