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

mendersoftware / mender-server / 10423

11 Nov 2025 04:53PM UTC coverage: 74.435% (-0.1%) from 74.562%
10423

push

gitlab-ci

web-flow
Merge pull request #1071 from mendersoftware/dependabot/npm_and_yarn/frontend/main/development-dependencies-92732187be

3868 of 5393 branches covered (71.72%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

176 existing lines in 95 files now uncovered.

64605 of 86597 relevant lines covered (74.6%)

7.74 hits per line

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

96.84
/frontend/src/js/components/auditlogs/AuditLogsFilter.tsx
1
// Copyright 2024 Northern.tech AS
2✔
2
//
2✔
3
//    Licensed under the Apache License, Version 2.0 (the "License");
2✔
4
//    you may not use this file except in compliance with the License.
2✔
5
//    You may obtain a copy of the License at
2✔
6
//
2✔
7
//        http://www.apache.org/licenses/LICENSE-2.0
2✔
8
//
2✔
9
//    Unless required by applicable law or agreed to in writing, software
2✔
10
//    distributed under the License is distributed on an "AS IS" BASIS,
2✔
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2✔
12
//    See the License for the specific language governing permissions and
2✔
13
//    limitations under the License.
2✔
14
import { useCallback, useState } from 'react';
2✔
15

2✔
16
import { TextField } from '@mui/material';
2✔
17

2✔
18
import { ControlledAutoComplete } from '@northern.tech/common-ui/forms/Autocomplete';
2✔
19
import ClickFilter from '@northern.tech/common-ui/forms/ClickFilter';
2✔
20
import Filters from '@northern.tech/common-ui/forms/Filters';
2✔
21
import TimeframePicker from '@northern.tech/common-ui/forms/TimeframePicker';
2✔
22
import { getISOStringBoundaries } from '@northern.tech/utils/helpers';
2✔
23

2✔
24
const detailsMap = {
6✔
25
  Deployment: 'to device group',
2✔
26
  User: 'email'
2✔
27
};
2✔
28

2✔
29
const getOptionLabel = option => option.title ?? option.email ?? option;
184✔
30

2✔
31
const renderOption = (props, option) => {
6✔
32
  const { key, ...rest } = props;
21✔
33
  return (
21✔
34
    <li key={key} {...rest}>
2✔
35
      {getOptionLabel(option)}
2✔
36
    </li>
2✔
37
  );
2✔
38
};
2✔
39
const isUserOptionEqualToValue = ({ email, id }, value) => id === value || email === value || email === value?.email;
6!
40

2✔
41
const autoSelectProps = {
6✔
42
  autoSelect: true,
2✔
43
  filterSelectedOptions: true,
2✔
44
  getOptionLabel,
2✔
45
  handleHomeEndKeys: true,
2✔
46
  renderOption
2✔
47
};
2✔
48

2✔
49
const LOG_RETENTION_PERIOD = 90;
6✔
50

2✔
51
export const AuditLogsFilter = ({
6✔
52
  groups,
2✔
53
  users,
2✔
54
  selectionState,
2✔
55
  disabled,
2✔
56
  isHosted,
2✔
57
  onFiltersChange,
2✔
58
  detailsReset,
2✔
59
  auditLogsTypes,
2✔
60
  dirtyField,
2✔
61
  setDirtyField
2✔
62
}) => {
2✔
63
  const { detail, endDate, user, startDate, type } = selectionState;
19✔
64
  const [date] = useState(getISOStringBoundaries(new Date()));
19✔
65
  const { start: today, end: tonight } = date;
19✔
66

2✔
67
  const typeOptionsMap = {
19✔
68
    Deployment: groups,
2✔
69
    User: Object.values(users)
2✔
70
  };
2✔
71
  const detailOptions = typeOptionsMap[type?.title] ?? [];
19✔
72

2✔
73
  const shouldShowRetentionText = useCallback(
19✔
74
    ({ startDate }) => {
2✔
75
      const cutOffDate = new Date();
16✔
76
      cutOffDate.setDate(cutOffDate.getDate() - LOG_RETENTION_PERIOD);
16✔
77
      const then = cutOffDate.toISOString().replace('Z', '');
16✔
78
      return isHosted && startDate < then;
16✔
79
    },
2✔
80
    [isHosted]
2✔
81
  );
2✔
82

2✔
83
  return (
19✔
84
    <ClickFilter disabled={disabled}>
2✔
85
      <Filters
2✔
86
        initialValues={{ startDate, endDate, user, type, detail }}
2✔
87
        defaultValues={{ startDate: today, endDate: tonight, user: '', type: null, detail: '' }}
2✔
88
        fieldResetTrigger={detailsReset}
2✔
89
        dirtyField={dirtyField}
2✔
90
        clearDirty={setDirtyField}
2✔
91
        filters={[
2✔
92
          {
2✔
93
            key: 'user',
2✔
94
            title: 'Performed by',
2✔
95
            Component: ControlledAutoComplete,
2✔
96
            componentProps: {
2✔
97
              ...autoSelectProps,
2✔
98
              freeSolo: true,
2✔
99
              isOptionEqualToValue: isUserOptionEqualToValue,
2✔
100
              options: Object.values(users),
2✔
101
              renderInput: params => <TextField {...params} placeholder="Select a user" InputProps={{ ...params.InputProps }} />
27✔
102
            }
2✔
103
          },
2✔
104
          {
2✔
105
            key: 'type',
2✔
106
            title: 'Filter by changes',
2✔
107
            Component: ControlledAutoComplete,
2✔
108
            componentProps: {
2✔
109
              ...autoSelectProps,
2✔
110
              options: auditLogsTypes,
2✔
UNCOV
111
              isOptionEqualToValue: (option, value) => option.value === value.value && option.object_type === value.object_type,
2!
112
              renderInput: params => <TextField {...params} placeholder="Type" InputProps={{ ...params.InputProps }} />
33✔
113
            }
2✔
114
          },
2✔
115
          {
2✔
116
            key: 'detail',
2✔
117
            title: '',
2✔
118
            Component: ControlledAutoComplete,
2✔
119
            componentProps: {
2✔
120
              ...autoSelectProps,
2✔
121
              freeSolo: true,
2✔
122
              options: detailOptions,
2✔
123
              disabled: !type,
2✔
124
              renderInput: params => <TextField {...params} placeholder={detailsMap[type] || '-'} InputProps={{ ...params.InputProps }} />
27✔
125
            }
2✔
126
          },
2✔
127
          {
2✔
128
            key: 'timeframe',
2✔
129
            title: 'Start time',
2✔
130
            Component: TimeframePicker,
2✔
131
            componentProps: {
2✔
132
              tonight,
2✔
133
              helperText: 'Audit logs are retained for a limited period of time, which means that older events might not be shown.',
2✔
134
              hasHelperText: shouldShowRetentionText
2✔
135
            }
2✔
136
          }
2✔
137
        ]}
2✔
138
        onChange={onFiltersChange}
2✔
139
      />
2✔
140
    </ClickFilter>
2✔
141
  );
2✔
142
};
2✔
143

2✔
144
export default AuditLogsFilter;
2✔
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