• 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.44
/frontend/src/js/components/releases/ReleaseDetails.tsx
1
// Copyright 2019 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, useMemo, useRef, useState } from 'react';
2✔
15
import { FormProvider, useForm } from 'react-hook-form';
2✔
16
import { useDispatch, useSelector } from 'react-redux';
2✔
17
import { useNavigate } from 'react-router-dom';
2✔
18

2✔
19
// material ui
2✔
20
import {
2✔
21
  HighlightOffOutlined as HighlightOffOutlinedIcon,
2✔
22
  LabelOutlined as LabelOutlinedIcon,
2✔
23
  Replay as ReplayIcon,
2✔
24
  Sort as SortIcon
2✔
25
} from '@mui/icons-material';
2✔
26
import { Button, ClickAwayListener, DialogActions, DialogContent, Divider, Drawer, SpeedDial, SpeedDialAction, SpeedDialIcon, Tooltip } from '@mui/material';
2✔
27
import { speedDialActionClasses } from '@mui/material/SpeedDialAction';
2✔
28
import { makeStyles } from 'tss-react/mui';
2✔
29

2✔
30
import ChipSelect from '@northern.tech/common-ui/ChipSelect';
2✔
31
import { ConfirmationButtons, EditButton } from '@northern.tech/common-ui/Confirm';
2✔
32
import { DrawerTitle } from '@northern.tech/common-ui/DrawerTitle';
2✔
33
import { EditableLongText } from '@northern.tech/common-ui/EditableLongText';
2✔
34
import FileSize from '@northern.tech/common-ui/FileSize';
2✔
35
import { RelativeTime } from '@northern.tech/common-ui/Time';
2✔
36
import { BaseDialog } from '@northern.tech/common-ui/dialogs/BaseDialog';
2✔
37
import storeActions from '@northern.tech/store/actions';
2✔
38
import { DEPLOYMENT_ROUTES } from '@northern.tech/store/constants';
2✔
39
import { generateReleasesPath } from '@northern.tech/store/locationutils';
2✔
40
import { getReleaseListState, getReleaseTags, getSelectedRelease, getUserCapabilities } from '@northern.tech/store/selectors';
2✔
41
import { removeArtifact, removeRelease, selectRelease, setReleaseTags, updateReleaseInfo } from '@northern.tech/store/thunks';
2✔
42
import { customSort, formatTime, isEmpty, toggle } from '@northern.tech/utils/helpers';
2✔
43
import { useWindowSize } from '@northern.tech/utils/resizehook';
2✔
44
import copy from 'copy-to-clipboard';
2✔
45
import pluralize from 'pluralize';
2✔
46

2✔
47
import { HELPTOOLTIPS } from '../helptips/HelpTooltips';
2✔
48
import { MenderHelpTooltip } from '../helptips/MenderTooltip';
2✔
49
import Artifact from './Artifact';
2✔
50
import RemoveArtifactDialog from './dialogs/RemoveArtifact';
2✔
51

2✔
52
const { setSnackbar } = storeActions;
9✔
53

2✔
54
const DeviceTypeCompatibility = ({ artifact }) => {
9✔
55
  const compatible = artifact.artifact_depends ? artifact.artifact_depends.device_type.join(', ') : artifact.device_types_compatible.join(', ');
22✔
56
  return (
22✔
57
    <Tooltip title={compatible} placement="top-start">
2✔
58
      <div className="text-overflow">{compatible}</div>
2✔
59
    </Tooltip>
2✔
60
  );
2✔
61
};
2✔
62

2✔
63
export const columns = [
9✔
64
  {
2✔
65
    title: 'Device type compatibility',
2✔
66
    name: 'device_types',
2✔
67
    sortable: false,
2✔
68
    render: DeviceTypeCompatibility,
2✔
69
    tooltip: <MenderHelpTooltip id={HELPTOOLTIPS.expandArtifact.id} className="margin-left-small" />
2✔
70
  },
2✔
71
  {
2✔
72
    title: 'Type',
2✔
73
    name: 'type',
2✔
74
    sortable: false,
2✔
75
    render: ({ artifact }) => <div style={{ maxWidth: '100vw' }}>{artifact.updates.reduce((accu, item) => (accu ? accu : item.type_info.type), '')}</div>
22!
76
  },
2✔
77
  { title: 'Size', name: 'size', sortable: true, render: ({ artifact }) => <FileSize fileSize={artifact.size} /> },
22✔
78
  { title: 'Last modified', name: 'modified', sortable: true, render: ({ artifact }) => <RelativeTime updateTime={formatTime(artifact.modified)} /> }
22✔
79
];
2✔
80

