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

mendersoftware / gui / 963002358

pending completion
963002358

Pull #3870

gitlab-ci

mzedel
chore: cleaned up left over onboarding tooltips & aligned with updated design

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

4348 of 6319 branches covered (68.81%)

95 of 122 new or added lines in 24 files covered. (77.87%)

1734 existing lines in 160 files now uncovered.

8174 of 9951 relevant lines covered (82.14%)

178.12 hits per line

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

71.11
/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
import { useDispatch } from 'react-redux';
16

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

21
import { setDeviceTags } from '../../../actions/deviceActions';
22
import { toggle } from '../../../helpers';
23
import Tracking from '../../../tracking';
24
import ConfigurationObject from '../../common/configurationobject';
25
import KeyValueEditor from '../../common/forms/keyvalueeditor';
26
import { NameTagTip } from '../../helptips/helptooltips';
27
import DeviceDataCollapse from './devicedatacollapse';
28

29
const configHelpTipsMap = {
11✔
30
  name: {
31
    position: 'right',
32
    component: NameTagTip
33
  }
34
};
35

36
export const DeviceTags = ({ device, setSnackbar, showHelptips, userCapabilities }) => {
11✔
37
  const { canWriteDevices } = userCapabilities;
6✔
38
  const theme = useTheme();
6✔
39
  const [changedTags, setChangedTags] = useState({});
6✔
40
  const [editableTags, setEditableTags] = useState();
6✔
41
  const [isEditDisabled, setIsEditDisabled] = useState(!canWriteDevices);
6✔
42
  const [isEditing, setIsEditing] = useState(false);
6✔
43
  const [shouldUpdateEditor, setShouldUpdateEditor] = useState(false);
6✔
44
  const dispatch = useDispatch();
6✔
45

46
  const { tags = {} } = device;
6✔
47
  const hasTags = !!Object.keys(tags).length;
6✔
48

49
  useEffect(() => {
6✔
50
    setShouldUpdateEditor(toggle);
4✔
51
  }, [isEditing]);
52

53
  useEffect(() => {
6✔
54
    if (canWriteDevices) {
2!
55
      setIsEditing(!hasTags);
2✔
56
    }
57
  }, [hasTags, canWriteDevices]);
58

59
  const onCancel = () => {
6✔
UNCOV
60
    setIsEditing(false);
×
UNCOV
61
    setChangedTags(tags);
×
62
  };
63

64
  const onStartEdit = e => {
6✔
UNCOV
65
    e.stopPropagation();
×
UNCOV
66
    setEditableTags(tags);
×
UNCOV
67
    setChangedTags(tags);
×
UNCOV
68
    setIsEditing(true);
×
69
  };
70

71
  const onSubmit = () => {
6✔
UNCOV
72
    Tracking.event({ category: 'devices', action: 'modify_tags' });
×
UNCOV
73
    setIsEditDisabled(true);
×
UNCOV
74
    return dispatch(setDeviceTags(device.id, changedTags))
×
UNCOV
75
      .then(() => setIsEditing(false))
×
UNCOV
76
      .finally(() => setIsEditDisabled(false));
×
77
  };
78

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

128
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