• 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

73.2
/src/js/components/app.js
1
// Copyright 2015 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, { useCallback, useEffect, useState } from 'react';
15
import { useIdleTimer, workerTimers } from 'react-idle-timer';
16
import { useDispatch, useSelector } from 'react-redux';
17
import { useLocation, useNavigate } from 'react-router-dom';
18

19
import { CssBaseline } from '@mui/material';
20
import { ThemeProvider, createTheme } from '@mui/material/styles';
21
import withStyles from '@mui/styles/withStyles';
22
import { makeStyles } from 'tss-react/mui';
23

24
import Cookies from 'universal-cookie';
25

26
import { parseEnvironmentInfo, setSnackbar } from '../actions/appActions';
27
import { logoutUser, setAccountActivationCode, setShowConnectingDialog } from '../actions/userActions';
28
import { expirySet, getToken, updateMaxAge } from '../auth';
29
import SharedSnackbar from '../components/common/sharedsnackbar';
30
import { PrivateRoutes, PublicRoutes } from '../config/routes';
31
import { onboardingSteps } from '../constants/onboardingConstants';
32
import ErrorBoundary from '../errorboundary';
33
import { isDarkMode, toggle } from '../helpers';
34
import { getOnboardingState, getUserSettings } from '../selectors';
35
import { dark as darkTheme, light as lightTheme } from '../themes/Mender';
36
import Tracking from '../tracking';
37
import { getOnboardingComponentFor } from '../utils/onboardingmanager';
38
import ConfirmDismissHelptips from './common/dialogs/confirmdismisshelptips';
39
import DeviceConnectionDialog from './common/dialogs/deviceconnectiondialog';
40
import Footer from './footer';
41
import Header from './header/header';
42
import LeftNav from './leftnav';
43
import SearchResult from './search-result';
44
import Uploads from './uploads';
45

46
const activationPath = '/activate';
2✔
47
export const timeout = 900000; // 15 minutes idle time
2✔
48
const cookies = new Cookies();
2✔
49

50
const reducePalette =
51
  prefix =>
2✔
52
  (accu, [key, value]) => {
1,081✔
53
    if (value instanceof Object) {
4,606✔
54
      return {
1,034✔
55
        ...accu,
56
        ...Object.entries(value).reduce(reducePalette(`${prefix}-${key}`), {})
57
      };
58
    } else {
59
      accu[`${prefix}-${key}`] = value;
3,572✔
60
    }
61
    return accu;
3,572✔
62
  };
63

64
const cssVariables = ({ palette }) => {
2✔
65
  const muiVariables = Object.entries(palette).reduce(reducePalette('--mui'), {});
47✔
66
  return {
47✔
67
    '@global': {
68
      ':root': {
69
        ...muiVariables,
70
        '--mui-overlay': palette.grey[400]
71
      }
72
    }
73
  };
74
};
75

76
const WrappedBaseline = withStyles(cssVariables)(CssBaseline);
2✔
77

78
const useStyles = makeStyles()(() => ({
6✔
79
  public: {
80
    display: 'grid',
81
    gridTemplateRows: 'max-content 1fr max-content',
82
    height: '100vh',
83
    '.content': {
84
      alignSelf: 'center',
85
      justifySelf: 'center'
86
    }
87
  }
88
}));
89