2✔
81
const defaultActions = [
9✔
82
  {
2✔
UNCOV
83
    action: ({ onCreateDeployment, selection }) => onCreateDeployment(selection),
2✔
84
    icon: <ReplayIcon />,
2✔
85
    isApplicable: ({ userCapabilities: { canDeploy }, selectedSingleRelease, selectedRows }) =>
2✔
86
      canDeploy && (selectedSingleRelease || selectedRows.length === 1),
9✔
87
    key: 'deploy',
2✔
88
    title: () => 'Create a deployment for this release'
19✔
89
  },
2✔
90
  {
2✔
UNCOV
91
    action: ({ onTagRelease, selection }) => onTagRelease(selection),
2✔
92
    icon: <LabelOutlinedIcon />,
2✔
93
    isApplicable: ({ userCapabilities: { canManageReleases }, selectedSingleRelease }) => canManageReleases && !selectedSingleRelease,
9✔
94
    key: 'tag',
2✔
95
    title: pluralized => `Tag ${pluralized}`
9✔
96
  },
2✔
97
  {
2✔
98
    action: ({ onDeleteRelease, selection }) => onDeleteRelease(selection),
3✔
99
    icon: <HighlightOffOutlinedIcon className="red" />,
2✔
100
    isApplicable: ({ userCapabilities: { canManageReleases } }) => canManageReleases,
9✔
101
    key: 'delete',
2✔
102
    title: pluralized => `Delete ${pluralized}`
23✔
103
  }
2✔
104
];
2✔
105

2✔
106
const useStyles = makeStyles()(theme => ({
9✔
107
  container: {
2✔
108
    display: 'flex',
2✔
109
    position: 'fixed',
2✔
110
    bottom: theme.spacing(6.5),
2✔
111
    right: theme.spacing(6.5),
2✔
112
    zIndex: 10,
2✔
113
    minWidth: 'max-content',
2✔
114
    alignItems: 'flex-end',
2✔
115
    justifyContent: 'flex-end',
2✔
116
    pointerEvents: 'none',
2✔
117
    [`.${speedDialActionClasses.staticTooltipLabel}`]: {
2✔
118
      minWidth: 'max-content'
2✔
119
    }
2✔
120
  },
2✔
121
  fab: { margin: theme.spacing(2) },
2✔
122
  tagSelect: { marginRight: theme.spacing(2), maxWidth: 350 },
2✔
123
  label: {
2✔
124
    marginRight: theme.spacing(2),
2✔
125
    marginBottom: theme.spacing(4)
2✔
126
  }
2✔
127
}));
2✔
128

