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

mendersoftware / gui / 947088195

pending completion
947088195

Pull #2661

gitlab-ci

mzedel
chore: improved device filter scrolling behaviour

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #2661: chore: added lint rules for hooks usage

4411 of 6415 branches covered (68.76%)

297 of 440 new or added lines in 62 files covered. (67.5%)

1617 existing lines in 163 files now uncovered.

8311 of 10087 relevant lines covered (82.39%)

192.12 hits per line

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

67.8
/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, { useMemo, useRef } from 'react';
15

16
import { makeStyles } from 'tss-react/mui';
17

18
import { SORTING_OPTIONS, canAccess as canShow } from '../../constants/appConstants';
19
import { DEVICE_LIST_DEFAULTS } from '../../constants/deviceConstants';
20
import { onboardingSteps } from '../../constants/onboardingConstants';
21
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
22
import DetailsTable from '../common/detailstable';
23
import Loader from '../common/loader';
24
import Pagination from '../common/pagination';
25
import { RelativeTime } from '../common/time';
26

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

58
const useStyles = makeStyles()(() => ({
5✔
59
  container: { maxWidth: 1600 }
60
}));
61

62
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
5✔
63

64
export const ReleasesList = ({ artifactIncluded, features, onboardingState, onSelect, releasesListState, releases, setReleasesListState }) => {
5✔
65
  const { isLoading, page = defaultPage, perPage = defaultPerPage, searchTerm, sort = {}, searchTotal, total } = releasesListState;
31!
66
  const { key: attribute, direction } = sort;
31✔
67
  const repoRef = useRef();
31✔
68
  const { classes } = useStyles();
31✔
69

70
  const onChangeSorting = sortKey => {
31✔
UNCOV
71
    let sort = { key: sortKey, direction: direction === SORTING_OPTIONS.asc ? SORTING_OPTIONS.desc : SORTING_OPTIONS.asc };
×
UNCOV
72
    if (sortKey !== attribute) {
×
UNCOV
73
      sort = { ...sort, direction: columns.find(({ key }) => key === sortKey)?.defaultSortDirection ?? SORTING_OPTIONS.desc };
×
74
    }
UNCOV
75
    setReleasesListState({ page: 1, sort });
×
76
  };
77

78
  const onChangePagination = (page, currentPerPage = perPage) => setReleasesListState({ page, perPage: currentPerPage });
31!
79

80
  const applicableColumns = useMemo(
31✔
81
    () =>
82
      columns.reduce((accu, column) => {
5✔
83
        if (column.canShow({ features })) {
20✔
84
          accu.push(column);
15✔
85
        }
86
        return accu;
20✔
87
      }, []),
88
    // eslint-disable-next-line react-hooks/exhaustive-deps
89
    [JSON.stringify(features)]
90
  );
91

92
  let onboardingComponent = null;
31✔
93
  if (repoRef.current?.lastChild?.lastChild) {
31✔
94
    const element = repoRef.current.lastChild.lastChild;
26✔
95
    const anchor = { left: element.offsetLeft + element.offsetWidth / 2, top: element.offsetTop + element.offsetParent?.offsetTop + element.offsetHeight };
26✔
96
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.ARTIFACT_INCLUDED_ONBOARDING, { ...onboardingState, artifactIncluded }, { anchor });
26✔
97
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED, onboardingState, { anchor }, onboardingComponent);
26✔
98
  }
99

100
  const potentialTotal = searchTerm ? searchTotal : total;
31✔
101
  return (
31✔
102
    <div className={classes.container}>
103
      {isLoading === undefined ? (
31!
104
        <Loader show />
105
      ) : !potentialTotal ? (
31✔
106
        <p className="margin-top muted align-center margin-right">There are no Releases {searchTerm ? `for ${searchTerm}` : 'yet'}</p>
2✔
107
      ) : (
108
        <>
109
          <DetailsTable columns={applicableColumns} items={releases} onItemClick={onSelect} sort={sort} onChangeSorting={onChangeSorting} tableRef={repoRef} />
110
          <div className="flexbox">
111
            <Pagination
112
              className="margin-top-none"
113
              count={potentialTotal}
114
              rowsPerPage={perPage}
115
              onChangePage={onChangePagination}
UNCOV
116
              onChangeRowsPerPage={newPerPage => onChangePagination(1, newPerPage)}
×
117
              page={page}
118
            />
119
            <Loader show={isLoading} small />
120
          </div>
121
          {onboardingComponent}
122
        </>
123
      )}
124
    </div>
125
  );
126
};
127

128
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