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

mendersoftware / gui / 908425489

pending completion
908425489

Pull #3799

gitlab-ci

mzedel
chore: aligned loader usage in devices list with deployment devices list

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

4406 of 6423 branches covered (68.6%)

18 of 19 new or added lines in 3 files covered. (94.74%)

1777 existing lines in 167 files now uncovered.

8329 of 10123 relevant lines covered (82.28%)

144.7 hits per line

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

43.48
/src/js/components/devices/troubleshoot/terminal.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, { useCallback, useEffect, useState } from 'react';
15

16
import { FitAddon } from 'xterm-addon-fit';
17
import { WebLinksAddon } from 'xterm-addon-web-links';
18

19
import { DEVICE_MESSAGE_TYPES as MessageTypes } from '../../../constants/deviceConstants';
20
import useWindowSize from '../../../utils/resizehook';
21
import XTerm from '../../common/xterm';
22

23
const fitAddon = new FitAddon();
13✔
24

25
export const options = {
13✔
26
  cursorBlink: 'block',
27
  macOptionIsMeta: true
28
};
29

30
// only matching absolute paths, so: /here/there - but not ../here or ./here or here/there
31
const unixPathRegex = new RegExp('(\\/([^\\0\\s!$`&*()\\[\\]+\'":;\\\\])+)');
13✔
32

33
export const Terminal = ({ onDownloadClick, sendMessage, sessionId, setSnackbar, socketInitialized, textInput, xtermRef, ...xtermProps }) => {
13✔
34
  const [dimensions, setDimensions] = useState({});
2✔
35
  const [isVisible, setIsVisible] = useState(false);
2✔
36
  const size = useWindowSize();
2✔
37

38
  const observer = new IntersectionObserver(([entry]) => setIsVisible(entry.isIntersecting));
2✔
39

40
  const tryFit = useCallback(() => {
2✔
UNCOV
41
    try {
×
UNCOV
42
      fitAddon.fit();
×
43
    } catch {
UNCOV
44
      setSnackbar('Fit not possible, terminal not yet visible', 5000);
×
45
    }
46
  }, [fitAddon, setSnackbar]);
47

48
  useEffect(() => {
2✔
49
    if (!socketInitialized) {
2!
50
      return;
2✔
51
    }
UNCOV
52
    observer.observe(xtermRef.current.terminalRef.current);
×
UNCOV
53
    tryFit();
×
54
    // Remove the observer as soon as the component is unmounted
UNCOV
55
    return () => {
×
UNCOV
56
      observer.disconnect();
×
57
    };
58
  }, [socketInitialized, tryFit]);
59

60
  useEffect(() => {
2✔
61
    if (!socketInitialized || !xtermRef.current?.terminal || sessionId) {
2!
62
      return;
2✔
63
    }
UNCOV
64
    xtermRef.current.terminal.reset();
×
UNCOV
65
    const webLinksAddon = new WebLinksAddon((e, link) => onDownloadClick(link), { urlRegex: unixPathRegex }, true);
×
UNCOV
66
    xtermRef.current.terminal.loadAddon(webLinksAddon);
×
UNCOV
67
    tryFit();
×
UNCOV
68
    const { rows = 40, cols = 80 } = fitAddon.proposeDimensions() || {};
×
UNCOV
69
    sendMessage({ typ: MessageTypes.New, props: { terminal_height: rows, terminal_width: cols } });
×
UNCOV
70
    setDimensions({ rows, cols });
×
UNCOV
71
    xtermRef.current.terminal.focus();
×
72
  }, [sessionId, socketInitialized, tryFit, xtermRef.current]);
73

74
  useEffect(() => {
2✔
75
    if (!socketInitialized || !xtermRef.current.terminal || !isVisible) {
2!
76
      return;
2✔
77
    }
UNCOV
78
    fitAddon.fit();
×
UNCOV
79
    const newDimensions = fitAddon.proposeDimensions();
×
UNCOV
80
    if (newDimensions.rows != dimensions.rows || newDimensions.cols != dimensions.cols) {
×
81
      //
UNCOV
82
      sendMessage({
×
83
        typ: MessageTypes.Resize,
84
        props: { terminal_height: newDimensions.rows, terminal_width: newDimensions.cols }
85
      });
UNCOV
86
      setDimensions(newDimensions);
×
87
    }
88
  }, [size, isVisible]);
89

90
  useEffect(() => {
2✔
91
    if (!socketInitialized || !xtermRef.current.terminal || !textInput) {
2!
92
      return;
2✔
93
    }
UNCOV
94
    xtermRef.current.terminal.paste(textInput);
×
95
  }, [socketInitialized, xtermRef.current, textInput]);
96

97
  const onData = data => sendMessage({ typ: MessageTypes.Shell, body: data });
2✔
98

99
  return <XTerm xtermRef={xtermRef} addons={[fitAddon]} options={options} onData={onData} {...xtermProps} />;
2✔
100
};
101

102
export default Terminal;
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