2✔
129
export const ReleaseQuickActions = ({ actionCallbacks }) => {
9✔
130
  const [showActions, setShowActions] = useState(false);
23✔
131
  const { classes } = useStyles();
23✔
132
  const { selection: selectedRows } = useSelector(getReleaseListState);
23✔
133
  const selectedRelease = useSelector(getSelectedRelease);
23✔
134
  const userCapabilities = useSelector(getUserCapabilities);
23✔
135

2✔
136
  const actions = useMemo(
23✔
137
    () =>
2✔
138
      Object.values(defaultActions).reduce((accu, action) => {
9✔
139
        if (action.isApplicable({ userCapabilities, selectedSingleRelease: !isEmpty(selectedRelease), selectedRows })) {
23✔
140
          accu.push(action);
17✔
141
        }
2✔
142
        return accu;
23✔
143
      }, []),
2✔
144
    // eslint-disable-next-line react-hooks/exhaustive-deps
2✔
145
    [JSON.stringify(userCapabilities), selectedRelease, selectedRows]
2✔
146
  );
2✔
147

2✔
148
  const handleShowActions = () => setShowActions(toggle);
23✔
149

2✔
150
  const handleClickAway = () => setShowActions(false);
23✔
151

2✔
152
  const pluralized = pluralize('releases', selectedRelease ? 1 : selectedRows.length);
23!
153

2✔
154
  if (!actions.length) {
23!
155
    return null;
2✔
156
  }
2✔
157
  return (
23✔
158
    <div className={classes.container}>
2✔
159
      <div className={classes.label}>{selectedRelease ? 'Release actions' : `${selectedRows.length} ${pluralized} selected`}</div>
2!
160
      <ClickAwayListener onClickAway={handleClickAway}>
2✔
161
        <SpeedDial className={classes.fab} ariaLabel="release-actions" icon={<SpeedDialIcon />} onClick={handleShowActions} open={Boolean(showActions)}>
2✔
162
          {actions.map(action => (
2✔
163
            <SpeedDialAction
47✔
164
              key={action.key}
2✔
165
              aria-label={action.key}
2✔
166
              icon={action.icon}
2✔
167
              tooltipTitle={action.title(pluralized)}
2✔
168
              tooltipOpen
2✔
169
              onClick={() => action.action({ ...actionCallbacks, selection: selectedRows })}
3✔
170
            />
2✔
171
          ))}
2✔
172
        </SpeedDial>
2✔
173
      </ClickAwayListener>
2✔
174
    </div>
2✔
175
  );
2✔
176
};
2✔
177

2✔
178
const ReleaseNotes = ({ onChange, release: { notes = '' } }) => (
9✔
179
  <>
19✔
180
    <h4>Release notes</h4>
2✔
181
    <EditableLongText contentFallback="Add release notes here" original={notes} onChange={onChange} placeholder="Release notes" />
2✔
182
  </>
2✔
183
);
2✔
184

2✔
185
const ReleaseTags = ({ existingTags = [], release: { tags = [] }, onChange, userCapabilities }) => {
9✔
186
  const [isEditing, setIsEditing] = useState(false);
21✔
187
  const [initialValues] = useState({ tags });
21✔
188
  const { classes } = useStyles();
21✔
189
  const { canManageReleases } = userCapabilities;
21✔
190

2✔
191
  const methods = useForm({ mode: 'onChange', defaultValues: initialValues });
21✔
192
  const { setValue, getValues } = methods;
21✔
193

2✔
194
  useEffect(() => {
21✔
195
    if (!initialValues.tags.length) {
21!
196
      setValue('tags', tags);
21✔
197
    }
2✔
198
  }, [initialValues.tags, setValue, tags]);
2✔
199

2✔
200
  const onToggleEdit = useCallback(() => {
21✔
201
    setValue('tags', tags);
2✔
202
    setIsEditing(toggle);
2✔
203
  }, [setValue, tags]);
2✔
204

2✔
205
  const onSave = () => onChange(getValues('tags')).then(() => setIsEditing(false));
21✔
206

2✔
207
  return (
21✔
208
    <div className="margin-bottom margin-top" style={{ maxWidth: 500 }}>
2✔
209
      <div className="flexbox center-aligned">
2✔
210
        <h4 className="margin-right">Tags</h4>
2✔
211
        {!isEditing && canManageReleases && <EditButton onClick={onToggleEdit} />}
2✔
212
      </div>
2✔
213
      <div className="flexbox" style={{ alignItems: 'center' }}>
2✔
214
        <FormProvider {...methods}>
2✔
215
          <form noValidate>
2✔
216
            <ChipSelect
2✔
217
              className={classes.tagSelect}
2✔
218
              disabled={!isEditing}
2✔
219
              label=""
2✔
220
              name="tags"
2✔
221
              options={existingTags}
2✔
222
              placeholder={isEditing ? 'Enter release tags' : canManageReleases ? 'Click edit to add release tags' : 'No tags yet'}
2!
223
            />
2✔
224
          </form>
2✔
225
        </FormProvider>
2✔
226
        {isEditing && <ConfirmationButtons onConfirm={onSave} onCancel={onToggleEdit} />}
2!
227
      </div>
2✔
228
    </div>
2✔
229
  );
2✔
230
};
2✔
231