90
export const AppRoot = () => {
2✔
91
  const [showSearchResult, setShowSearchResult] = useState(false);
71✔
92
  const navigate = useNavigate();
70✔
93
  const { pathname = '', hash } = useLocation();
70!
94

95
  const dispatch = useDispatch();
70✔
96
  const currentUser = useSelector(state => state.users.currentUser);
1,218✔
97
  const onboardingState = useSelector(getOnboardingState);
70✔
98
  const showDismissHelptipsDialog = useSelector(state => !state.onboarding.complete && state.onboarding.showTipsDialog);
1,218✔
99
  const showDeviceConnectionDialog = useSelector(state => state.users.showConnectDeviceDialog);
1,218✔
100
  const snackbar = useSelector(state => state.app.snackbar);
1,218✔
101
  const trackingCode = useSelector(state => state.app.trackerCode);
1,218✔
102
  const { mode } = useSelector(getUserSettings);
70✔
103

104
  const trackLocationChange = useCallback(
70✔
105
    pathname => {
106
      let page = pathname;
6✔
107
      // if we're on page whose path might contain sensitive device/ group/ deployment names etc. we sanitize the sent information before submission
108
      if (page.includes('=') && (page.startsWith('/devices') || page.startsWith('/deployments'))) {
6!
NEW
109
        const splitter = page.lastIndexOf('/');
×
NEW
110
        const filters = page.slice(splitter + 1);
×
NEW
111
        const keyOnlyFilters = filters.split('&').reduce((accu, item) => `${accu}:${item.split('=')[0]}&`, ''); // assume the keys to filter by are not as revealing as the values things are filtered by
×
NEW
112
        page = `${page.substring(0, splitter)}?${keyOnlyFilters.substring(0, keyOnlyFilters.length - 1)}`; // cut off the last & of the reduced filters string
×
113
      } else if (page.startsWith(activationPath)) {
6!
NEW
114
        dispatch(setAccountActivationCode(page.substring(activationPath.length + 1)));
×
NEW
115
        navigate('/settings/my-profile', { replace: true });
×
116
      }
117
      Tracking.pageview(page);
6✔
118
    },
119
    [dispatch, navigate]
120
  );
121

122
  useEffect(() => {
70✔
123
    dispatch(parseEnvironmentInfo());
5✔
124
    if (!trackingCode) {
5✔
125
      return;
3✔
126
    }
127
    if (!cookies.get('_ga')) {
2!
UNCOV
128
      Tracking.cookieconsent().then(({ trackingConsentGiven }) => {
×
UNCOV
129
        if (trackingConsentGiven) {
×
UNCOV
130
          Tracking.initialize(trackingCode);
×
UNCOV
131
          Tracking.pageview();
×
132
        }
133
      });
134
    } else {
135
      Tracking.initialize(trackingCode);
2✔
136
    }
137
    trackLocationChange(pathname);
2✔
138
  }, [dispatch, pathname, trackLocationChange, trackingCode]);
139

140
  useEffect(() => {
70✔
141
    trackLocationChange(pathname);
4✔
142
    // the following is added to ensure backwards capability for hash containing routes & links (e.g. /ui/#/devices => /ui/devices)
143
    if (hash) {
4!
UNCOV
144
      navigate(hash.substring(1));
×
145
    }
146
  }, [hash, navigate, pathname, trackLocationChange]);
147

148
  const onIdle = () => {
70✔
149
    if (expirySet() && currentUser) {
2✔
150
      // logout user and warn
151
      return dispatch(logoutUser('Your session has expired. You have been automatically logged out due to inactivity.')).catch(updateMaxAge);
1✔
152
    }
153
  };
154

155
  useIdleTimer({ crossTab: true, onAction: updateMaxAge, onActive: updateMaxAge, onIdle, syncTimers: 400, timeout, timers: workerTimers });
70✔
156

157
  const onToggleSearchResult = () => setShowSearchResult(toggle);
70✔
158

159
  const onboardingComponent = getOnboardingComponentFor(onboardingSteps.ARTIFACT_CREATION_DIALOG, onboardingState);
70✔
160
  const theme = createTheme(isDarkMode(mode) ? darkTheme : lightTheme);
70!
161

162
  const { classes } = useStyles();
70✔
163

164
  return (
70✔
165
    <ThemeProvider theme={theme}>
166
      <WrappedBaseline enableColorScheme />
167
      <>
168
        {getToken() ? (
70✔
169
          <div id="app">
170
            <Header mode={mode} />
171
            <LeftNav />
172
            <div className="rightFluid container">
173
              <ErrorBoundary>
174
                <SearchResult onToggleSearchResult={onToggleSearchResult} open={showSearchResult} />
175
                <PrivateRoutes />
176
              </ErrorBoundary>
177
            </div>
178
            {onboardingComponent ? onboardingComponent : null}
52!
179
            {showDismissHelptipsDialog && <ConfirmDismissHelptips />}
52!
UNCOV
180
            {showDeviceConnectionDialog && <DeviceConnectionDialog onCancel={() => dispatch(setShowConnectingDialog(false))} />}
×
181
          </div>
182
        ) : (
183
          <div className={classes.public}>
184
            <PublicRoutes />
185
            <Footer />
186
          </div>
187
        )}
UNCOV
188
        <SharedSnackbar snackbar={snackbar} setSnackbar={message => dispatch(setSnackbar(message))} />
×
189
        <Uploads />
190
      </>
191
    </ThemeProvider>
192
  );
193
};
194

195
export default AppRoot;
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