• 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

97.79
/frontend/src/js/components/deployments/PastDeployments.tsx
1
// Copyright 2015 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
import { useSelector } from 'react-redux';
2✔
16

2✔
17
// material ui
2✔
18
import { TextField } from '@mui/material';
2✔
19

2✔
20
import { ControlledAutoComplete } from '@northern.tech/common-ui/forms/Autocomplete';
2✔
21
import Filters from '@northern.tech/common-ui/forms/Filters';
2✔
22
import TimeframePicker from '@northern.tech/common-ui/forms/TimeframePicker';
2✔
23
import storeActions from '@northern.tech/store/actions';
2✔
24
import { BEGINNING_OF_TIME, DEPLOYMENT_STATES, DEPLOYMENT_TYPES, onboardingSteps } from '@northern.tech/store/constants';
2✔
25
import {
2✔
26
  getDeploymentsSelectionState,
2✔
27
  getDevicesById,
2✔
28
  getGroupNames,
2✔
29
  getIdAttribute,
2✔
30
  getMappedDeploymentSelection,
2✔
31
  getOnboardingState,
2✔
32
  getUserCapabilities
2✔
33
} from '@northern.tech/store/selectors';
2✔
34
import { useAppDispatch } from '@northern.tech/store/store';
2✔
35
import { advanceOnboarding, getDeploymentsByStatus, setDeploymentsState } from '@northern.tech/store/thunks';
2✔
36
import { dateRangeToUnix, getISOStringBoundaries } from '@northern.tech/utils/helpers';
2✔
37
import { useWindowSize } from '@northern.tech/utils/resizehook';
2✔
38
import { clearAllRetryTimers, clearRetryTimer, setRetryTimer } from '@northern.tech/utils/retrytimer';
2✔
39
import dayjs from 'dayjs';
2✔
40
import utc from 'dayjs/plugin/utc';
2✔
41

2✔
42
import historyImage from '../../../assets/img/history.png';
2✔
43
import { getOnboardingComponentFor } from '../../utils/onboardingManager';
2✔
44
import { DeploymentSize, DeploymentStatus } from './DeploymentItem';
2✔
45
import DeploymentsList, { defaultHeaders } from './DeploymentsList';
2✔
46
import { defaultRefreshDeploymentsLength as refreshDeploymentsLength } from './constants';
2✔
47

2✔
48
dayjs.extend(utc);
7✔
49

2✔
50
const { setSnackbar } = storeActions;
7✔
51

2✔
52
const headers = [
7✔
53
  ...defaultHeaders.slice(0, defaultHeaders.length - 1),
2✔
54
  { title: 'Status', renderer: DeploymentStatus },
2✔
55
  { title: 'Data downloaded', renderer: DeploymentSize }
2✔
56
];
2✔
57

2✔
58
const type = DEPLOYMENT_STATES.finished;
7✔
59

