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

mendersoftware / gui / 901187442

pending completion
901187442

Pull #3795

gitlab-ci

mzedel
feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3795: feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

4389 of 6365 branches covered (68.96%)

5 of 5 new or added lines in 1 file covered. (100.0%)

1729 existing lines in 165 files now uncovered.

8274 of 10019 relevant lines covered (82.58%)

144.86 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,
197✔
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,
197!
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} />,
197✔
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;
28!
66
  const { key: attribute, direction } = sort;
28✔
67
  const repoRef = useRef();
28✔
68
  const { classes } = useStyles();
28✔
69

70
  const onChangeSorting = sortKey => {
28✔
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 });
28!
79

80
  const applicableColumns = useMemo(
28✔
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
    [JSON.stringify(features)]
89
  );
90

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

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

124
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