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

mendersoftware / gui / 944676341

pending completion
944676341

Pull #3875

gitlab-ci

mzedel
chore: aligned snapshots with updated design

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3875: MEN-5414

4469 of 6446 branches covered (69.33%)

230 of 266 new or added lines in 43 files covered. (86.47%)

1712 existing lines in 161 files now uncovered.

8406 of 10170 relevant lines covered (82.65%)

196.7 hits per line

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

57.29
/src/js/components/releases/releaseslist.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, { useCallback, useMemo, useRef } from 'react';
15
import Dropzone from 'react-dropzone';
16
import { useDispatch, useSelector } from 'react-redux';
17

18
import { makeStyles } from 'tss-react/mui';
19

20
import { setSnackbar } from '../../actions/appActions';
21
import { selectRelease, setReleasesListState } from '../../actions/releaseActions';
22
import { SORTING_OPTIONS, canAccess as canShow } from '../../constants/appConstants';
23
import { DEVICE_LIST_DEFAULTS } from '../../constants/deviceConstants';
24
import { onboardingSteps } from '../../constants/onboardingConstants';
25
import { getFeatures, getOnboardingState, getReleasesList, getUserCapabilities } from '../../selectors';
26
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
27
import DetailsTable from '../common/detailstable';
28
import Loader from '../common/loader';
29
import Pagination from '../common/pagination';
30
import { RelativeTime } from '../common/time';
31

32
const columns = [
5✔
33
  {
34
    key: 'name',
35
    title: 'Name',
36
    render: ({ Name }) => Name,
221✔
37
    sortable: true,
38
    defaultSortDirection: SORTING_OPTIONS.asc,
39
    canShow
40
  },
41
  {
42
    key: 'artifacts-count',
43
    title: 'Number of artifacts',
44
    render: ({ Artifacts = [] }) => Artifacts.length,
221!
45
    canShow
46
  },
47
  {
48
    key: 'tags',
49
    title: 'Tags',
UNCOV
50
    render: ({ tags = [] }) => tags.join(', ') || '-',
×
51
    canShow: ({ features: { hasReleaseTags } }) => hasReleaseTags
5✔
52
  },
53
  {
54
    key: 'modified',
55
    title: 'Last modified',
56
    render: ({ modified }) => <RelativeTime updateTime={modified} />,
221✔
57
    defaultSortDirection: SORTING_OPTIONS.desc,
58
    sortable: true,
59
    canShow
60
  }
61
];
62

63
const useStyles = makeStyles()(() => ({
5✔
64
  container: { maxWidth: 1600 },
65
  empty: { margin: '8vh auto' }
66
}));
67

68
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
5✔
69

70
const EmptyState = ({ canUpload, className = '', dropzoneRef, uploading, onDrop, onUpload }) => (
5!
NEW
71
  <div className={`dashboard-placeholder fadeIn ${className}`} ref={dropzoneRef}>
×
72
    <Dropzone activeClassName="active" disabled={uploading} multiple={false} noClick={true} onDrop={onDrop} rejectClassName="active">
73
      {({ getRootProps, getInputProps }) => (
NEW
74
        <div {...getRootProps({ className: uploading ? 'dropzone disabled muted' : 'dropzone' })} onClick={() => onUpload()}>
×
75
          <input {...getInputProps()} disabled={uploading} />
76
          <p>
77
            There are no Releases yet.{' '}
78
            {canUpload && (
×
79
              <>
80
                <a>Upload an Artifact</a> to create a new Release
81
              </>
82
            )}
83
          </p>
84
        </div>
85
      )}
86
    </Dropzone>
87
  </div>
88
);
89

