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

mendersoftware / gui / 991356850

04 Sep 2023 11:31AM UTC coverage: 82.394% (-17.6%) from 99.964%
991356850

Pull #4017

gitlab-ci

web-flow
chore: Bump @stripe/stripe-js from 1.54.2 to 2.1.1

Bumps [@stripe/stripe-js](https://github.com/stripe/stripe-js) from 1.54.2 to 2.1.1.
- [Release notes](https://github.com/stripe/stripe-js/releases)
- [Commits](https://github.com/stripe/stripe-js/compare/v1.54.2...v2.1.1)

---
updated-dependencies:
- dependency-name: "@stripe/stripe-js"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4017: chore: Bump @stripe/stripe-js from 1.54.2 to 2.1.1

4347 of 6321 branches covered (0.0%)

8260 of 10025 relevant lines covered (82.39%)

193.25 hits per line

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

87.36
/src/js/components/deployments/pastdeployments.js
1
// Copyright 2015 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, { useCallback, useEffect, useRef, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Autocomplete, TextField } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import historyImage from '../../../assets/img/history.png';
22
import { setSnackbar } from '../../actions/appActions';
23
import { getDeploymentsByStatus, setDeploymentsState } from '../../actions/deploymentActions';
24
import { advanceOnboarding } from '../../actions/onboardingActions';
25
import { BEGINNING_OF_TIME, SORTING_OPTIONS, TIMEOUTS } from '../../constants/appConstants';
26
import { DEPLOYMENT_STATES, DEPLOYMENT_TYPES } from '../../constants/deploymentConstants';
27
import { onboardingSteps } from '../../constants/onboardingConstants';
28
import { getISOStringBoundaries } from '../../helpers';
29
import {
30
  getDeploymentsSelectionState,
31
  getDevicesById,
32
  getGroupNames,
33
  getIdAttribute,
34
  getMappedDeploymentSelection,
35
  getOnboardingState,
36
  getUserCapabilities
37
} from '../../selectors';
38
import { useDebounce } from '../../utils/debouncehook';
39
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
40
import useWindowSize from '../../utils/resizehook';
41
import { clearAllRetryTimers, clearRetryTimer, setRetryTimer } from '../../utils/retrytimer';
42
import TimeframePicker from '../common/timeframe-picker';
43
import TimerangePicker from '../common/timerange-picker';
44
import { DeploymentSize, DeploymentStatus } from './deploymentitem';
45
import { defaultRefreshDeploymentsLength as refreshDeploymentsLength } from './deployments';
46
import DeploymentsList, { defaultHeaders } from './deploymentslist';
47

48
const headers = [
7✔
49
  ...defaultHeaders.slice(0, defaultHeaders.length - 1),
50
  { title: 'Status', renderer: DeploymentStatus },
51
  { title: 'Data downloaded', renderer: DeploymentSize }
52
];
53

54
const type = DEPLOYMENT_STATES.finished;
7✔
55

56
const useStyles = makeStyles()(theme => ({
7✔
57
  datepickerContainer: {
58
    backgroundColor: theme.palette.background.lightgrey
59
  }
60
}));
61

62
export const Past = props => {
7✔
63
  const { createClick, isShowingDetails } = props;
76✔
64
  // eslint-disable-next-line no-unused-vars
65
  const size = useWindowSize();
75✔
66
  const [tonight] = useState(getISOStringBoundaries(new Date()).end);
75✔
67
  const [loading, setLoading] = useState(false);
75✔
68
  const deploymentsRef = useRef();
75✔
69
  const timer = useRef();
75✔
70
  const [searchValue, setSearchValue] = useState('');
75✔
71
  const [typeValue, setTypeValue] = useState('');
75✔
72
  const { classes } = useStyles();
75✔
73

74
  const dispatch = useDispatch();
75✔
75
  const dispatchedSetSnackbar = useCallback((...args) => dispatch(setSnackbar(...args)), [dispatch]);
75✔
76

77
  const { finished: pastSelectionState } = useSelector(getDeploymentsSelectionState);
75✔
78
  const past = useSelector(state => getMappedDeploymentSelection(state, type));
139✔
79
  const { canConfigure, canDeploy } = useSelector(getUserCapabilities);
75✔
80
  const { attribute: idAttribute } = useSelector(getIdAttribute);
75✔
81
  const onboardingState = useSelector(getOnboardingState);
75✔
82
  const devices = useSelector(getDevicesById);
75✔
83
  const groupNames = useSelector(getGroupNames);
75✔
84

85
  const debouncedSearch = useDebounce(searchValue, TIMEOUTS.debounceDefault);
75✔
86
  const debouncedType = useDebounce(typeValue, TIMEOUTS.debounceDefault);
75✔
87

88
  const { endDate, page, perPage, search: deviceGroup, startDate, total: count, type: deploymentType } = pastSelectionState;
75✔
89

90
  /*
91
  / refresh only finished deployments
92
  /
93
  */
94
  const refreshPast = useCallback(
75✔
95
    (
96
      currentPage = page,
4✔
97
      currentPerPage = perPage,
4✔
98
      currentStartDate = startDate,
4✔
99
      currentEndDate = endDate,
4✔
100
      currentDeviceGroup = deviceGroup,
4✔
101
      currentType = deploymentType
4✔
102
    ) => {
103
      const roundedStartDate = Math.round(Date.parse(currentStartDate) / 1000);
4✔
104
      const roundedEndDate = Math.round(Date.parse(currentEndDate) / 1000);
4✔
105
      setLoading(true);
4✔
106
      return dispatch(getDeploymentsByStatus(type, currentPage, currentPerPage, roundedStartDate, roundedEndDate, currentDeviceGroup, currentType))
4✔
107
        .then(deploymentsAction => {
108
          setLoading(false);
3✔
109
          clearRetryTimer(type, dispatchedSetSnackbar);
3✔
110
          const { total, deploymentIds } = deploymentsAction[deploymentsAction.length - 1];
3✔
111
          if (total && !deploymentIds.length) {
3!
112
            return refreshPast(currentPage, currentPerPage, currentStartDate, currentEndDate, currentDeviceGroup);
×
113
          }
114
        })
115
        .catch(err => setRetryTimer(err, 'deployments', `Couldn't load deployments.`, refreshDeploymentsLength, dispatchedSetSnackbar));
×
116
    },
117
    [deploymentType, deviceGroup, dispatch, dispatchedSetSnackbar, endDate, page, perPage, startDate]
118
  );
119

120
  useEffect(() => {
75✔
121
    const roundedStartDate = Math.round(Date.parse(startDate || BEGINNING_OF_TIME) / 1000);
4✔
122
    const roundedEndDate = Math.round(Date.parse(endDate) / 1000);
4✔
123
    setLoading(true);
4✔
124
    dispatch(getDeploymentsByStatus(type, page, perPage, roundedStartDate, roundedEndDate, deviceGroup, deploymentType, true, SORTING_OPTIONS.desc))
4✔
125
      .then(deploymentsAction => {
126
        const deploymentsList = deploymentsAction ? Object.values(deploymentsAction[0].deployments) : [];
3!
127
        if (deploymentsList.length) {
3!
128
          let newStartDate = new Date(deploymentsList[deploymentsList.length - 1].created);
3✔
129
          const { start: startDate } = getISOStringBoundaries(newStartDate);
3✔
130
          dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { startDate } }));
3✔
131
        }
132
      })
133
      .finally(() => setLoading(false));
3✔
134
    return () => {
4✔
135
      clearAllRetryTimers(dispatchedSetSnackbar);
4✔
136
    };
137
  }, [deploymentType, deviceGroup, dispatch, dispatchedSetSnackbar, endDate, page, perPage, startDate]);
138

139
  useEffect(() => {
75✔
140
    clearInterval(timer.current);
4✔
141
    timer.current = setInterval(refreshPast, refreshDeploymentsLength);
4✔
142
    refreshPast();
4✔
143
    return () => {
4✔
144
      clearInterval(timer.current);
4✔
145
    };
146
  }, [page, perPage, startDate, endDate, deviceGroup, deploymentType, refreshPast]);
147

148
  useEffect(() => {
75✔
149
    if (!past.length || onboardingState.complete) {
30✔
150
      return;
14✔
151
    }
152
    const pastDeploymentsFailed = past.reduce(
16✔
153
      (accu, item) =>
154
        item.status === 'failed' ||
28✔
155
        (item.statistics?.status &&
156
          item.statistics.status.noartifact + item.statistics.status.failure + item.statistics.status['already-installed'] + item.statistics.status.aborted >
157
            0) ||
158
        accu,
159
      false
160
    );
161
    let onboardingStep = onboardingSteps.DEPLOYMENTS_PAST;
16✔
162
    if (pastDeploymentsFailed) {
16!
163
      onboardingStep = onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_FAILURE;
×
164
    }
165
    dispatch(advanceOnboarding(onboardingStep));
16✔
166
  }, [dispatch, onboardingState.complete, past]);
167

168
  useEffect(() => {
75✔
169
    dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, search: debouncedSearch, type: debouncedType } }));
