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

mendersoftware / mender-server / 14628

27 Apr 2026 12:11PM UTC coverage: 48.242% (-29.4%) from 77.64%
14628

push

gitlab-ci

web-flow
Merge pull request #1724 from mineralsfree/upgrade/mui

Upgrade/mui

4089 of 5760 branches covered (70.99%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 8 files covered. (92.86%)

362 existing lines in 43 files now uncovered.

65310 of 138095 relevant lines covered (47.29%)

5.76 hits per line

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

92.29
/frontend/src/js/components/deployments/progress/SubstateProgressBar.tsx
1
// Copyright 2025 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 React, { useEffect, useState } from 'react';
2✔
15

2✔
16
import { CheckCircle, ErrorRounded, Pause } from '@mui/icons-material';
2✔
17
import { Button } from '@mui/material';
2✔
18
import { makeStyles } from 'tss-react/mui';
2✔
19

2✔
20
import Confirm from '@northern.tech/common-ui/Confirm';
2✔
21
import { deploymentDisplayStates, deploymentSubstates, installationSubstatesMap, pauseMap } from '@northern.tech/store/constants';
2✔
22
import type { Deployment } from '@northern.tech/store/deploymentsSlice';
2✔
23
import { getDeploymentState, groupDeploymentStats, statCollector } from '@northern.tech/store/utils';
2✔
24
import pluralize from 'pluralize';
2✔
25

2✔
26
import inprogressImage from '../../../../assets/img/pending_status.png';
2✔
27

2✔
28
const stepTotalWidth = 100 / Object.keys(installationSubstatesMap).length;
2✔
29

2✔
30
export const substateIconMap = {
17✔
31
  finished: { state: 'finished', icon: <CheckCircle fontSize="small" /> },
2✔
32
  inprogress: { state: 'inprogress', icon: <img src={inprogressImage} /> },
17✔
33
  failed: { state: 'failed', icon: <ErrorRounded fontSize="small" /> },
2✔
34
  paused: { state: 'paused', icon: <Pause fontSize="small" /> },
2✔
35
  pendingPause: { state: 'pendingPause', icon: <Pause fontSize="small" color="disabled" /> }
2✔
36
};
2✔
37

2✔
38
const useStyles = makeStyles()(theme => ({
2✔
39
  container: {
2✔
40
    backgroundColor: theme.palette.background.default,
17✔
41
    padding: '10px 20px',
2✔
42
    borderRadius: theme.spacing(0.5),
2✔
43
    alignContent: 'center',
2✔
44
    minHeight: 70,
2✔
45
    '.progress-bar': { height: theme.spacing(0.5) },
2✔
46
    '.progress-chart': { minHeight: 45 },
2✔
47
    '.progress-step': { minHeight: 45 },
2✔
48
    '.progress-step, .progress-step-total': {
2✔
49
      position: 'absolute',
2✔
50
      borderRightStyle: 'none'
2✔
51
    },
2✔
52
    '.progress-step-total .progress-bar': { backgroundColor: theme.palette.grey[50] },
2✔
53
    '.progress-step-number': { alignSelf: 'flex-start', marginTop: theme.spacing(-1) },
2✔
54
    '&.no-background': { background: 'none' },
2✔
55
    '&.stepped-progress .progress-step-total': { marginLeft: '-0.25%', width: '100.5%' },
2✔
56
    '&.stepped-progress .progress-step-total .progress-bar': {
2✔
57
      backgroundColor: theme.palette.background.default,
2✔
58
      border: `1px solid ${theme.palette.grey[800]}`,
2✔
59
      borderRadius: 2,
2✔
60
      height: theme.spacing()
2✔
61
    },
2✔
62
    '&.stepped-progress .progress-step': { minHeight: 20 }
2✔
63
  },
2✔
64
  phaseDelimiter: {
2✔
65
    display: 'grid',
2✔
66
    rowGap: 4,
2✔
67
    placeItems: 'center',
2✔
68
    position: 'absolute',
2✔
69
    gridTemplateRows: '20px 1.25rem min-content',
2✔
70
    top: theme.spacing(1.5),
2✔
71
    zIndex: 2
2✔
72
  },
2✔
73
  active: { borderLeftColor: theme.palette.text.primary },
2✔
74
  borderColor: { borderLeftStyle: 'solid', borderLeftWidth: 1, height: '100%', zIndex: 1 },
2✔
75
  failureIcon: { fontSize: 16, marginRight: 10 },
2✔
76
  inactive: { borderLeftColor: theme.palette.grey[500] },
2✔
77
  phaseInfo: { marginBottom: theme.spacing() }
2✔
78
}));
2✔
79

2✔
80
const shortCircuitIndicators = [deploymentSubstates.alreadyInstalled, deploymentSubstates.noartifact];
2✔
81

2✔
82
interface SubstatePhase {
17✔
83
  failures: number;
2✔
84
  failureWidth: number;
2✔
85
  offset: number;
2✔
86
  status?: string;
2✔
87
  substate: {
2✔
88
    failureIndicators: string[];
2✔
89
    pauseConfigurationIndicator: string;
2✔
90
    pauseIndicator: string;
2✔
91
    successIndicators: string[];
2✔
92
    title: string;
2✔
93
  };
2✔
94
  successes: number;
2✔
95
  successWidth: number;
2✔
96
  width: number;
2✔
97
}
2✔
98

2✔
99
const determineSubstateStatus = (successes: number, failures: number, totalDeviceCount: number, pauseIndicator: boolean, hasPauseDefined: boolean) => {
2✔
100
  let status;
2✔
101
  if (successes === totalDeviceCount) {
17✔
102
    status = substateIconMap.finished.state;
2✔
103
  } else if (failures === totalDeviceCount) {
6!
104
    status = substateIconMap.failed.state;
2✔
105
  } else if (pauseIndicator) {
6!
106
    status = substateIconMap.paused.state;
2✔
107
  } else if (successes || failures) {
6!
108
    status = substateIconMap.inprogress.state;
2✔
109
  } else if (hasPauseDefined) {
6!
110
    status = substateIconMap.pendingPause.state;
2✔
111
  }
6!
UNCOV
112
  return status;
2✔
113
};
2✔
114

6✔
115
export const getDisplayableSubstatePhases = ({ deployment, totalDeviceCount }: { deployment: Deployment; totalDeviceCount: number }): SubstatePhase[] => {
2✔
116
  const { statistics = {}, update_control_map = {} } = deployment;
2✔
117
  const { status: stats = {} } = statistics;
17✔
118
  const currentPauseState = Object.keys(pauseMap)
3✔
119
    .reverse()
3✔
120
    .find(key => stats[key] > 0);
3✔
121
  return Object.values(installationSubstatesMap).reduce(
2✔
122
    (accu, substate, index) => {
5✔
123
      let successes = statCollector(substate.successIndicators, stats);
3✔
124
      let failures = statCollector(substate.failureIndicators, stats);
2✔
125
      if (
6✔
126
        !currentPauseState ||
6✔
127
        index <= Object.keys(pauseMap).indexOf(currentPauseState) ||
6!
128
        (index && accu.displayablePhases[index - 1].failures + accu.displayablePhases[index - 1].successes === totalDeviceCount)
2!
129
      ) {
2✔
130
        failures = accu.displayablePhases[index - 1]?.failures || failures;
2✔
131
        successes = successes + accu.shortCutSuccesses;
2✔
132
      }
6✔
133
      successes = Math.min(totalDeviceCount, successes);
6✔
134
      failures = Math.min(totalDeviceCount - successes, failures);
2✔
135
      const successWidth = (successes / totalDeviceCount) * 100 || 0;
6✔
136
      const failureWidth = (failures / totalDeviceCount) * 100 || 0;
6✔
137
      const { states = {} } = update_control_map;
6✔
138
      const hasPauseDefined = states[substate.pauseConfigurationIndicator]?.action === 'pause';
6✔
139
      const status = determineSubstateStatus(successes, failures, totalDeviceCount, !!stats[substate.pauseIndicator], hasPauseDefined);
6✔
140
      accu.displayablePhases.push({ substate, successes, failures, offset: stepTotalWidth * index, width: stepTotalWidth, successWidth, failureWidth, status });
6✔
141
      return accu;
6✔
142
    },
6✔
143
    { displayablePhases: [] as SubstatePhase[], shortCutSuccesses: statCollector(shortCircuitIndicators, stats) }
6✔
144
  ).displayablePhases;
2✔
145
};
2✔
146

2✔
147
const SubstateHeader = ({ device_count, totalDeviceCount }: { device_count: number; totalDeviceCount: number }) => (
2✔
148
  <>
2✔
149
    Phase 1: {Math.round((device_count / totalDeviceCount || 0) * 100)}% ({device_count} {pluralize('device', device_count)})
17✔
150
  </>
3✔
151
);
2✔
152

2✔
153
const SubstateDelimiter = ({ index, phase }: { index: number; phase: SubstatePhase }) => {
2✔
154
  const { classes } = useStyles();
2✔
155
  const { status } = phase;
17✔
156
  const isActive = status === substateIconMap.inprogress.state;
5✔
157
  const icon = substateIconMap[status as keyof typeof substateIconMap]?.icon;
5✔
158

5✔
159
  const offset = `${stepTotalWidth * (index + 1) - stepTotalWidth / 2}%`;
5✔
160
  return (
2✔
161
    <div className={classes.phaseDelimiter} style={{ left: offset, width: `${stepTotalWidth}%` }}>
5✔
162
      <div className={`${classes.borderColor} ${isActive ? classes.active : classes.inactive}`} />
5✔
163
      {icon ? icon : <div />}
2✔
164
    </div>
2!
165
  );
2!
166
};
2✔
167

2✔
168
const SubstatePhaseLabel = ({ phase }: { phase: SubstatePhase }) => <div className="capitalized progress-step-number">{phase.substate.title}</div>;
2✔
169

2✔
170
const SubstateProgressChart = ({ phases }: { phases: SubstatePhase[] }) => (
17✔
171
  <div className="flexbox relative margin-top-small">
2✔
172
    {phases.map((phase, index) => (
17✔
173
      <React.Fragment key={`substate-phase-${index}`}>
3✔
174
        <div className="progress-step" style={{ left: `${phase.offset}%`, width: `${phase.width}%` }}>
2✔
175
          <SubstatePhaseLabel phase={phase} />
6✔
176
          <div style={{ display: 'contents' }}>
2✔
177
            <div className="progress-bar green" style={{ width: `${phase.successWidth}%` }} />
2✔
178
            <div className="progress-bar warning" style={{ left: `${phase.successWidth}%`, width: `${phase.failureWidth}%` }} />
2✔
179
          </div>
2✔
180
        </div>
2✔
181
        {index !== phases.length - 1 && <SubstateDelimiter index={index} phase={phase} />}
2✔
182
      </React.Fragment>
2✔
183
    ))}
2✔
184
    <div className="progress-step relative flexbox progress-step-total">
2✔
185
      <div className="progress-bar" />
2✔
186
    </div>
2✔
187
  </div>
2✔
188
);
2✔
189

2✔
190
const confirmationStyle = {
2✔
191
  justifyContent: 'flex-start',
2✔
192
  paddingLeft: 100
17✔
193
};
2✔
194

2✔
195
interface SubstateProgressBarProps {
2✔
196
  className?: string;
2✔
197
  deployment: Deployment;
2✔
198
  onAbort: (id: string) => void;
2✔
199
  onUpdateControlChange: (update: { states: Record<string, { action: string }> }) => void;
2✔
200
}
2✔
201

2✔
202
export const SubstateProgressBar = ({ className = '', deployment, onAbort, onUpdateControlChange }: SubstateProgressBarProps) => {
2✔
203
  const { classes } = useStyles();
2✔
204
  const [shouldContinue, setShouldContinue] = useState(false);
17✔
205
  const [shouldAbort, setShouldAbort] = useState(false);
3✔
206
  const [isLoading, setIsLoading] = useState(false);
3✔
207

3✔
208
  const { id, device_count, max_devices, statistics = {}, update_control_map = {} } = deployment;
3✔
209
  const { status: stats = {} } = statistics;
2✔
210
  const { states = {} } = update_control_map;
3✔
211
  const { failures: totalFailureCount, paused: totalPausedCount } = groupDeploymentStats(deployment);
3✔
212
  const totalDeviceCount = Math.max(device_count, max_devices);
3✔
213

3✔
214
  const status = getDeploymentState(deployment);
3✔
215
  const currentPauseState = Object.keys(pauseMap)
2✔
216
    .reverse()
3✔
217
    .find(key => stats[key] > 0);
3✔
218

2✔
219
  useEffect(() => {
5✔
220
    if (!isLoading) {
2✔
221
      return;
3✔
222
    }
3!
223
    setIsLoading(false);
3✔
224
  }, [isLoading, status]);
2✔
UNCOV
225

2✔
226
  const onAbortClick = () => {
2✔
227
    setShouldAbort(false);
2✔
228
    onAbort(id);
3✔
UNCOV
229
  };
2✔
UNCOV
230

2✔
231
  const onContinueClick = () => {
2✔
232
    if (!currentPauseState || !pauseMap[currentPauseState]) {
2✔
233
      return;
3✔
UNCOV
234
    }
2!
235
    setIsLoading(true);
2✔
236
    setShouldContinue(false);
2✔
237
    onUpdateControlChange({ states: { [pauseMap[currentPauseState as keyof typeof pauseMap].followUp]: { action: 'continue' } } });
2✔
UNCOV
238
  };
2✔
UNCOV
239

2✔
240
  const displayablePhases = getDisplayableSubstatePhases({ deployment, totalDeviceCount });
2✔
241

2✔
242
  const isPaused = status === deploymentDisplayStates.paused;
3✔
243
  const canContinue = isPaused && currentPauseState && states[pauseMap[currentPauseState as keyof typeof pauseMap].followUp];
2✔
244
  const disableContinuationButtons =
3✔
245
    isLoading || (canContinue && currentPauseState && states[pauseMap[currentPauseState as keyof typeof pauseMap].followUp]?.action !== 'pause');
3!
246

2✔
247
  return (
3!
248
    <div className={`flexbox column ${className}`}>
2✔
249
      <div className={`relative flexbox column ${classes.container}`}>
3✔
250
        <SubstateHeader device_count={device_count} totalDeviceCount={totalDeviceCount} />
2✔
251
        <SubstateProgressChart phases={displayablePhases} />
2✔
252
      </div>
2✔
253
      <div className="margin-top">
2✔
254
        Deployment is <span className="uppercased">{status}</span> with {totalFailureCount} {pluralize('failure', totalFailureCount)}
2✔
255
        {isPaused && !canContinue && ` - waiting for an action on the ${pluralize('device', totalPausedCount)} to continue`}
2✔
256
      </div>
2✔
257
      {canContinue && (
2!
258
        <div className="margin-top margin-bottom relative">
2✔
259
          {shouldContinue && (
2!
260
            <Confirm
2✔
261
              type="deploymentContinuation"
2!
262
              classes="confirmation-overlay"
2✔
263
              action={onContinueClick}
2✔
264
              cancel={() => setShouldContinue(false)}
2✔
265
              style={confirmationStyle}
2✔
UNCOV
266
            />
2✔
267
          )}
2✔
268
          {shouldAbort && (
2✔
269
            <Confirm
2✔
270
              type="deploymentAbort"
2!
271
              classes="confirmation-overlay"
2✔
272
              action={onAbortClick}
2✔
273
              cancel={() => setShouldAbort(false)}
2✔
274
              style={confirmationStyle}
2✔
UNCOV
275
            />
2✔
276
          )}
2✔
277
          <Button disabled={disableContinuationButtons} onClick={() => setShouldContinue(true)} variant="contained" className="margin-right">
2✔
278
            Continue
2✔
UNCOV
279
          </Button>
2✔
280
          <Button disabled={disableContinuationButtons} onClick={() => setShouldAbort(true)}>
2✔
281
            Abort
2✔
UNCOV
282
          </Button>
2✔
283
        </div>
2✔
284
      )}
2✔
285
    </div>
2✔
286
  );
2✔
287
};
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

© 2026 Coveralls, Inc