90
export const ReleasesList = ({ onFileUploadClick }) => {
5✔
91
  const repoRef = useRef();
32✔
92
  const dropzoneRef = useRef();
32✔
93
  const uploading = useSelector(state => state.app.uploading);
65✔
94
  const hasReleases = useSelector(
32✔
95
    state => !!(Object.keys(state.releases.byId).length || state.releases.releasesList.total || state.releases.releasesList.searchTotal)
65!
96
  );
97
  const features = useSelector(getFeatures);
32✔
98
  const onboardingState = useSelector(getOnboardingState);
32✔
99
  const { artifactIncluded } = onboardingState;
32✔
100
  const releases = useSelector(getReleasesList);
32✔
101
  const releasesListState = useSelector(state => state.releases.releasesList);
65✔
102
  const userCapabilities = useSelector(getUserCapabilities);
32✔
103
  const dispatch = useDispatch();
32✔
104
  const { classes } = useStyles();
32✔
105

106
  const { canUploadReleases } = userCapabilities;
32✔
107
  const { isLoading, page = defaultPage, perPage = defaultPerPage, searchTerm, sort = {}, searchTotal, total } = releasesListState;
32!
108
  const { key: attribute, direction } = sort;
32✔
109

110
  const onSelect = useCallback(id => dispatch(selectRelease(id)), [dispatch]);
32✔
111

112
  const onChangeSorting = sortKey => {
32✔
UNCOV
113
    let sort = { key: sortKey, direction: direction === SORTING_OPTIONS.asc ? SORTING_OPTIONS.desc : SORTING_OPTIONS.asc };
×
UNCOV
114
    if (sortKey !== attribute) {
×
UNCOV
115
      sort = { ...sort, direction: columns.find(({ key }) => key === sortKey)?.defaultSortDirection ?? SORTING_OPTIONS.desc };
×
116
    }
NEW
117
    dispatch(setReleasesListState({ page: 1, sort }));
×
118
  };
119

120
  const onChangePagination = (page, currentPerPage = perPage) => dispatch(setReleasesListState({ page, perPage: currentPerPage }));
32!
121

122
  const onDrop = (acceptedFiles, rejectedFiles) => {
32✔
NEW
123
    if (acceptedFiles.length) {
×
NEW
124
      onFileUploadClick(acceptedFiles[0]);
×
125
    }
NEW
126
    if (rejectedFiles.length) {
×
NEW
127
      dispatch(setSnackbar(`File '${rejectedFiles[0].name}' was rejected. File should be of type .mender`, null));
×
128
    }
129
  };
130

131
  const applicableColumns = useMemo(
32✔
132
    () =>
133
      columns.reduce((accu, column) => {
5✔
134
        if (column.canShow({ features })) {
20✔
135
          accu.push(column);
15✔
136
        }
137
        return accu;
20✔
138
      }, []),
139
    [JSON.stringify(features)]
140
  );
141

142
  let onboardingComponent = null;
32✔
143
  if (repoRef.current?.lastChild?.lastChild) {
32✔
144
    const element = repoRef.current.lastChild.lastChild;
27✔
145
    const anchor = { left: element.offsetLeft + element.offsetWidth / 2, top: element.offsetTop + element.offsetParent?.offsetTop + element.offsetHeight };
27✔
146
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.ARTIFACT_INCLUDED_ONBOARDING, { ...onboardingState, artifactIncluded }, { anchor });
27✔
147
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED, onboardingState, { anchor }, onboardingComponent);
27✔
148
  }
149

150
  const potentialTotal = searchTerm ? searchTotal : total;
32✔
151
  if (!hasReleases) {
32!
NEW
152
    return (
×
153
      <EmptyState
154
        canUpload={canUploadReleases}
155
        className={classes.empty}
156
        dropzoneRef={dropzoneRef}
157
        uploading={uploading}
158
        onDrop={onDrop}
159
        onUpload={onFileUploadClick}
160
      />
161
    );
162
  }
163

164
  return (
32✔
165
    <div className={classes.container}>
166
      {isLoading === undefined ? (
32!
167
        <Loader show />
168
      ) : !potentialTotal ? (
32✔
169
        <p className="margin-top muted align-center margin-right">There are no Releases {searchTerm ? `for ${searchTerm}` : 'yet'}</p>
1!
170
      ) : (
171
        <>
172
          <DetailsTable columns={applicableColumns} items={releases} onItemClick={onSelect} sort={sort} onChangeSorting={onChangeSorting} tableRef={repoRef} />
173
          <div className="flexbox">
174
            <Pagination
175
              className="margin-top-none"
176
              count={potentialTotal}
177
              rowsPerPage={perPage}
178
              onChangePage={onChangePagination}
UNCOV
179
              onChangeRowsPerPage={newPerPage => onChangePagination(1, newPerPage)}
×
180
              page={page}
181
            />
182
            <Loader show={isLoading} small />
183
          </div>
184
          {onboardingComponent}
185
        </>
186
      )}
187
    </div>
188
  );
189
};
190

191
export default ReleasesList;
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