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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

68.33
/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 } 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 canShow = () => true;
15✔
28

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

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

64
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
5✔
65

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

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

80
  const onChangePagination = (page, currentPerPage = perPage) => setReleasesListState({ page, perPage: currentPerPage });
28!
81

82
  const applicableColumns = useMemo(
28✔
83
    () =>
84
      columns.reduce((accu, column) => {
5✔
85
        if (column.canShow({ features })) {
20✔
86
          accu.push(column);
15✔
87
        }
88
        return accu;
20✔
89
      }, []),
90
    [JSON.stringify(features)]
91
  );
92

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

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

126
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