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

mendersoftware / gui / 901187442

pending completion
901187442

Pull #3795

gitlab-ci

mzedel
feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3795: feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

4389 of 6365 branches covered (68.96%)

5 of 5 new or added lines in 1 file covered. (100.0%)

1729 existing lines in 165 files now uncovered.

8274 of 10019 relevant lines covered (82.58%)

144.86 hits per line

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

71.43
/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 { NameTagTip } from '../../helptips/helptooltips';
25
import DeviceDataCollapse from './devicedatacollapse';
26

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

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

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

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

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

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

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

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

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

123
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