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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

89.74
/src/js/components/common/devicenameinput.js
1
// Copyright 2021 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
import { connect } from 'react-redux';
16

17
// material ui
18
import { Check as CheckIcon, Clear as ClearIcon, Edit as EditIcon } from '@mui/icons-material';
19
import { IconButton, Input, InputAdornment } from '@mui/material';
20
import { makeStyles } from 'tss-react/mui';
21

22
import { setSnackbar } from '../../actions/appActions';
23
import { setDeviceTags } from '../../actions/deviceActions';
24

25
const useStyles = makeStyles()(theme => ({
33✔
26
  icon: {
27
    fontSize: '1.25rem'
28
  },
29
  input: {
30
    color: theme.palette.text.primary,
31
    fontSize: '0.8125rem'
32
  }
33
}));
34

35
export const DeviceNameInput = ({ device, isHovered, setSnackbar, setDeviceTags }) => {
33✔
36
  const [isEditing, setIsEditing] = useState(false);
18✔
37
  const [value, setValue] = useState('');
18✔
38
  const { classes } = useStyles();
18✔
39

40
  const { id = '', tags = {} } = device;
18!
41
  const { name = '' } = tags;
18✔
42

43
  useEffect(() => {
18✔
44
    if (!isEditing && name !== value) {
7✔
45
      setValue(name);
2✔
46
    }
47
  }, [device, isEditing]);
48

49
  const onSubmit = () => {
18✔
50
    const changedTags = {
1✔
51
      ...tags,
52
      name: value
53
    };
54
    setDeviceTags(id, changedTags).then(() => {
1✔
55
      setSnackbar('Device name changed');
1✔
56
      setIsEditing(false);
1✔
57
    });
58
  };
59

60
  const onCancel = () => {
18✔
61
    setValue(name);
×
62
    setIsEditing(false);
×
63
  };
64

65
  const onStartEdit = e => {
18✔
66
    e.stopPropagation();
1✔
67
    setIsEditing(true);
1✔
68
  };
69

70
  const editButton = (
71
    <IconButton onClick={onStartEdit} size="small">
18✔
72
      <EditIcon className={classes.icon} />
73
    </IconButton>
74
  );
75

76
  const buttonArea = isEditing ? (
18✔
77
    <>
78
      <IconButton onClick={onSubmit} size="small">
79
        <CheckIcon className={classes.icon} />
80
      </IconButton>
81
      <IconButton onClick={onCancel} size="small">
82
        <ClearIcon className={classes.icon} />
83
      </IconButton>
84
    </>
85
  ) : (
86
    editButton
87
  );
88

89
  const onInputClick = e => e.stopPropagation();
18✔
90

91
  return (
18✔
92
    <Input
93
      id={`${device.id}-id-input`}
94
      className={classes.input}
95
      disabled={!isEditing}
96
      value={value}
97
      placeholder={`${id.substring(0, 6)}...`}
98
      onClick={onInputClick}
99
      onChange={({ target: { value } }) => setValue(value)}
9✔
100
      type="text"
101
      endAdornment={(isHovered || isEditing) && <InputAdornment position="end">{buttonArea}</InputAdornment>}
36!
102
    />
103
  );
104
};
105

106
const actionCreators = {
33✔
107
  setDeviceTags,
108
  setSnackbar
109
};
110

111
export default connect(undefined, actionCreators)(DeviceNameInput);
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