2✔
232
const ArtifactsList = ({ artifacts, selectedArtifact, setSelectedArtifact, setShowRemoveArtifactDialog }) => {
9✔
233
  const [sortCol, setSortCol] = useState('modified');
24✔
234
  const [sortDown, setSortDown] = useState(true);
24✔
235
  const [items, setItems] = useState([...artifacts]);
24✔
236

2✔
237
  useEffect(() => {
24✔
238
    const items = [...artifacts].sort(customSort(sortDown, sortCol));
11✔
239
    setItems(items);
11✔
240
  }, [artifacts, sortCol, sortDown]);
2✔
241

2✔
242
  const onRowSelection = artifact => {
24✔
243
    if (artifact?.id === selectedArtifact?.id) {
3!
244
      return setSelectedArtifact();
2✔
245
    }
2✔
246
    setSelectedArtifact(artifact);
3✔
247
  };
2✔
248

2✔
249
  const sortColumn = col => {
24✔
250
    if (!col.sortable) {
2!
251
      return;
2✔
252
    }
2✔
253
    // sort table
2✔
254
    setSortDown(toggle);
2✔
255
    setSortCol(col);
2✔
256
  };
2✔
257

2✔
258
  if (!items.length) {
24✔
259
    return null;
7✔
260
  }
2✔
261

2✔
262
  return (
19✔
263
    <>
2✔
264
      <h4>Artifacts in this Release:</h4>
2✔
265
      <div>
2✔
266
        <div className="release-repo-item repo-item repo-header">
2✔
267
          {columns.map(item => (
2✔
268
            <div className="columnHeader" key={item.name} onClick={() => sortColumn(item)}>
70✔
269
              <Tooltip title={item.title} placement="top-start">
2✔
270
                {item.title}
2✔
271
              </Tooltip>
2✔
272
              {item.sortable ? <SortIcon className={`sortIcon ${sortCol === item.name ? 'selected' : ''} ${sortDown.toString()}`} /> : null}
2✔
273
              {item.tooltip}
2✔
274
            </div>
2✔
275
          ))}
2✔
276
          <div style={{ width: 48 }} />
2✔
277
        </div>
2✔
278
        {items.map((artifact, index) => {
2✔
279
          const expanded = selectedArtifact?.id === artifact.id;
21✔
280
          return (
21✔
281
            <Artifact
2✔
282
              key={`repository-item-${index}`}
2✔
283
              artifact={artifact}
2✔
284
              columns={columns}
2✔
285
              expanded={expanded}
2✔
286
              index={index}
2✔
287
              onRowSelection={() => onRowSelection(artifact)}
3✔
288
              // this will be run after expansion + collapse and both need some time to fully settle
2✔
289
              // otherwise the measurements are off
2✔
290
              showRemoveArtifactDialog={setShowRemoveArtifactDialog}
2✔
291
            />
2✔
292
          );
2✔
293
        })}
2✔
294
      </div>
2✔
295
    </>
2✔
296
  );
2✔
297
};
2✔
298

