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

mendersoftware / gui / 944676341

pending completion
944676341

Pull #3875

gitlab-ci

mzedel
chore: aligned snapshots with updated design

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

4469 of 6446 branches covered (69.33%)

230 of 266 new or added lines in 43 files covered. (86.47%)

1712 existing lines in 161 files now uncovered.

8406 of 10170 relevant lines covered (82.65%)

196.7 hits per line

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

72.09
/src/js/components/devices/device-details/devicetags.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

16
import { Edit as EditIcon } from '@mui/icons-material';
17
import { Button } from '@mui/material';
18
import { useTheme } from '@mui/material/styles';
19

20
import { toggle } from '../../../helpers';
21
import Tracking from '../../../tracking';
22
import ConfigurationObject from '../../common/configurationobject';
23
import KeyValueEditor from '../../common/forms/keyvalueeditor';
24
import { HELPTOOLTIPS, MenderHelpTooltip } from '../../helptips/helptooltips';
25
import DeviceDataCollapse from './devicedatacollapse';
26

27
const NameTipComponent = props => <MenderHelpTooltip id={HELPTOOLTIPS.nameTagTip.id} {...props} />;
11✔
28

29
const configHelpTipsMap = {
11✔
30
  name: { component: NameTipComponent, position: 'right' }
31
};
32

33
export const DeviceTags = ({ device, setDeviceTags, setSnackbar, userCapabilities }) => {
11✔
34
  const { canWriteDevices } = userCapabilities;
6✔
35
  const theme = useTheme();
6✔
36
  const [changedTags, setChangedTags] = useState({});
6✔
37
  const [isEditDisabled, setIsEditDisabled] = useState(!canWriteDevices);
6✔
38
  const [isEditing, setIsEditing] = useState(false);
6✔
39
  const [shouldUpdateEditor, setShouldUpdateEditor] = useState(false);
6✔
40

41
  const { tags = {} } = device;
6✔
42
  const hasTags = !!Object.keys(tags).length;
6✔
43

44
  useEffect(() => {
6✔
45
    setShouldUpdateEditor(toggle);
4✔
46
  }, [isEditing]);
47

48
  useEffect(() => {
6✔
49
    if (canWriteDevices) {
2!
50
      setIsEditing(!hasTags);
2✔
51
    }
52
  }, [hasTags, canWriteDevices]);
53

54
  const onCancel = () => {
6✔
UNCOV
55
    setIsEditing(false);
×
UNCOV
56
    setChangedTags(tags);
×
57
  };
58

59
  const onStartEdit = e => {
6✔
UNCOV
60
    e.stopPropagation();
×
UNCOV
61
    setChangedTags(tags);
×
UNCOV
62
    setIsEditing(true);
×
63
  };
64

65
  const onSubmit = () => {
6✔
UNCOV
66
    Tracking.event({ category: 'devices', action: 'modify_tags' });
×
UNCOV
67
    setIsEditDisabled(true);
×
UNCOV
68
    return setDeviceTags(device.id, changedTags)
×
UNCOV
69
      .then(() => setIsEditing(false))
×
UNCOV
70
      .finally(() => setIsEditDisabled(false));
×
71
  };
72

73
  const helpTipsMap = Object.entries(configHelpTipsMap).reduce((accu, [key, value]) => {
6✔
74
    accu[key] = {
6✔
75
      ...value,
76
      props: { deviceId: device.id }
77
    };
78
    return accu;
6✔
79
  }, {});
80
  return (
6✔
81
    <DeviceDataCollapse
82
      title={
83
        <div className="two-columns">
84
          <div className="flexbox center-aligned">
85
            <h4 className="margin-right">Tags</h4>
86
            {!isEditing && canWriteDevices && (
10✔
87
              <Button onClick={onStartEdit} startIcon={<EditIcon />} size="small">
88
                Edit
89
              </Button>
90
            )}
91
          </div>
92
        </div>
93
      }
94
    >
95
      <div className="relative" style={{ maxWidth: 700 }}>
96
        {isEditing ? (
6✔
97
          <>
98
            <KeyValueEditor
99
              disabled={isEditDisabled}
100
              errortext=""
101
              input={changedTags}
102
              inputHelpTipsMap={helpTipsMap}
103
              onInputChange={setChangedTags}
104
              reset={shouldUpdateEditor}
105
            />
106
            <div className="flexbox center-aligned margin-bottom-small" style={{ justifyContent: 'flex-end' }}>
107
              <Button color="primary" onClick={onSubmit} variant="contained" style={{ marginRight: theme.spacing(2) }}>
108
                Save
109
              </Button>
110
              <Button onClick={onCancel}>Cancel</Button>
111
            </div>
112
          </>
113
        ) : (
114
          hasTags && <ConfigurationObject config={tags} setSnackbar={setSnackbar} />
2!
115
        )}
116
      </div>
117
    </DeviceDataCollapse>
118
  );
119
};
120

121
export default DeviceTags;
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