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

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

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

94.29
/src/js/components/helptips/baseonboardingtip.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, { useEffect, useRef, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
import {
18
  ArrowBack as ArrowBackIcon,
19
  ArrowDownward as ArrowDownwardIcon,
20
  ArrowForward as ArrowForwardIcon,
21
  ArrowUpward as ArrowUpwardIcon
22
} from '@mui/icons-material';
23
import { buttonBaseClasses, buttonClasses } from '@mui/material';
24
import { makeStyles } from 'tss-react/mui';
25

26
import { setShowDismissOnboardingTipsDialog } from '../../actions/onboardingActions';
27
import { TIMEOUTS } from '../../constants/appConstants';
28
import { toggle } from '../../helpers';
29
import Tracking from '../../tracking';
30
import { OnboardingTooltip } from '../common/mendertooltip';
31

32
const iconWidth = 30;
183✔
33

34
export const orientations = {
183✔
35
  top: {
36
    arrow: <ArrowUpwardIcon />,
37
    placement: 'bottom',
38
    offsetStyle: style => {
39
      style.left = style.left - iconWidth / 2;
5✔
40
      return style;
5✔
41
    }
42
  },
43
  right: {
44
    arrow: <ArrowBackIcon />,
45
    placement: 'right',
46
    offsetStyle: style => {
47
      style.top = style.top - iconWidth / 2;
1✔
48
      style.left = style.left + iconWidth / 2;
1✔
49
      return style;
1✔
50
    }
51
  },
52
  bottom: {
53
    arrow: <ArrowDownwardIcon />,
54
    placement: 'top',
55
    offsetStyle: style => {
56
      style.left = style.left - iconWidth / 2;
1✔
57
      return style;
1✔
58
    }
59
  },
60
  left: {
61
    arrow: <ArrowForwardIcon />,
62
    placement: 'left',
63
    offsetStyle: style => {
64
      style.top = style.top - iconWidth / 2;
1✔
65
      return style;
1✔
66
    }
67
  }
68
};
69

70
const useStyles = makeStyles()(theme => ({
183✔
71
  root: {
72
    [`.${buttonBaseClasses.root}.${buttonClasses.text}`]: { color: theme.palette.background.paper, paddingRight: 0 }
73
  }
74
}));
75

76
export const BaseOnboardingTooltip = ({ anchor = { left: 0, top: 0 }, icon, children, id = '1', place = 'top', ...props }) => {
183✔
77
  const [open, setOpen] = useState(false);
4✔
78
  const showDismissHelptipsDialog = useSelector(state => state.onboarding.showTipsDialog);
8✔
79
  const showDeviceConnectionDialog = useSelector(state => state.users.showConnectDeviceDialog);
8✔
80
  const delayTimer = useRef();
4✔
81

82
  const { classes } = useStyles();
4✔
83

84
  useEffect(() => {
4✔
85
    Tracking.event({ category: 'onboarding', action: id });
4✔
86
    clearTimeout(delayTimer.current);
4✔
87
    delayTimer.current = setTimeout(() => setOpen(true), TIMEOUTS.debounceShort);
4✔
88
    return () => {
4✔
89
      clearTimeout(delayTimer.current);
4✔
90
    };
91
  }, [id]);
92

93
  const toggleVisibility = () => setOpen(toggle);
4✔
94

95
  const hide = () => setOpen(false);
4✔
96

97
  if (showDismissHelptipsDialog || showDeviceConnectionDialog) {
4!
98
    return null;
×
99
  }
100

101
  const orientation = orientations[place];
4✔
102
  const style = orientation.offsetStyle({ left: anchor.left, top: anchor.top, overflow: 'initial' });
4✔
103
  return (
4✔
104
    <OnboardingTooltip
105
      disableFocusListener
106
      disableHoverListener
107
      disableTouchListener
108
      id={id}
109
      onClose={hide}
110
      open={open}
111
      placement={orientation.placement}
112
      PopperProps={{
113
        className: classes.root,
114
        disablePortal: true,
115
        popperOptions: {
116
          strategy: 'fixed',
117
          modifiers: [
118
            { name: 'flip', enabled: false },
119
            { name: 'preventOverflow', enabled: true, options: { boundary: window, altBoundary: false } }
120
          ]
121
        }
122
      }}
123
      title={children}
124
      className={classes.root}
125
      {...props}
126
    >
127
      <div className="onboard-tip" onClick={toggleVisibility} style={style}>
128
        <div className={`tooltip onboard-icon ${orientation.placement}`}>{icon ?? orientation.arrow}</div>
7✔
129
      </div>
130
    </OnboardingTooltip>
131
  );
132
};
133

134
export const BaseOnboardingTip = ({ anchor, icon, component, place, id, ...others }) => {
183✔
135
  const dispatch = useDispatch();
2✔
136
  return (
2✔
137
    <BaseOnboardingTooltip anchor={anchor} icon={icon} place={place} id={id}>
138
      <div className="content">
139
        {React.cloneElement(component, others)}
140
        <div>
141
          <b className="clickable" onClick={() => dispatch(setShowDismissOnboardingTipsDialog(true))}>
×
142
            Dismiss the tutorial
143
          </b>
144
        </div>
145
      </div>
146
    </BaseOnboardingTooltip>
147
  );
148
};
149

150
export default BaseOnboardingTip;
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