3✔
170
  }, [debouncedSearch, debouncedType, dispatch]);
171

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

191
  const onGroupFilterChange = (e, value) => {
75✔
192
    if (!e) {
×
193
      return;
×
194
    }
195
    setSearchValue(value);
×
196
  };
197

198
  const onTypeFilterChange = (e, value) => {
75✔
199
    if (!e) {
×
200
      return;
×
201
    }
202
    setTypeValue(value);
×
203
  };
204

205
  const onTimeFilterChange = (startDate, endDate) => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, startDate, endDate } }));
75✔
206

207
  return (
75✔
208
    <div className="fadeIn margin-left margin-top-large">
209
      <div className={`datepicker-container ${classes.datepickerContainer}`}>
210
        <TimerangePicker endDate={endDate} onChange={onTimeFilterChange} startDate={startDate} />
211
        <TimeframePicker onChange={onTimeFilterChange} endDate={endDate} startDate={startDate} tonight={tonight} />
212
        <Autocomplete
213
          id="device-group-selection"
214
          autoHighlight
215
          autoSelect
216
          filterSelectedOptions
217
          freeSolo
218
          handleHomeEndKeys
219
          inputValue={deviceGroup}
220
          options={groupNames}
221
          onInputChange={onGroupFilterChange}
222
          renderInput={params => (
223
            <TextField {...params} label="Filter by device group" placeholder="Select a group" InputProps={{ ...params.InputProps }} style={{ marginTop: 0 }} />
73✔
224
          )}
225
        />
226
        <Autocomplete
227
          id="deployment-type-selection"
228
          autoHighlight
229
          autoSelect
230
          filterSelectedOptions
231
          handleHomeEndKeys
232
          classes={{ input: deploymentType ? 'capitalized' : '', option: 'capitalized' }}
75!
233
          inputValue={deploymentType}
234
          onInputChange={onTypeFilterChange}
235
          options={Object.keys(DEPLOYMENT_TYPES)}
236
          renderInput={params => (
237
            <TextField {...params} label="Filter by type" placeholder="Select a type" InputProps={{ ...params.InputProps }} style={{ marginTop: 0 }} />
73✔
238
          )}
239
        />
240
      </div>
241
      <div className="deploy-table-contain">
242
        {/* TODO: fix status retrieval for past deployments to decide what to show here - */}
243
        {!loading && !!past.length && !!onboardingComponent && !isShowingDetails && onboardingComponent}
148!
244
        {!!past.length && (
120✔
245
          <DeploymentsList
246
            {...props}
247
            canConfigure={canConfigure}
248
            canDeploy={canDeploy}
249
            componentClass="margin-left-small"
250
            count={count}
251
            devices={devices}
252
            headers={headers}
253
            idAttribute={idAttribute}
254
            items={past}
255
            loading={loading}
256
            onChangePage={page => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page } }))}
×
257
            onChangeRowsPerPage={perPage => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, perPage } }))}
×
258
            page={page}
259
            pageSize={perPage}
260
            rootRef={deploymentsRef}
261
            showPagination
262
            type={type}
263
          />
264
        )}
265
        {!(loading || past.length) && (
188✔
266
          <div className="dashboard-placeholder">
267
            <p>No finished deployments were found.</p>
268
            <p>
269
              Try adjusting the filters, or <a onClick={createClick}>Create a new deployment</a> to get started
270
            </p>
271
            <img src={historyImage} alt="Past" />
272
          </div>
273
        )}
274
      </div>
275
    </div>
276
  );
277
};
278

279
export default Past;
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