2✔
60
export const Past = props => {
7✔
61
  const { createClick, isShowingDetails } = props;
86✔
62
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2✔
63
  const size = useWindowSize();
86✔
64
  const [tonight] = useState(getISOStringBoundaries(new Date()).end);
86✔
65
  const [loading, setLoading] = useState(false);
86✔
66
  const deploymentsRef = useRef();
86✔
67
  const timer = useRef();
86✔
68

2✔
69
  const dispatch = useAppDispatch();
86✔
70
  const dispatchedSetSnackbar = useCallback((...args) => dispatch(setSnackbar(...args)), [dispatch]);
86✔
71

2✔
72
  const { finished: pastSelectionState } = useSelector(getDeploymentsSelectionState);
86✔
73
  const past = useSelector(state => getMappedDeploymentSelection(state, type));
221✔
74
  const { canConfigure, canDeploy } = useSelector(getUserCapabilities);
86✔
75
  const idAttribute = useSelector(getIdAttribute);
86✔
76
  const onboardingState = useSelector(getOnboardingState);
86✔
77
  const devices = useSelector(getDevicesById);
86✔
78
  const groupNames = useSelector(getGroupNames);
86✔
79

2✔
80
  const { endDate, page, perPage, search: deviceGroup, startDate, total: count, type: deploymentType } = pastSelectionState;
86✔
81

2✔
82
  /*
2✔
83
  / refresh only finished deployments
2✔
84
  /
2✔
85
  */
2✔
86
  const refreshPast = useCallback(
86✔
87
    (
2✔
88
      currentPage = page,
2✔
89
      currentPerPage = perPage,
2✔
90
      currentStartDate = startDate,
2✔
91
      currentEndDate = endDate,
2✔
92
      currentDeviceGroup = deviceGroup,
2✔
93
      currentType = deploymentType
2✔
94
    ) => {
2✔
95
      const { start: roundedStartDate, end: roundedEndDate } = dateRangeToUnix(currentStartDate, currentEndDate);
5✔
96
      setLoading(true);
5✔
97
      return dispatch(
5✔
98
        getDeploymentsByStatus({
2✔
99
          status: type,
2✔
100
          page: currentPage,
2✔
101
          perPage: currentPerPage,
2✔
102
          startDate: roundedStartDate,
2✔
103
          endDate: roundedEndDate,
2✔
104
          group: currentDeviceGroup,
2✔
105
          type: currentType
2✔
106
        })
2✔
107
      )
2✔
108
        .then(({ payload }) => {
2✔
109
          setLoading(false);
5✔
110
          clearRetryTimer(type, dispatchedSetSnackbar);
5✔
111
          const { total, deploymentIds } = payload[payload.length - 1];
5✔
112
          if (total && !deploymentIds.length) {
5!
113
            // TODO: check if https://github.com/facebook/react/issues/34888 gets addressed and adjust
2✔
114
            // eslint-disable-next-line react-hooks/immutability
2✔
115
            return refreshPast(currentPage, currentPerPage, currentStartDate, currentEndDate, currentDeviceGroup);
2✔
116
          }
2✔
117
        })
2✔
118
        .catch(err => setRetryTimer(err, 'deployments', `Couldn't load deployments.`, refreshDeploymentsLength, dispatchedSetSnackbar));
2✔
119
    },
2✔
120
    [deploymentType, deviceGroup, dispatch, dispatchedSetSnackbar, endDate, page, perPage, startDate]
2✔
121
  );
2✔
122

2✔
123
  useEffect(() => {
86✔
124
    const { start: roundedStartDate, end: roundedEndDate } = dateRangeToUnix(startDate || BEGINNING_OF_TIME, endDate);
8✔
125
    setLoading(true);
8✔
126
    dispatch(
8✔
127
      getDeploymentsByStatus({ status: type, page, perPage, startDate: roundedStartDate, endDate: roundedEndDate, group: deviceGroup, type: deploymentType })
2✔
128
    )
2✔
129
      .unwrap()
2✔
130
      .then(deploymentsAction => {
2✔
131
        const deploymentsList = deploymentsAction ? Object.values(deploymentsAction[0].payload) : [];
8!
132
        if (deploymentsList.length) {
8!
133
          const newStartDate = new Date(deploymentsList[deploymentsList.length - 1].created);
8✔
134
          const { start } = getISOStringBoundaries(newStartDate);
8✔
135
          dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { startDate: startDate || start } }));
8✔
136
        }
2✔
137
      })
2✔
138
      .finally(() => setLoading(false));
8✔
139
    return () => {
8✔
140
      clearAllRetryTimers(dispatchedSetSnackbar);
8✔
141
    };
2✔
142
  }, [deploymentType, deviceGroup, dispatch, dispatchedSetSnackbar, endDate, page, perPage, startDate]);
2✔
143

2✔
144
  useEffect(() => {
86✔
145
    clearInterval(timer.current);
8✔
146
    timer.current = setInterval(refreshPast, refreshDeploymentsLength);
8✔
147
    // refreshPast();
2✔
148
    return () => {
8✔
149
      clearInterval(timer.current);
8✔
150
    };
2✔
151
  }, [page, perPage, startDate, endDate, deviceGroup, deploymentType, refreshPast]);
2✔
152

2✔
153
  useEffect(() => {
86✔
154
    if (!past.length || onboardingState.complete) {
29✔
155
      return;
5✔
156
    }
2✔
157
    const pastDeploymentsFailed = past.reduce(
26✔
158
      (accu, item) =>
2✔
159
        item.status === 'failed' ||
64✔
160
        (item.statistics?.status &&
2✔
161
          item.statistics.status.noartifact + item.statistics.status.failure + item.statistics.status['already-installed'] + item.statistics.status.aborted >
2✔
162
            0) ||
2✔
163
        accu,
2✔
164
      false
2✔
165
    );
2✔
166
    let onboardingStep = onboardingSteps.DEPLOYMENTS_PAST;
26✔
167
    if (pastDeploymentsFailed) {
26!
168
      onboardingStep = onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_FAILURE;
2✔
169
    }
2✔
170
    dispatch(advanceOnboarding(onboardingStep));
26✔
171
  }, [dispatch, onboardingState.complete, past]);
2✔
172

2✔
173
  let onboardingComponent = null;