2✔
299
export const ReleaseDetails = () => {
9✔
300
  const [showRemoveDialog, setShowRemoveArtifactDialog] = useState(false);
74✔
301
  const [confirmReleaseDeletion, setConfirmReleaseDeletion] = useState(false);
74✔
302
  const [selectedArtifact, setSelectedArtifact] = useState();
74✔
303

2✔
304
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2✔
305
  const windowSize = useWindowSize();
74✔
306
  const drawerRef = useRef();
74✔
307
  const navigate = useNavigate();
74✔
308
  const dispatch = useDispatch();
74✔
309
  const release = useSelector(getSelectedRelease);
74✔
310
  const existingTags = useSelector(getReleaseTags);
74✔
311
  const userCapabilities = useSelector(getUserCapabilities);
74✔
312

2✔
313
  const { name: releaseName, artifacts = [] } = release;
74✔
314

2✔
315
  const onRemoveArtifact = artifact => dispatch(removeArtifact(artifact.id)).finally(() => setShowRemoveArtifactDialog(false));
74✔
316

2✔
317
  const copyLinkToClipboard = () => {
74✔
318
    const location = window.location.href.substring(0, window.location.href.indexOf('/releases'));
2✔
319
    copy(`${location}${generateReleasesPath({ pageState: { selectedRelease: releaseName } })}`);
2✔
320
    dispatch(setSnackbar('Link copied to clipboard'));
2✔
321
  };
2✔
322

2✔
323
  const onCloseClick = () => dispatch(selectRelease(null));
74✔
324

2✔
325
  const onCreateDeployment = () => navigate(`${DEPLOYMENT_ROUTES.active.route}?open=true&release=${encodeURIComponent(releaseName)}`);
74✔
326

2✔
327
  const onToggleReleaseDeletion = () => setConfirmReleaseDeletion(toggle);
74✔
328

2✔
329
  const onDeleteRelease = () => dispatch(removeRelease(releaseName)).then(() => setConfirmReleaseDeletion(false));
74✔
330

2✔
331
  const onReleaseNotesChanged = useCallback(notes => dispatch(updateReleaseInfo({ name: releaseName, info: { notes } })), [dispatch, releaseName]);
74✔
332

2✔
333
  const onTagSelectionChanged = useCallback(tags => dispatch(setReleaseTags({ name: releaseName, tags })).unwrap(), [dispatch, releaseName]);
74✔
334

2✔
335
  return (
74✔
336
    <Drawer anchor="right" open={!!releaseName} onClose={onCloseClick} PaperProps={{ style: { minWidth: '60vw' }, ref: drawerRef }}>
2✔
337
      <DrawerTitle
2✔
338
        title={
2✔
339
          <>
2✔
340
            Release information for <div className="margin-left-small margin-right-small">{releaseName}</div>
2✔
341
          </>
2✔
342
        }
2✔
343
        onLinkCopy={copyLinkToClipboard}
2✔
344
        preCloser={
2✔
345
          <div className="muted margin-right flexbox">
2✔
346
            <div className="margin-right-small">Last modified:</div>
2✔
347
            <RelativeTime updateTime={release.modified} />
2✔
348
          </div>
2✔
349
        }
2✔
350
        onClose={onCloseClick}
2✔
351
      />
2✔
352
      <Divider className="margin-bottom" />
2✔
353
      <ReleaseNotes onChange={onReleaseNotesChanged} release={release} />
2✔
354
      <ReleaseTags existingTags={existingTags} onChange={onTagSelectionChanged} release={release} userCapabilities={userCapabilities} />
2✔
355
      <ArtifactsList
2✔
356
        artifacts={artifacts}
2✔
357
        selectedArtifact={selectedArtifact}
2✔
358
        setSelectedArtifact={setSelectedArtifact}
2✔
359
        setShowRemoveArtifactDialog={setShowRemoveArtifactDialog}
2✔
360
      />
2✔
361
      <RemoveArtifactDialog
2✔
362
        artifact={selectedArtifact}
2✔
363
        open={!!showRemoveDialog}
2✔
364
        onCancel={() => setShowRemoveArtifactDialog(false)}
3✔
UNCOV
365
        onRemove={() => onRemoveArtifact(selectedArtifact)}
2✔
366
      />
2✔
367
      <RemoveArtifactDialog open={!!confirmReleaseDeletion} onRemove={onDeleteRelease} onCancel={onToggleReleaseDeletion} release={release} />
2✔
368
      <ReleaseQuickActions actionCallbacks={{ onCreateDeployment, onDeleteRelease: onToggleReleaseDeletion }} />
2✔
369
    </Drawer>
2✔
370
  );
2✔
371
};
2✔
372

2✔
373
export default ReleaseDetails;
2✔
374

2✔
375
export const DeleteReleasesConfirmationDialog = ({ onClose, onSubmit }) => (
9✔
376
  <BaseDialog open title="Delete releases?" onClose={onClose}>
3✔
377
    <DialogContent style={{ overflow: 'hidden' }}>All releases artifacts will be deleted. Are you sure you want to delete these releases ?</DialogContent>
2✔
378
    <DialogActions>
2✔
379
      <Button style={{ marginRight: 10 }} onClick={onClose}>
2✔
380
        Cancel
2✔
381
      </Button>
2✔
382
      <Button variant="contained" color="primary" onClick={onSubmit}>
2✔
383
        Delete
2✔
384
      </Button>
2✔
385
    </DialogActions>
2✔
386
  </BaseDialog>
2✔
387
);
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