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

mendersoftware / gui / 1015445845

25 Sep 2023 09:43AM UTC coverage: 82.537% (-17.4%) from 99.964%
1015445845

Pull #4028

gitlab-ci

mzedel
chore: aligned release retrieval with v2 api models

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

4355 of 6315 branches covered (0.0%)

184 of 206 new or added lines in 19 files covered. (89.32%)

1724 existing lines in 164 files now uncovered.

8323 of 10084 relevant lines covered (82.54%)

208.49 hits per line

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

93.75
/src/js/components/common/timerange-picker.js
1
// Copyright 2020 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, { useEffect, useState } from 'react';
15

16
import { getISOStringBoundaries } from '../../helpers';
17
import ClickFilter from './forms/clickfilter';
18

19
const timeranges = {
9✔
20
  today: { start: 0, end: 0, title: 'Today' },
21
  yesterday: { start: 1, end: 1, title: 'Yesterday' },
22
  week: { start: 6, end: 0, title: 'Last 7 days' },
23
  month: { start: 29, end: 0, title: 'Last 30 days' }
24
};
25

26
export const TimerangePicker = ({ classNames = '', disabled = false, endDate, onChange, startDate }) => {
9✔
27
  const [active, setActive] = useState();
95✔
28

29
  useEffect(() => {
95✔
30
    if (!(endDate && startDate)) {
15✔
31
      setActive(Object.keys(timeranges)[0]);
9✔
32
      return;
9✔
33
    }
34
    if (!(endDate || startDate)) {
6!
UNCOV
35
      setActive();
×
UNCOV
36
      return;
×
37
    }
38
    const currentRange = Object.entries(timeranges).reduce((accu, [key, range]) => {
6✔
39
      let rangeEndDate = new Date();
24✔
40
      rangeEndDate.setDate(rangeEndDate.getDate() - (range.end || 0));
24✔
41
      const { end } = getISOStringBoundaries(rangeEndDate);
24✔
42
      let rangeStartDate = new Date();
24✔
43
      rangeStartDate.setDate(rangeStartDate.getDate() - (range.start || 0));
24✔
44
      const { start } = getISOStringBoundaries(rangeStartDate);
24✔
45
      if (startDate == start && endDate == end) {
24✔
46
        return key;
5✔
47
      }
48
      return accu;
19✔
49
    }, undefined);
50
    setActive(currentRange);
6✔
51
  }, [endDate, startDate]);
52

53
  const setRange = (after, before) => {
95✔
54
    let newStartDate = new Date();
3✔
55
    newStartDate.setDate(newStartDate.getDate() - (after || 0));
3!
56
    const { start } = getISOStringBoundaries(newStartDate);
3✔
57
    let newEndDate = new Date();
3✔
58
    newEndDate.setDate(newEndDate.getDate() - (before || 0));
3✔
59
    const { end } = getISOStringBoundaries(newEndDate);
3✔
60
    onChange(start, end);
3✔
61
  };
62

63
  return (
95✔
64
    <ClickFilter disabled={disabled}>
65
      <div className={`${classNames} ${disabled ? 'muted' : ''}`}>
95!
66
        <span>Filter by date</span>
67
        <ul className="unstyled link-list horizontal">
68
          {Object.entries(timeranges).map(([key, range]) => (
69
            <li key={`filter-by-${key}`}>
380✔
70
              <a className={active === key ? 'active' : ''} onClick={() => setRange(range.start, range.end)}>
3✔
71
                {range.title}
72
              </a>
73
            </li>
74
          ))}
75
        </ul>
76
      </div>
77
    </ClickFilter>
78
  );
79
};
80

81
export default TimerangePicker;
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