86✔
174
  if (deploymentsRef.current) {
86✔
175
    const detailsButtons = deploymentsRef.current.getElementsByClassName('MuiButton-contained');
78✔
176
    const left = detailsButtons.length
78!
177
      ? deploymentsRef.current.offsetLeft + detailsButtons[0].offsetLeft + detailsButtons[0].offsetWidth / 2 + 15
2✔
178
      : deploymentsRef.current.offsetWidth;
2✔
179
    const anchor = { left: deploymentsRef.current.offsetWidth / 2, top: deploymentsRef.current.offsetTop };
78✔
180
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED, onboardingState, {
78✔
181
      anchor,
2✔
182
      setSnackbar: dispatchedSetSnackbar
2✔
183
    });
2✔
184
    onboardingComponent = getOnboardingComponentFor(
78✔
185
      onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_FAILURE,
2✔
186
      onboardingState,
2✔
187
      { anchor: { left, top: detailsButtons[0].parentElement.offsetTop + detailsButtons[0].parentElement.offsetHeight } },
2✔
188
      onboardingComponent
2✔
189
    );
2✔
190
  }
2✔
191

2✔
192
  const onFiltersChange = useCallback(
86✔
193
    ({ endDate, group, startDate, type }) =>
2✔
194
      dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, search: group, type, startDate, endDate } })),
6✔
195
    [dispatch]
2✔
196
  );
2✔
197

2✔
198
  const autoCompleteProps = { autoHighlight: true, autoSelect: true, filterSelectedOptions: true, freeSolo: true, handleHomeEndKeys: true };
86✔
199
  return (
86✔
200
    <div className="fadeIn margin-left margin-top-large">
2✔
201
      <Filters
2✔
202
        initialValues={{ startDate, endDate, group: deviceGroup, type: deploymentType }}
2✔
203
        defaultValues={{ startDate: '', endDate: tonight, group: '', type: '' }}
2✔
204
        filters={[
2✔
205
          {
2✔
206
            key: 'group',
2✔
207
            title: 'Device group',
2✔
208
            Component: ControlledAutoComplete,
2✔
209
            componentProps: {
2✔
210
              ...autoCompleteProps,
2✔
211
              options: groupNames,
2✔
212
              renderInput: params => <TextField {...params} label="Target devices" placeholder="Select a group" InputProps={{ ...params.InputProps }} />
85✔
213
            }
2✔
214
          },
2✔
215
          {
2✔
216
            key: 'type',
2✔
217
            title: 'Contains Artifact type',
2✔
218
            Component: ControlledAutoComplete,
2✔
219
            componentProps: {
2✔
220
              ...autoCompleteProps,
2✔
221
              options: Object.keys(DEPLOYMENT_TYPES),
2✔
222
              renderInput: params => <TextField {...params} label="Deployment type" placeholder="Select a type" InputProps={{ ...params.InputProps }} />
85✔
223
            }
2✔
224
          },
2✔
225
          {
2✔
226
            key: 'timeframe',
2✔
227
            title: 'Start time',
2✔
228
            Component: TimeframePicker,
2✔
229
            componentProps: {
2✔
230
              tonight
2✔
231
            }
2✔
232
          }
2✔
233
        ]}
2✔
234
        onChange={onFiltersChange}
2✔
235
      />
2✔
236
      <div className="deploy-table-contain">
2✔
237
        {/* TODO: fix status retrieval for past deployments to decide what to show here - */}
2✔
238
        {!loading && !!past.length && !!onboardingComponent && !isShowingDetails && onboardingComponent}
2!
239
        {!!past.length && (
2✔
240
          <DeploymentsList
2✔
241
            {...props}
2✔
242
            canConfigure={canConfigure}
2✔
243
            canDeploy={canDeploy}
2✔
244
            componentClass="margin-left-small"
2✔
245
            count={count}
2✔
246
            devices={devices}
2✔
247
            headers={headers}
2✔
248
            idAttribute={idAttribute}
2✔
249
            items={past}
2✔
250
            loading={loading}
2✔
UNCOV
251
            onChangePage={page => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page } }))}
2✔
UNCOV
252
            onChangeRowsPerPage={perPage => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, perPage } }))}
2✔
253
            page={page}
2✔
254
            pageSize={perPage}
2✔
255
            rootRef={deploymentsRef}
2✔
256
            showPagination
2✔
257
            type={type}
2✔
258
          />
2✔
259
        )}
2✔
260
        {!(loading || past.length) && (
2✔
261
          <div className="dashboard-placeholder">
2✔
262
            <p>No finished deployments were found.</p>
2✔
263
            <p>
2✔
264
              Try adjusting the filters, or <a onClick={createClick}>Create a new deployment</a> to get started
2✔
265
            </p>
2✔
266
            <img src={historyImage} alt="Past" />
2✔
267
          </div>
2✔
268
        )}
2✔
269
      </div>
2✔
270
    </div>
2✔
271
  );
2✔
272
};
2✔
273

2✔
274
export default Past;
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