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

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

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

74.47
/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 { getFeatures, getHasReleases, getReleaseListState, getReleasesList, getUserCapabilities } from '../../selectors';
25
import DetailsTable from '../common/detailstable';
26
import Loader from '../common/loader';
27
import Pagination from '../common/pagination';
28
import { RelativeTime } from '../common/time';
29

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

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

67
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
4✔
68

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

89
export const ReleasesList = ({ className = '', onFileUploadClick }) => {
4✔
90
  const repoRef = useRef();
45✔
91
  const dropzoneRef = useRef();
45✔
92
  const uploading = useSelector(state => state.app.uploading);
85✔
93
  const releasesListState = useSelector(getReleaseListState);
45✔
94
  const { isLoading, page = defaultPage, perPage = defaultPerPage, searchTerm, sort = {}, searchTotal, selectedTags = [], total, type } = releasesListState;
45!
95
  const hasReleases = useSelector(getHasReleases);
45✔
96
  const features = useSelector(getFeatures);
45✔
97
  const releases = useSelector(getReleasesList);
45✔
98
  const userCapabilities = useSelector(getUserCapabilities);
45✔
99
  const dispatch = useDispatch();
45✔
100
  const { classes } = useStyles();
45✔
101

102
  const { canUploadReleases } = userCapabilities;
45✔
103
  const { key: attribute, direction } = sort;
45✔
104

105
  const onSelect = useCallback(id => dispatch(selectRelease(id)), [dispatch]);
45✔
106

107
  const onChangeSorting = sortKey => {
45✔
108
    let sort = { key: sortKey, direction: direction === SORTING_OPTIONS.asc ? SORTING_OPTIONS.desc : SORTING_OPTIONS.asc };
×
109
    if (sortKey !== attribute) {
×
110
      sort = { ...sort, direction: columns.find(({ key }) => key === sortKey)?.defaultSortDirection ?? SORTING_OPTIONS.desc };
×
111
    }
112
    dispatch(setReleasesListState({ page: 1, sort }));
×
113
  };
114

115
  const onChangePagination = (page, currentPerPage = perPage) => dispatch(setReleasesListState({ page, perPage: currentPerPage }));
45!
116

117
  const onDrop = (acceptedFiles, rejectedFiles) => {
45✔
118
    if (acceptedFiles.length) {
×
119
      onFileUploadClick(acceptedFiles[0]);
×
120
    }
121
    if (rejectedFiles.length) {
×
122
      dispatch(setSnackbar(`File '${rejectedFiles[0].name}' was rejected. File should be of type .mender`, null));
×
123
    }
124
  };
125

126
  const applicableColumns = useMemo(
45✔
127
    () =>
128
      columns.reduce((accu, column) => {
5✔
129
        if (column.canShow({ features })) {
20!
130
          accu.push(column);
20✔
131
        }
132
        return accu;
20✔
133
      }, []),
134
    // eslint-disable-next-line react-hooks/exhaustive-deps
135
    [JSON.stringify(features)]
136
  );
137

138
  const isFiltering = !!(selectedTags.length || type || searchTerm);
45✔
139
  const potentialTotal = isFiltering ? searchTotal : total;
45✔
140
  if (!hasReleases) {
45!
141
    return (
×
142
      <EmptyState
143
        canUpload={canUploadReleases}
144
        className={classes.empty}
145
        dropzoneRef={dropzoneRef}
146
        uploading={uploading}
147
        onDrop={onDrop}
148
        onUpload={onFileUploadClick}
149
      />
150
    );
151
  }
152

153
  return (
45✔
154
    <div className={className}>
155
      {isLoading === undefined ? (
45!
156
        <Loader show />
157
      ) : !potentialTotal ? (
45✔
158
        <p className="margin-top muted align-center margin-right">There are no Releases {isFiltering ? 'for the filter selection' : 'yet'}</p>
1!
159
      ) : (
160
        <>
161
          <DetailsTable columns={applicableColumns} items={releases} onItemClick={onSelect} sort={sort} onChangeSorting={onChangeSorting} tableRef={repoRef} />
162
          <div className="flexbox">
163
            <Pagination
164
              className="margin-top-none"
165
              count={potentialTotal}
166
              rowsPerPage={perPage}
167
              onChangePage={onChangePagination}
168
              onChangeRowsPerPage={newPerPage => onChangePagination(1, newPerPage)}
×
169
              page={page}
170
            />
171
            <Loader show={isLoading} small />
172
          </div>
173
        </>
174
      )}
175
    </div>
176
  );
177
};
178

179
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